mirror of
https://github.com/ziglang/zig.git
synced 2024-11-13 23:52:57 +00:00
sema: rework comptime mutation
Split Value into an immutable value that always has an InternPool.Index representation, and a mutable value that is part of a new ComptimeMemory abstraction. Mainly, this deletes WipAnonDecl, deletes InternPool.Key.Ptr.Addr.MutDecl, and then updates all comptime-mutable allocations to happen via ComptimeMemory. This makes no comptime mutable memory escape from the Sema instance in which the comptime memory is allocated, reducing the amount of garbage in the global InternPool, and forces comptime memory mutations to be completely reworked in the compiler. This has sweeping implications to the codebase, and will require quite a few follow up changes to unbreak things
This commit is contained in:
parent
0266017b59
commit
f34deec4e2
10
src/Air.zig
10
src/Air.zig
@ -8,7 +8,7 @@ const builtin = @import("builtin");
|
||||
const assert = std.debug.assert;
|
||||
|
||||
const Air = @This();
|
||||
const Value = @import("value.zig").Value;
|
||||
const Value = @import("Value.zig");
|
||||
const Type = @import("type.zig").Type;
|
||||
const InternPool = @import("InternPool.zig");
|
||||
const Module = @import("Module.zig");
|
||||
@ -986,6 +986,12 @@ pub const Inst = struct {
|
||||
empty_struct = @intFromEnum(InternPool.Index.empty_struct),
|
||||
generic_poison = @intFromEnum(InternPool.Index.generic_poison),
|
||||
|
||||
/// This Ref does not correspond to any AIR instruction.
|
||||
/// It is a special value recognized only by Sema.
|
||||
/// It indicates the value is mutable comptime memory, and represented
|
||||
/// via the comptime_memory field of Sema. This value never occurs
|
||||
/// in AIR which is emitted to backends.
|
||||
mutable_comptime = @intFromEnum(InternPool.Index.mutable_comptime),
|
||||
/// This Ref does not correspond to any AIR instruction or constant
|
||||
/// value. It is used to handle argument types of var args functions.
|
||||
var_args_param_type = @intFromEnum(InternPool.Index.var_args_param_type),
|
||||
@ -1095,7 +1101,7 @@ pub const Inst = struct {
|
||||
inferred_alloc: InferredAlloc,
|
||||
|
||||
pub const InferredAllocComptime = struct {
|
||||
decl_index: InternPool.DeclIndex,
|
||||
comptime_memory_value_index: @import("Sema/ComptimeMemory.zig").Value.Index,
|
||||
alignment: InternPool.Alignment,
|
||||
is_const: bool,
|
||||
};
|
||||
|
@ -11,7 +11,7 @@ const ThreadPool = std.Thread.Pool;
|
||||
const WaitGroup = std.Thread.WaitGroup;
|
||||
const ErrorBundle = std.zig.ErrorBundle;
|
||||
|
||||
const Value = @import("value.zig").Value;
|
||||
const Value = @import("Value.zig");
|
||||
const Type = @import("type.zig").Type;
|
||||
const target_util = @import("target.zig");
|
||||
const Package = @import("Package.zig");
|
||||
|
@ -98,6 +98,7 @@ const InternPool = @This();
|
||||
const Module = @import("Module.zig");
|
||||
const Zcu = Module;
|
||||
const Zir = @import("Zir.zig");
|
||||
const Air = @import("Air.zig");
|
||||
|
||||
const KeyAdapter = struct {
|
||||
intern_pool: *const InternPool,
|
||||
@ -132,16 +133,6 @@ pub const MapIndex = enum(u32) {
|
||||
}
|
||||
};
|
||||
|
||||
pub const RuntimeIndex = enum(u32) {
|
||||
zero = 0,
|
||||
comptime_field_ptr = std.math.maxInt(u32),
|
||||
_,
|
||||
|
||||
pub fn increment(ri: *RuntimeIndex) void {
|
||||
ri.* = @as(RuntimeIndex, @enumFromInt(@intFromEnum(ri.*) + 1));
|
||||
}
|
||||
};
|
||||
|
||||
pub const DeclIndex = enum(u32) {
|
||||
_,
|
||||
|
||||
@ -1203,7 +1194,6 @@ pub const Key = union(enum) {
|
||||
const Tag = @typeInfo(Addr).Union.tag_type.?;
|
||||
|
||||
decl: DeclIndex,
|
||||
mut_decl: MutDecl,
|
||||
anon_decl: AnonDecl,
|
||||
comptime_field: Index,
|
||||
int: Index,
|
||||
@ -1212,10 +1202,6 @@ pub const Key = union(enum) {
|
||||
elem: BaseIndex,
|
||||
field: BaseIndex,
|
||||
|
||||
pub const MutDecl = struct {
|
||||
decl: DeclIndex,
|
||||
runtime_index: RuntimeIndex,
|
||||
};
|
||||
pub const BaseIndex = struct {
|
||||
base: Index,
|
||||
index: u64,
|
||||
@ -1373,11 +1359,6 @@ pub const Key = union(enum) {
|
||||
return switch (ptr.addr) {
|
||||
.decl => |x| Hash.hash(seed2, common ++ asBytes(&x)),
|
||||
|
||||
.mut_decl => |x| Hash.hash(
|
||||
seed2,
|
||||
common ++ asBytes(&x.decl) ++ asBytes(&x.runtime_index),
|
||||
),
|
||||
|
||||
.anon_decl => |x| Hash.hash(seed2, common ++ asBytes(&x)),
|
||||
|
||||
.int,
|
||||
@ -1651,7 +1632,6 @@ pub const Key = union(enum) {
|
||||
|
||||
return switch (a_info.addr) {
|
||||
.decl => |a_decl| a_decl == b_info.addr.decl,
|
||||
.mut_decl => |a_mut_decl| std.meta.eql(a_mut_decl, b_info.addr.mut_decl),
|
||||
.anon_decl => |ad| ad.val == b_info.addr.anon_decl.val and
|
||||
ad.orig_ty == b_info.addr.anon_decl.orig_ty,
|
||||
.int => |a_int| a_int == b_info.addr.int,
|
||||
@ -2171,6 +2151,7 @@ pub const Index = enum(u32) {
|
||||
generic_poison,
|
||||
|
||||
/// Used by Air/Sema only.
|
||||
mutable_comptime = std.math.maxInt(u32) - 2,
|
||||
var_args_param_type = std.math.maxInt(u32) - 1,
|
||||
none = std.math.maxInt(u32),
|
||||
|
||||
@ -2280,7 +2261,6 @@ pub const Index = enum(u32) {
|
||||
undef: DataIsIndex,
|
||||
simple_value: struct { data: SimpleValue },
|
||||
ptr_decl: struct { data: *PtrDecl },
|
||||
ptr_mut_decl: struct { data: *PtrMutDecl },
|
||||
ptr_anon_decl: struct { data: *PtrAnonDecl },
|
||||
ptr_anon_decl_aligned: struct { data: *PtrAnonDeclAligned },
|
||||
ptr_comptime_field: struct { data: *PtrComptimeField },
|
||||
@ -2732,9 +2712,6 @@ pub const Tag = enum(u8) {
|
||||
/// A pointer to a decl.
|
||||
/// data is extra index of `PtrDecl`, which contains the type and address.
|
||||
ptr_decl,
|
||||
/// A pointer to a decl that can be mutated at comptime.
|
||||
/// data is extra index of `PtrMutDecl`, which contains the type and address.
|
||||
ptr_mut_decl,
|
||||
/// A pointer to an anonymous decl.
|
||||
/// data is extra index of `PtrAnonDecl`, which contains the pointer type and decl value.
|
||||
/// The alignment of the anonymous decl is communicated via the pointer type.
|
||||
@ -2939,7 +2916,6 @@ pub const Tag = enum(u8) {
|
||||
.undef => unreachable,
|
||||
.simple_value => unreachable,
|
||||
.ptr_decl => PtrDecl,
|
||||
.ptr_mut_decl => PtrMutDecl,
|
||||
.ptr_anon_decl => PtrAnonDecl,
|
||||
.ptr_anon_decl_aligned => PtrAnonDeclAligned,
|
||||
.ptr_comptime_field => PtrComptimeField,
|
||||
@ -3570,12 +3546,6 @@ pub const PtrAnonDeclAligned = struct {
|
||||
orig_ty: Index,
|
||||
};
|
||||
|
||||
pub const PtrMutDecl = struct {
|
||||
ty: Index,
|
||||
decl: DeclIndex,
|
||||
runtime_index: RuntimeIndex,
|
||||
};
|
||||
|
||||
pub const PtrComptimeField = struct {
|
||||
ty: Index,
|
||||
field_val: Index,
|
||||
@ -3910,16 +3880,6 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
|
||||
.addr = .{ .decl = info.decl },
|
||||
} };
|
||||
},
|
||||
.ptr_mut_decl => {
|
||||
const info = ip.extraData(PtrMutDecl, data);
|
||||
return .{ .ptr = .{
|
||||
.ty = info.ty,
|
||||
.addr = .{ .mut_decl = .{
|
||||
.decl = info.decl,
|
||||
.runtime_index = info.runtime_index,
|
||||
} },
|
||||
} };
|
||||
},
|
||||
.ptr_anon_decl => {
|
||||
const info = ip.extraData(PtrAnonDecl, data);
|
||||
return .{ .ptr = .{
|
||||
@ -4712,14 +4672,6 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
|
||||
.decl = decl,
|
||||
}),
|
||||
}),
|
||||
.mut_decl => |mut_decl| ip.items.appendAssumeCapacity(.{
|
||||
.tag = .ptr_mut_decl,
|
||||
.data = try ip.addExtra(gpa, PtrMutDecl{
|
||||
.ty = ptr.ty,
|
||||
.decl = mut_decl.decl,
|
||||
.runtime_index = mut_decl.runtime_index,
|
||||
}),
|
||||
}),
|
||||
.anon_decl => |anon_decl| ip.items.appendAssumeCapacity(
|
||||
if (ptrsHaveSameAlignment(ip, ptr.ty, ptr_type, anon_decl.orig_ty)) .{
|
||||
.tag = .ptr_anon_decl,
|
||||
@ -6147,7 +6099,7 @@ fn finishFuncInstance(
|
||||
.has_tv = true,
|
||||
.owns_tv = true,
|
||||
.ty = @import("type.zig").Type.fromInterned(func_ty),
|
||||
.val = @import("value.zig").Value.fromInterned(func_index),
|
||||
.val = @import("Value.zig").fromInterned(func_index),
|
||||
.alignment = .none,
|
||||
.@"linksection" = section,
|
||||
.@"addrspace" = fn_owner_decl.@"addrspace",
|
||||
@ -6501,7 +6453,6 @@ fn addExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 {
|
||||
OptionalNamespaceIndex,
|
||||
MapIndex,
|
||||
OptionalMapIndex,
|
||||
RuntimeIndex,
|
||||
String,
|
||||
NullTerminatedString,
|
||||
OptionalNullTerminatedString,
|
||||
@ -6577,7 +6528,6 @@ fn extraDataTrail(ip: *const InternPool, comptime T: type, index: usize) struct
|
||||
OptionalNamespaceIndex,
|
||||
MapIndex,
|
||||
OptionalMapIndex,
|
||||
RuntimeIndex,
|
||||
String,
|
||||
NullTerminatedString,
|
||||
OptionalNullTerminatedString,
|
||||
@ -7344,7 +7294,6 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void {
|
||||
.simple_type => 0,
|
||||
.simple_value => 0,
|
||||
.ptr_decl => @sizeOf(PtrDecl),
|
||||
.ptr_mut_decl => @sizeOf(PtrMutDecl),
|
||||
.ptr_anon_decl => @sizeOf(PtrAnonDecl),
|
||||
.ptr_anon_decl_aligned => @sizeOf(PtrAnonDeclAligned),
|
||||
.ptr_comptime_field => @sizeOf(PtrComptimeField),
|
||||
@ -7474,7 +7423,6 @@ fn dumpAllFallible(ip: *const InternPool) anyerror!void {
|
||||
.type_function,
|
||||
.undef,
|
||||
.ptr_decl,
|
||||
.ptr_mut_decl,
|
||||
.ptr_anon_decl,
|
||||
.ptr_anon_decl_aligned,
|
||||
.ptr_comptime_field,
|
||||
@ -7887,7 +7835,6 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {
|
||||
.simple_value => unreachable, // handled via Index above
|
||||
|
||||
inline .ptr_decl,
|
||||
.ptr_mut_decl,
|
||||
.ptr_anon_decl,
|
||||
.ptr_anon_decl_aligned,
|
||||
.ptr_comptime_field,
|
||||
@ -7951,6 +7898,7 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {
|
||||
.memoized_call => unreachable,
|
||||
},
|
||||
|
||||
.mutable_comptime => unreachable,
|
||||
.var_args_param_type => unreachable,
|
||||
.none => unreachable,
|
||||
};
|
||||
@ -8019,9 +7967,7 @@ pub fn getBackingDecl(ip: *const InternPool, val: Index) OptionalDeclIndex {
|
||||
var base = @intFromEnum(val);
|
||||
while (true) {
|
||||
switch (ip.items.items(.tag)[base]) {
|
||||
inline .ptr_decl,
|
||||
.ptr_mut_decl,
|
||||
=> |tag| return @enumFromInt(ip.extra.items[
|
||||
.ptr_decl => |tag| return @enumFromInt(ip.extra.items[
|
||||
ip.items.items(.data)[base] + std.meta.fieldIndex(tag.Payload(), "decl").?
|
||||
]),
|
||||
inline .ptr_eu_payload,
|
||||
@ -8044,7 +7990,6 @@ pub fn getBackingAddrTag(ip: *const InternPool, val: Index) ?Key.Ptr.Addr.Tag {
|
||||
while (true) {
|
||||
switch (ip.items.items(.tag)[base]) {
|
||||
.ptr_decl => return .decl,
|
||||
.ptr_mut_decl => return .mut_decl,
|
||||
.ptr_anon_decl, .ptr_anon_decl_aligned => return .anon_decl,
|
||||
.ptr_comptime_field => return .comptime_field,
|
||||
.ptr_int => return .int,
|
||||
@ -8219,7 +8164,6 @@ pub fn zigTypeTagOrPoison(ip: *const InternPool, index: Index) error{GenericPois
|
||||
.undef,
|
||||
.simple_value,
|
||||
.ptr_decl,
|
||||
.ptr_mut_decl,
|
||||
.ptr_anon_decl,
|
||||
.ptr_anon_decl_aligned,
|
||||
.ptr_comptime_field,
|
||||
|
@ -19,7 +19,7 @@ const Module = Zcu;
|
||||
const Zcu = @This();
|
||||
const Compilation = @import("Compilation.zig");
|
||||
const Cache = std.Build.Cache;
|
||||
const Value = @import("value.zig").Value;
|
||||
const Value = @import("Value.zig");
|
||||
const Type = @import("type.zig").Type;
|
||||
const TypedValue = @import("TypedValue.zig");
|
||||
const Package = @import("Package.zig");
|
||||
@ -3416,8 +3416,8 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void {
|
||||
defer sema_arena.deinit();
|
||||
const sema_arena_allocator = sema_arena.allocator();
|
||||
|
||||
var comptime_mutable_decls = std.ArrayList(Decl.Index).init(gpa);
|
||||
defer comptime_mutable_decls.deinit();
|
||||
var comptime_memory: Sema.ComptimeMemory = .{};
|
||||
defer comptime_memory.deinit(gpa);
|
||||
|
||||
var comptime_err_ret_trace = std.ArrayList(SrcLoc).init(gpa);
|
||||
defer comptime_err_ret_trace.deinit();
|
||||
@ -3434,7 +3434,7 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void {
|
||||
.fn_ret_ty = Type.void,
|
||||
.fn_ret_ty_ies = null,
|
||||
.owner_func_index = .none,
|
||||
.comptime_mutable_decls = &comptime_mutable_decls,
|
||||
.comptime_memory = &comptime_memory,
|
||||
.comptime_err_ret_trace = &comptime_err_ret_trace,
|
||||
};
|
||||
defer sema.deinit();
|
||||
@ -3448,10 +3448,6 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void {
|
||||
};
|
||||
// TODO: figure out InternPool removals for incremental compilation
|
||||
//errdefer ip.remove(struct_ty);
|
||||
for (comptime_mutable_decls.items) |decl_index| {
|
||||
const decl = mod.declPtr(decl_index);
|
||||
_ = try decl.internValue(mod);
|
||||
}
|
||||
|
||||
new_namespace.ty = Type.fromInterned(struct_ty);
|
||||
new_decl.val = Value.fromInterned(struct_ty);
|
||||
@ -3540,8 +3536,8 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
|
||||
var analysis_arena = std.heap.ArenaAllocator.init(gpa);
|
||||
defer analysis_arena.deinit();
|
||||
|
||||
var comptime_mutable_decls = std.ArrayList(Decl.Index).init(gpa);
|
||||
defer comptime_mutable_decls.deinit();
|
||||
var comptime_memory: Sema.ComptimeMemory = .{};
|
||||
defer comptime_memory.deinit(gpa);
|
||||
|
||||
var comptime_err_ret_trace = std.ArrayList(SrcLoc).init(gpa);
|
||||
defer comptime_err_ret_trace.deinit();
|
||||
@ -3558,7 +3554,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
|
||||
.fn_ret_ty = Type.void,
|
||||
.fn_ret_ty_ies = null,
|
||||
.owner_func_index = .none,
|
||||
.comptime_mutable_decls = &comptime_mutable_decls,
|
||||
.comptime_memory = &comptime_memory,
|
||||
.comptime_err_ret_trace = &comptime_err_ret_trace,
|
||||
.builtin_type_target_index = builtin_type_target_index,
|
||||
};
|
||||
@ -3584,10 +3580,6 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
|
||||
// We'll do some other bits with the Sema. Clear the type target index just
|
||||
// in case they analyze any type.
|
||||
sema.builtin_type_target_index = .none;
|
||||
for (comptime_mutable_decls.items) |ct_decl_index| {
|
||||
const ct_decl = mod.declPtr(ct_decl_index);
|
||||
_ = try ct_decl.internValue(mod);
|
||||
}
|
||||
const align_src: LazySrcLoc = .{ .node_offset_var_decl_align = 0 };
|
||||
const section_src: LazySrcLoc = .{ .node_offset_var_decl_section = 0 };
|
||||
const address_space_src: LazySrcLoc = .{ .node_offset_var_decl_addrspace = 0 };
|
||||
@ -4362,8 +4354,8 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
|
||||
const decl_index = func.owner_decl;
|
||||
const decl = mod.declPtr(decl_index);
|
||||
|
||||
var comptime_mutable_decls = std.ArrayList(Decl.Index).init(gpa);
|
||||
defer comptime_mutable_decls.deinit();
|
||||
var comptime_memory: Sema.ComptimeMemory = .{};
|
||||
defer comptime_memory.deinit(gpa);
|
||||
|
||||
var comptime_err_ret_trace = std.ArrayList(SrcLoc).init(gpa);
|
||||
defer comptime_err_ret_trace.deinit();
|
||||
@ -4389,7 +4381,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
|
||||
.fn_ret_ty_ies = null,
|
||||
.owner_func_index = func_index,
|
||||
.branch_quota = @max(func.branchQuota(ip).*, Sema.default_branch_quota),
|
||||
.comptime_mutable_decls = &comptime_mutable_decls,
|
||||
.comptime_memory = &comptime_memory,
|
||||
.comptime_err_ret_trace = &comptime_err_ret_trace,
|
||||
};
|
||||
defer sema.deinit();
|
||||
@ -4522,11 +4514,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
|
||||
};
|
||||
}
|
||||
|
||||
for (comptime_mutable_decls.items) |ct_decl_index| {
|
||||
const ct_decl = mod.declPtr(ct_decl_index);
|
||||
_ = try ct_decl.internValue(mod);
|
||||
}
|
||||
|
||||
// Copy the block into place and mark that as the main block.
|
||||
try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len +
|
||||
inner_block.instructions.items.len);
|
||||
@ -5213,6 +5200,7 @@ pub fn populateTestFunctions(
|
||||
mod: *Module,
|
||||
main_progress_node: *std.Progress.Node,
|
||||
) !void {
|
||||
if (true) @panic("TODO implement populateTestFunctions");
|
||||
const gpa = mod.gpa;
|
||||
const ip = &mod.intern_pool;
|
||||
const builtin_mod = mod.root_mod.getBuiltinDependency();
|
||||
@ -5436,7 +5424,6 @@ pub fn markReferencedDeclsAlive(mod: *Module, val: Value) Allocator.Error!void {
|
||||
.ptr => |ptr| switch (ptr.addr) {
|
||||
.decl => |decl| try mod.markDeclIndexAlive(decl),
|
||||
.anon_decl => {},
|
||||
.mut_decl => |mut_decl| try mod.markDeclIndexAlive(mut_decl.decl),
|
||||
.int, .comptime_field => {},
|
||||
.eu_payload, .opt_payload => |parent| try mod.markReferencedDeclsAlive(Value.fromInterned(parent)),
|
||||
.elem, .field => |base_index| try mod.markReferencedDeclsAlive(Value.fromInterned(base_index.base)),
|
||||
|
@ -4,7 +4,7 @@ const Order = std.math.Order;
|
||||
|
||||
const InternPool = @import("InternPool.zig");
|
||||
const Type = @import("type.zig").Type;
|
||||
const Value = @import("value.zig").Value;
|
||||
const Value = @import("Value.zig");
|
||||
const Module = @import("Module.zig");
|
||||
const RangeSet = @This();
|
||||
const SwitchProngSrc = @import("Module.zig").SwitchProngSrc;
|
||||
|
792
src/Sema.zig
792
src/Sema.zig
File diff suppressed because it is too large
Load Diff
63
src/Sema/ComptimeMemory.zig
Normal file
63
src/Sema/ComptimeMemory.zig
Normal file
@ -0,0 +1,63 @@
|
||||
/// The index points into `value_map_values`.
|
||||
value_map: std.AutoArrayHashMapUnmanaged(Zir.Inst.Index, void) = .{},
|
||||
value_map_values: std.MultiArrayList(Value) = .{},
|
||||
|
||||
// The following fields are used by the untagged union of Value:
|
||||
|
||||
/// Corresponds to `Value.Index`
|
||||
value_list: std.MultiArrayList(Value) = .{},
|
||||
/// Corresponds to `Slice.Index`
|
||||
slice_list: std.ArrayListUnmanaged(Slice) = .{},
|
||||
/// Corresponds to `Bytes.Index`
|
||||
bytes_list: std.ArrayListUnmanaged(Bytes) = .{},
|
||||
/// Corresponds to `Aggregate.Index`
|
||||
aggregate_list: std.ArrayListUnmanaged(Aggregate) = .{},
|
||||
/// Corresponds to `Union.Index`
|
||||
union_list: std.ArrayListUnmanaged(Union) = .{},
|
||||
|
||||
pub const Value = @import("ComptimeMemory/Value.zig");
|
||||
|
||||
pub const Bytes = struct {
|
||||
/// The full slice of data owned by the allocation backing this value.
|
||||
memory_island: []u8,
|
||||
start: usize,
|
||||
/// Includes the sentinel, if any.
|
||||
len: usize,
|
||||
|
||||
pub const Index = enum(u32) { _ };
|
||||
};
|
||||
|
||||
pub const Slice = struct {
|
||||
ptr: Value,
|
||||
len: Value,
|
||||
|
||||
pub const Index = enum(u32) { _ };
|
||||
};
|
||||
|
||||
pub const Aggregate = struct {
|
||||
start: Value.Index,
|
||||
len: u32,
|
||||
|
||||
pub const Index = enum(u32) { _ };
|
||||
};
|
||||
|
||||
pub const Union = struct {
|
||||
/// none means undefined tag.
|
||||
tag: Value.OptionalIndex,
|
||||
val: Value,
|
||||
|
||||
pub const Index = enum(u32) { _ };
|
||||
};
|
||||
|
||||
pub const RuntimeIndex = enum(u32) {
|
||||
zero = 0,
|
||||
comptime_field_ptr = std.math.maxInt(u32),
|
||||
_,
|
||||
|
||||
pub fn increment(ri: *RuntimeIndex) void {
|
||||
ri.* = @enumFromInt(@intFromEnum(ri.*) + 1);
|
||||
}
|
||||
};
|
||||
|
||||
const std = @import("std");
|
||||
const Zir = @import("../Zir.zig");
|
66
src/Sema/ComptimeMemory/Value.zig
Normal file
66
src/Sema/ComptimeMemory/Value.zig
Normal file
@ -0,0 +1,66 @@
|
||||
ty: InternPool.Index,
|
||||
tag: Tag,
|
||||
repr: Repr,
|
||||
|
||||
comptime {
|
||||
switch (builtin.mode) {
|
||||
.ReleaseFast, .ReleaseSmall => {
|
||||
assert(@sizeOf(InternPool.Index) == 4);
|
||||
assert(@sizeOf(Repr) == 4);
|
||||
assert(@sizeOf(Tag) == 1);
|
||||
},
|
||||
.Debug, .ReleaseSafe => {},
|
||||
}
|
||||
}
|
||||
|
||||
pub const Tag = enum(u8) {
|
||||
/// Represents an value stored in `InternPool`.
|
||||
interned,
|
||||
/// Represents an error union value that is not an error.
|
||||
/// The value is the payload value.
|
||||
eu_payload,
|
||||
/// Represents an optional value that is not null.
|
||||
/// The value is the payload value.
|
||||
opt_payload,
|
||||
/// The type must be an array, vector, or tuple. The element is this sub
|
||||
/// value repeated according to the length provided by the type.
|
||||
repeated,
|
||||
/// The type must be a slice pointer type.
|
||||
slice,
|
||||
/// The value is index into ComptimeMemory buffers array.
|
||||
bytes,
|
||||
/// An instance of a struct, array, or vector.
|
||||
/// Each element/field stored as a `Value`.
|
||||
/// In the case of sentinel-terminated arrays, the sentinel value *is* stored,
|
||||
/// so the slice length will be one more than the type's array length.
|
||||
aggregate,
|
||||
/// An instance of a union.
|
||||
@"union",
|
||||
};
|
||||
|
||||
pub const Repr = union {
|
||||
ip_index: InternPool.Index,
|
||||
eu_payload: Index,
|
||||
opt_payload: Index,
|
||||
repeated: Index,
|
||||
slice: ComptimeMemory.Slice.Index,
|
||||
bytes: ComptimeMemory.Bytes.Index,
|
||||
aggregate: ComptimeMemory.Aggregate.Index,
|
||||
@"union": ComptimeMemory.Union.Index,
|
||||
};
|
||||
|
||||
pub const Index = enum(u32) { _ };
|
||||
|
||||
pub const OptionalIndex = enum(u32) {
|
||||
none = std.math.maxInt(u32),
|
||||
_,
|
||||
};
|
||||
|
||||
const builtin = @import("builtin");
|
||||
const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
const Value = @This();
|
||||
const ConstValue = @import("../../Value.zig");
|
||||
|
||||
const InternPool = @import("../../InternPool.zig");
|
||||
const ComptimeMemory = @import("../ComptimeMemory.zig");
|
@ -1,6 +1,6 @@
|
||||
const std = @import("std");
|
||||
const Type = @import("type.zig").Type;
|
||||
const Value = @import("value.zig").Value;
|
||||
const Value = @import("Value.zig");
|
||||
const Module = @import("Module.zig");
|
||||
const Allocator = std.mem.Allocator;
|
||||
const TypedValue = @This();
|
||||
@ -329,14 +329,6 @@ pub fn print(
|
||||
.val = Value.fromInterned(decl_val),
|
||||
}, writer, level - 1, mod);
|
||||
},
|
||||
.mut_decl => |mut_decl| {
|
||||
const decl = mod.declPtr(mut_decl.decl);
|
||||
if (level == 0) return writer.print("(mut decl '{}')", .{decl.name.fmt(ip)});
|
||||
return print(.{
|
||||
.ty = decl.ty,
|
||||
.val = decl.val,
|
||||
}, writer, level - 1, mod);
|
||||
},
|
||||
.comptime_field => |field_val_ip| {
|
||||
return print(.{
|
||||
.ty = Type.fromInterned(ip.typeOf(field_val_ip)),
|
||||
|
3787
src/Value.zig
Normal file
3787
src/Value.zig
Normal file
File diff suppressed because it is too large
Load Diff
@ -2211,6 +2211,11 @@ pub const Inst = struct {
|
||||
empty_struct = @intFromEnum(InternPool.Index.empty_struct),
|
||||
generic_poison = @intFromEnum(InternPool.Index.generic_poison),
|
||||
|
||||
/// This Ref does not correspond to any ZIR instruction.
|
||||
/// It is a special value recognized only by Sema.
|
||||
/// It indicates the value is mutable comptime memory, and represented
|
||||
/// via the comptime_memory field of Sema. This value never occurs in ZIR.
|
||||
mutable_comptime = @intFromEnum(InternPool.Index.mutable_comptime),
|
||||
/// This tag is here to match Air and InternPool, however it is unused
|
||||
/// for ZIR purposes.
|
||||
var_args_param_type = @intFromEnum(InternPool.Index.var_args_param_type),
|
||||
|
@ -9,7 +9,7 @@ const Mir = @import("Mir.zig");
|
||||
const Emit = @import("Emit.zig");
|
||||
const Liveness = @import("../../Liveness.zig");
|
||||
const Type = @import("../../type.zig").Type;
|
||||
const Value = @import("../../value.zig").Value;
|
||||
const Value = @import("../../Value.zig");
|
||||
const TypedValue = @import("../../TypedValue.zig");
|
||||
const link = @import("../../link.zig");
|
||||
const Module = @import("../../Module.zig");
|
||||
|
@ -9,7 +9,7 @@ const Mir = @import("Mir.zig");
|
||||
const Emit = @import("Emit.zig");
|
||||
const Liveness = @import("../../Liveness.zig");
|
||||
const Type = @import("../../type.zig").Type;
|
||||
const Value = @import("../../value.zig").Value;
|
||||
const Value = @import("../../Value.zig");
|
||||
const TypedValue = @import("../../TypedValue.zig");
|
||||
const link = @import("../../link.zig");
|
||||
const Module = @import("../../Module.zig");
|
||||
|
@ -8,7 +8,7 @@ const Mir = @import("Mir.zig");
|
||||
const Emit = @import("Emit.zig");
|
||||
const Liveness = @import("../../Liveness.zig");
|
||||
const Type = @import("../../type.zig").Type;
|
||||
const Value = @import("../../value.zig").Value;
|
||||
const Value = @import("../../Value.zig");
|
||||
const TypedValue = @import("../../TypedValue.zig");
|
||||
const link = @import("../../link.zig");
|
||||
const Module = @import("../../Module.zig");
|
||||
|
@ -14,7 +14,7 @@ const Module = @import("../../Module.zig");
|
||||
const InternPool = @import("../../InternPool.zig");
|
||||
const Decl = Module.Decl;
|
||||
const Type = @import("../../type.zig").Type;
|
||||
const Value = @import("../../value.zig").Value;
|
||||
const Value = @import("../../Value.zig");
|
||||
const Compilation = @import("../../Compilation.zig");
|
||||
const LazySrcLoc = Module.LazySrcLoc;
|
||||
const link = @import("../../link.zig");
|
||||
@ -3082,10 +3082,6 @@ fn lowerParentPtr(func: *CodeGen, ptr_val: Value, offset: u32) InnerError!WValue
|
||||
return func.lowerParentPtrDecl(ptr_val, decl_index, offset);
|
||||
},
|
||||
.anon_decl => |ad| return func.lowerAnonDeclRef(ad, offset),
|
||||
.mut_decl => |mut_decl| {
|
||||
const decl_index = mut_decl.decl;
|
||||
return func.lowerParentPtrDecl(ptr_val, decl_index, offset);
|
||||
},
|
||||
.eu_payload => |tag| return func.fail("TODO: Implement lowerParentPtr for {}", .{tag}),
|
||||
.int => |base| return func.lowerConstant(Value.fromInterned(base), Type.usize),
|
||||
.opt_payload => |base_ptr| return func.lowerParentPtr(Value.fromInterned(base_ptr), offset),
|
||||
@ -3346,7 +3342,6 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {
|
||||
},
|
||||
.ptr => |ptr| switch (ptr.addr) {
|
||||
.decl => |decl| return func.lowerDeclRefValue(.{ .ty = ty, .val = val }, decl, 0),
|
||||
.mut_decl => |mut_decl| return func.lowerDeclRefValue(.{ .ty = ty, .val = val }, mut_decl.decl, 0),
|
||||
.int => |int| return func.lowerConstant(Value.fromInterned(int), Type.fromInterned(ip.typeOf(int))),
|
||||
.opt_payload, .elem, .field => return func.lowerParentPtr(val, 0),
|
||||
.anon_decl => |ad| return func.lowerAnonDeclRef(ad, 0),
|
||||
|
@ -33,7 +33,7 @@ const Alignment = InternPool.Alignment;
|
||||
const Target = std.Target;
|
||||
const Type = @import("../../type.zig").Type;
|
||||
const TypedValue = @import("../../TypedValue.zig");
|
||||
const Value = @import("../../value.zig").Value;
|
||||
const Value = @import("../../Value.zig");
|
||||
const Instruction = @import("encoder.zig").Instruction;
|
||||
|
||||
const abi = @import("abi.zig");
|
||||
|
@ -570,4 +570,4 @@ const Module = @import("../../Module.zig");
|
||||
const Register = @import("bits.zig").Register;
|
||||
const RegisterManagerFn = @import("../../register_manager.zig").RegisterManager;
|
||||
const Type = @import("../../type.zig").Type;
|
||||
const Value = @import("../../value.zig").Value;
|
||||
const Value = @import("../../Value.zig");
|
||||
|
@ -20,7 +20,7 @@ const Module = @import("Module.zig");
|
||||
const Target = std.Target;
|
||||
const Type = @import("type.zig").Type;
|
||||
const TypedValue = @import("TypedValue.zig");
|
||||
const Value = @import("value.zig").Value;
|
||||
const Value = @import("Value.zig");
|
||||
const Zir = @import("Zir.zig");
|
||||
const Alignment = InternPool.Alignment;
|
||||
|
||||
@ -678,7 +678,6 @@ fn lowerParentPtr(
|
||||
const ptr = mod.intern_pool.indexToKey(parent_ptr).ptr;
|
||||
return switch (ptr.addr) {
|
||||
.decl => |decl| try lowerDeclRef(bin_file, src_loc, decl, code, debug_output, reloc_info),
|
||||
.mut_decl => |md| try lowerDeclRef(bin_file, src_loc, md.decl, code, debug_output, reloc_info),
|
||||
.anon_decl => |ad| try lowerAnonDeclRef(bin_file, src_loc, ad, code, debug_output, reloc_info),
|
||||
.int => |int| try generateSymbol(bin_file, src_loc, .{
|
||||
.ty = Type.usize,
|
||||
@ -1087,7 +1086,6 @@ pub fn genTypedValue(
|
||||
if (!typed_value.ty.isSlice(zcu)) switch (zcu.intern_pool.indexToKey(typed_value.val.toIntern())) {
|
||||
.ptr => |ptr| switch (ptr.addr) {
|
||||
.decl => |decl| return genDeclRef(lf, src_loc, typed_value, decl),
|
||||
.mut_decl => |mut_decl| return genDeclRef(lf, src_loc, typed_value, mut_decl.decl),
|
||||
else => {},
|
||||
},
|
||||
else => {},
|
||||
|
@ -7,7 +7,7 @@ const log = std.log.scoped(.c);
|
||||
const link = @import("../link.zig");
|
||||
const Module = @import("../Module.zig");
|
||||
const Compilation = @import("../Compilation.zig");
|
||||
const Value = @import("../value.zig").Value;
|
||||
const Value = @import("../Value.zig");
|
||||
const Type = @import("../type.zig").Type;
|
||||
const TypedValue = @import("../TypedValue.zig");
|
||||
const C = link.File.C;
|
||||
@ -691,7 +691,6 @@ pub const DeclGen = struct {
|
||||
const ptr = mod.intern_pool.indexToKey(ptr_val).ptr;
|
||||
switch (ptr.addr) {
|
||||
.decl => |d| try dg.renderDeclValue(writer, ptr_ty, Value.fromInterned(ptr_val), d, location),
|
||||
.mut_decl => |md| try dg.renderDeclValue(writer, ptr_ty, Value.fromInterned(ptr_val), md.decl, location),
|
||||
.anon_decl => |anon_decl| try dg.renderAnonDeclValue(writer, ptr_ty, Value.fromInterned(ptr_val), anon_decl, location),
|
||||
.int => |int| {
|
||||
try writer.writeByte('(');
|
||||
@ -1221,7 +1220,6 @@ pub const DeclGen = struct {
|
||||
},
|
||||
.ptr => |ptr| switch (ptr.addr) {
|
||||
.decl => |d| try dg.renderDeclValue(writer, ty, val, d, location),
|
||||
.mut_decl => |md| try dg.renderDeclValue(writer, ty, val, md.decl, location),
|
||||
.anon_decl => |decl_val| try dg.renderAnonDeclValue(writer, ty, val, decl_val, location),
|
||||
.int => |int| {
|
||||
try writer.writeAll("((");
|
||||
|
@ -21,7 +21,7 @@ const Package = @import("../Package.zig");
|
||||
const TypedValue = @import("../TypedValue.zig");
|
||||
const Air = @import("../Air.zig");
|
||||
const Liveness = @import("../Liveness.zig");
|
||||
const Value = @import("../value.zig").Value;
|
||||
const Value = @import("../Value.zig");
|
||||
const Type = @import("../type.zig").Type;
|
||||
const LazySrcLoc = Module.LazySrcLoc;
|
||||
const x86_64_abi = @import("../arch/x86_64/abi.zig");
|
||||
@ -3875,7 +3875,6 @@ pub const Object = struct {
|
||||
},
|
||||
.ptr => |ptr| return switch (ptr.addr) {
|
||||
.decl => |decl| try o.lowerDeclRefValue(ty, decl),
|
||||
.mut_decl => |mut_decl| try o.lowerDeclRefValue(ty, mut_decl.decl),
|
||||
.anon_decl => |anon_decl| try o.lowerAnonDeclRef(ty, anon_decl),
|
||||
.int => |int| try o.lowerIntAsPtr(int),
|
||||
.eu_payload,
|
||||
@ -4340,7 +4339,6 @@ pub const Object = struct {
|
||||
const ptr = ip.indexToKey(ptr_val.toIntern()).ptr;
|
||||
return switch (ptr.addr) {
|
||||
.decl => |decl| try o.lowerParentPtrDecl(decl),
|
||||
.mut_decl => |mut_decl| try o.lowerParentPtrDecl(mut_decl.decl),
|
||||
.anon_decl => |ad| try o.lowerAnonDeclRef(Type.fromInterned(ad.orig_ty), ad),
|
||||
.int => |int| try o.lowerIntAsPtr(int),
|
||||
.eu_payload => |eu_ptr| {
|
||||
|
@ -7,7 +7,7 @@ const assert = std.debug.assert;
|
||||
const Module = @import("../Module.zig");
|
||||
const Decl = Module.Decl;
|
||||
const Type = @import("../type.zig").Type;
|
||||
const Value = @import("../value.zig").Value;
|
||||
const Value = @import("../Value.zig");
|
||||
const LazySrcLoc = Module.LazySrcLoc;
|
||||
const Air = @import("../Air.zig");
|
||||
const Zir = @import("../Zir.zig");
|
||||
@ -992,7 +992,6 @@ const DeclGen = struct {
|
||||
const mod = self.module;
|
||||
switch (mod.intern_pool.indexToKey(ptr_val.toIntern()).ptr.addr) {
|
||||
.decl => |decl| return try self.constantDeclRef(ptr_ty, decl),
|
||||
.mut_decl => |decl_mut| return try self.constantDeclRef(ptr_ty, decl_mut.decl),
|
||||
.anon_decl => |anon_decl| return try self.constantAnonDeclRef(ptr_ty, anon_decl),
|
||||
.int => |int| {
|
||||
const ptr_id = self.spv.allocId();
|
||||
|
@ -14,7 +14,7 @@ const codegen = @import("../codegen/c.zig");
|
||||
const link = @import("../link.zig");
|
||||
const trace = @import("../tracy.zig").trace;
|
||||
const Type = @import("../type.zig").Type;
|
||||
const Value = @import("../value.zig").Value;
|
||||
const Value = @import("../Value.zig");
|
||||
const Air = @import("../Air.zig");
|
||||
const Liveness = @import("../Liveness.zig");
|
||||
|
||||
|
@ -2753,7 +2753,7 @@ const Relocation = @import("Coff/Relocation.zig");
|
||||
const TableSection = @import("table_section.zig").TableSection;
|
||||
const StringTable = @import("StringTable.zig");
|
||||
const Type = @import("../type.zig").Type;
|
||||
const Value = @import("../value.zig").Value;
|
||||
const Value = @import("../Value.zig");
|
||||
const TypedValue = @import("../TypedValue.zig");
|
||||
|
||||
pub const base_tag: link.File.Tag = .coff;
|
||||
|
@ -2847,4 +2847,4 @@ const Module = @import("../Module.zig");
|
||||
const InternPool = @import("../InternPool.zig");
|
||||
const StringTable = @import("StringTable.zig");
|
||||
const Type = @import("../type.zig").Type;
|
||||
const Value = @import("../value.zig").Value;
|
||||
const Value = @import("../Value.zig");
|
||||
|
@ -1667,6 +1667,6 @@ const Object = @import("Object.zig");
|
||||
const Symbol = @import("Symbol.zig");
|
||||
const StringTable = @import("../StringTable.zig");
|
||||
const Type = @import("../../type.zig").Type;
|
||||
const Value = @import("../../value.zig").Value;
|
||||
const Value = @import("../../Value.zig");
|
||||
const TypedValue = @import("../../TypedValue.zig");
|
||||
const ZigObject = @This();
|
||||
|
@ -1462,6 +1462,6 @@ const Relocation = @import("Relocation.zig");
|
||||
const Symbol = @import("Symbol.zig");
|
||||
const StringTable = @import("../StringTable.zig");
|
||||
const Type = @import("../../type.zig").Type;
|
||||
const Value = @import("../../value.zig").Value;
|
||||
const Value = @import("../../Value.zig");
|
||||
const TypedValue = @import("../../TypedValue.zig");
|
||||
const ZigObject = @This();
|
||||
|
@ -14,7 +14,7 @@ const build_options = @import("build_options");
|
||||
const Air = @import("../Air.zig");
|
||||
const Liveness = @import("../Liveness.zig");
|
||||
const Type = @import("../type.zig").Type;
|
||||
const Value = @import("../value.zig").Value;
|
||||
const Value = @import("../Value.zig");
|
||||
const TypedValue = @import("../TypedValue.zig");
|
||||
|
||||
const std = @import("std");
|
||||
|
@ -36,7 +36,7 @@ const trace = @import("../tracy.zig").trace;
|
||||
const build_options = @import("build_options");
|
||||
const Air = @import("../Air.zig");
|
||||
const Liveness = @import("../Liveness.zig");
|
||||
const Value = @import("../value.zig").Value;
|
||||
const Value = @import("../Value.zig");
|
||||
|
||||
const SpvModule = @import("../codegen/spirv/Module.zig");
|
||||
const spec = @import("../codegen/spirv/spec.zig");
|
||||
|
@ -23,7 +23,7 @@ const build_options = @import("build_options");
|
||||
const wasi_libc = @import("../wasi_libc.zig");
|
||||
const Cache = std.Build.Cache;
|
||||
const Type = @import("../type.zig").Type;
|
||||
const Value = @import("../value.zig").Value;
|
||||
const Value = @import("../Value.zig");
|
||||
const TypedValue = @import("../TypedValue.zig");
|
||||
const LlvmObject = @import("../codegen/llvm.zig").Object;
|
||||
const Air = @import("../Air.zig");
|
||||
|
@ -3,7 +3,7 @@ const Allocator = std.mem.Allocator;
|
||||
const fmtIntSizeBin = std.fmt.fmtIntSizeBin;
|
||||
|
||||
const Module = @import("Module.zig");
|
||||
const Value = @import("value.zig").Value;
|
||||
const Value = @import("Value.zig");
|
||||
const Type = @import("type.zig").Type;
|
||||
const Air = @import("Air.zig");
|
||||
const Liveness = @import("Liveness.zig");
|
||||
|
@ -1,6 +1,6 @@
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const Value = @import("value.zig").Value;
|
||||
const Value = @import("Value.zig");
|
||||
const assert = std.debug.assert;
|
||||
const Target = std.Target;
|
||||
const Module = @import("Module.zig");
|
||||
|
4077
src/value.zig
4077
src/value.zig
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user