diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e9e20262e38..75d76d1494de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -519,8 +519,9 @@ set(ZIG_STAGE2_SOURCES "${CMAKE_SOURCE_DIR}/lib/std/zig/system/NativeTargetInfo.zig" "${CMAKE_SOURCE_DIR}/lib/std/zig/system/x86.zig" "${CMAKE_SOURCE_DIR}/lib/std/zig/tokenizer.zig" + "${CMAKE_SOURCE_DIR}/lib/std/zig/Zir.zig" + "${CMAKE_SOURCE_DIR}/lib/std/zig/AstGen.zig" "${CMAKE_SOURCE_DIR}/src/Air.zig" - "${CMAKE_SOURCE_DIR}/src/AstGen.zig" "${CMAKE_SOURCE_DIR}/src/Compilation.zig" "${CMAKE_SOURCE_DIR}/src/Liveness.zig" "${CMAKE_SOURCE_DIR}/src/Module.zig" @@ -529,7 +530,6 @@ set(ZIG_STAGE2_SOURCES "${CMAKE_SOURCE_DIR}/src/RangeSet.zig" "${CMAKE_SOURCE_DIR}/src/Sema.zig" "${CMAKE_SOURCE_DIR}/src/TypedValue.zig" - "${CMAKE_SOURCE_DIR}/src/Zir.zig" "${CMAKE_SOURCE_DIR}/src/arch/aarch64/CodeGen.zig" "${CMAKE_SOURCE_DIR}/src/arch/aarch64/Emit.zig" "${CMAKE_SOURCE_DIR}/src/arch/aarch64/Mir.zig" diff --git a/lib/std/zig.zig b/lib/std/zig.zig index 2d2aaf17ba40..b0a59561a498 100644 --- a/lib/std/zig.zig +++ b/lib/std/zig.zig @@ -19,6 +19,9 @@ pub const system = @import("zig/system.zig"); pub const CrossTarget = @import("zig/CrossTarget.zig"); pub const BuiltinFn = @import("zig/BuiltinFn.zig"); pub const AstRlAnnotate = @import("zig/AstRlAnnotate.zig"); +pub const Zir = @import("zig/Zir.zig"); +pub const InternPool = @import("zig/InternPool.zig"); +pub const AstGen = @import("zig/AstGen.zig"); // Character literal parsing pub const ParsedCharLiteral = string_literal.ParsedCharLiteral; diff --git a/src/AstGen.zig b/lib/std/zig/AstGen.zig similarity index 99% rename from src/AstGen.zig rename to lib/std/zig/AstGen.zig index 060e2af62b2e..92bd873e2bf9 100644 --- a/src/AstGen.zig +++ b/lib/std/zig/AstGen.zig @@ -12,7 +12,7 @@ const StringIndexContext = std.hash_map.StringIndexContext; const isPrimitive = std.zig.primitives.isPrimitive; -const Zir = @import("Zir.zig"); +const Zir = std.zig.Zir; const BuiltinFn = std.zig.BuiltinFn; const AstRlAnnotate = std.zig.AstRlAnnotate; diff --git a/src/InternPool.zig b/lib/std/zig/InternPool.zig similarity index 91% rename from src/InternPool.zig rename to lib/std/zig/InternPool.zig index e06597373e41..70008ba1419f 100644 --- a/src/InternPool.zig +++ b/lib/std/zig/InternPool.zig @@ -20,25 +20,6 @@ limbs: std.ArrayListUnmanaged(u64) = .{}, /// `string_bytes` array is agnostic to either usage. string_bytes: std.ArrayListUnmanaged(u8) = .{}, -/// Rather than allocating Decl objects with an Allocator, we instead allocate -/// them with this SegmentedList. This provides four advantages: -/// * Stable memory so that one thread can access a Decl object while another -/// thread allocates additional Decl objects from this list. -/// * It allows us to use u32 indexes to reference Decl objects rather than -/// pointers, saving memory in Type, Value, and dependency sets. -/// * Using integers to reference Decl objects rather than pointers makes -/// serialization trivial. -/// * It provides a unique integer to be used for anonymous symbol names, avoiding -/// multi-threaded contention on an atomic counter. -allocated_decls: std.SegmentedList(Module.Decl, 0) = .{}, -/// When a Decl object is freed from `allocated_decls`, it is pushed into this stack. -decls_free_list: std.ArrayListUnmanaged(DeclIndex) = .{}, - -/// Same pattern as with `allocated_decls`. -allocated_namespaces: std.SegmentedList(Module.Namespace, 0) = .{}, -/// Same pattern as with `decls_free_list`. -namespaces_free_list: std.ArrayListUnmanaged(NamespaceIndex) = .{}, - /// Some types such as enums, structs, and unions need to store mappings from field names /// to field index, or value to field index. In such cases, they will store the underlying /// field names and values directly, relying on one of these maps, stored separately, @@ -66,10 +47,9 @@ const Limb = std.math.big.Limb; const Hash = std.hash.Wyhash; const InternPool = @This(); -const Module = @import("Module.zig"); -const Zir = @import("Zir.zig"); +const Zir = std.zig.Zir; -const KeyAdapter = struct { +pub const KeyAdapter = struct { intern_pool: *const InternPool, pub fn eql(ctx: @This(), a: Key, b_void: void, b_map_index: usize) bool { @@ -2850,14 +2830,14 @@ pub const Tag = enum(u8) { /// data is extra index to `MemoizedCall` memoized_call, - const ErrorUnionType = Key.ErrorUnionType; - const OpaqueType = Key.OpaqueType; - const TypeValue = Key.TypeValue; - const Error = Key.Error; - const EnumTag = Key.EnumTag; - const ExternFunc = Key.ExternFunc; - const Union = Key.Union; - const TypePointer = Key.PtrType; + pub const ErrorUnionType = Key.ErrorUnionType; + pub const OpaqueType = Key.OpaqueType; + pub const TypeValue = Key.TypeValue; + pub const Error = Key.Error; + pub const EnumTag = Key.EnumTag; + pub const ExternFunc = Key.ExternFunc; + pub const Union = Key.Union; + pub const TypePointer = Key.PtrType; fn Payload(comptime tag: Tag) type { return switch (tag) { @@ -3421,16 +3401,6 @@ pub const Alignment = enum(u6) { if (n == @intFromEnum(Alignment.none)) return 0; return n + 1; } - - const LlvmBuilderAlignment = @import("codegen/llvm/Builder.zig").Alignment; - - pub fn toLlvm(this: @This()) LlvmBuilderAlignment { - return @enumFromInt(@intFromEnum(this)); - } - - pub fn fromLlvm(other: LlvmBuilderAlignment) @This() { - return @enumFromInt(@intFromEnum(other)); - } }; /// Used for non-sentineled arrays that have length fitting in u32, as well as @@ -3697,12 +3667,6 @@ pub fn deinit(ip: *InternPool, gpa: Allocator) void { ip.limbs.deinit(gpa); ip.string_bytes.deinit(gpa); - ip.decls_free_list.deinit(gpa); - ip.allocated_decls.deinit(gpa); - - ip.namespaces_free_list.deinit(gpa); - ip.allocated_namespaces.deinit(gpa); - for (ip.maps.items) |*map| map.deinit(gpa); ip.maps.deinit(gpa); @@ -4399,7 +4363,7 @@ fn extraPackedStructType(ip: *const InternPool, extra_index: u32, inits: bool) K }; } -fn extraFuncType(ip: *const InternPool, extra_index: u32) Key.FuncType { +pub fn extraFuncType(ip: *const InternPool, extra_index: u32) Key.FuncType { const type_function = ip.extraDataTrail(Tag.TypeFunction, extra_index); var index: usize = type_function.end; const comptime_bits: u32 = if (!type_function.data.flags.has_comptime_bits) 0 else b: { @@ -4453,7 +4417,7 @@ fn extraFuncDecl(ip: *const InternPool, extra_index: u32) Key.Func { }; } -fn extraFuncInstance(ip: *const InternPool, extra_index: u32) Key.Func { +pub fn extraFuncInstance(ip: *const InternPool, extra_index: u32) Key.Func { const P = Tag.FuncInstance; const fi = ip.extraDataTrail(P, extra_index); const func_decl = ip.funcDeclInfo(fi.data.generic_owner); @@ -5937,276 +5901,6 @@ pub fn getErrorSetType( return @enumFromInt(ip.items.len - 1); } -pub const GetFuncInstanceKey = struct { - /// Has the length of the instance function (may be lesser than - /// comptime_args). - param_types: []Index, - /// Has the length of generic_owner's parameters (may be greater than - /// param_types). - comptime_args: []const Index, - noalias_bits: u32, - bare_return_type: Index, - cc: std.builtin.CallingConvention, - alignment: Alignment, - section: OptionalNullTerminatedString, - is_noinline: bool, - generic_owner: Index, - inferred_error_set: bool, - generation: u32, -}; - -pub fn getFuncInstance(ip: *InternPool, gpa: Allocator, arg: GetFuncInstanceKey) Allocator.Error!Index { - if (arg.inferred_error_set) - return getFuncInstanceIes(ip, gpa, arg); - - const func_ty = try ip.getFuncType(gpa, .{ - .param_types = arg.param_types, - .return_type = arg.bare_return_type, - .noalias_bits = arg.noalias_bits, - .alignment = arg.alignment, - .cc = arg.cc, - .is_noinline = arg.is_noinline, - }); - - const generic_owner = unwrapCoercedFunc(ip, arg.generic_owner); - - assert(arg.comptime_args.len == ip.funcTypeParamsLen(ip.typeOf(generic_owner))); - - try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(Tag.FuncInstance).Struct.fields.len + - arg.comptime_args.len); - const prev_extra_len = ip.extra.items.len; - errdefer ip.extra.items.len = prev_extra_len; - - const func_extra_index = ip.addExtraAssumeCapacity(Tag.FuncInstance{ - .analysis = .{ - .state = if (arg.cc == .Inline) .inline_only else .none, - .is_cold = false, - .is_noinline = arg.is_noinline, - .calls_or_awaits_errorable_fn = false, - .stack_alignment = .none, - .inferred_error_set = false, - }, - // This is populated after we create the Decl below. It is not read - // by equality or hashing functions. - .owner_decl = undefined, - .ty = func_ty, - .branch_quota = 0, - .generic_owner = generic_owner, - }); - ip.extra.appendSliceAssumeCapacity(@ptrCast(arg.comptime_args)); - - const gop = try ip.map.getOrPutAdapted(gpa, Key{ - .func = extraFuncInstance(ip, func_extra_index), - }, KeyAdapter{ .intern_pool = ip }); - errdefer _ = ip.map.pop(); - - if (gop.found_existing) { - ip.extra.items.len = prev_extra_len; - return @enumFromInt(gop.index); - } - - const func_index: Index = @enumFromInt(ip.items.len); - - try ip.items.append(gpa, .{ - .tag = .func_instance, - .data = func_extra_index, - }); - errdefer ip.items.len -= 1; - - return finishFuncInstance( - ip, - gpa, - generic_owner, - func_index, - func_extra_index, - arg.generation, - func_ty, - arg.section, - ); -} - -/// This function exists separately than `getFuncInstance` because it needs to -/// create 4 new items in the InternPool atomically before it can look for an -/// existing item in the map. -pub fn getFuncInstanceIes( - ip: *InternPool, - gpa: Allocator, - arg: GetFuncInstanceKey, -) Allocator.Error!Index { - // Validate input parameters. - assert(arg.inferred_error_set); - assert(arg.bare_return_type != .none); - for (arg.param_types) |param_type| assert(param_type != .none); - - const generic_owner = unwrapCoercedFunc(ip, arg.generic_owner); - - // The strategy here is to add the function decl unconditionally, then to - // ask if it already exists, and if so, revert the lengths of the mutated - // arrays. This is similar to what `getOrPutTrailingString` does. - const prev_extra_len = ip.extra.items.len; - const params_len: u32 = @intCast(arg.param_types.len); - - try ip.map.ensureUnusedCapacity(gpa, 4); - try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(Tag.FuncInstance).Struct.fields.len + - 1 + // inferred_error_set - arg.comptime_args.len + - @typeInfo(Tag.ErrorUnionType).Struct.fields.len + - @typeInfo(Tag.TypeFunction).Struct.fields.len + - @intFromBool(arg.noalias_bits != 0) + - params_len); - try ip.items.ensureUnusedCapacity(gpa, 4); - - const func_index: Index = @enumFromInt(ip.items.len); - const error_union_type: Index = @enumFromInt(ip.items.len + 1); - const error_set_type: Index = @enumFromInt(ip.items.len + 2); - const func_ty: Index = @enumFromInt(ip.items.len + 3); - - const func_extra_index = ip.addExtraAssumeCapacity(Tag.FuncInstance{ - .analysis = .{ - .state = if (arg.cc == .Inline) .inline_only else .none, - .is_cold = false, - .is_noinline = arg.is_noinline, - .calls_or_awaits_errorable_fn = false, - .stack_alignment = .none, - .inferred_error_set = true, - }, - // This is populated after we create the Decl below. It is not read - // by equality or hashing functions. - .owner_decl = undefined, - .ty = func_ty, - .branch_quota = 0, - .generic_owner = generic_owner, - }); - ip.extra.appendAssumeCapacity(@intFromEnum(Index.none)); // resolved error set - ip.extra.appendSliceAssumeCapacity(@ptrCast(arg.comptime_args)); - - const func_type_extra_index = ip.addExtraAssumeCapacity(Tag.TypeFunction{ - .params_len = params_len, - .return_type = error_union_type, - .flags = .{ - .alignment = arg.alignment, - .cc = arg.cc, - .is_var_args = false, - .has_comptime_bits = false, - .has_noalias_bits = arg.noalias_bits != 0, - .is_generic = false, - .is_noinline = arg.is_noinline, - .align_is_generic = false, - .cc_is_generic = false, - .section_is_generic = false, - .addrspace_is_generic = false, - }, - }); - // no comptime_bits because has_comptime_bits is false - if (arg.noalias_bits != 0) ip.extra.appendAssumeCapacity(arg.noalias_bits); - ip.extra.appendSliceAssumeCapacity(@ptrCast(arg.param_types)); - - // TODO: add appendSliceAssumeCapacity to MultiArrayList. - ip.items.appendAssumeCapacity(.{ - .tag = .func_instance, - .data = func_extra_index, - }); - ip.items.appendAssumeCapacity(.{ - .tag = .type_error_union, - .data = ip.addExtraAssumeCapacity(Tag.ErrorUnionType{ - .error_set_type = error_set_type, - .payload_type = arg.bare_return_type, - }), - }); - ip.items.appendAssumeCapacity(.{ - .tag = .type_inferred_error_set, - .data = @intFromEnum(func_index), - }); - ip.items.appendAssumeCapacity(.{ - .tag = .type_function, - .data = func_type_extra_index, - }); - - const adapter: KeyAdapter = .{ .intern_pool = ip }; - const gop = ip.map.getOrPutAssumeCapacityAdapted(Key{ - .func = extraFuncInstance(ip, func_extra_index), - }, adapter); - if (gop.found_existing) { - // Hot path: undo the additions to our two arrays. - ip.items.len -= 4; - ip.extra.items.len = prev_extra_len; - return @enumFromInt(gop.index); - } - - // Synchronize the map with items. - assert(!ip.map.getOrPutAssumeCapacityAdapted(Key{ .error_union_type = .{ - .error_set_type = error_set_type, - .payload_type = arg.bare_return_type, - } }, adapter).found_existing); - assert(!ip.map.getOrPutAssumeCapacityAdapted(Key{ - .inferred_error_set_type = func_index, - }, adapter).found_existing); - assert(!ip.map.getOrPutAssumeCapacityAdapted(Key{ - .func_type = extraFuncType(ip, func_type_extra_index), - }, adapter).found_existing); - - return finishFuncInstance( - ip, - gpa, - generic_owner, - func_index, - func_extra_index, - arg.generation, - func_ty, - arg.section, - ); -} - -fn finishFuncInstance( - ip: *InternPool, - gpa: Allocator, - generic_owner: Index, - func_index: Index, - func_extra_index: u32, - generation: u32, - func_ty: Index, - section: OptionalNullTerminatedString, -) Allocator.Error!Index { - const fn_owner_decl = ip.declPtr(ip.funcDeclOwner(generic_owner)); - const decl_index = try ip.createDecl(gpa, .{ - .name = undefined, - .src_namespace = fn_owner_decl.src_namespace, - .src_node = fn_owner_decl.src_node, - .src_line = fn_owner_decl.src_line, - .has_tv = true, - .owns_tv = true, - .ty = @import("type.zig").Type.fromInterned(func_ty), - .val = @import("value.zig").Value.fromInterned(func_index), - .alignment = .none, - .@"linksection" = section, - .@"addrspace" = fn_owner_decl.@"addrspace", - .analysis = .complete, - .zir_decl_index = fn_owner_decl.zir_decl_index, - .src_scope = fn_owner_decl.src_scope, - .generation = generation, - .is_pub = fn_owner_decl.is_pub, - .is_exported = fn_owner_decl.is_exported, - .has_linksection_or_addrspace = fn_owner_decl.has_linksection_or_addrspace, - .has_align = fn_owner_decl.has_align, - .alive = true, - .kind = .anon, - }); - errdefer ip.destroyDecl(gpa, decl_index); - - // Populate the owner_decl field which was left undefined until now. - ip.extra.items[ - func_extra_index + std.meta.fieldIndex(Tag.FuncInstance, "owner_decl").? - ] = @intFromEnum(decl_index); - - // TODO: improve this name - const decl = ip.declPtr(decl_index); - decl.name = try ip.getOrPutStringFmt(gpa, "{}__anon_{d}", .{ - fn_owner_decl.name.fmt(ip), @intFromEnum(decl_index), - }); - - return func_index; -} - /// Provides API for completing an enum type after calling `getIncompleteEnum`. pub const IncompleteEnumType = struct { index: Index, @@ -6522,7 +6216,7 @@ fn addExtra(ip: *InternPool, gpa: Allocator, extra: anytype) Allocator.Error!u32 return ip.addExtraAssumeCapacity(extra); } -fn addExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 { +pub fn addExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 { const result = @as(u32, @intCast(ip.extra.items.len)); inline for (@typeInfo(@TypeOf(extra)).Struct.fields) |field| { ip.extra.appendAssumeCapacity(switch (field.type) { @@ -6637,12 +6331,12 @@ fn extraDataTrail(ip: *const InternPool, comptime T: type, index: usize) struct }; } -fn extraData(ip: *const InternPool, comptime T: type, index: usize) T { +pub fn extraData(ip: *const InternPool, comptime T: type, index: usize) T { return extraDataTrail(ip, T, index).data; } /// Asserts the struct has 32-bit fields and the number of fields is evenly divisible by 2. -fn limbData(ip: *const InternPool, comptime T: type, index: usize) T { +pub fn limbData(ip: *const InternPool, comptime T: type, index: usize) T { switch (@sizeOf(Limb)) { @sizeOf(u32) => return extraData(ip, T, index), @sizeOf(u64) => {}, @@ -6666,7 +6360,7 @@ fn limbData(ip: *const InternPool, comptime T: type, index: usize) T { } /// This function returns the Limb slice that is trailing data after a payload. -fn limbSlice(ip: *const InternPool, comptime S: type, limb_index: u32, len: u32) []const Limb { +pub fn limbSlice(ip: *const InternPool, comptime S: type, limb_index: u32, len: u32) []const Limb { const field_count = @typeInfo(S).Struct.fields.len; switch (@sizeOf(Limb)) { @sizeOf(u32) => { @@ -7227,436 +6921,6 @@ pub fn mutateVarInit(ip: *InternPool, index: Index, init_index: Index) void { ip.extra.items[item.data + std.meta.fieldIndex(Tag.Variable, "init").?] = @intFromEnum(init_index); } -pub fn dump(ip: *const InternPool) void { - dumpStatsFallible(ip, std.heap.page_allocator) catch return; - dumpAllFallible(ip) catch return; -} - -fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void { - const items_size = (1 + 4) * ip.items.len; - const extra_size = 4 * ip.extra.items.len; - const limbs_size = 8 * ip.limbs.items.len; - const decls_size = ip.allocated_decls.len * @sizeOf(Module.Decl); - - // TODO: map overhead size is not taken into account - const total_size = @sizeOf(InternPool) + items_size + extra_size + limbs_size + decls_size; - - std.debug.print( - \\InternPool size: {d} bytes - \\ {d} items: {d} bytes - \\ {d} extra: {d} bytes - \\ {d} limbs: {d} bytes - \\ {d} decls: {d} bytes - \\ - , .{ - total_size, - ip.items.len, - items_size, - ip.extra.items.len, - extra_size, - ip.limbs.items.len, - limbs_size, - ip.allocated_decls.len, - decls_size, - }); - - const tags = ip.items.items(.tag); - const datas = ip.items.items(.data); - const TagStats = struct { - count: usize = 0, - bytes: usize = 0, - }; - var counts = std.AutoArrayHashMap(Tag, TagStats).init(arena); - for (tags, datas) |tag, data| { - const gop = try counts.getOrPut(tag); - if (!gop.found_existing) gop.value_ptr.* = .{}; - gop.value_ptr.count += 1; - gop.value_ptr.bytes += 1 + 4 + @as(usize, switch (tag) { - .type_int_signed => 0, - .type_int_unsigned => 0, - .type_array_small => @sizeOf(Vector), - .type_array_big => @sizeOf(Array), - .type_vector => @sizeOf(Vector), - .type_pointer => @sizeOf(Tag.TypePointer), - .type_slice => 0, - .type_optional => 0, - .type_anyframe => 0, - .type_error_union => @sizeOf(Key.ErrorUnionType), - .type_anyerror_union => 0, - .type_error_set => b: { - const info = ip.extraData(Tag.ErrorSet, data); - break :b @sizeOf(Tag.ErrorSet) + (@sizeOf(u32) * info.names_len); - }, - .type_inferred_error_set => 0, - .type_enum_explicit, .type_enum_nonexhaustive => @sizeOf(EnumExplicit), - .type_enum_auto => @sizeOf(EnumAuto), - .type_opaque => @sizeOf(Key.OpaqueType), - .type_struct => b: { - const info = ip.extraData(Tag.TypeStruct, data); - var ints: usize = @typeInfo(Tag.TypeStruct).Struct.fields.len; - ints += info.fields_len; // types - if (!info.flags.is_tuple) { - ints += 1; // names_map - ints += info.fields_len; // names - } - if (info.flags.any_default_inits) - ints += info.fields_len; // inits - ints += @intFromBool(info.flags.has_namespace); // namespace - if (info.flags.any_aligned_fields) - ints += (info.fields_len + 3) / 4; // aligns - if (info.flags.any_comptime_fields) - ints += (info.fields_len + 31) / 32; // comptime bits - if (!info.flags.is_extern) - ints += info.fields_len; // runtime order - ints += info.fields_len; // offsets - break :b @sizeOf(u32) * ints; - }, - .type_struct_ns => @sizeOf(Module.Namespace), - .type_struct_anon => b: { - const info = ip.extraData(TypeStructAnon, data); - break :b @sizeOf(TypeStructAnon) + (@sizeOf(u32) * 3 * info.fields_len); - }, - .type_struct_packed => b: { - const info = ip.extraData(Tag.TypeStructPacked, data); - break :b @sizeOf(u32) * (@typeInfo(Tag.TypeStructPacked).Struct.fields.len + - info.fields_len + info.fields_len); - }, - .type_struct_packed_inits => b: { - const info = ip.extraData(Tag.TypeStructPacked, data); - break :b @sizeOf(u32) * (@typeInfo(Tag.TypeStructPacked).Struct.fields.len + - info.fields_len + info.fields_len + info.fields_len); - }, - .type_tuple_anon => b: { - const info = ip.extraData(TypeStructAnon, data); - break :b @sizeOf(TypeStructAnon) + (@sizeOf(u32) * 2 * info.fields_len); - }, - - .type_union => b: { - const info = ip.extraData(Tag.TypeUnion, data); - const enum_info = ip.indexToKey(info.tag_ty).enum_type; - const fields_len: u32 = @intCast(enum_info.names.len); - const per_field = @sizeOf(u32); // field type - // 1 byte per field for alignment, rounded up to the nearest 4 bytes - const alignments = if (info.flags.any_aligned_fields) - ((fields_len + 3) / 4) * 4 - else - 0; - break :b @sizeOf(Tag.TypeUnion) + (fields_len * per_field) + alignments; - }, - - .type_function => b: { - const info = ip.extraData(Tag.TypeFunction, data); - break :b @sizeOf(Tag.TypeFunction) + - (@sizeOf(Index) * info.params_len) + - (@as(u32, 4) * @intFromBool(info.flags.has_comptime_bits)) + - (@as(u32, 4) * @intFromBool(info.flags.has_noalias_bits)); - }, - - .undef => 0, - .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), - .ptr_int => @sizeOf(PtrBase), - .ptr_eu_payload => @sizeOf(PtrBase), - .ptr_opt_payload => @sizeOf(PtrBase), - .ptr_elem => @sizeOf(PtrBaseIndex), - .ptr_field => @sizeOf(PtrBaseIndex), - .ptr_slice => @sizeOf(PtrSlice), - .opt_null => 0, - .opt_payload => @sizeOf(Tag.TypeValue), - .int_u8 => 0, - .int_u16 => 0, - .int_u32 => 0, - .int_i32 => 0, - .int_usize => 0, - .int_comptime_int_u32 => 0, - .int_comptime_int_i32 => 0, - .int_small => @sizeOf(IntSmall), - - .int_positive, - .int_negative, - => b: { - const int = ip.limbData(Int, data); - break :b @sizeOf(Int) + int.limbs_len * 8; - }, - - .int_lazy_align, .int_lazy_size => @sizeOf(IntLazy), - - .error_set_error, .error_union_error => @sizeOf(Key.Error), - .error_union_payload => @sizeOf(Tag.TypeValue), - .enum_literal => 0, - .enum_tag => @sizeOf(Tag.EnumTag), - - .bytes => b: { - const info = ip.extraData(Bytes, data); - const len = @as(u32, @intCast(ip.aggregateTypeLenIncludingSentinel(info.ty))); - break :b @sizeOf(Bytes) + len + - @intFromBool(ip.string_bytes.items[@intFromEnum(info.bytes) + len - 1] != 0); - }, - .aggregate => b: { - const info = ip.extraData(Tag.Aggregate, data); - const fields_len: u32 = @intCast(ip.aggregateTypeLenIncludingSentinel(info.ty)); - break :b @sizeOf(Tag.Aggregate) + (@sizeOf(Index) * fields_len); - }, - .repeated => @sizeOf(Repeated), - - .float_f16 => 0, - .float_f32 => 0, - .float_f64 => @sizeOf(Float64), - .float_f80 => @sizeOf(Float80), - .float_f128 => @sizeOf(Float128), - .float_c_longdouble_f80 => @sizeOf(Float80), - .float_c_longdouble_f128 => @sizeOf(Float128), - .float_comptime_float => @sizeOf(Float128), - .variable => @sizeOf(Tag.Variable), - .extern_func => @sizeOf(Tag.ExternFunc), - .func_decl => @sizeOf(Tag.FuncDecl), - .func_instance => b: { - const info = ip.extraData(Tag.FuncInstance, data); - const ty = ip.typeOf(info.generic_owner); - const params_len = ip.indexToKey(ty).func_type.param_types.len; - break :b @sizeOf(Tag.FuncInstance) + @sizeOf(Index) * params_len; - }, - .func_coerced => @sizeOf(Tag.FuncCoerced), - .only_possible_value => 0, - .union_value => @sizeOf(Key.Union), - - .memoized_call => b: { - const info = ip.extraData(MemoizedCall, data); - break :b @sizeOf(MemoizedCall) + (@sizeOf(Index) * info.args_len); - }, - }); - } - const SortContext = struct { - map: *std.AutoArrayHashMap(Tag, TagStats), - pub fn lessThan(ctx: @This(), a_index: usize, b_index: usize) bool { - const values = ctx.map.values(); - return values[a_index].bytes > values[b_index].bytes; - //return values[a_index].count > values[b_index].count; - } - }; - counts.sort(SortContext{ .map = &counts }); - const len = @min(50, counts.count()); - std.debug.print(" top 50 tags:\n", .{}); - for (counts.keys()[0..len], counts.values()[0..len]) |tag, stats| { - std.debug.print(" {s}: {d} occurrences, {d} total bytes\n", .{ - @tagName(tag), stats.count, stats.bytes, - }); - } -} - -fn dumpAllFallible(ip: *const InternPool) anyerror!void { - const tags = ip.items.items(.tag); - const datas = ip.items.items(.data); - var bw = std.io.bufferedWriter(std.io.getStdErr().writer()); - const w = bw.writer(); - for (tags, datas, 0..) |tag, data, i| { - try w.print("${d} = {s}(", .{ i, @tagName(tag) }); - switch (tag) { - .simple_type => try w.print("{s}", .{@tagName(@as(SimpleType, @enumFromInt(data)))}), - .simple_value => try w.print("{s}", .{@tagName(@as(SimpleValue, @enumFromInt(data)))}), - - .type_int_signed, - .type_int_unsigned, - .type_array_small, - .type_array_big, - .type_vector, - .type_pointer, - .type_optional, - .type_anyframe, - .type_error_union, - .type_anyerror_union, - .type_error_set, - .type_inferred_error_set, - .type_enum_explicit, - .type_enum_nonexhaustive, - .type_enum_auto, - .type_opaque, - .type_struct, - .type_struct_ns, - .type_struct_anon, - .type_struct_packed, - .type_struct_packed_inits, - .type_tuple_anon, - .type_union, - .type_function, - .undef, - .ptr_decl, - .ptr_mut_decl, - .ptr_anon_decl, - .ptr_anon_decl_aligned, - .ptr_comptime_field, - .ptr_int, - .ptr_eu_payload, - .ptr_opt_payload, - .ptr_elem, - .ptr_field, - .ptr_slice, - .opt_payload, - .int_u8, - .int_u16, - .int_u32, - .int_i32, - .int_usize, - .int_comptime_int_u32, - .int_comptime_int_i32, - .int_small, - .int_positive, - .int_negative, - .int_lazy_align, - .int_lazy_size, - .error_set_error, - .error_union_error, - .error_union_payload, - .enum_literal, - .enum_tag, - .bytes, - .aggregate, - .repeated, - .float_f16, - .float_f32, - .float_f64, - .float_f80, - .float_f128, - .float_c_longdouble_f80, - .float_c_longdouble_f128, - .float_comptime_float, - .variable, - .extern_func, - .func_decl, - .func_instance, - .func_coerced, - .union_value, - .memoized_call, - => try w.print("{d}", .{data}), - - .opt_null, - .type_slice, - .only_possible_value, - => try w.print("${d}", .{data}), - } - try w.writeAll(")\n"); - } - try bw.flush(); -} - -pub fn dumpGenericInstances(ip: *const InternPool, allocator: Allocator) void { - ip.dumpGenericInstancesFallible(allocator) catch return; -} - -pub fn dumpGenericInstancesFallible(ip: *const InternPool, allocator: Allocator) anyerror!void { - var arena_allocator = std.heap.ArenaAllocator.init(allocator); - defer arena_allocator.deinit(); - const arena = arena_allocator.allocator(); - - var bw = std.io.bufferedWriter(std.io.getStdErr().writer()); - const w = bw.writer(); - - var instances: std.AutoArrayHashMapUnmanaged(Index, std.ArrayListUnmanaged(Index)) = .{}; - const datas = ip.items.items(.data); - for (ip.items.items(.tag), 0..) |tag, i| { - if (tag != .func_instance) continue; - const info = ip.extraData(Tag.FuncInstance, datas[i]); - - const gop = try instances.getOrPut(arena, info.generic_owner); - if (!gop.found_existing) gop.value_ptr.* = .{}; - - try gop.value_ptr.append(arena, @enumFromInt(i)); - } - - const SortContext = struct { - values: []std.ArrayListUnmanaged(Index), - pub fn lessThan(ctx: @This(), a_index: usize, b_index: usize) bool { - return ctx.values[a_index].items.len > ctx.values[b_index].items.len; - } - }; - - instances.sort(SortContext{ .values = instances.values() }); - var it = instances.iterator(); - while (it.next()) |entry| { - const generic_fn_owner_decl = ip.declPtrConst(ip.funcDeclOwner(entry.key_ptr.*)); - try w.print("{} ({}): \n", .{ generic_fn_owner_decl.name.fmt(ip), entry.value_ptr.items.len }); - for (entry.value_ptr.items) |index| { - const func = ip.extraFuncInstance(datas[@intFromEnum(index)]); - const owner_decl = ip.declPtrConst(func.owner_decl); - try w.print(" {}: (", .{owner_decl.name.fmt(ip)}); - for (func.comptime_args.get(ip)) |arg| { - if (arg != .none) { - const key = ip.indexToKey(arg); - try w.print(" {} ", .{key}); - } - } - try w.writeAll(")\n"); - } - } - - try bw.flush(); -} - -pub fn declPtr(ip: *InternPool, index: DeclIndex) *Module.Decl { - return ip.allocated_decls.at(@intFromEnum(index)); -} - -pub fn declPtrConst(ip: *const InternPool, index: DeclIndex) *const Module.Decl { - return ip.allocated_decls.at(@intFromEnum(index)); -} - -pub fn namespacePtr(ip: *InternPool, index: NamespaceIndex) *Module.Namespace { - return ip.allocated_namespaces.at(@intFromEnum(index)); -} - -pub fn createDecl( - ip: *InternPool, - gpa: Allocator, - initialization: Module.Decl, -) Allocator.Error!DeclIndex { - if (ip.decls_free_list.popOrNull()) |index| { - ip.allocated_decls.at(@intFromEnum(index)).* = initialization; - return index; - } - const ptr = try ip.allocated_decls.addOne(gpa); - ptr.* = initialization; - return @enumFromInt(ip.allocated_decls.len - 1); -} - -pub fn destroyDecl(ip: *InternPool, gpa: Allocator, index: DeclIndex) void { - ip.declPtr(index).* = undefined; - ip.decls_free_list.append(gpa, index) catch { - // In order to keep `destroyDecl` a non-fallible function, we ignore memory - // allocation failures here, instead leaking the Decl until garbage collection. - }; -} - -pub fn createNamespace( - ip: *InternPool, - gpa: Allocator, - initialization: Module.Namespace, -) Allocator.Error!NamespaceIndex { - if (ip.namespaces_free_list.popOrNull()) |index| { - ip.allocated_namespaces.at(@intFromEnum(index)).* = initialization; - return index; - } - const ptr = try ip.allocated_namespaces.addOne(gpa); - ptr.* = initialization; - return @enumFromInt(ip.allocated_namespaces.len - 1); -} - -pub fn destroyNamespace(ip: *InternPool, gpa: Allocator, index: NamespaceIndex) void { - ip.namespacePtr(index).* = .{ - .parent = undefined, - .file_scope = undefined, - .ty = undefined, - }; - ip.namespaces_free_list.append(gpa, index) catch { - // In order to keep `destroyNamespace` a non-fallible function, we ignore memory - // allocation failures here, instead leaking the Namespace until garbage collection. - }; -} - pub fn getOrPutString( ip: *InternPool, gpa: Allocator, @@ -8413,7 +7677,7 @@ pub fn funcTypeParamsLen(ip: *const InternPool, i: Index) u32 { return ip.extra.items[start + std.meta.fieldIndex(Tag.TypeFunction, "params_len").?]; } -fn unwrapCoercedFunc(ip: *const InternPool, i: Index) Index { +pub fn unwrapCoercedFunc(ip: *const InternPool, i: Index) Index { const tags = ip.items.items(.tag); return switch (tags[@intFromEnum(i)]) { .func_coerced => { diff --git a/src/Zir.zig b/lib/std/zig/Zir.zig similarity index 99% rename from src/Zir.zig rename to lib/std/zig/Zir.zig index 8d885ff69226..affe3e6154ef 100644 --- a/src/Zir.zig +++ b/lib/std/zig/Zir.zig @@ -19,10 +19,8 @@ const BigIntConst = std.math.big.int.Const; const BigIntMutable = std.math.big.int.Mutable; const Ast = std.zig.Ast; -const InternPool = @import("InternPool.zig"); +const InternPool = std.zig.InternPool; const Zir = @This(); -const Module = @import("Module.zig"); -const LazySrcLoc = Module.LazySrcLoc; instructions: std.MultiArrayList(Inst).Slice, /// In order to store references to strings in fewer bytes, we copy all @@ -2246,54 +2244,71 @@ pub const Inst = struct { /// this union. `Tag` determines which union field is active, as well as /// how to interpret the data within. pub const Data = union { - /// Used for `Tag.extended`. The extended opcode determines the meaning - /// of the `small` and `operand` fields. - extended: Extended.InstData, - /// Used for unary operators, with an AST node source location. - un_node: struct { - /// Offset from Decl AST node index. - src_node: i32, - /// The meaning of this operand depends on the corresponding `Tag`. - operand: Ref, - - pub fn src(self: @This()) LazySrcLoc { - return LazySrcLoc.nodeOffset(self.src_node); - } - }, - /// Used for unary operators, with a token source location. - un_tok: struct { + pub const UnTok = struct { /// Offset from Decl AST token index. src_tok: Ast.TokenIndex, /// The meaning of this operand depends on the corresponding `Tag`. operand: Ref, + }; - pub fn src(self: @This()) LazySrcLoc { - return .{ .token_offset = self.src_tok }; - } - }, - pl_node: struct { + pub const PlNode = struct { /// Offset from Decl AST node index. /// `Tag` determines which kind of AST node this points to. src_node: i32, /// index into extra. /// `Tag` determines what lives there. payload_index: u32, + }; - pub fn src(self: @This()) LazySrcLoc { - return LazySrcLoc.nodeOffset(self.src_node); - } - }, - pl_tok: struct { + pub const PlTok = struct { /// Offset from Decl AST token index. src_tok: Ast.TokenIndex, /// index into extra. /// `Tag` determines what lives there. payload_index: u32, + }; + + pub const StrTok = struct { + /// Offset into `string_bytes`. Null-terminated. + start: u32, + /// Offset from Decl AST token index. + src_tok: u32, - pub fn src(self: @This()) LazySrcLoc { - return .{ .token_offset = self.src_tok }; + pub fn get(self: @This(), code: Zir) [:0]const u8 { + return code.nullTerminatedString(self.start); } - }, + }; + + pub const IntType = struct { + /// Offset from Decl AST node index. + /// `Tag` determines which kind of AST node this points to. + src_node: i32, + signedness: std.builtin.Signedness, + bit_count: u16, + }; + + pub const Unreachable = struct { + /// Offset from Decl AST node index. + /// `Tag` determines which kind of AST node this points to. + src_node: i32, + }; + + pub const InstNode = struct { + /// Offset from Decl AST node index. + src_node: i32, + /// The meaning of this operand depends on the corresponding `Tag`. + inst: Index, + }; + + /// Used for `Tag.extended`. The extended opcode determines the meaning + /// of the `small` and `operand` fields. + extended: Extended.InstData, + /// Used for unary operators, with an AST node source location. + un_node: UnNode.InstData, + /// Used for unary operators, with a token source location. + un_tok: UnTok, + pl_node: PlNode, + pl_tok: PlTok, bin: Bin, /// For strings which may contain null bytes. str: struct { @@ -2306,20 +2321,7 @@ pub const Inst = struct { return code.string_bytes[self.start..][0..self.len]; } }, - str_tok: struct { - /// Offset into `string_bytes`. Null-terminated. - start: u32, - /// Offset from Decl AST token index. - src_tok: u32, - - pub fn get(self: @This(), code: Zir) [:0]const u8 { - return code.nullTerminatedString(self.start); - } - - pub fn src(self: @This()) LazySrcLoc { - return .{ .token_offset = self.src_tok }; - } - }, + str_tok: StrTok, /// Offset from Decl AST token index. tok: Ast.TokenIndex, /// Offset from Decl AST node index. @@ -2341,31 +2343,13 @@ pub const Inst = struct { /// Index into extra. See `PtrType`. payload_index: u32, }, - int_type: struct { - /// Offset from Decl AST node index. - /// `Tag` determines which kind of AST node this points to. - src_node: i32, - signedness: std.builtin.Signedness, - bit_count: u16, - - pub fn src(self: @This()) LazySrcLoc { - return LazySrcLoc.nodeOffset(self.src_node); - } - }, + int_type: IntType, bool_br: struct { lhs: Ref, /// Points to a `Block`. payload_index: u32, }, - @"unreachable": struct { - /// Offset from Decl AST node index. - /// `Tag` determines which kind of AST node this points to. - src_node: i32, - - pub fn src(self: @This()) LazySrcLoc { - return LazySrcLoc.nodeOffset(self.src_node); - } - }, + @"unreachable": Unreachable, @"break": struct { operand: Ref, payload_index: u32, @@ -2373,16 +2357,7 @@ pub const Inst = struct { dbg_stmt: LineColumn, /// Used for unary operators which reference an inst, /// with an AST node source location. - inst_node: struct { - /// Offset from Decl AST node index. - src_node: i32, - /// The meaning of this operand depends on the corresponding `Tag`. - inst: Index, - - pub fn src(self: @This()) LazySrcLoc { - return LazySrcLoc.nodeOffset(self.src_node); - } - }, + inst_node: InstNode, str_op: struct { /// Offset into `string_bytes`. Null-terminated. str: u32, @@ -2776,6 +2751,13 @@ pub const Inst = struct { pub const UnNode = struct { node: i32, operand: Ref, + + pub const InstData = struct { + /// Offset from Decl AST node index. + src_node: i32, + /// The meaning of this operand depends on the corresponding `Tag`. + operand: Ref, + }; }; pub const ElemPtrImm = struct { diff --git a/src/Air.zig b/src/Air.zig index 8e867e4b4111..164a90ecfd4c 100644 --- a/src/Air.zig +++ b/src/Air.zig @@ -10,7 +10,7 @@ const assert = std.debug.assert; const Air = @This(); const Value = @import("value.zig").Value; const Type = @import("type.zig").Type; -const InternPool = @import("InternPool.zig"); +const InternPool = std.zig.InternPool; const Module = @import("Module.zig"); instructions: std.MultiArrayList(Inst).Slice, diff --git a/src/Autodoc.zig b/src/Autodoc.zig index 9ea484ba1355..711ca6f39447 100644 --- a/src/Autodoc.zig +++ b/src/Autodoc.zig @@ -8,8 +8,8 @@ const CompilationModule = @import("Module.zig"); const File = CompilationModule.File; const Module = @import("Package.zig").Module; const Tokenizer = std.zig.Tokenizer; -const InternPool = @import("InternPool.zig"); -const Zir = @import("Zir.zig"); +const InternPool = std.zig.InternPool; +const Zir = std.zig.Zir; const Ref = Zir.Inst.Ref; const log = std.log.scoped(.autodoc); const renderer = @import("autodoc/render_source.zig"); diff --git a/src/Compilation.zig b/src/Compilation.zig index 598f7a5a8b19..4c44ad0d5eb1 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -29,12 +29,12 @@ const wasi_libc = @import("wasi_libc.zig"); const fatal = @import("main.zig").fatal; const clangMain = @import("main.zig").clangMain; const Module = @import("Module.zig"); -const InternPool = @import("InternPool.zig"); +const InternPool = std.zig.InternPool; const BuildId = std.Build.CompileStep.BuildId; const Cache = std.Build.Cache; const c_codegen = @import("codegen/c.zig"); const libtsan = @import("libtsan.zig"); -const Zir = @import("Zir.zig"); +const Zir = std.zig.Zir; const Autodoc = @import("Autodoc.zig"); const Color = @import("main.zig").Color; const resinator = @import("resinator.zig"); @@ -2512,7 +2512,7 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void std.debug.print("intern pool stats for '{s}':\n", .{ comp.bin_file.options.root_name, }); - module.intern_pool.dump(); + module.dump(); } if (builtin.mode == .Debug and comp.verbose_generic_instances) { @@ -2520,7 +2520,7 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void comp.bin_file.options.root_name, @as(usize, @intFromPtr(module)), }); - module.intern_pool.dumpGenericInstances(comp.gpa); + module.dumpGenericInstances(); } if (comp.bin_file.options.is_test and comp.totalErrorCount() == 0) { diff --git a/src/Liveness.zig b/src/Liveness.zig index 36c45ccbfcb1..ee33d27fc880 100644 --- a/src/Liveness.zig +++ b/src/Liveness.zig @@ -14,7 +14,7 @@ const Log2Int = std.math.Log2Int; const Liveness = @This(); const trace = @import("tracy.zig").trace; const Air = @import("Air.zig"); -const InternPool = @import("InternPool.zig"); +const InternPool = std.zig.InternPool; pub const Verify = @import("Liveness/Verify.zig"); diff --git a/src/Liveness/Verify.zig b/src/Liveness/Verify.zig index ec1b621f53e6..409bf54d165a 100644 --- a/src/Liveness/Verify.zig +++ b/src/Liveness/Verify.zig @@ -602,5 +602,5 @@ const log = std.log.scoped(.liveness_verify); const Air = @import("../Air.zig"); const Liveness = @import("../Liveness.zig"); -const InternPool = @import("../InternPool.zig"); +const InternPool = std.zig.InternPool; const Verify = @This(); diff --git a/src/Module.zig b/src/Module.zig index f5850d7a3a85..bf3125e2162d 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -23,16 +23,16 @@ const TypedValue = @import("TypedValue.zig"); const Package = @import("Package.zig"); const link = @import("link.zig"); const Air = @import("Air.zig"); -const Zir = @import("Zir.zig"); +const Zir = std.zig.Zir; const trace = @import("tracy.zig").trace; -const AstGen = @import("AstGen.zig"); +const AstGen = std.zig.AstGen; const Sema = @import("Sema.zig"); const target_util = @import("target.zig"); const build_options = @import("build_options"); const Liveness = @import("Liveness.zig"); const isUpDir = @import("introspect.zig").isUpDir; const clang = @import("clang.zig"); -const InternPool = @import("InternPool.zig"); +const InternPool = std.zig.InternPool; const Alignment = InternPool.Alignment; const BuiltinFn = std.zig.BuiltinFn; @@ -69,14 +69,14 @@ local_zir_cache: Compilation.Directory, /// map of Decl indexes to details about them being exported. /// The Export memory is owned by the `export_owners` table; the slice itself /// is owned by this table. The slice is guaranteed to not be empty. -decl_exports: std.AutoArrayHashMapUnmanaged(Decl.Index, ArrayListUnmanaged(*Export)) = .{}, +decl_exports: std.AutoArrayHashMapUnmanaged(InternPool.DeclIndex, ArrayListUnmanaged(*Export)) = .{}, /// Same as `decl_exports` but for exported constant values. value_exports: std.AutoArrayHashMapUnmanaged(InternPool.Index, ArrayListUnmanaged(*Export)) = .{}, /// This models the Decls that perform exports, so that `decl_exports` can be updated when a Decl /// is modified. Note that the key of this table is not the Decl being exported, but the Decl that /// is performing the export of another Decl. /// This table owns the Export memory. -export_owners: std.AutoArrayHashMapUnmanaged(Decl.Index, ArrayListUnmanaged(*Export)) = .{}, +export_owners: std.AutoArrayHashMapUnmanaged(InternPool.DeclIndex, ArrayListUnmanaged(*Export)) = .{}, /// The set of all the Zig source files in the Module. We keep track of this in order /// to iterate over it and check which source files have been modified on the file system when /// an update is requested, as well as to cache `@import` results. @@ -116,10 +116,10 @@ tmp_hack_arena: std.heap.ArenaAllocator, /// The ErrorMsg memory is owned by the decl, using Module's general purpose allocator. /// Note that a Decl can succeed but the Fn it represents can fail. In this case, /// a Decl can have a failed_decls entry but have analysis status of success. -failed_decls: std.AutoArrayHashMapUnmanaged(Decl.Index, *ErrorMsg) = .{}, +failed_decls: std.AutoArrayHashMapUnmanaged(InternPool.DeclIndex, *ErrorMsg) = .{}, /// Keep track of one `@compileLog` callsite per owner Decl. /// The value is the AST node index offset from the Decl. -compile_log_decls: std.AutoArrayHashMapUnmanaged(Decl.Index, i32) = .{}, +compile_log_decls: std.AutoArrayHashMapUnmanaged(InternPool.DeclIndex, i32) = .{}, /// Using a map here for consistency with the other fields here. /// The ErrorMsg memory is owned by the `File`, using Module's general purpose allocator. failed_files: std.AutoArrayHashMapUnmanaged(*File, ?*ErrorMsg) = .{}, @@ -130,7 +130,7 @@ failed_embed_files: std.AutoArrayHashMapUnmanaged(*EmbedFile, *ErrorMsg) = .{}, failed_exports: std.AutoArrayHashMapUnmanaged(*Export, *ErrorMsg) = .{}, /// If a decl failed due to a cimport error, the corresponding Clang errors /// are stored here. -cimport_errors: std.AutoArrayHashMapUnmanaged(Decl.Index, std.zig.ErrorBundle) = .{}, +cimport_errors: std.AutoArrayHashMapUnmanaged(InternPool.DeclIndex, std.zig.ErrorBundle) = .{}, /// Key is the error name, index is the error tag value. Index 0 has a length-0 string. global_error_set: GlobalErrorSet = .{}, @@ -143,6 +143,25 @@ error_limit: ErrorInt, /// previous analysis. generation: u32 = 0, +/// Rather than allocating Decl objects with an Allocator, we instead allocate +/// them with this SegmentedList. This provides four advantages: +/// * Stable memory so that one thread can access a Decl object while another +/// thread allocates additional Decl objects from this list. +/// * It allows us to use u32 indexes to reference Decl objects rather than +/// pointers, saving memory in Type, Value, and dependency sets. +/// * Using integers to reference Decl objects rather than pointers makes +/// serialization trivial. +/// * It provides a unique integer to be used for anonymous symbol names, avoiding +/// multi-threaded contention on an atomic counter. +allocated_decls: std.SegmentedList(Decl, 0) = .{}, +/// When a Decl object is freed from `allocated_decls`, it is pushed into this stack. +decls_free_list: std.ArrayListUnmanaged(InternPool.DeclIndex) = .{}, + +/// Same pattern as with `allocated_decls`. +allocated_namespaces: std.SegmentedList(Namespace, 0) = .{}, +/// Same pattern as with `decls_free_list`. +namespaces_free_list: std.ArrayListUnmanaged(InternPool.NamespaceIndex) = .{}, + stage1_flags: packed struct { have_winmain: bool = false, have_wwinmain: bool = false, @@ -159,16 +178,16 @@ compile_log_text: ArrayListUnmanaged(u8) = .{}, emit_h: ?*GlobalEmitH, -test_functions: std.AutoArrayHashMapUnmanaged(Decl.Index, void) = .{}, +test_functions: std.AutoArrayHashMapUnmanaged(InternPool.DeclIndex, void) = .{}, -global_assembly: std.AutoArrayHashMapUnmanaged(Decl.Index, []u8) = .{}, +global_assembly: std.AutoArrayHashMapUnmanaged(InternPool.DeclIndex, []u8) = .{}, -reference_table: std.AutoHashMapUnmanaged(Decl.Index, struct { - referencer: Decl.Index, +reference_table: std.AutoHashMapUnmanaged(InternPool.DeclIndex, struct { + referencer: InternPool.DeclIndex, src: LazySrcLoc, }) = .{}, -panic_messages: [PanicId.len]Decl.OptionalIndex = .{.none} ** PanicId.len, +panic_messages: [PanicId.len]InternPool.OptionalDeclIndex = .{.none} ** PanicId.len, /// The panic function body. panic_func_index: InternPool.Index = .none, null_stack_trace: InternPool.Index = .none, @@ -227,15 +246,15 @@ pub const GlobalEmitH = struct { /// When emit_h is non-null, each Decl gets one more compile error slot for /// emit-h failing for that Decl. This table is also how we tell if a Decl has /// failed emit-h or succeeded. - failed_decls: std.AutoArrayHashMapUnmanaged(Decl.Index, *ErrorMsg) = .{}, + failed_decls: std.AutoArrayHashMapUnmanaged(InternPool.DeclIndex, *ErrorMsg) = .{}, /// Tracks all decls in order to iterate over them and emit .h code for them. - decl_table: std.AutoArrayHashMapUnmanaged(Decl.Index, void) = .{}, + decl_table: std.AutoArrayHashMapUnmanaged(InternPool.DeclIndex, void) = .{}, /// Similar to the allocated_decls field of Module, this is where `EmitH` objects /// are allocated. There will be exactly one EmitH object per Decl object, with /// identical indexes. allocated_emit_h: std.SegmentedList(EmitH, 0) = .{}, - pub fn declPtr(global_emit_h: *GlobalEmitH, decl_index: Decl.Index) *EmitH { + pub fn declPtr(global_emit_h: *GlobalEmitH, decl_index: InternPool.DeclIndex) *EmitH { return global_emit_h.allocated_emit_h.at(@intFromEnum(decl_index)); } }; @@ -244,7 +263,7 @@ pub const ErrorInt = u32; pub const Exported = union(enum) { /// The Decl being exported. Note this is *not* the Decl performing the export. - decl_index: Decl.Index, + decl_index: InternPool.DeclIndex, /// Constant value being exported. value: InternPool.Index, }; @@ -253,10 +272,10 @@ pub const Export = struct { opts: Options, src: LazySrcLoc, /// The Decl that performs the export. Note that this is *not* the Decl being exported. - owner_decl: Decl.Index, + owner_decl: InternPool.DeclIndex, /// The Decl containing the export statement. Inline function calls /// may cause this to be different from the owner_decl. - src_decl: Decl.Index, + src_decl: InternPool.DeclIndex, exported: Exported, status: enum { in_progress, @@ -364,7 +383,7 @@ pub const Decl = struct { /// Reference to externally owned memory. /// In the case of the Decl corresponding to a file, this is /// the namespace of the struct, since there is no parent. - src_namespace: Namespace.Index, + src_namespace: InternPool.NamespaceIndex, /// The scope which lexically contains this decl. A decl must depend /// on its lexical parent, in order to ensure that this pointer is valid. @@ -600,7 +619,7 @@ pub const Decl = struct { const ip = &mod.intern_pool; const count = count: { var count: usize = ip.stringToSlice(decl.name).len + 1; - var ns: Namespace.Index = decl.src_namespace; + var ns: InternPool.NamespaceIndex = decl.src_namespace; while (true) { const namespace = mod.namespacePtr(ns); const ns_decl = mod.declPtr(namespace.getDeclIndex(mod)); @@ -693,7 +712,7 @@ pub const Decl = struct { /// Gets the namespace that this Decl creates by being a struct, union, /// enum, or opaque. - pub fn getInnerNamespaceIndex(decl: Decl, mod: *Module) Namespace.OptionalIndex { + pub fn getInnerNamespaceIndex(decl: Decl, mod: *Module) InternPool.OptionalNamespaceIndex { if (!decl.has_tv) return .none; return switch (decl.val.ip_index) { .empty_struct_type => .none, @@ -709,7 +728,7 @@ pub const Decl = struct { } /// Like `getInnerNamespaceIndex`, but only returns it if the Decl is the owner. - pub fn getOwnedInnerNamespaceIndex(decl: Decl, mod: *Module) Namespace.OptionalIndex { + pub fn getOwnedInnerNamespaceIndex(decl: Decl, mod: *Module) InternPool.OptionalNamespaceIndex { if (!decl.owns_tv) return .none; return decl.getInnerNamespaceIndex(mod); } @@ -743,15 +762,15 @@ pub const Decl = struct { return mod.namespacePtr(decl.src_namespace).file_scope; } - pub fn removeDependant(decl: *Decl, other: Decl.Index) void { + pub fn removeDependant(decl: *Decl, other: InternPool.DeclIndex) void { assert(decl.dependants.swapRemove(other)); } - pub fn removeDependency(decl: *Decl, other: Decl.Index) void { + pub fn removeDependency(decl: *Decl, other: InternPool.DeclIndex) void { assert(decl.dependencies.swapRemove(other)); } - pub fn getExternDecl(decl: Decl, mod: *Module) OptionalIndex { + pub fn getExternDecl(decl: Decl, mod: *Module) InternPool.OptionalDeclIndex { assert(decl.has_tv); return switch (mod.intern_pool.indexToKey(decl.val.toIntern())) { .variable => |variable| if (variable.is_extern) variable.decl.toOptional() else .none, @@ -784,7 +803,7 @@ pub const DeclAdapter = struct { return std.hash.uint32(@intFromEnum(s)); } - pub fn eql(self: @This(), a: InternPool.NullTerminatedString, b_decl_index: Decl.Index, b_index: usize) bool { + pub fn eql(self: @This(), a: InternPool.NullTerminatedString, b_decl_index: InternPool.DeclIndex, b_index: usize) bool { _ = b_index; const b_decl = self.mod.declPtr(b_decl_index); return a == b_decl.name; @@ -793,7 +812,7 @@ pub const DeclAdapter = struct { /// The container that structs, enums, unions, and opaques have. pub const Namespace = struct { - parent: OptionalIndex, + parent: InternPool.OptionalNamespaceIndex, file_scope: *File, /// Will be a struct, enum, union, or opaque. ty: Type, @@ -802,7 +821,7 @@ pub const Namespace = struct { /// Declaration order is preserved via entry order. /// These are only declarations named directly by the AST; anonymous /// declarations are not stored here. - decls: std.ArrayHashMapUnmanaged(Decl.Index, void, DeclContext, true) = .{}, + decls: std.ArrayHashMapUnmanaged(InternPool.DeclIndex, void, DeclContext, true) = .{}, /// Key is usingnamespace Decl itself. To find the namespace being included, /// the Decl Value has to be resolved as a Type which has a Namespace. @@ -815,12 +834,12 @@ pub const Namespace = struct { const DeclContext = struct { module: *Module, - pub fn hash(ctx: @This(), decl_index: Decl.Index) u32 { + pub fn hash(ctx: @This(), decl_index: InternPool.DeclIndex) u32 { const decl = ctx.module.declPtr(decl_index); return std.hash.uint32(@intFromEnum(decl.name)); } - pub fn eql(ctx: @This(), a_decl_index: Decl.Index, b_decl_index: Decl.Index, b_index: usize) bool { + pub fn eql(ctx: @This(), a_decl_index: InternPool.DeclIndex, b_decl_index: InternPool.DeclIndex, b_index: usize) bool { _ = b_index; const a_decl = ctx.module.declPtr(a_decl_index); const b_decl = ctx.module.declPtr(b_decl_index); @@ -862,14 +881,14 @@ pub const Namespace = struct { if (name != .empty) try writer.print("{c}{}", .{ separator_char, name.fmt(&mod.intern_pool) }); } - pub fn getDeclIndex(ns: Namespace, mod: *Module) Decl.Index { + pub fn getDeclIndex(ns: Namespace, mod: *Module) InternPool.DeclIndex { return ns.ty.getOwnerDecl(mod); } }; pub const File = struct { /// The Decl of the struct that represents this File. - root_decl: Decl.OptionalIndex, + root_decl: InternPool.OptionalDeclIndex, status: enum { never_loaded, retryable_failure, @@ -900,11 +919,11 @@ pub const File = struct { /// Used by change detection algorithm, after astgen, contains the /// set of decls that existed in the previous ZIR but not in the new one. - deleted_decls: ArrayListUnmanaged(Decl.Index) = .{}, + deleted_decls: ArrayListUnmanaged(InternPool.DeclIndex) = .{}, /// Used by change detection algorithm, after astgen, contains the /// set of decls that existed both in the previous ZIR and in the new one, /// but their source code has been modified. - outdated_decls: ArrayListUnmanaged(Decl.Index) = .{}, + outdated_decls: ArrayListUnmanaged(InternPool.DeclIndex) = .{}, /// The most recent successful ZIR for this file, with no errors. /// This is only populated when a previously successful ZIR @@ -2284,14 +2303,14 @@ pub const LazySrcLoc = union(enum) { for_capture_from_input: i32, /// The source location points to the argument node of a function call. call_arg: struct { - decl: Decl.Index, + decl: InternPool.DeclIndex, /// Points to the function call AST node. call_node_offset: i32, /// The index of the argument the source location points to. arg_index: u32, }, fn_proto_param: struct { - decl: Decl.Index, + decl: InternPool.DeclIndex, /// Points to the function prototype AST node. fn_proto_node_offset: i32, /// The index of the parameter the source location points to. @@ -2401,6 +2420,38 @@ pub const LazySrcLoc = union(enum) { }, }; } + + pub fn fromUnNode(un_node: Zir.Inst.UnNode.InstData) LazySrcLoc { + return LazySrcLoc.nodeOffset(un_node.src_node); + } + + pub fn fromPlNode(pl_node: Zir.Inst.Data.PlNode) LazySrcLoc { + return LazySrcLoc.nodeOffset(pl_node.src_node); + } + + pub fn fromIntType(int_type: Zir.Inst.Data.IntType) LazySrcLoc { + return LazySrcLoc.nodeOffset(int_type.src_node); + } + + pub fn fromUnreachable(@"unreachable": Zir.Inst.Data.Unreachable) LazySrcLoc { + return LazySrcLoc.nodeOffset(@"unreachable".src_node); + } + + pub fn fromInstNode(inst_node: Zir.Inst.Data.InstNode) LazySrcLoc { + return LazySrcLoc.nodeOffset(inst_node.src_node); + } + + pub fn fromUnTok(un_tok: Zir.Inst.Data.UnTok) LazySrcLoc { + return .{ .token_offset = un_tok.src_tok }; + } + + pub fn fromPlTok(pl_tok: Zir.Inst.Data.PlTok) LazySrcLoc { + return .{ .token_offset = pl_tok.src_tok }; + } + + pub fn fromStrTok(str_tok: Zir.Inst.Data.StrTok) LazySrcLoc { + return .{ .token_offset = str_tok.src_tok }; + } }; pub const SemaError = error{ OutOfMemory, AnalysisFail }; @@ -2524,7 +2575,7 @@ pub fn deinit(mod: *Module) void { mod.reference_table.deinit(gpa); { - var it = mod.intern_pool.allocated_namespaces.iterator(0); + var it = mod.allocated_namespaces.iterator(0); while (it.next()) |namespace| { namespace.decls.deinit(gpa); namespace.usingnamespace_set.deinit(gpa); @@ -2537,11 +2588,66 @@ pub fn deinit(mod: *Module) void { mod.capture_scope_parents.deinit(gpa); mod.runtime_capture_scopes.deinit(gpa); mod.comptime_capture_scopes.deinit(gpa); + + mod.decls_free_list.deinit(gpa); + mod.allocated_decls.deinit(gpa); + + mod.namespaces_free_list.deinit(gpa); + mod.allocated_namespaces.deinit(gpa); +} + +pub fn declPtr(mod: *Module, index: InternPool.DeclIndex) *Module.Decl { + return mod.allocated_decls.at(@intFromEnum(index)); +} + +pub fn declPtrConst(mod: *const Module, index: InternPool.DeclIndex) *const Module.Decl { + return mod.allocated_decls.at(@intFromEnum(index)); +} + +pub fn namespacePtr(mod: *Module, index: InternPool.NamespaceIndex) *Module.Namespace { + return mod.allocated_namespaces.at(@intFromEnum(index)); +} + +pub fn createDecl( + mod: *Module, + initialization: Module.Decl, +) Allocator.Error!InternPool.DeclIndex { + if (mod.decls_free_list.popOrNull()) |index| { + mod.allocated_decls.at(@intFromEnum(index)).* = initialization; + return index; + } + const ptr = try mod.allocated_decls.addOne(mod.gpa); + ptr.* = initialization; + return @enumFromInt(mod.allocated_decls.len - 1); +} + +pub fn createNamespace( + mod: *Module, + initialization: Module.Namespace, +) Allocator.Error!InternPool.NamespaceIndex { + if (mod.namespaces_free_list.popOrNull()) |index| { + mod.allocated_namespaces.at(@intFromEnum(index)).* = initialization; + return index; + } + const ptr = try mod.allocated_namespaces.addOne(mod.gpa); + ptr.* = initialization; + return @enumFromInt(mod.allocated_namespaces.len - 1); +} + +pub fn destroyNamespace(mod: *Module, index: InternPool.NamespaceIndex) void { + mod.namespacePtr(index).* = .{ + .parent = undefined, + .file_scope = undefined, + .ty = undefined, + }; + mod.namespaces_free_list.append(mod.gpa, index) catch { + // In order to keep `destroyNamespace` a non-fallible function, we ignore memory + // allocation failures here, instead leaking the Namespace until garbage collection. + }; } -pub fn destroyDecl(mod: *Module, decl_index: Decl.Index) void { +pub fn destroyDecl(mod: *Module, decl_index: InternPool.DeclIndex) void { const gpa = mod.gpa; - const ip = &mod.intern_pool; { _ = mod.test_functions.swapRemove(decl_index); @@ -2550,7 +2656,11 @@ pub fn destroyDecl(mod: *Module, decl_index: Decl.Index) void { } } - ip.destroyDecl(gpa, decl_index); + mod.declPtr(decl_index).* = undefined; + mod.decls_free_list.append(gpa, decl_index) catch { + // In order to keep `destroyDecl` a non-fallible function, we ignore memory + // allocation failures here, instead leaking the Decl until garbage collection. + }; if (mod.emit_h) |mod_emit_h| { const decl_emit_h = mod_emit_h.declPtr(decl_index); @@ -2559,20 +2669,12 @@ pub fn destroyDecl(mod: *Module, decl_index: Decl.Index) void { } } -pub fn declPtr(mod: *Module, index: Decl.Index) *Decl { - return mod.intern_pool.declPtr(index); -} - -pub fn namespacePtr(mod: *Module, index: Namespace.Index) *Namespace { - return mod.intern_pool.namespacePtr(index); -} - -pub fn namespacePtrUnwrap(mod: *Module, index: Namespace.OptionalIndex) ?*Namespace { +pub fn namespacePtrUnwrap(mod: *Module, index: InternPool.OptionalNamespaceIndex) ?*Namespace { return mod.namespacePtr(index.unwrap() orelse return null); } /// Returns true if and only if the Decl is the top level struct associated with a File. -pub fn declIsRoot(mod: *Module, decl_index: Decl.Index) bool { +pub fn declIsRoot(mod: *Module, decl_index: InternPool.DeclIndex) bool { const decl = mod.declPtr(decl_index); const namespace = mod.namespacePtr(decl.src_namespace); if (namespace.parent != .none) @@ -2978,7 +3080,7 @@ fn updateZirRefs(mod: *Module, file: *File, old_zir: Zir) !void { // Walk the Decl graph, updating ZIR indexes, strings, and populating // the deleted and outdated lists. - var decl_stack: ArrayListUnmanaged(Decl.Index) = .{}; + var decl_stack: ArrayListUnmanaged(InternPool.DeclIndex) = .{}; defer decl_stack.deinit(gpa); try decl_stack.append(gpa, root_decl); @@ -3173,7 +3275,7 @@ pub fn mapOldZirToNew( /// However the resolution status of the Type may not be fully resolved. /// For example an inferred error set is not resolved until after `analyzeFnBody`. /// is called. -pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void { +pub fn ensureDeclAnalyzed(mod: *Module, decl_index: InternPool.DeclIndex) SemaError!void { const tracy = trace(@src()); defer tracy.end(); @@ -3485,7 +3587,7 @@ 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); + var comptime_mutable_decls = std.ArrayList(InternPool.DeclIndex).init(gpa); defer comptime_mutable_decls.deinit(); var sema: Sema = .{ @@ -3549,7 +3651,7 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void { /// Returns `true` if the Decl type changed. /// Returns `true` if this is the first time analyzing the Decl. /// Returns `false` otherwise. -fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool { +fn semaDecl(mod: *Module, decl_index: InternPool.DeclIndex) !bool { const tracy = trace(@src()); defer tracy.end(); @@ -3602,7 +3704,7 @@ 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); + var comptime_mutable_decls = std.ArrayList(InternPool.DeclIndex).init(gpa); defer comptime_mutable_decls.deinit(); var sema: Sema = .{ @@ -4129,7 +4231,7 @@ fn newEmbedFile( pub fn scanNamespace( mod: *Module, - namespace_index: Namespace.Index, + namespace_index: InternPool.NamespaceIndex, extra_start: usize, decls_len: u32, parent_decl: *Decl, @@ -4174,7 +4276,7 @@ pub fn scanNamespace( const ScanDeclIter = struct { module: *Module, - namespace_index: Namespace.Index, + namespace_index: InternPool.NamespaceIndex, parent_decl: *Decl, usingnamespace_index: usize = 0, comptime_index: usize = 0, @@ -4353,11 +4455,10 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err /// This function is exclusively called for anonymous decls. /// All resources referenced by anonymous decls are owned by InternPool /// so there is no cleanup to do here. -pub fn deleteUnusedDecl(mod: *Module, decl_index: Decl.Index) void { +pub fn deleteUnusedDecl(mod: *Module, decl_index: InternPool.DeclIndex) void { const gpa = mod.gpa; - const ip = &mod.intern_pool; - ip.destroyDecl(gpa, decl_index); + mod.destroyDecl(decl_index); if (mod.emit_h) |mod_emit_h| { const decl_emit_h = mod_emit_h.declPtr(decl_index); @@ -4368,13 +4469,13 @@ pub fn deleteUnusedDecl(mod: *Module, decl_index: Decl.Index) void { /// Cancel the creation of an anon decl and delete any references to it. /// If other decls depend on this decl, they must be aborted first. -pub fn abortAnonDecl(mod: *Module, decl_index: Decl.Index) void { +pub fn abortAnonDecl(mod: *Module, decl_index: InternPool.DeclIndex) void { assert(!mod.declIsRoot(decl_index)); mod.destroyDecl(decl_index); } /// Finalize the creation of an anon decl. -pub fn finalizeAnonDecl(mod: *Module, decl_index: Decl.Index) Allocator.Error!void { +pub fn finalizeAnonDecl(mod: *Module, decl_index: InternPool.DeclIndex) Allocator.Error!void { // The Decl starts off with alive=false and the codegen backend will set alive=true // if the Decl is referenced by an instruction or another constant. Otherwise, // the Decl will be garbage collected by the `codegen_decl` task instead of sent @@ -4386,7 +4487,7 @@ pub fn finalizeAnonDecl(mod: *Module, decl_index: Decl.Index) Allocator.Error!vo /// Delete all the Export objects that are caused by this Decl. Re-analysis of /// this Decl will cause them to be re-created (or not). -fn deleteDeclExports(mod: *Module, decl_index: Decl.Index) Allocator.Error!void { +fn deleteDeclExports(mod: *Module, decl_index: InternPool.DeclIndex) Allocator.Error!void { var export_owners = (mod.export_owners.fetchSwapRemove(decl_index) orelse return).value; for (export_owners.items) |exp| { @@ -4451,7 +4552,7 @@ 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); + var comptime_mutable_decls = std.ArrayList(InternPool.DeclIndex).init(gpa); defer comptime_mutable_decls.deinit(); // In the case of a generic function instance, this is the type of the @@ -4690,7 +4791,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato }; } -fn markOutdatedDecl(mod: *Module, decl_index: Decl.Index) !void { +fn markOutdatedDecl(mod: *Module, decl_index: InternPool.DeclIndex) !void { const decl = mod.declPtr(decl_index); try mod.comp.work_queue.writeItem(.{ .analyze_decl = decl_index }); if (mod.failed_decls.fetchSwapRemove(decl_index)) |kv| { @@ -4709,23 +4810,14 @@ fn markOutdatedDecl(mod: *Module, decl_index: Decl.Index) !void { decl.analysis = .outdated; } -pub fn createNamespace(mod: *Module, initialization: Namespace) !Namespace.Index { - return mod.intern_pool.createNamespace(mod.gpa, initialization); -} - -pub fn destroyNamespace(mod: *Module, index: Namespace.Index) void { - return mod.intern_pool.destroyNamespace(mod.gpa, index); -} - pub fn allocateNewDecl( mod: *Module, - namespace: Namespace.Index, + namespace: InternPool.NamespaceIndex, src_node: Ast.Node.Index, src_scope: CaptureScope.Index, -) !Decl.Index { - const ip = &mod.intern_pool; +) !InternPool.DeclIndex { const gpa = mod.gpa; - const decl_index = try ip.createDecl(gpa, .{ + const decl_index = try mod.createDecl(.{ .name = undefined, .src_namespace = namespace, .src_node = src_node, @@ -4780,7 +4872,7 @@ pub fn errorSetBits(mod: *Module) u16 { return std.math.log2_int_ceil(ErrorInt, mod.error_limit + 1); // +1 for no error } -pub fn createAnonymousDecl(mod: *Module, block: *Sema.Block, typed_value: TypedValue) !Decl.Index { +pub fn createAnonymousDecl(mod: *Module, block: *Sema.Block, typed_value: TypedValue) !InternPool.DeclIndex { const src_decl = mod.declPtr(block.src_decl); return mod.createAnonymousDeclFromDecl(src_decl, block.namespace, block.wip_capture_scope, typed_value); } @@ -4788,10 +4880,10 @@ pub fn createAnonymousDecl(mod: *Module, block: *Sema.Block, typed_value: TypedV pub fn createAnonymousDeclFromDecl( mod: *Module, src_decl: *Decl, - namespace: Namespace.Index, + namespace: InternPool.NamespaceIndex, src_scope: CaptureScope.Index, tv: TypedValue, -) !Decl.Index { +) !InternPool.DeclIndex { const new_decl_index = try mod.allocateNewDecl(namespace, src_decl.src_node, src_scope); errdefer mod.destroyDecl(new_decl_index); const name = try mod.intern_pool.getOrPutStringFmt(mod.gpa, "{}__anon_{d}", .{ @@ -4803,7 +4895,7 @@ pub fn createAnonymousDeclFromDecl( pub fn initNewAnonDecl( mod: *Module, - new_decl_index: Decl.Index, + new_decl_index: InternPool.DeclIndex, src_line: u32, typed_value: TypedValue, name: InternPool.NullTerminatedString, @@ -5338,7 +5430,7 @@ pub fn populateTestFunctions( defer gpa.free(test_fn_vals); // Add a dependency on each test name and function pointer. - var array_decl_dependencies = std.ArrayListUnmanaged(Decl.Index){}; + var array_decl_dependencies = std.ArrayListUnmanaged(InternPool.DeclIndex){}; defer array_decl_dependencies.deinit(gpa); try array_decl_dependencies.ensureUnusedCapacity(gpa, test_fn_vals.len * 2); @@ -5436,7 +5528,7 @@ pub fn populateTestFunctions( try mod.linkerUpdateDecl(decl_index); } -pub fn linkerUpdateDecl(mod: *Module, decl_index: Decl.Index) !void { +pub fn linkerUpdateDecl(mod: *Module, decl_index: InternPool.DeclIndex) !void { const comp = mod.comp; const no_bin_file = (comp.bin_file.options.emit == null and @@ -5546,11 +5638,11 @@ pub fn markDeclAlive(mod: *Module, decl: *Decl) Allocator.Error!void { try mod.markReferencedDeclsAlive(decl.val); } -fn markDeclIndexAlive(mod: *Module, decl_index: Decl.Index) Allocator.Error!void { +fn markDeclIndexAlive(mod: *Module, decl_index: InternPool.DeclIndex) Allocator.Error!void { return mod.markDeclAlive(mod.declPtr(decl_index)); } -pub fn addGlobalAssembly(mod: *Module, decl_index: Decl.Index, source: []const u8) !void { +pub fn addGlobalAssembly(mod: *Module, decl_index: InternPool.DeclIndex, source: []const u8) !void { const gop = try mod.global_assembly.getOrPut(mod.gpa, decl_index); if (gop.found_existing) { const new_value = try std.fmt.allocPrint(mod.gpa, "{s}\n{s}", .{ gop.value_ptr.*, source }); @@ -5565,7 +5657,7 @@ pub fn wantDllExports(mod: Module) bool { return mod.comp.bin_file.options.dll_export_fns and mod.getTarget().os.tag == .windows; } -pub fn getDeclExports(mod: Module, decl_index: Decl.Index) []const *Export { +pub fn getDeclExports(mod: Module, decl_index: InternPool.DeclIndex) []const *Export { if (mod.decl_exports.get(decl_index)) |l| { return l.items; } else { @@ -6070,11 +6162,11 @@ pub fn opaqueFullyQualifiedName(mod: *Module, opaque_type: InternPool.Key.Opaque return mod.declPtr(opaque_type.decl).getFullyQualifiedName(mod); } -pub fn declFileScope(mod: *Module, decl_index: Decl.Index) *File { +pub fn declFileScope(mod: *Module, decl_index: InternPool.DeclIndex) *File { return mod.declPtr(decl_index).getFileScope(mod); } -pub fn namespaceDeclIndex(mod: *Module, namespace_index: Namespace.Index) Decl.Index { +pub fn namespaceDeclIndex(mod: *Module, namespace_index: InternPool.NamespaceIndex) InternPool.DeclIndex { return mod.namespacePtr(namespace_index).getDeclIndex(mod); } @@ -6117,7 +6209,7 @@ pub fn funcOwnerDeclPtr(mod: *Module, func_index: InternPool.Index) *Decl { return mod.declPtr(mod.funcOwnerDeclIndex(func_index)); } -pub fn funcOwnerDeclIndex(mod: *Module, func_index: InternPool.Index) Decl.Index { +pub fn funcOwnerDeclIndex(mod: *Module, func_index: InternPool.Index) InternPool.DeclIndex { return mod.funcInfo(func_index).owner_decl; } @@ -6129,7 +6221,7 @@ pub fn funcInfo(mod: *Module, func_index: InternPool.Index) InternPool.Key.Func return mod.intern_pool.indexToKey(func_index).func; } -pub fn fieldSrcLoc(mod: *Module, owner_decl_index: Decl.Index, query: FieldSrcQuery) SrcLoc { +pub fn fieldSrcLoc(mod: *Module, owner_decl_index: InternPool.DeclIndex, query: FieldSrcQuery) SrcLoc { @setCold(true); const owner_decl = mod.declPtr(owner_decl_index); const file = owner_decl.getFileScope(mod); @@ -6363,3 +6455,379 @@ pub fn structPackedFieldBitOffset( } unreachable; // index out of bounds } + +pub fn dump(mod: *const Module) void { + mod.dumpStatsFallible(std.heap.page_allocator) catch return; + mod.dumpAllFallible() catch return; +} + +fn dumpStatsFallible(mod: *const Module, arena: Allocator) anyerror!void { + const ip = mod.intern_pool; + + const items_size = (1 + 4) * ip.items.len; + const extra_size = 4 * ip.extra.items.len; + const limbs_size = 8 * ip.limbs.items.len; + const decls_size = mod.allocated_decls.len * @sizeOf(Module.Decl); + + // TODO: map overhead size is not taken into account + const total_size = @sizeOf(InternPool) + items_size + extra_size + limbs_size + decls_size; + + std.debug.print( + \\InternPool size: {d} bytes + \\ {d} items: {d} bytes + \\ {d} extra: {d} bytes + \\ {d} limbs: {d} bytes + \\ {d} decls: {d} bytes + \\ + , .{ + total_size, + ip.items.len, + items_size, + ip.extra.items.len, + extra_size, + ip.limbs.items.len, + limbs_size, + mod.allocated_decls.len, + decls_size, + }); + + const tags = ip.items.items(.tag); + const datas = ip.items.items(.data); + const TagStats = struct { + count: usize = 0, + bytes: usize = 0, + }; + var counts = std.AutoArrayHashMap(InternPool.Tag, TagStats).init(arena); + for (tags, datas) |tag, data| { + const gop = try counts.getOrPut(tag); + if (!gop.found_existing) gop.value_ptr.* = .{}; + gop.value_ptr.count += 1; + gop.value_ptr.bytes += 1 + 4 + @as(usize, switch (tag) { + .type_int_signed => 0, + .type_int_unsigned => 0, + .type_array_small => @sizeOf(InternPool.Vector), + .type_array_big => @sizeOf(InternPool.Array), + .type_vector => @sizeOf(InternPool.Vector), + .type_pointer => @sizeOf(InternPool.Tag.TypePointer), + .type_slice => 0, + .type_optional => 0, + .type_anyframe => 0, + .type_error_union => @sizeOf(InternPool.Key.ErrorUnionType), + .type_anyerror_union => 0, + .type_error_set => b: { + const info = ip.extraData(InternPool.Tag.ErrorSet, data); + break :b @sizeOf(InternPool.Tag.ErrorSet) + (@sizeOf(u32) * info.names_len); + }, + .type_inferred_error_set => 0, + .type_enum_explicit, .type_enum_nonexhaustive => @sizeOf(InternPool.EnumExplicit), + .type_enum_auto => @sizeOf(InternPool.EnumAuto), + .type_opaque => @sizeOf(InternPool.Key.OpaqueType), + .type_struct => b: { + const info = ip.extraData(InternPool.Tag.TypeStruct, data); + var ints: usize = @typeInfo(InternPool.Tag.TypeStruct).Struct.fields.len; + ints += info.fields_len; // types + if (!info.flags.is_tuple) { + ints += 1; // names_map + ints += info.fields_len; // names + } + if (info.flags.any_default_inits) + ints += info.fields_len; // inits + ints += @intFromBool(info.flags.has_namespace); // namespace + if (info.flags.any_aligned_fields) + ints += (info.fields_len + 3) / 4; // aligns + if (info.flags.any_comptime_fields) + ints += (info.fields_len + 31) / 32; // comptime bits + if (!info.flags.is_extern) + ints += info.fields_len; // runtime order + ints += info.fields_len; // offsets + break :b @sizeOf(u32) * ints; + }, + .type_struct_ns => @sizeOf(Module.Namespace), + .type_struct_anon => b: { + const info = ip.extraData(InternPool.TypeStructAnon, data); + break :b @sizeOf(InternPool.TypeStructAnon) + (@sizeOf(u32) * 3 * info.fields_len); + }, + .type_struct_packed => b: { + const info = ip.extraData(InternPool.Tag.TypeStructPacked, data); + break :b @sizeOf(u32) * (@typeInfo(InternPool.Tag.TypeStructPacked).Struct.fields.len + + info.fields_len + info.fields_len); + }, + .type_struct_packed_inits => b: { + const info = ip.extraData(InternPool.Tag.TypeStructPacked, data); + break :b @sizeOf(u32) * (@typeInfo(InternPool.Tag.TypeStructPacked).Struct.fields.len + + info.fields_len + info.fields_len + info.fields_len); + }, + .type_tuple_anon => b: { + const info = ip.extraData(InternPool.TypeStructAnon, data); + break :b @sizeOf(InternPool.TypeStructAnon) + (@sizeOf(u32) * 2 * info.fields_len); + }, + + .type_union => b: { + const info = ip.extraData(InternPool.Tag.TypeUnion, data); + const enum_info = ip.indexToKey(info.tag_ty).enum_type; + const fields_len: u32 = @intCast(enum_info.names.len); + const per_field = @sizeOf(u32); // field type + // 1 byte per field for alignment, rounded up to the nearest 4 bytes + const alignments = if (info.flags.any_aligned_fields) + ((fields_len + 3) / 4) * 4 + else + 0; + break :b @sizeOf(InternPool.Tag.TypeUnion) + (fields_len * per_field) + alignments; + }, + + .type_function => b: { + const info = ip.extraData(InternPool.Tag.TypeFunction, data); + break :b @sizeOf(InternPool.Tag.TypeFunction) + + (@sizeOf(InternPool.Index) * info.params_len) + + (@as(u32, 4) * @intFromBool(info.flags.has_comptime_bits)) + + (@as(u32, 4) * @intFromBool(info.flags.has_noalias_bits)); + }, + + .undef => 0, + .simple_type => 0, + .simple_value => 0, + .ptr_decl => @sizeOf(InternPool.PtrDecl), + .ptr_mut_decl => @sizeOf(InternPool.PtrMutDecl), + .ptr_anon_decl => @sizeOf(InternPool.PtrAnonDecl), + .ptr_anon_decl_aligned => @sizeOf(InternPool.PtrAnonDeclAligned), + .ptr_comptime_field => @sizeOf(InternPool.PtrComptimeField), + .ptr_int => @sizeOf(InternPool.PtrBase), + .ptr_eu_payload => @sizeOf(InternPool.PtrBase), + .ptr_opt_payload => @sizeOf(InternPool.PtrBase), + .ptr_elem => @sizeOf(InternPool.PtrBaseIndex), + .ptr_field => @sizeOf(InternPool.PtrBaseIndex), + .ptr_slice => @sizeOf(InternPool.PtrSlice), + .opt_null => 0, + .opt_payload => @sizeOf(InternPool.Tag.TypeValue), + .int_u8 => 0, + .int_u16 => 0, + .int_u32 => 0, + .int_i32 => 0, + .int_usize => 0, + .int_comptime_int_u32 => 0, + .int_comptime_int_i32 => 0, + .int_small => @sizeOf(InternPool.IntSmall), + + .int_positive, + .int_negative, + => b: { + const int = ip.limbData(InternPool.Int, data); + break :b @sizeOf(InternPool.Int) + int.limbs_len * 8; + }, + + .int_lazy_align, .int_lazy_size => @sizeOf(InternPool.IntLazy), + + .error_set_error, .error_union_error => @sizeOf(InternPool.Key.Error), + .error_union_payload => @sizeOf(InternPool.Tag.TypeValue), + .enum_literal => 0, + .enum_tag => @sizeOf(InternPool.Tag.EnumTag), + + .bytes => b: { + const info = ip.extraData(InternPool.Bytes, data); + const len = @as(u32, @intCast(ip.aggregateTypeLenIncludingSentinel(info.ty))); + break :b @sizeOf(InternPool.Bytes) + len + + @intFromBool(ip.string_bytes.items[@intFromEnum(info.bytes) + len - 1] != 0); + }, + .aggregate => b: { + const info = ip.extraData(InternPool.Tag.Aggregate, data); + const fields_len: u32 = @intCast(ip.aggregateTypeLenIncludingSentinel(info.ty)); + break :b @sizeOf(InternPool.Tag.Aggregate) + (@sizeOf(InternPool.Index) * fields_len); + }, + .repeated => @sizeOf(InternPool.Repeated), + + .float_f16 => 0, + .float_f32 => 0, + .float_f64 => @sizeOf(InternPool.Float64), + .float_f80 => @sizeOf(InternPool.Float80), + .float_f128 => @sizeOf(InternPool.Float128), + .float_c_longdouble_f80 => @sizeOf(InternPool.Float80), + .float_c_longdouble_f128 => @sizeOf(InternPool.Float128), + .float_comptime_float => @sizeOf(InternPool.Float128), + .variable => @sizeOf(InternPool.Tag.Variable), + .extern_func => @sizeOf(InternPool.Tag.ExternFunc), + .func_decl => @sizeOf(InternPool.Tag.FuncDecl), + .func_instance => b: { + const info = ip.extraData(InternPool.Tag.FuncInstance, data); + const ty = ip.typeOf(info.generic_owner); + const params_len = ip.indexToKey(ty).func_type.param_types.len; + break :b @sizeOf(InternPool.Tag.FuncInstance) + @sizeOf(InternPool.Index) * params_len; + }, + .func_coerced => @sizeOf(InternPool.Tag.FuncCoerced), + .only_possible_value => 0, + .union_value => @sizeOf(InternPool.Key.Union), + + .memoized_call => b: { + const info = ip.extraData(InternPool.MemoizedCall, data); + break :b @sizeOf(InternPool.MemoizedCall) + (@sizeOf(InternPool.Index) * info.args_len); + }, + }); + } + const SortContext = struct { + map: *std.AutoArrayHashMap(InternPool.Tag, TagStats), + pub fn lessThan(ctx: @This(), a_index: usize, b_index: usize) bool { + const values = ctx.map.values(); + return values[a_index].bytes > values[b_index].bytes; + //return values[a_index].count > values[b_index].count; + } + }; + counts.sort(SortContext{ .map = &counts }); + const len = @min(50, counts.count()); + std.debug.print(" top 50 tags:\n", .{}); + for (counts.keys()[0..len], counts.values()[0..len]) |tag, stats| { + std.debug.print(" {s}: {d} occurrences, {d} total bytes\n", .{ + @tagName(tag), stats.count, stats.bytes, + }); + } +} + +fn dumpAllFallible(mod: *const Module) anyerror!void { + const ip = mod.intern_pool; + + const tags = ip.items.items(.tag); + const datas = ip.items.items(.data); + var bw = std.io.bufferedWriter(std.io.getStdErr().writer()); + const w = bw.writer(); + for (tags, datas, 0..) |tag, data, i| { + try w.print("${d} = {s}(", .{ i, @tagName(tag) }); + switch (tag) { + .simple_type => try w.print("{s}", .{@tagName(@as(InternPool.SimpleType, @enumFromInt(data)))}), + .simple_value => try w.print("{s}", .{@tagName(@as(InternPool.SimpleValue, @enumFromInt(data)))}), + + .type_int_signed, + .type_int_unsigned, + .type_array_small, + .type_array_big, + .type_vector, + .type_pointer, + .type_optional, + .type_anyframe, + .type_error_union, + .type_anyerror_union, + .type_error_set, + .type_inferred_error_set, + .type_enum_explicit, + .type_enum_nonexhaustive, + .type_enum_auto, + .type_opaque, + .type_struct, + .type_struct_ns, + .type_struct_anon, + .type_struct_packed, + .type_struct_packed_inits, + .type_tuple_anon, + .type_union, + .type_function, + .undef, + .ptr_decl, + .ptr_mut_decl, + .ptr_anon_decl, + .ptr_anon_decl_aligned, + .ptr_comptime_field, + .ptr_int, + .ptr_eu_payload, + .ptr_opt_payload, + .ptr_elem, + .ptr_field, + .ptr_slice, + .opt_payload, + .int_u8, + .int_u16, + .int_u32, + .int_i32, + .int_usize, + .int_comptime_int_u32, + .int_comptime_int_i32, + .int_small, + .int_positive, + .int_negative, + .int_lazy_align, + .int_lazy_size, + .error_set_error, + .error_union_error, + .error_union_payload, + .enum_literal, + .enum_tag, + .bytes, + .aggregate, + .repeated, + .float_f16, + .float_f32, + .float_f64, + .float_f80, + .float_f128, + .float_c_longdouble_f80, + .float_c_longdouble_f128, + .float_comptime_float, + .variable, + .extern_func, + .func_decl, + .func_instance, + .func_coerced, + .union_value, + .memoized_call, + => try w.print("{d}", .{data}), + + .opt_null, + .type_slice, + .only_possible_value, + => try w.print("${d}", .{data}), + } + try w.writeAll(")\n"); + } + try bw.flush(); +} + +pub fn dumpGenericInstances(mod: *const Module) void { + mod.dumpGenericInstancesFallible() catch return; +} + +pub fn dumpGenericInstancesFallible(mod: *const Module) anyerror!void { + var arena_allocator = std.heap.ArenaAllocator.init(mod.gpa); + defer arena_allocator.deinit(); + const arena = arena_allocator.allocator(); + + const ip = &mod.intern_pool; + + var bw = std.io.bufferedWriter(std.io.getStdErr().writer()); + const w = bw.writer(); + + var instances: std.AutoArrayHashMapUnmanaged(InternPool.Index, std.ArrayListUnmanaged(InternPool.Index)) = .{}; + const datas = ip.items.items(.data); + for (ip.items.items(.tag), 0..) |tag, i| { + if (tag != .func_instance) continue; + const info = ip.extraData(InternPool.Tag.FuncInstance, datas[i]); + + const gop = try instances.getOrPut(arena, info.generic_owner); + if (!gop.found_existing) gop.value_ptr.* = .{}; + + try gop.value_ptr.append(arena, @enumFromInt(i)); + } + + const SortContext = struct { + values: []std.ArrayListUnmanaged(InternPool.Index), + pub fn lessThan(ctx: @This(), a_index: usize, b_index: usize) bool { + return ctx.values[a_index].items.len > ctx.values[b_index].items.len; + } + }; + + instances.sort(SortContext{ .values = instances.values() }); + var it = instances.iterator(); + while (it.next()) |entry| { + const generic_fn_owner_decl = mod.declPtrConst(ip.funcDeclOwner(entry.key_ptr.*)); + try w.print("{} ({}): \n", .{ generic_fn_owner_decl.name.fmt(ip), entry.value_ptr.items.len }); + for (entry.value_ptr.items) |index| { + const func = ip.extraFuncInstance(datas[@intFromEnum(index)]); + const owner_decl = mod.declPtrConst(func.owner_decl); + try w.print(" {}: (", .{owner_decl.name.fmt(ip)}); + for (func.comptime_args.get(ip)) |arg| { + if (arg != .none) { + const key = ip.indexToKey(arg); + try w.print(" {} ", .{key}); + } + } + try w.writeAll(")\n"); + } + } + + try bw.flush(); +} diff --git a/src/RangeSet.zig b/src/RangeSet.zig index 158f81612964..8ef8d8e3d83d 100644 --- a/src/RangeSet.zig +++ b/src/RangeSet.zig @@ -2,7 +2,7 @@ const std = @import("std"); const assert = std.debug.assert; const Order = std.math.Order; -const InternPool = @import("InternPool.zig"); +const InternPool = std.zig.InternPool; const Type = @import("type.zig").Type; const Value = @import("value.zig").Value; const Module = @import("Module.zig"); diff --git a/src/Sema.zig b/src/Sema.zig index 55bd531f961d..bc46989b4438 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -152,7 +152,7 @@ const Value = @import("value.zig").Value; const Type = @import("type.zig").Type; const TypedValue = @import("TypedValue.zig"); const Air = @import("Air.zig"); -const Zir = @import("Zir.zig"); +const Zir = std.zig.Zir; const Module = @import("Module.zig"); const trace = @import("tracy.zig").trace; const Namespace = Module.Namespace; @@ -167,7 +167,7 @@ const Package = @import("Package.zig"); const crash_report = @import("crash_report.zig"); const build_options = @import("build_options"); const Compilation = @import("Compilation.zig"); -const InternPool = @import("InternPool.zig"); +const InternPool = std.zig.InternPool; const Alignment = InternPool.Alignment; pub const default_branch_quota = 1000; @@ -1477,7 +1477,7 @@ fn analyzeBodyInner( .check_comptime_control_flow => { if (!block.is_comptime) { const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const inline_block = inst_data.operand.toIndex().?; var check_block = block; @@ -1662,7 +1662,7 @@ fn analyzeBodyInner( try labeled_block.block.instructions.appendSlice(gpa, block.instructions.items[block_index..]); block.instructions.items.len = block_index; - const block_result = try sema.analyzeBlockBody(block, inst_data.src(), &labeled_block.block, &labeled_block.label.merges); + const block_result = try sema.analyzeBlockBody(block, LazySrcLoc.fromPlNode(inst_data), &labeled_block.block, &labeled_block.label.merges); { // Destroy the ad-hoc block entry so that it does not interfere with // the next iteration of comptime control flow, if any. @@ -1736,7 +1736,7 @@ fn analyzeBodyInner( .@"try" => blk: { if (!block.is_comptime) break :blk try sema.zirTry(block, inst); const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len); @@ -1767,7 +1767,7 @@ fn analyzeBodyInner( .try_ptr => blk: { if (!block.is_comptime) break :blk try sema.zirTryPtr(block, inst); const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len); @@ -2009,7 +2009,7 @@ fn genericPoisonReason(sema: *Sema, ref: Zir.Inst.Ref) GenericPoisonReason { cur = un_node.operand; } else { // This must be an anyopaque pointer! - return .{ .anyopaque_ptr = un_node.src() }; + return .{ .anyopaque_ptr = LazySrcLoc.fromUnNode(un_node) }; } }, .call, .field_call => { @@ -2017,7 +2017,7 @@ fn genericPoisonReason(sema: *Sema, ref: Zir.Inst.Ref) GenericPoisonReason { // evaluating an `anytype` function parameter. // TODO: better source location - function decl rather than call const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - return .{ .anytype_param = pl_node.src() }; + return .{ .anytype_param = LazySrcLoc.fromPlNode(pl_node) }; }, else => return .unknown, } @@ -3307,7 +3307,7 @@ fn zirErrorSetDecl( const mod = sema.mod; const gpa = sema.gpa; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const extra = sema.code.extraData(Zir.Inst.ErrorSetDecl, inst_data.payload_index); var names: InferredErrorSet.NameMap = .{}; @@ -3371,7 +3371,7 @@ fn zirRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok; const operand = try sema.resolveInst(inst_data.operand); - return sema.analyzeRef(block, inst_data.src(), operand); + return sema.analyzeRef(block, LazySrcLoc.fromUnTok(inst_data), operand); } fn zirEnsureResultUsed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { @@ -3380,7 +3380,7 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; const operand = try sema.resolveInst(inst_data.operand); - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); return sema.ensureResultUsed(block, sema.typeOf(operand), src); } @@ -3423,7 +3423,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; const operand = try sema.resolveInst(inst_data.operand); - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const operand_ty = sema.typeOf(operand); switch (operand_ty.zigTypeTag(mod)) { .ErrorSet, .ErrorUnion => { @@ -3445,7 +3445,7 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const operand = try sema.resolveInst(inst_data.operand); const operand_ty = sema.typeOf(operand); const err_union_ty = if (operand_ty.zigTypeTag(mod) == .Pointer) @@ -3470,7 +3470,7 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE defer tracy.end(); const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const object = try sema.resolveInst(inst_data.operand); return indexablePtrLen(sema, block, src, object); @@ -3997,7 +3997,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com const mod = sema.mod; const gpa = sema.gpa; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; const ptr = try sema.resolveInst(inst_data.operand); const ptr_inst = Air.refToIndex(ptr).?; @@ -4137,7 +4137,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); const args = sema.code.refSlice(extra.end, extra.data.operands_len); - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); var len: Air.Inst.Ref = .none; var len_val: ?Value = null; @@ -4275,13 +4275,13 @@ fn optEuBasePtrInit(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, src: LazySrcL fn zirOptEuBasePtrInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; const ptr = try sema.resolveInst(un_node.operand); - return sema.optEuBasePtrInit(block, ptr, un_node.src()); + return sema.optEuBasePtrInit(block, ptr, LazySrcLoc.fromUnNode(un_node)); } fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { const mod = sema.mod; const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = pl_node.src(); + const src = LazySrcLoc.fromPlNode(pl_node); const extra = sema.code.extraData(Zir.Inst.Bin, pl_node.payload_index).data; const uncoerced_val = try sema.resolveInst(extra.rhs); const maybe_wrapped_ptr_ty = sema.resolveType(block, .unneeded, extra.lhs) catch |err| switch (err) { @@ -4332,7 +4332,7 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { const mod = sema.mod; const un_tok = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok; - const src = un_tok.src(); + const src = LazySrcLoc.fromUnTok(un_tok); // In case of GenericPoison, we don't actually have a type, so this will be // treated as an untyped address-of operator. if (un_tok.operand == .var_args_param_type) return; @@ -4363,7 +4363,7 @@ fn zirValidateArrayInitRefTy( ) CompileError!Air.Inst.Ref { const mod = sema.mod; const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = pl_node.src(); + const src = LazySrcLoc.fromPlNode(pl_node); const extra = sema.code.extraData(Zir.Inst.ArrayInitRefTy, pl_node.payload_index).data; const maybe_wrapped_ptr_ty = sema.resolveType(block, .unneeded, extra.ptr_ty) catch |err| switch (err) { error.GenericPoison => return .generic_poison_type, @@ -4399,7 +4399,7 @@ fn zirValidateArrayInitTy( ) CompileError!void { const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const ty_src: LazySrcLoc = if (is_result_ty) src else .{ .node_offset_init_ty = inst_data.src_node }; const extra = sema.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data; const ty = sema.resolveType(block, ty_src, extra.ty) catch |err| switch (err) { @@ -4462,7 +4462,7 @@ fn zirValidateStructInitTy( ) CompileError!void { const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const ty = sema.resolveType(block, src, inst_data.operand) catch |err| switch (err) { // It's okay for the type to be unknown: this will result in an anonymous struct init. error.GenericPoison => return, @@ -4487,7 +4487,7 @@ fn zirValidatePtrStructInit( const mod = sema.mod; const validate_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const init_src = validate_inst.src(); + const init_src = LazySrcLoc.fromPlNode(validate_inst); const validate_extra = sema.code.extraData(Zir.Inst.Block, validate_inst.payload_index); const instrs = sema.code.bodySlice(validate_extra.end, validate_extra.data.body_len); const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(instrs[0])].pl_node; @@ -4646,7 +4646,7 @@ fn validateUnionInit( try sema.storePtr2(block, init_src, union_ptr, init_src, union_init, init_src, .store); return; } else if (try sema.typeRequiresComptime(union_ty)) { - return sema.failWithNeededComptime(block, field_ptr_data.src(), .{ + return sema.failWithNeededComptime(block, LazySrcLoc.fromPlNode(field_ptr_data), .{ .needed_comptime_reason = "initializer of comptime only union must be comptime-known", }); } @@ -4833,7 +4833,7 @@ fn validateStructInit( field_values[i] = val.toIntern(); } else if (require_comptime) { const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node; - return sema.failWithNeededComptime(block, field_ptr_data.src(), .{ + return sema.failWithNeededComptime(block, LazySrcLoc.fromPlNode(field_ptr_data), .{ .needed_comptime_reason = "initializer of comptime only struct must be comptime-known", }); } else { @@ -4952,7 +4952,7 @@ fn zirValidatePtrArrayInit( ) CompileError!void { const mod = sema.mod; const validate_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const init_src = validate_inst.src(); + const init_src = LazySrcLoc.fromPlNode(validate_inst); const validate_extra = sema.code.extraData(Zir.Inst.Block, validate_inst.payload_index); const instrs = sema.code.bodySlice(validate_extra.end, validate_extra.data.body_len); const first_elem_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(instrs[0])].pl_node; @@ -5149,7 +5149,7 @@ fn zirValidatePtrArrayInit( fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const operand = try sema.resolveInst(inst_data.operand); const operand_ty = sema.typeOf(operand); @@ -5193,7 +5193,7 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const extra = sema.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const destructure_src = LazySrcLoc.nodeOffset(extra.destructure_node); const operand = try sema.resolveInst(extra.operand); const operand_ty = sema.typeOf(operand); @@ -5393,7 +5393,7 @@ fn storeToInferredAllocComptime( fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const quota: u32 = @intCast(try sema.resolveInt(block, src, inst_data.operand, Type.u32, .{ .needed_comptime_reason = "eval branch quota must be comptime-known", })); @@ -5418,7 +5418,7 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v const zir_tags = sema.code.instructions.items(.tag); const zir_datas = sema.code.instructions.items(.data); const inst_data = zir_datas[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; const ptr = try sema.resolveInst(extra.lhs); const operand = try sema.resolveInst(extra.rhs); @@ -5550,7 +5550,7 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro defer tracy.end(); const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; const msg = try sema.resolveConstString(block, operand_src, inst_data.operand, .{ .needed_comptime_reason = "compile error string must be comptime-known", @@ -5600,7 +5600,7 @@ fn zirCompileLog( fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index { const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const msg_inst = try sema.resolveInst(inst_data.operand); if (block.is_comptime) { @@ -5626,7 +5626,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index); const body = sema.code.bodySlice(extra.end, extra.data.body_len); const gpa = sema.gpa; @@ -5698,7 +5698,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr const comp = mod.comp; const gpa = sema.gpa; const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = pl_node.src(); + const src = LazySrcLoc.fromPlNode(pl_node); const extra = sema.code.extraData(Zir.Inst.Block, pl_node.payload_index); const body = sema.code.bodySlice(extra.end, extra.data.body_len); @@ -5776,7 +5776,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr fn zirSuspendBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); return sema.failWithUseOfAsync(parent_block, src); } @@ -5785,7 +5785,7 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt defer tracy.end(); const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = pl_node.src(); + const src = LazySrcLoc.fromPlNode(pl_node); const extra = sema.code.extraData(Zir.Inst.Block, pl_node.payload_index); const body = sema.code.bodySlice(extra.end, extra.data.body_len); const gpa = sema.gpa; @@ -6000,7 +6000,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const extra = sema.code.extraData(Zir.Inst.Export, inst_data.payload_index).data; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; const decl_name = try mod.intern_pool.getOrPutString(mod.gpa, sema.code.nullTerminatedString(extra.decl_name)); @@ -6036,7 +6036,7 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const extra = sema.code.extraData(Zir.Inst.ExportValue, inst_data.payload_index).data; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; const operand = try sema.resolveInstConst(block, operand_src, extra.operand, .{ @@ -6364,7 +6364,7 @@ fn addDbgVar( fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok; - const src = inst_data.src(); + const src = LazySrcLoc.fromStrTok(inst_data); const decl_name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); const decl_index = try sema.lookupIdentifier(block, src, decl_name); try sema.addReferencedBy(block, src, decl_index); @@ -6374,7 +6374,7 @@ fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok; - const src = inst_data.src(); + const src = LazySrcLoc.fromStrTok(inst_data); const decl_name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); const decl = try sema.lookupIdentifier(block, src, decl_name); return sema.analyzeDeclVal(block, src, decl); @@ -6637,7 +6637,7 @@ fn zirCall( const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const callee_src: LazySrcLoc = .{ .node_offset_call_func = inst_data.src_node }; - const call_src = inst_data.src(); + const call_src = LazySrcLoc.fromPlNode(inst_data); const ExtraType = switch (kind) { .direct => Zir.Inst.Call, .field => Zir.Inst.FieldCall, @@ -7097,15 +7097,15 @@ const InlineCallSema = struct { .callee => .caller, }; // zig fmt: off - std.mem.swap(Zir, &ics.sema.code, &ics.other_code); - std.mem.swap(InternPool.Index, &ics.sema.func_index, &ics.other_func_index); - std.mem.swap(Type, &ics.sema.fn_ret_ty, &ics.other_fn_ret_ty); - std.mem.swap(?*InferredErrorSet, &ics.sema.fn_ret_ty_ies, &ics.other_fn_ret_ty_ies); - std.mem.swap(InstMap, &ics.sema.inst_map, &ics.other_inst_map); - std.mem.swap(InternPool.Index, &ics.sema.generic_owner, &ics.other_generic_owner); - std.mem.swap(LazySrcLoc, &ics.sema.generic_call_src, &ics.other_generic_call_src); + std.mem.swap(Zir, &ics.sema.code, &ics.other_code); + std.mem.swap(InternPool.Index, &ics.sema.func_index, &ics.other_func_index); + std.mem.swap(Type, &ics.sema.fn_ret_ty, &ics.other_fn_ret_ty); + std.mem.swap(?*InferredErrorSet, &ics.sema.fn_ret_ty_ies, &ics.other_fn_ret_ty_ies); + std.mem.swap(InstMap, &ics.sema.inst_map, &ics.other_inst_map); + std.mem.swap(InternPool.Index, &ics.sema.generic_owner, &ics.other_generic_owner); + std.mem.swap(LazySrcLoc, &ics.sema.generic_call_src, &ics.other_generic_call_src); std.mem.swap(InternPool.OptionalDeclIndex, &ics.sema.generic_call_decl, &ics.other_generic_call_decl); - std.mem.swap(Air.Inst.Ref, &ics.sema.error_return_trace_index_on_fn_entry, &ics.other_error_return_trace_index_on_fn_entry); + std.mem.swap(Air.Inst.Ref, &ics.sema.error_return_trace_index_on_fn_entry, &ics.other_error_return_trace_index_on_fn_entry); // zig fmt: on } }; @@ -7656,7 +7656,7 @@ fn analyzeInlineCallArg( // Evaluate the parameter type expression now that previous ones have // been mapped, and coerce the corresponding argument to it. const pl_tok = ics.callee().code.instructions.items(.data)[@intFromEnum(inst)].pl_tok; - const param_src = pl_tok.src(); + const param_src = LazySrcLoc.fromPlTok(pl_tok); const extra = ics.callee().code.extraData(Zir.Inst.Param, pl_tok.payload_index); const param_body = ics.callee().code.bodySlice(extra.end, extra.data.body_len); const param_ty = param_ty: { @@ -7895,7 +7895,7 @@ fn instantiateGenericCall( } const param_ty_inst = try child_sema.resolveBody(&child_block, param_ty_body, param_inst); - break :param_ty try child_sema.analyzeAsType(&child_block, param_data.src(), param_ty_inst); + break :param_ty try child_sema.analyzeAsType(&child_block, LazySrcLoc.fromPlTok(param_data), param_ty_inst); }, else => unreachable, } @@ -7929,8 +7929,8 @@ fn instantiateGenericCall( const msg = try sema.errMsg(block, arg_src, "runtime-known argument passed to comptime parameter", .{}); errdefer msg.destroy(sema.gpa); const param_src = switch (param_tag) { - .param_comptime => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok.src(), - .param_anytype_comptime => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.src(), + .param_comptime => LazySrcLoc.fromPlTok(fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok), + .param_anytype_comptime => LazySrcLoc.fromStrTok(fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok), else => unreachable, }; try child_sema.errNote(&child_block, param_src, msg, "declared comptime here", .{}); @@ -7944,8 +7944,8 @@ fn instantiateGenericCall( const msg = try sema.errMsg(block, arg_src, "runtime-known argument passed to parameter of comptime-only type", .{}); errdefer msg.destroy(sema.gpa); const param_src = switch (param_tag) { - .param => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok.src(), - .param_anytype => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.src(), + .param => LazySrcLoc.fromPlTok(fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok), + .param_anytype => LazySrcLoc.fromStrTok(fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok), else => unreachable, }; try child_sema.errNote(&child_block, param_src, msg, "declared here", .{}); @@ -8153,7 +8153,7 @@ fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { const mod = sema.mod; const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = un_node.src(); + const src = LazySrcLoc.fromUnNode(un_node); const ptr_ty = sema.resolveType(block, src, un_node.operand) catch |err| switch (err) { error.GenericPoison => return .generic_poison_type, else => |e| return e, @@ -8178,7 +8178,7 @@ fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr else => |e| return e, }; if (!vec_ty.isVector(mod)) { - return sema.fail(block, un_node.src(), "expected vector type, found '{}'", .{vec_ty.fmt(mod)}); + return sema.fail(block, LazySrcLoc.fromUnNode(un_node), "expected vector type, found '{}'", .{vec_ty.fmt(mod)}); } return Air.internedToRef(vec_ty.childType(mod).toIntern()); } @@ -8265,7 +8265,7 @@ fn zirAnyframeType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; if (true) { - return sema.failWithUseOfAsync(block, inst_data.src()); + return sema.failWithUseOfAsync(block, LazySrcLoc.fromUnNode(inst_data)); } const mod = sema.mod; const operand_src: LazySrcLoc = .{ .node_offset_anyframe_type = inst_data.src_node }; @@ -8477,7 +8477,7 @@ fn zirEnumLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; const operand = try sema.resolveInst(inst_data.operand); const operand_ty = sema.typeOf(operand); @@ -8523,7 +8523,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@enumFromInt"); const operand = try sema.resolveInst(extra.rhs); @@ -8604,7 +8604,7 @@ fn zirOptionalPayloadPtr( const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; const optional_ptr = try sema.resolveInst(inst_data.operand); - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); return sema.analyzeOptionalPayloadPtr(block, src, optional_ptr, safety_check, false); } @@ -8688,7 +8688,7 @@ fn zirOptionalPayload( const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const operand = try sema.resolveInst(inst_data.operand); const operand_ty = sema.typeOf(operand); const result_ty = switch (operand_ty.zigTypeTag(mod)) { @@ -8740,7 +8740,7 @@ fn zirErrUnionPayload( const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const operand = try sema.resolveInst(inst_data.operand); const operand_src = src; const err_union_ty = sema.typeOf(operand); @@ -8793,7 +8793,7 @@ fn zirErrUnionPayloadPtr( const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; const operand = try sema.resolveInst(inst_data.operand); - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); return sema.analyzeErrUnionPayloadPtr(block, src, operand, false, false); } @@ -8876,7 +8876,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro defer tracy.end(); const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const operand = try sema.resolveInst(inst_data.operand); return sema.analyzeErrUnionCode(block, src, operand); } @@ -8910,7 +8910,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const operand = try sema.resolveInst(inst_data.operand); const operand_ty = sema.typeOf(operand); assert(operand_ty.zigTypeTag(mod) == .Pointer); @@ -9312,7 +9312,7 @@ fn funcCommon( if (inferred_error_set) { try sema.validateErrorUnionPayloadType(block, bare_return_type, ret_ty_src); } - const func_index = try ip.getFuncInstance(gpa, .{ + const func_index = try sema.getFuncInstance(.{ .param_types = param_types, .noalias_bits = noalias_bits, .bare_return_type = bare_return_type.toIntern(), @@ -9584,8 +9584,8 @@ fn finishFunc( ) |is_comptime, name_nts, param_index| { if (!is_comptime) { const param_src = switch (tags[@intFromEnum(param_index)]) { - .param => data[@intFromEnum(param_index)].pl_tok.src(), - .param_anytype => data[@intFromEnum(param_index)].str_tok.src(), + .param => LazySrcLoc.fromPlTok(data[@intFromEnum(param_index)].pl_tok), + .param_anytype => LazySrcLoc.fromStrTok(data[@intFromEnum(param_index)].str_tok), else => unreachable, }; const name = sema.code.nullTerminatedString2(name_nts); @@ -9660,7 +9660,7 @@ fn zirParam( comptime_syntax: bool, ) CompileError!void { const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_tok; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlTok(inst_data); const extra = sema.code.extraData(Zir.Inst.Param, inst_data.payload_index); const param_name: Zir.NullTerminatedString = @enumFromInt(extra.data.name); const body = sema.code.bodySlice(extra.end, extra.data.body_len); @@ -9778,7 +9778,7 @@ fn zirAsNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. defer tracy.end(); const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const extra = sema.code.extraData(Zir.Inst.As, inst_data.payload_index).data; sema.src = src; return sema.analyzeAs(block, src, extra.dest_type, extra.operand, false); @@ -9789,7 +9789,7 @@ fn zirAsShiftOperand(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr defer tracy.end(); const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const extra = sema.code.extraData(Zir.Inst.As, inst_data.payload_index).data; return sema.analyzeAs(block, src, extra.dest_type, extra.operand, true); } @@ -9881,7 +9881,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! .storage = .{ .elems = new_elems }, } })); } - try sema.requireRuntimeBlock(block, inst_data.src(), ptr_src); + try sema.requireRuntimeBlock(block, LazySrcLoc.fromUnNode(inst_data), ptr_src); if (!is_vector) { return block.addUnOp(.int_from_ptr, operand); } @@ -9902,7 +9902,7 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; const field_name = try mod.intern_pool.getOrPutString(sema.gpa, sema.code.nullTerminatedString(extra.field_name_start)); @@ -9916,7 +9916,7 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; const field_name = try mod.intern_pool.getOrPutString(sema.gpa, sema.code.nullTerminatedString(extra.field_name_start)); @@ -9930,7 +9930,7 @@ fn zirStructInitFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const field_name_src: LazySrcLoc = .{ .node_offset_field_name_init = inst_data.src_node }; const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; const field_name = try mod.intern_pool.getOrPutString(sema.gpa, sema.code.nullTerminatedString(extra.field_name_start)); @@ -9951,7 +9951,7 @@ fn zirFieldValNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr defer tracy.end(); const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; const object = try sema.resolveInst(extra.lhs); @@ -9966,7 +9966,7 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr defer tracy.end(); const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; const object_ptr = try sema.resolveInst(extra.lhs); @@ -9981,14 +9981,14 @@ fn zirIntCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air defer tracy.end(); const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@intCast"); const operand = try sema.resolveInst(extra.rhs); - return sema.intCast(block, inst_data.src(), dest_ty, src, operand, operand_src, true); + return sema.intCast(block, LazySrcLoc.fromPlNode(inst_data), dest_ty, src, operand, operand_src, true); } fn intCast( @@ -10150,7 +10150,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; @@ -10284,7 +10284,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air .Vector, => {}, } - return sema.bitCast(block, dest_ty, operand, inst_data.src(), operand_src); + return sema.bitCast(block, dest_ty, operand, LazySrcLoc.fromPlNode(inst_data), operand_src); } fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { @@ -10293,7 +10293,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; @@ -10347,7 +10347,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A if (dest_is_comptime_float) { return sema.fail(block, operand_src, "unable to cast runtime value to 'comptime_float'", .{}); } - try sema.requireRuntimeBlock(block, inst_data.src(), operand_src); + try sema.requireRuntimeBlock(block, LazySrcLoc.fromPlNode(inst_data), operand_src); const src_bits = operand_scalar_ty.floatBits(target); const dst_bits = dest_scalar_ty.floatBits(target); @@ -10372,7 +10372,7 @@ fn zirElemVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air defer tracy.end(); const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; const array = try sema.resolveInst(extra.lhs); const elem_index = try sema.resolveInst(extra.rhs); @@ -10384,7 +10384,7 @@ fn zirElemValNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError defer tracy.end(); const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node }; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; const array = try sema.resolveInst(extra.lhs); @@ -10409,7 +10409,7 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; const array_ptr = try sema.resolveInst(extra.lhs); const elem_index = try sema.resolveInst(extra.rhs); @@ -10436,7 +10436,7 @@ fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError defer tracy.end(); const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node }; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; const array_ptr = try sema.resolveInst(extra.lhs); @@ -10450,7 +10450,7 @@ fn zirArrayInitElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const extra = sema.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data; const array_ptr = try sema.resolveInst(extra.ptr); const elem_index = try sema.mod.intRef(Type.usize, extra.index); @@ -10469,7 +10469,7 @@ fn zirSliceStart(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! defer tracy.end(); const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const extra = sema.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data; const array_ptr = try sema.resolveInst(extra.lhs); const start = try sema.resolveInst(extra.start); @@ -10485,7 +10485,7 @@ fn zirSliceEnd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai defer tracy.end(); const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const extra = sema.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data; const array_ptr = try sema.resolveInst(extra.lhs); const start = try sema.resolveInst(extra.start); @@ -10502,7 +10502,7 @@ fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr defer tracy.end(); const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const sentinel_src: LazySrcLoc = .{ .node_offset_slice_sentinel = inst_data.src_node }; const extra = sema.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data; const array_ptr = try sema.resolveInst(extra.lhs); @@ -10521,7 +10521,7 @@ fn zirSliceLength(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError defer tracy.end(); const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const extra = sema.code.extraData(Zir.Inst.SliceLength, inst_data.payload_index).data; const array_ptr = try sema.resolveInst(extra.lhs); const start = try sema.resolveInst(extra.start); @@ -10581,7 +10581,7 @@ const SwitchProngAnalysis = struct { merges: *Block.Merges, ) CompileError!Air.Inst.Ref { const sema = spa.sema; - const src = sema.code.instructions.items(.data)[@intFromEnum(spa.switch_block_inst)].pl_node.src(); + const src = LazySrcLoc.fromPlNode(sema.code.instructions.items(.data)[@intFromEnum(spa.switch_block_inst)].pl_node); if (has_tag_capture) { const tag_ref = try spa.analyzeTagCapture(child_block, raw_capture_src, inline_case_capture); @@ -11147,7 +11147,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r const gpa = sema.gpa; const ip = &mod.intern_pool; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const src_node_offset = inst_data.src_node; const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = src_node_offset }; const special_prong_src: LazySrcLoc = .{ .node_offset_switch_special_prong = src_node_offset }; @@ -12976,7 +12976,7 @@ fn maybeErrorUnwrapComptime(sema: *Sema, block: *Block, body: []const Zir.Inst.I } } else return; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].@"unreachable"; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnreachable(inst_data); if (try sema.resolveDefinedValue(block, src, operand)) |val| { if (val.getErrorName(sema.mod).unwrap()) |name| { @@ -13040,7 +13040,7 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; const container_type = try sema.resolveType(block, lhs_src, extra.lhs); @@ -13067,7 +13067,7 @@ fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok; - const operand_src = inst_data.src(); + const operand_src = LazySrcLoc.fromStrTok(inst_data); const operand = inst_data.get(sema.code); const result = mod.importFile(block.getFileScope(mod), operand) catch |err| switch (err) { @@ -13143,7 +13143,7 @@ fn zirShl( const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); sema.src = src; const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; @@ -13326,7 +13326,7 @@ fn zirShr( const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); sema.src = src; const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; @@ -13517,7 +13517,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; const operand = try sema.resolveInst(inst_data.operand); @@ -13656,7 +13656,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai const rhs = try sema.resolveInst(extra.rhs); const lhs_ty = sema.typeOf(lhs); const rhs_ty = sema.typeOf(rhs); - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const lhs_is_tuple = lhs_ty.isTuple(mod); const rhs_is_tuple = rhs_ty.isTuple(mod); @@ -13983,7 +13983,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai const extra = sema.code.extraData(Zir.Inst.ArrayMul, inst_data.payload_index).data; const uncoerced_lhs = try sema.resolveInst(extra.lhs); const uncoerced_lhs_ty = sema.typeOf(uncoerced_lhs); - const src: LazySrcLoc = inst_data.src(); + const src: LazySrcLoc = LazySrcLoc.fromPlNode(inst_data); const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; const operator_src: LazySrcLoc = .{ .node_offset_main_token = inst_data.src_node }; const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; @@ -14151,7 +14151,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const lhs_src = src; const rhs_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; @@ -14183,7 +14183,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const lhs_src = src; const rhs_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; @@ -16106,7 +16106,7 @@ fn zirLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.In defer tracy.end(); const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const ptr_src = src; // TODO better source location const ptr = try sema.resolveInst(inst_data.operand); return sema.analyzeLoad(block, src, ptr, ptr_src); @@ -16287,7 +16287,7 @@ fn zirCmpEq( const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; - const src: LazySrcLoc = inst_data.src(); + const src: LazySrcLoc = LazySrcLoc.fromPlNode(inst_data); const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; const lhs = try sema.resolveInst(extra.lhs); @@ -16403,7 +16403,7 @@ fn zirCmp( const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; - const src: LazySrcLoc = inst_data.src(); + const src: LazySrcLoc = LazySrcLoc.fromPlNode(inst_data); const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; const lhs = try sema.resolveInst(extra.lhs); @@ -16702,9 +16702,9 @@ fn zirClosureGet(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! }; const msg = if (name) |some| - try sema.errMsg(block, inst_data.src(), "'{s}' not accessible outside function scope", .{some}) + try sema.errMsg(block, LazySrcLoc.fromInstNode(inst_data), "'{s}' not accessible outside function scope", .{some}) else - try sema.errMsg(block, inst_data.src(), "variable not accessible outside function scope", .{}); + try sema.errMsg(block, LazySrcLoc.fromInstNode(inst_data), "variable not accessible outside function scope", .{}); errdefer msg.destroy(sema.gpa); // TODO add "declared here" note @@ -16730,9 +16730,9 @@ fn zirClosureGet(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! }; const msg = if (name) |some| - try sema.errMsg(block, inst_data.src(), "'{s}' not accessible from inner function", .{some}) + try sema.errMsg(block, LazySrcLoc.fromInstNode(inst_data), "'{s}' not accessible from inner function", .{some}) else - try sema.errMsg(block, inst_data.src(), "variable not accessible from inner function", .{}); + try sema.errMsg(block, LazySrcLoc.fromInstNode(inst_data), "variable not accessible from inner function", .{}); errdefer msg.destroy(sema.gpa); try sema.errNote(block, LazySrcLoc.nodeOffset(0), msg, "crossed function definition here", .{}); @@ -16852,7 +16852,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai const gpa = sema.gpa; const ip = &mod.intern_pool; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const ty = try sema.resolveType(block, src, inst_data.operand); const type_info_ty = try sema.getBuiltinType("Type"); const type_info_tag_ty = type_info_ty.unionTagType(mod).?; @@ -17971,7 +17971,7 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr fn zirTypeofLog2IntType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const operand = try sema.resolveInst(inst_data.operand); const operand_ty = sema.typeOf(operand); const res_ty = try sema.log2IntType(block, operand_ty, src); @@ -18063,7 +18063,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; const uncasted_operand = try sema.resolveInst(inst_data.operand); @@ -18208,7 +18208,7 @@ fn zirIsNonNull( defer tracy.end(); const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const operand = try sema.resolveInst(inst_data.operand); try sema.checkNullableType(block, src, sema.typeOf(operand)); return sema.analyzeIsNull(block, src, operand, true); @@ -18224,7 +18224,7 @@ fn zirIsNonNullPtr( const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const ptr = try sema.resolveInst(inst_data.operand); try sema.checkNullableType(block, src, sema.typeOf(ptr).elemType2(mod)); if ((try sema.resolveValue(ptr)) == null) { @@ -18249,7 +18249,7 @@ fn zirIsNonErr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai defer tracy.end(); const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const operand = try sema.resolveInst(inst_data.operand); try sema.checkErrorType(block, src, sema.typeOf(operand)); return sema.analyzeIsNonErr(block, src, operand); @@ -18261,7 +18261,7 @@ fn zirIsNonErrPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const ptr = try sema.resolveInst(inst_data.operand); try sema.checkErrorType(block, src, sema.typeOf(ptr).elemType2(mod)); const loaded = try sema.analyzeLoad(block, src, ptr, src); @@ -18273,7 +18273,7 @@ fn zirRetIsNonErr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError defer tracy.end(); const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const operand = try sema.resolveInst(inst_data.operand); return sema.analyzeIsNonErr(block, src, operand); } @@ -18356,7 +18356,7 @@ fn zirCondbr( fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); const body = sema.code.bodySlice(extra.end, extra.data.body_len); @@ -18402,7 +18402,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError! fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); const body = sema.code.bodySlice(extra.end, extra.data.body_len); @@ -18518,7 +18518,7 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, break_data: BreakData) !voi fn zirUnreachable(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index { const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].@"unreachable"; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnreachable(inst_data); if (block.is_comptime) { return sema.fail(block, src, "reached unreachable code", .{}); @@ -18545,7 +18545,7 @@ fn zirRetErrValue( const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok; const err_name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); _ = try mod.getErrorValue(err_name); - const src = inst_data.src(); + const src = LazySrcLoc.fromStrTok(inst_data); // Return the error code from the function. const error_set_type = try mod.singleErrorSetType(err_name); const result_inst = Air.internedToRef((try mod.intern(.{ .err = .{ @@ -18565,7 +18565,7 @@ fn zirRetImplicit( const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok; - const r_brace_src = inst_data.src(); + const r_brace_src = LazySrcLoc.fromUnTok(inst_data); if (block.inlining == null and sema.func_is_naked) { assert(!block.is_comptime); if (block.wantSafety()) { @@ -18611,7 +18611,7 @@ fn zirRetNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; const operand = try sema.resolveInst(inst_data.operand); - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); return sema.analyzeRet(block, operand, src); } @@ -18621,7 +18621,7 @@ fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir defer tracy.end(); const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const ret_ptr = try sema.resolveInst(inst_data.operand); if (block.is_comptime or block.inlining != null or sema.func_is_naked) { @@ -19013,7 +19013,7 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE defer tracy.end(); const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const obj_ty = try sema.resolveType(block, src, inst_data.operand); const mod = sema.mod; @@ -19032,7 +19032,7 @@ fn zirStructInitEmptyResult(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const ty_operand = sema.resolveType(block, src, inst_data.operand) catch |err| switch (err) { // Generic poison means this is an untyped anonymous empty struct init error.GenericPoison => return .empty_struct, @@ -19170,7 +19170,7 @@ fn zirStructInit( const zir_datas = sema.code.instructions.items(.data); const inst_data = zir_datas[@intFromEnum(inst)].pl_node; const extra = sema.code.extraData(Zir.Inst.StructInit, inst_data.payload_index); - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const mod = sema.mod; const ip = &mod.intern_pool; @@ -19490,7 +19490,7 @@ fn zirStructInitAnon( inst: Zir.Inst.Index, ) CompileError!Air.Inst.Ref { const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const extra = sema.code.extraData(Zir.Inst.StructInitAnon, inst_data.payload_index); return sema.structInitAnon(block, src, .anon_init, extra.data, extra.end, false); } @@ -19643,7 +19643,7 @@ fn zirArrayInit( const mod = sema.mod; const gpa = sema.gpa; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); const args = sema.code.refSlice(extra.end, extra.data.operands_len); @@ -19810,7 +19810,7 @@ fn zirArrayInitAnon( inst: Zir.Inst.Index, ) CompileError!Air.Inst.Ref { const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); const operands = sema.code.refSlice(extra.end, extra.data.operands_len); return sema.arrayInitAnon(block, src, operands, false); @@ -19923,7 +19923,7 @@ fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp const ip = &mod.intern_pool; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data; - const ty_src = inst_data.src(); + const ty_src = LazySrcLoc.fromPlNode(inst_data); const field_name_src: LazySrcLoc = .{ .node_offset_field_name_init = inst_data.src_node }; const wrapped_aggregate_ty = sema.resolveType(block, ty_src, extra.container_type) catch |err| switch (err) { // Since this is a ZIR instruction that returns a type, encountering @@ -20046,7 +20046,7 @@ fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const operand = try sema.resolveInst(inst_data.operand); const operand_ty = sema.typeOf(operand); const is_vector = operand_ty.zigTypeTag(mod) == .Vector; @@ -20207,7 +20207,7 @@ fn zirUnaryMath( fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const operand = try sema.resolveInst(inst_data.operand); const operand_ty = sema.typeOf(operand); const mod = sema.mod; @@ -21405,20 +21405,20 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai fn zirFrameType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); return sema.failWithUseOfAsync(block, src); } fn zirFrameSize(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); return sema.failWithUseOfAsync(block, src); } fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@intFromFloat"); @@ -21443,7 +21443,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro }); } - try sema.requireRuntimeBlock(block, inst_data.src(), operand_src); + try sema.requireRuntimeBlock(block, LazySrcLoc.fromPlNode(inst_data), operand_src); if (dest_scalar_ty.intInfo(mod).bits == 0) { if (!is_vector) { if (block.wantSafety()) { @@ -21500,7 +21500,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@floatFromInt"); @@ -21542,7 +21542,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; @@ -21815,7 +21815,7 @@ fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDa fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, "@ptrCast"); @@ -22245,7 +22245,7 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@truncate"); @@ -22334,7 +22334,7 @@ fn zirBitCount( ) CompileError!Air.Inst.Ref { const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; const operand = try sema.resolveInst(inst_data.operand); const operand_ty = sema.typeOf(operand); @@ -22388,7 +22388,7 @@ fn zirBitCount( fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; const operand = try sema.resolveInst(inst_data.operand); const operand_ty = sema.typeOf(operand); @@ -22444,7 +22444,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; const operand = try sema.resolveInst(inst_data.operand); const operand_ty = sema.typeOf(operand); @@ -23191,7 +23191,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const scalar_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@splat"); @@ -23205,7 +23205,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I return Air.internedToRef((try sema.splat(dest_ty, scalar_val)).toIntern()); } - try sema.requireRuntimeBlock(block, inst_data.src(), scalar_src); + try sema.requireRuntimeBlock(block, LazySrcLoc.fromPlNode(inst_data), scalar_src); return block.addTyOp(.splat, dest_ty, scalar); } @@ -23270,7 +23270,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. return Air.internedToRef(accum.toIntern()); } - try sema.requireRuntimeBlock(block, inst_data.src(), operand_src); + try sema.requireRuntimeBlock(block, LazySrcLoc.fromPlNode(inst_data), operand_src); return block.addInst(.{ .tag = if (block.float_mode == .Optimized) .reduce_optimized else .reduce, .data = .{ .reduce = .{ @@ -23596,7 +23596,7 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! } } - try sema.requireRuntimeBlock(block, inst_data.src(), ptr_src); + try sema.requireRuntimeBlock(block, LazySrcLoc.fromPlNode(inst_data), ptr_src); return block.addInst(.{ .tag = .atomic_load, .data = .{ .atomic_load = .{ @@ -23610,7 +23610,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const extra = sema.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); // zig fmt: off const elem_ty_src : LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; const ptr_src : LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; @@ -23695,7 +23695,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const extra = sema.code.extraData(Zir.Inst.AtomicStore, inst_data.payload_index).data; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); // zig fmt: off const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; const ptr_src : LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; @@ -23731,7 +23731,7 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const extra = sema.code.extraData(Zir.Inst.MulAdd, inst_data.payload_index).data; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const mulend1_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; const mulend2_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; @@ -23801,7 +23801,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError const modifier_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; const func_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; const args_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; - const call_src = inst_data.src(); + const call_src = LazySrcLoc.fromPlNode(inst_data); const extra = sema.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data; const func = try sema.resolveInst(extra.callee); @@ -23890,7 +23890,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const extra = sema.code.extraData(Zir.Inst.FieldParentPtr, inst_data.payload_index).data; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; @@ -24012,7 +24012,7 @@ fn zirMinMax( ) CompileError!Air.Inst.Ref { const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; const lhs = try sema.resolveInst(extra.lhs); @@ -24311,7 +24311,7 @@ fn upgradeToArrayPtr(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, len: u64) !A fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const dest_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; const src_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; const dest_ptr = try sema.resolveInst(extra.lhs); @@ -24531,7 +24531,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void const ip = &mod.intern_pool; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const dest_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; const value_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; const dest_ptr = try sema.resolveInst(extra.lhs); @@ -24616,7 +24616,7 @@ fn zirBuiltinAsyncCall(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.I fn zirResume(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); return sema.failWithUseOfAsync(block, src); } @@ -24626,7 +24626,7 @@ fn zirAwait( inst: Zir.Inst.Index, ) CompileError!Air.Inst.Ref { const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromUnNode(inst_data); return sema.failWithUseOfAsync(block, src); } @@ -38109,3 +38109,273 @@ fn ptrType(sema: *Sema, info: InternPool.Key.PtrType) CompileError!Type { } return sema.mod.ptrType(info); } + +const GetFuncInstanceKey = struct { + /// Has the length of the instance function (may be lesser than + /// comptime_args). + param_types: []InternPool.Index, + /// Has the length of generic_owner's parameters (may be greater than + /// param_types). + comptime_args: []const InternPool.Index, + noalias_bits: u32, + bare_return_type: InternPool.Index, + cc: std.builtin.CallingConvention, + alignment: Alignment, + section: InternPool.OptionalNullTerminatedString, + is_noinline: bool, + generic_owner: InternPool.Index, + inferred_error_set: bool, + generation: u32, +}; + +fn getFuncInstance(sema: *Sema, arg: GetFuncInstanceKey) Allocator.Error!InternPool.Index { + const gpa = sema.gpa; + const ip = &sema.mod.intern_pool; + + if (arg.inferred_error_set) + return sema.getFuncInstanceIes(arg); + + const func_ty = try ip.getFuncType(gpa, .{ + .param_types = arg.param_types, + .return_type = arg.bare_return_type, + .noalias_bits = arg.noalias_bits, + .alignment = arg.alignment, + .cc = arg.cc, + .is_noinline = arg.is_noinline, + }); + + const generic_owner = ip.unwrapCoercedFunc(arg.generic_owner); + + assert(arg.comptime_args.len == ip.funcTypeParamsLen(ip.typeOf(generic_owner))); + + try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(InternPool.Tag.FuncInstance).Struct.fields.len + + arg.comptime_args.len); + const prev_extra_len = ip.extra.items.len; + errdefer ip.extra.items.len = prev_extra_len; + + const func_extra_index = ip.addExtraAssumeCapacity(InternPool.Tag.FuncInstance{ + .analysis = .{ + .state = if (arg.cc == .Inline) .inline_only else .none, + .is_cold = false, + .is_noinline = arg.is_noinline, + .calls_or_awaits_errorable_fn = false, + .stack_alignment = .none, + .inferred_error_set = false, + }, + // This is populated after we create the Decl below. It is not read + // by equality or hashing functions. + .owner_decl = undefined, + .ty = func_ty, + .branch_quota = 0, + .generic_owner = generic_owner, + }); + ip.extra.appendSliceAssumeCapacity(@ptrCast(arg.comptime_args)); + + const gop = try ip.map.getOrPutAdapted(gpa, InternPool.Key{ + .func = ip.extraFuncInstance(func_extra_index), + }, InternPool.KeyAdapter{ .intern_pool = ip }); + errdefer _ = ip.map.pop(); + + if (gop.found_existing) { + ip.extra.items.len = prev_extra_len; + return @enumFromInt(gop.index); + } + + const func_index: InternPool.Index = @enumFromInt(ip.items.len); + + try ip.items.append(gpa, .{ + .tag = .func_instance, + .data = func_extra_index, + }); + errdefer ip.items.len -= 1; + + return sema.finishFuncInstance( + generic_owner, + func_index, + func_extra_index, + arg.generation, + func_ty, + arg.section, + ); +} + +/// This function exists separately than `getFuncInstance` because it needs to +/// create 4 new items in the InternPool atomically before it can look for an +/// existing item in the map. +pub fn getFuncInstanceIes(sema: *Sema, arg: GetFuncInstanceKey) Allocator.Error!InternPool.Index { + const gpa = sema.gpa; + const ip = &sema.mod.intern_pool; + + // Validate input parameters. + assert(arg.inferred_error_set); + assert(arg.bare_return_type != .none); + for (arg.param_types) |param_type| assert(param_type != .none); + + const generic_owner = ip.unwrapCoercedFunc(arg.generic_owner); + + // The strategy here is to add the function decl unconditionally, then to + // ask if it already exists, and if so, revert the lengths of the mutated + // arrays. This is similar to what `getOrPutTrailingString` does. + const prev_extra_len = ip.extra.items.len; + const params_len: u32 = @intCast(arg.param_types.len); + + try ip.map.ensureUnusedCapacity(gpa, 4); + try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(InternPool.Tag.FuncInstance).Struct.fields.len + + 1 + // inferred_error_set + arg.comptime_args.len + + @typeInfo(InternPool.Tag.ErrorUnionType).Struct.fields.len + + @typeInfo(InternPool.Tag.TypeFunction).Struct.fields.len + + @intFromBool(arg.noalias_bits != 0) + + params_len); + try ip.items.ensureUnusedCapacity(gpa, 4); + + const func_index: InternPool.Index = @enumFromInt(ip.items.len); + const error_union_type: InternPool.Index = @enumFromInt(ip.items.len + 1); + const error_set_type: InternPool.Index = @enumFromInt(ip.items.len + 2); + const func_ty: InternPool.Index = @enumFromInt(ip.items.len + 3); + + const func_extra_index = ip.addExtraAssumeCapacity(InternPool.Tag.FuncInstance{ + .analysis = .{ + .state = if (arg.cc == .Inline) .inline_only else .none, + .is_cold = false, + .is_noinline = arg.is_noinline, + .calls_or_awaits_errorable_fn = false, + .stack_alignment = .none, + .inferred_error_set = true, + }, + // This is populated after we create the Decl below. It is not read + // by equality or hashing functions. + .owner_decl = undefined, + .ty = func_ty, + .branch_quota = 0, + .generic_owner = generic_owner, + }); + ip.extra.appendAssumeCapacity(@intFromEnum(InternPool.Index.none)); // resolved error set + ip.extra.appendSliceAssumeCapacity(@ptrCast(arg.comptime_args)); + + const func_type_extra_index = ip.addExtraAssumeCapacity(InternPool.Tag.TypeFunction{ + .params_len = params_len, + .return_type = error_union_type, + .flags = .{ + .alignment = arg.alignment, + .cc = arg.cc, + .is_var_args = false, + .has_comptime_bits = false, + .has_noalias_bits = arg.noalias_bits != 0, + .is_generic = false, + .is_noinline = arg.is_noinline, + .align_is_generic = false, + .cc_is_generic = false, + .section_is_generic = false, + .addrspace_is_generic = false, + }, + }); + // no comptime_bits because has_comptime_bits is false + if (arg.noalias_bits != 0) ip.extra.appendAssumeCapacity(arg.noalias_bits); + ip.extra.appendSliceAssumeCapacity(@ptrCast(arg.param_types)); + + // TODO: add appendSliceAssumeCapacity to MultiArrayList. + ip.items.appendAssumeCapacity(.{ + .tag = .func_instance, + .data = func_extra_index, + }); + ip.items.appendAssumeCapacity(.{ + .tag = .type_error_union, + .data = ip.addExtraAssumeCapacity(InternPool.Tag.ErrorUnionType{ + .error_set_type = error_set_type, + .payload_type = arg.bare_return_type, + }), + }); + ip.items.appendAssumeCapacity(.{ + .tag = .type_inferred_error_set, + .data = @intFromEnum(func_index), + }); + ip.items.appendAssumeCapacity(.{ + .tag = .type_function, + .data = func_type_extra_index, + }); + + const adapter: InternPool.KeyAdapter = .{ .intern_pool = ip }; + const gop = ip.map.getOrPutAssumeCapacityAdapted(InternPool.Key{ + .func = ip.extraFuncInstance(func_extra_index), + }, adapter); + if (gop.found_existing) { + // Hot path: undo the additions to our two arrays. + ip.items.len -= 4; + ip.extra.items.len = prev_extra_len; + return @enumFromInt(gop.index); + } + + // Synchronize the map with items. + assert(!ip.map.getOrPutAssumeCapacityAdapted(InternPool.Key{ .error_union_type = .{ + .error_set_type = error_set_type, + .payload_type = arg.bare_return_type, + } }, adapter).found_existing); + assert(!ip.map.getOrPutAssumeCapacityAdapted(InternPool.Key{ + .inferred_error_set_type = func_index, + }, adapter).found_existing); + assert(!ip.map.getOrPutAssumeCapacityAdapted(InternPool.Key{ + .func_type = ip.extraFuncType(func_type_extra_index), + }, adapter).found_existing); + + return sema.finishFuncInstance( + generic_owner, + func_index, + func_extra_index, + arg.generation, + func_ty, + arg.section, + ); +} + +fn finishFuncInstance( + sema: *Sema, + generic_owner: InternPool.Index, + func_index: InternPool.Index, + func_extra_index: u32, + generation: u32, + func_ty: InternPool.Index, + section: InternPool.OptionalNullTerminatedString, +) Allocator.Error!InternPool.Index { + const gpa = sema.gpa; + const ip = &sema.mod.intern_pool; + + const fn_owner_decl = sema.mod.declPtr(ip.funcDeclOwner(generic_owner)); + const decl_index = try sema.mod.createDecl(.{ + .name = undefined, + .src_namespace = fn_owner_decl.src_namespace, + .src_node = fn_owner_decl.src_node, + .src_line = fn_owner_decl.src_line, + .has_tv = true, + .owns_tv = true, + .ty = @import("type.zig").Type.fromInterned(func_ty), + .val = @import("value.zig").Value.fromInterned(func_index), + .alignment = .none, + .@"linksection" = section, + .@"addrspace" = fn_owner_decl.@"addrspace", + .analysis = .complete, + .zir_decl_index = fn_owner_decl.zir_decl_index, + .src_scope = fn_owner_decl.src_scope, + .generation = generation, + .is_pub = fn_owner_decl.is_pub, + .is_exported = fn_owner_decl.is_exported, + .has_linksection_or_addrspace = fn_owner_decl.has_linksection_or_addrspace, + .has_align = fn_owner_decl.has_align, + .alive = true, + .kind = .anon, + }); + errdefer sema.mod.destroyDecl(decl_index); + + // Populate the owner_decl field which was left undefined until now. + ip.extra.items[ + func_extra_index + std.meta.fieldIndex(InternPool.Tag.FuncInstance, "owner_decl").? + ] = @intFromEnum(decl_index); + + // TODO: improve this name + const decl = sema.mod.declPtr(decl_index); + decl.name = try ip.getOrPutStringFmt(gpa, "{}__anon_{d}", .{ + fn_owner_decl.name.fmt(ip), @intFromEnum(decl_index), + }); + + return func_index; +} diff --git a/src/arch/aarch64/CodeGen.zig b/src/arch/aarch64/CodeGen.zig index 611eb267c2f9..303f73310a6c 100644 --- a/src/arch/aarch64/CodeGen.zig +++ b/src/arch/aarch64/CodeGen.zig @@ -13,7 +13,7 @@ const Value = @import("../../value.zig").Value; const TypedValue = @import("../../TypedValue.zig"); const link = @import("../../link.zig"); const Module = @import("../../Module.zig"); -const InternPool = @import("../../InternPool.zig"); +const InternPool = std.zig.InternPool; const Compilation = @import("../../Compilation.zig"); const ErrorMsg = Module.ErrorMsg; const Target = std.Target; diff --git a/src/arch/arm/CodeGen.zig b/src/arch/arm/CodeGen.zig index 5bb2b8838a7b..c1f836e5014e 100644 --- a/src/arch/arm/CodeGen.zig +++ b/src/arch/arm/CodeGen.zig @@ -13,7 +13,7 @@ const Value = @import("../../value.zig").Value; const TypedValue = @import("../../TypedValue.zig"); const link = @import("../../link.zig"); const Module = @import("../../Module.zig"); -const InternPool = @import("../../InternPool.zig"); +const InternPool = std.zig.InternPool; const Compilation = @import("../../Compilation.zig"); const ErrorMsg = Module.ErrorMsg; const Target = std.Target; diff --git a/src/arch/riscv64/CodeGen.zig b/src/arch/riscv64/CodeGen.zig index 3ea648f033ae..275490b0b9c4 100644 --- a/src/arch/riscv64/CodeGen.zig +++ b/src/arch/riscv64/CodeGen.zig @@ -12,7 +12,7 @@ const Value = @import("../../value.zig").Value; const TypedValue = @import("../../TypedValue.zig"); const link = @import("../../link.zig"); const Module = @import("../../Module.zig"); -const InternPool = @import("../../InternPool.zig"); +const InternPool = std.zig.InternPool; const Compilation = @import("../../Compilation.zig"); const ErrorMsg = Module.ErrorMsg; const Target = std.Target; diff --git a/src/arch/sparc64/CodeGen.zig b/src/arch/sparc64/CodeGen.zig index 62173e56f1d2..bbf1dbfaade3 100644 --- a/src/arch/sparc64/CodeGen.zig +++ b/src/arch/sparc64/CodeGen.zig @@ -11,7 +11,7 @@ const Allocator = mem.Allocator; const builtin = @import("builtin"); const link = @import("../../link.zig"); const Module = @import("../../Module.zig"); -const InternPool = @import("../../InternPool.zig"); +const InternPool = std.zig.InternPool; const TypedValue = @import("../../TypedValue.zig"); const ErrorMsg = Module.ErrorMsg; const codegen = @import("../../codegen.zig"); diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index caa71fe7ea9d..ea7f92a5ef6f 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/src/arch/wasm/CodeGen.zig @@ -11,7 +11,7 @@ const log = std.log.scoped(.codegen); const codegen = @import("../../codegen.zig"); const Module = @import("../../Module.zig"); -const InternPool = @import("../../InternPool.zig"); +const InternPool = std.zig.InternPool; const Decl = Module.Decl; const Type = @import("../../type.zig").Type; const Value = @import("../../value.zig").Value; diff --git a/src/arch/wasm/Emit.zig b/src/arch/wasm/Emit.zig index d1b7114b1255..b7afb3ca8ff2 100644 --- a/src/arch/wasm/Emit.zig +++ b/src/arch/wasm/Emit.zig @@ -6,8 +6,8 @@ const std = @import("std"); const Mir = @import("Mir.zig"); const link = @import("../../link.zig"); const Module = @import("../../Module.zig"); -const InternPool = @import("../../InternPool.zig"); const codegen = @import("../../codegen.zig"); +const InternPool = std.zig.InternPool; const leb128 = std.leb; /// Contains our list of instructions diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig index 478a1f712041..7cd946ea5028 100644 --- a/src/arch/x86_64/CodeGen.zig +++ b/src/arch/x86_64/CodeGen.zig @@ -26,7 +26,7 @@ const Liveness = @import("../../Liveness.zig"); const Lower = @import("Lower.zig"); const Mir = @import("Mir.zig"); const Module = @import("../../Module.zig"); -const InternPool = @import("../../InternPool.zig"); +const InternPool = std.zig.InternPool; const Alignment = InternPool.Alignment; const Target = std.Target; const Type = @import("../../type.zig").Type; @@ -10527,7 +10527,7 @@ fn genArgDbgInfo(self: Self, ty: Type, name: [:0]const u8, mcv: MCValue) !void { else => unreachable, // not a valid function parameter }; // TODO: this might need adjusting like the linkers do. - // Instead of flattening the owner and passing Decl.Index here we may + // Instead of flattening the owner and passing InternPool.DeclIndex here we may // want to special case LazySymbol in DWARF linker too. try dw.genArgDbgInfo(name, ty, self.owner.getDecl(mod), loc); }, @@ -10578,7 +10578,7 @@ fn genVarDbgInfo( }, }; // TODO: this might need adjusting like the linkers do. - // Instead of flattening the owner and passing Decl.Index here we may + // Instead of flattening the owner and passing InternPool.DeclIndex here we may // want to special case LazySymbol in DWARF linker too. try dw.genVarDbgInfo(name, ty, self.owner.getDecl(mod), is_ptr, loc); }, diff --git a/src/arch/x86_64/Mir.zig b/src/arch/x86_64/Mir.zig index de3db8d2245d..58148a1ae971 100644 --- a/src/arch/x86_64/Mir.zig +++ b/src/arch/x86_64/Mir.zig @@ -1196,6 +1196,6 @@ const encoder = @import("encoder.zig"); const std = @import("std"); const IntegerBitSet = std.bit_set.IntegerBitSet; -const InternPool = @import("../../InternPool.zig"); +const InternPool = std.zig.InternPool; const Mir = @This(); const Register = bits.Register; diff --git a/src/codegen.zig b/src/codegen.zig index b7f50c217450..a8a459e4706f 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -14,14 +14,14 @@ const Air = @import("Air.zig"); const Allocator = mem.Allocator; const Compilation = @import("Compilation.zig"); const ErrorMsg = Module.ErrorMsg; -const InternPool = @import("InternPool.zig"); +const InternPool = std.zig.InternPool; const Liveness = @import("Liveness.zig"); 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 Zir = @import("Zir.zig"); +const Zir = std.zig.Zir; const Alignment = InternPool.Alignment; pub const Result = union(enum) { diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 5e326336a5e2..2e71fd8a6b19 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -16,7 +16,7 @@ const trace = @import("../tracy.zig").trace; const LazySrcLoc = Module.LazySrcLoc; const Air = @import("../Air.zig"); const Liveness = @import("../Liveness.zig"); -const InternPool = @import("../InternPool.zig"); +const InternPool = std.zig.InternPool; const Alignment = InternPool.Alignment; const BigIntLimb = std.math.big.Limb; diff --git a/src/codegen/c/type.zig b/src/codegen/c/type.zig index 57b6b97d75c5..002b1710badc 100644 --- a/src/codegen/c/type.zig +++ b/src/codegen/c/type.zig @@ -5,9 +5,9 @@ const assert = std.debug.assert; const autoHash = std.hash.autoHash; const Target = std.Target; -const Alignment = @import("../../InternPool.zig").Alignment; +const InternPool = std.zig.InternPool; +const Alignment = InternPool.Alignment; const Module = @import("../../Module.zig"); -const InternPool = @import("../../InternPool.zig"); const Type = @import("../../type.zig").Type; pub const CType = extern union { diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index a179b4cc1bfd..0273a7ca3db9 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -15,7 +15,7 @@ const link = @import("../link.zig"); const Compilation = @import("../Compilation.zig"); const build_options = @import("build_options"); const Module = @import("../Module.zig"); -const InternPool = @import("../InternPool.zig"); +const InternPool = std.zig.InternPool; const Package = @import("../Package.zig"); const TypedValue = @import("../TypedValue.zig"); const Air = @import("../Air.zig"); @@ -1087,7 +1087,7 @@ pub const Object = struct { table_variable_index.setMutability(.constant, &o.builder); table_variable_index.setUnnamedAddr(.unnamed_addr, &o.builder); table_variable_index.setAlignment( - slice_ty.abiAlignment(mod).toLlvm(), + Builder.Alignment.fromInternPool(slice_ty.abiAlignment(mod)), &o.builder, ); @@ -1346,7 +1346,7 @@ pub const Object = struct { const stack_alignment = func.analysis(ip).stack_alignment; if (stack_alignment != .none) { - try attributes.addFnAttr(.{ .alignstack = stack_alignment.toLlvm() }, &o.builder); + try attributes.addFnAttr(.{ .alignstack = Builder.Alignment.fromInternPool(stack_alignment) }, &o.builder); try attributes.addFnAttr(.@"noinline", &o.builder); } else { _ = try attributes.removeFnAttr(.alignstack); @@ -1434,7 +1434,7 @@ pub const Object = struct { const param = wip.arg(llvm_arg_i); if (isByRef(param_ty, mod)) { - const alignment = param_ty.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(param_ty.abiAlignment(mod)); const param_llvm_ty = param.typeOfWip(&wip); const arg_ptr = try buildAllocaInner(&wip, false, param_llvm_ty, alignment, target); _ = try wip.store(.normal, param, arg_ptr, alignment); @@ -1450,7 +1450,7 @@ pub const Object = struct { const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]); const param_llvm_ty = try o.lowerType(param_ty); const param = wip.arg(llvm_arg_i); - const alignment = param_ty.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(param_ty.abiAlignment(mod)); try o.addByRefParamAttrs(&attributes, llvm_arg_i, alignment, it.byval_attr, param_llvm_ty); llvm_arg_i += 1; @@ -1465,7 +1465,7 @@ pub const Object = struct { const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]); const param_llvm_ty = try o.lowerType(param_ty); const param = wip.arg(llvm_arg_i); - const alignment = param_ty.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(param_ty.abiAlignment(mod)); try attributes.addParamAttr(llvm_arg_i, .noundef, &o.builder); llvm_arg_i += 1; @@ -1483,7 +1483,7 @@ pub const Object = struct { llvm_arg_i += 1; const param_llvm_ty = try o.lowerType(param_ty); - const alignment = param_ty.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(param_ty.abiAlignment(mod)); const arg_ptr = try buildAllocaInner(&wip, false, param_llvm_ty, alignment, target); _ = try wip.store(.normal, param, arg_ptr, alignment); @@ -1508,10 +1508,10 @@ pub const Object = struct { if (ptr_info.flags.is_const) { try attributes.addParamAttr(llvm_arg_i, .readonly, &o.builder); } - const elem_align = (if (ptr_info.flags.alignment != .none) + const elem_align = Builder.Alignment.fromInternPool(if (ptr_info.flags.alignment != .none) @as(InternPool.Alignment, ptr_info.flags.alignment) else - Type.fromInterned(ptr_info.child).abiAlignment(mod).max(.@"1")).toLlvm(); + Type.fromInterned(ptr_info.child).abiAlignment(mod).max(.@"1")); try attributes.addParamAttr(llvm_arg_i, .{ .@"align" = elem_align }, &o.builder); const ptr_param = wip.arg(llvm_arg_i); llvm_arg_i += 1; @@ -1528,7 +1528,7 @@ pub const Object = struct { const field_types = it.types_buffer[0..it.types_len]; const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]); const param_llvm_ty = try o.lowerType(param_ty); - const param_alignment = param_ty.abiAlignment(mod).toLlvm(); + const param_alignment = Builder.Alignment.fromInternPool(param_ty.abiAlignment(mod)); const arg_ptr = try buildAllocaInner(&wip, false, param_llvm_ty, param_alignment, target); const llvm_ty = try o.builder.structType(.normal, field_types); for (0..field_types.len) |field_i| { @@ -1558,7 +1558,7 @@ pub const Object = struct { const param = wip.arg(llvm_arg_i); llvm_arg_i += 1; - const alignment = param_ty.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(param_ty.abiAlignment(mod)); const arg_ptr = try buildAllocaInner(&wip, false, param_llvm_ty, alignment, target); _ = try wip.store(.normal, param, arg_ptr, alignment); @@ -1573,7 +1573,7 @@ pub const Object = struct { const param = wip.arg(llvm_arg_i); llvm_arg_i += 1; - const alignment = param_ty.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(param_ty.abiAlignment(mod)); const arg_ptr = try buildAllocaInner(&wip, false, param_llvm_ty, alignment, target); _ = try wip.store(.normal, param, arg_ptr, alignment); @@ -3007,7 +3007,7 @@ pub const Object = struct { } if (fn_info.alignment != .none) - function_index.setAlignment(fn_info.alignment.toLlvm(), &o.builder); + function_index.setAlignment(Builder.Alignment.fromInternPool(fn_info.alignment), &o.builder); // Function attributes that are independent of analysis results of the function body. try o.addCommonFnAttributes(&attributes); @@ -3031,7 +3031,7 @@ pub const Object = struct { const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]); const param_llvm_ty = try o.lowerType(param_ty); const alignment = param_ty.abiAlignment(mod); - try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment.toLlvm(), it.byval_attr, param_llvm_ty); + try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, Builder.Alignment.fromInternPool(alignment), it.byval_attr, param_llvm_ty); }, .byref_mut => try attributes.addParamAttr(it.llvm_index - 1, .noundef, &o.builder), // No attributes needed for these. @@ -3126,9 +3126,9 @@ pub const Object = struct { if (gop.found_existing) { // Keep the greater of the two alignments. const variable_index = gop.value_ptr.ptr(&o.builder).kind.variable; - const old_alignment = InternPool.Alignment.fromLlvm(variable_index.getAlignment(&o.builder)); + const old_alignment = Builder.Alignment.toInternPool(variable_index.getAlignment(&o.builder)); const max_alignment = old_alignment.maxStrict(alignment); - variable_index.setAlignment(max_alignment.toLlvm(), &o.builder); + variable_index.setAlignment(Builder.Alignment.fromInternPool(max_alignment), &o.builder); return variable_index; } errdefer assert(o.anon_decl_map.remove(decl_val)); @@ -3146,7 +3146,7 @@ pub const Object = struct { try variable_index.setInitializer(try o.lowerValue(decl_val), &o.builder); variable_index.setLinkage(.internal, &o.builder); variable_index.setUnnamedAddr(.unnamed_addr, &o.builder); - variable_index.setAlignment(alignment.toLlvm(), &o.builder); + variable_index.setAlignment(Builder.Alignment.fromInternPool(alignment), &o.builder); return variable_index; } @@ -4621,7 +4621,7 @@ pub const Object = struct { ptr_info.flags.alignment else Type.fromInterned(ptr_info.child).abiAlignment(mod).max(.@"1"); - try attributes.addParamAttr(llvm_arg_i, .{ .@"align" = elem_align.toLlvm() }, &o.builder); + try attributes.addParamAttr(llvm_arg_i, .{ .@"align" = Builder.Alignment.fromInternPool(elem_align) }, &o.builder); } else if (ccAbiPromoteInt(fn_info.cc, mod, param_ty)) |s| switch (s) { .signed => try attributes.addParamAttr(llvm_arg_i, .signext, &o.builder), .unsigned => try attributes.addParamAttr(llvm_arg_i, .zeroext, &o.builder), @@ -4679,7 +4679,7 @@ pub const DeclGen = struct { } else { const variable_index = try o.resolveGlobalDecl(decl_index); variable_index.setAlignment( - decl.getAlignment(mod).toLlvm(), + Builder.Alignment.fromInternPool(decl.getAlignment(mod)), &o.builder, ); if (mod.intern_pool.stringToSliceUnwrap(decl.@"linksection")) |section| @@ -4821,7 +4821,7 @@ pub const FuncGen = struct { variable_index.setLinkage(.private, &o.builder); variable_index.setMutability(.constant, &o.builder); variable_index.setUnnamedAddr(.unnamed_addr, &o.builder); - variable_index.setAlignment(tv.ty.abiAlignment(mod).toLlvm(), &o.builder); + variable_index.setAlignment(Builder.Alignment.fromInternPool(tv.ty.abiAlignment(mod)), &o.builder); return o.builder.convConst( .unneeded, variable_index.toConst(&o.builder), @@ -5137,7 +5137,7 @@ pub const FuncGen = struct { const llvm_ret_ty = try o.lowerType(return_type); try attributes.addParamAttr(0, .{ .sret = llvm_ret_ty }, &o.builder); - const alignment = return_type.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(return_type.abiAlignment(mod)); const ret_ptr = try self.buildAllocaWorkaround(return_type, alignment); try llvm_args.append(ret_ptr); break :blk ret_ptr; @@ -5159,7 +5159,7 @@ pub const FuncGen = struct { const llvm_arg = try self.resolveInst(arg); const llvm_param_ty = try o.lowerType(param_ty); if (isByRef(param_ty, mod)) { - const alignment = param_ty.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(param_ty.abiAlignment(mod)); const loaded = try self.wip.load(.normal, llvm_param_ty, llvm_arg, alignment, ""); try llvm_args.append(loaded); } else { @@ -5173,7 +5173,7 @@ pub const FuncGen = struct { if (isByRef(param_ty, mod)) { try llvm_args.append(llvm_arg); } else { - const alignment = param_ty.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(param_ty.abiAlignment(mod)); const param_llvm_ty = llvm_arg.typeOfWip(&self.wip); const arg_ptr = try self.buildAlloca(param_llvm_ty, alignment); _ = try self.wip.store(.normal, llvm_arg, arg_ptr, alignment); @@ -5185,7 +5185,7 @@ pub const FuncGen = struct { const param_ty = self.typeOf(arg); const llvm_arg = try self.resolveInst(arg); - const alignment = param_ty.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(param_ty.abiAlignment(mod)); const param_llvm_ty = try o.lowerType(param_ty); const arg_ptr = try self.buildAllocaWorkaround(param_ty, alignment); if (isByRef(param_ty, mod)) { @@ -5203,13 +5203,13 @@ pub const FuncGen = struct { const int_llvm_ty = try o.builder.intType(@intCast(param_ty.abiSize(mod) * 8)); if (isByRef(param_ty, mod)) { - const alignment = param_ty.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(param_ty.abiAlignment(mod)); const loaded = try self.wip.load(.normal, int_llvm_ty, llvm_arg, alignment, ""); try llvm_args.append(loaded); } else { // LLVM does not allow bitcasting structs so we must allocate // a local, store as one type, and then load as another type. - const alignment = param_ty.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(param_ty.abiAlignment(mod)); const int_ptr = try self.buildAllocaWorkaround(param_ty, alignment); _ = try self.wip.store(.normal, llvm_arg, int_ptr, alignment); const loaded = try self.wip.load(.normal, int_llvm_ty, int_ptr, alignment, ""); @@ -5230,7 +5230,7 @@ pub const FuncGen = struct { const llvm_arg = try self.resolveInst(arg); const is_by_ref = isByRef(param_ty, mod); const arg_ptr = if (is_by_ref) llvm_arg else ptr: { - const alignment = param_ty.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(param_ty.abiAlignment(mod)); const ptr = try self.buildAlloca(llvm_arg.typeOfWip(&self.wip), alignment); _ = try self.wip.store(.normal, llvm_arg, ptr, alignment); break :ptr ptr; @@ -5256,7 +5256,7 @@ pub const FuncGen = struct { const arg = args[it.zig_index - 1]; const arg_ty = self.typeOf(arg); var llvm_arg = try self.resolveInst(arg); - const alignment = arg_ty.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(arg_ty.abiAlignment(mod)); if (!isByRef(arg_ty, mod)) { const ptr = try self.buildAlloca(llvm_arg.typeOfWip(&self.wip), alignment); _ = try self.wip.store(.normal, llvm_arg, ptr, alignment); @@ -5274,7 +5274,7 @@ pub const FuncGen = struct { const arg = args[it.zig_index - 1]; const arg_ty = self.typeOf(arg); var llvm_arg = try self.resolveInst(arg); - const alignment = arg_ty.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(arg_ty.abiAlignment(mod)); if (!isByRef(arg_ty, mod)) { const ptr = try self.buildAlloca(llvm_arg.typeOfWip(&self.wip), alignment); _ = try self.wip.store(.normal, llvm_arg, ptr, alignment); @@ -5305,7 +5305,7 @@ pub const FuncGen = struct { const param_index = it.zig_index - 1; const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]); const param_llvm_ty = try o.lowerType(param_ty); - const alignment = param_ty.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(param_ty.abiAlignment(mod)); try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment, it.byval_attr, param_llvm_ty); }, .byref_mut => try attributes.addParamAttr(it.llvm_index - 1, .noundef, &o.builder), @@ -5336,10 +5336,10 @@ pub const FuncGen = struct { if (ptr_info.flags.is_const) { try attributes.addParamAttr(llvm_arg_i, .readonly, &o.builder); } - const elem_align = (if (ptr_info.flags.alignment != .none) + const elem_align = Builder.Alignment.fromInternPool(if (ptr_info.flags.alignment != .none) @as(InternPool.Alignment, ptr_info.flags.alignment) else - Type.fromInterned(ptr_info.child).abiAlignment(mod).max(.@"1")).toLlvm(); + Type.fromInterned(ptr_info.child).abiAlignment(mod).max(.@"1")); try attributes.addParamAttr(llvm_arg_i, .{ .@"align" = elem_align }, &o.builder); }, }; @@ -5374,7 +5374,7 @@ pub const FuncGen = struct { return rp; } else { // our by-ref status disagrees with sret so we must load. - const return_alignment = return_type.abiAlignment(mod).toLlvm(); + const return_alignment = Builder.Alignment.fromInternPool(return_type.abiAlignment(mod)); return self.wip.load(.normal, llvm_ret_ty, rp, return_alignment, ""); } } @@ -5385,7 +5385,7 @@ pub const FuncGen = struct { // In this case the function return type is honoring the calling convention by having // a different LLVM type than the usual one. We solve this here at the callsite // by using our canonical type, then loading it if necessary. - const alignment = return_type.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(return_type.abiAlignment(mod)); if (o.builder.useLibLlvm()) assert(o.target_data.abiSizeOfType(abi_ret_ty.toLlvm(&o.builder)) >= o.target_data.abiSizeOfType(llvm_ret_ty.toLlvm(&o.builder))); @@ -5400,7 +5400,7 @@ pub const FuncGen = struct { if (isByRef(return_type, mod)) { // our by-ref status disagrees with sret so we must allocate, store, // and return the allocation pointer. - const alignment = return_type.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(return_type.abiAlignment(mod)); const rp = try self.buildAlloca(llvm_ret_ty, alignment); _ = try self.wip.store(.normal, call, rp, alignment); return rp; @@ -5484,7 +5484,7 @@ pub const FuncGen = struct { const abi_ret_ty = try lowerFnRetTy(o, fn_info); const operand = try self.resolveInst(un_op); - const alignment = ret_ty.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(ret_ty.abiAlignment(mod)); if (isByRef(ret_ty, mod)) { // operand is a pointer however self.ret_ptr is null so that means @@ -5529,7 +5529,7 @@ pub const FuncGen = struct { } const ptr = try self.resolveInst(un_op); const abi_ret_ty = try lowerFnRetTy(o, fn_info); - const alignment = ret_ty.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(ret_ty.abiAlignment(mod)); _ = try self.wip.ret(try self.wip.load(.normal, abi_ret_ty, ptr, alignment, "")); return .none; } @@ -5552,7 +5552,7 @@ pub const FuncGen = struct { const llvm_va_list_ty = try o.lowerType(va_list_ty); const mod = o.module; - const result_alignment = va_list_ty.abiAlignment(mod).toLlvm(); + const result_alignment = Builder.Alignment.fromInternPool(va_list_ty.abiAlignment(mod)); const dest_list = try self.buildAllocaWorkaround(va_list_ty, result_alignment); _ = try self.wip.callIntrinsic(.normal, .none, .va_copy, &.{}, &.{ dest_list, src_list }, ""); @@ -5576,7 +5576,7 @@ pub const FuncGen = struct { const va_list_ty = self.typeOfIndex(inst); const llvm_va_list_ty = try o.lowerType(va_list_ty); - const result_alignment = va_list_ty.abiAlignment(mod).toLlvm(); + const result_alignment = Builder.Alignment.fromInternPool(va_list_ty.abiAlignment(mod)); const dest_list = try self.buildAllocaWorkaround(va_list_ty, result_alignment); _ = try self.wip.callIntrinsic(.normal, .none, .va_start, &.{}, &.{dest_list}, ""); @@ -5909,7 +5909,7 @@ pub const FuncGen = struct { return fg.wip.gepStruct(err_union_llvm_ty, err_union, offset, ""); } else if (isByRef(err_union_ty, mod)) { const payload_ptr = try fg.wip.gepStruct(err_union_llvm_ty, err_union, offset, ""); - const payload_alignment = payload_ty.abiAlignment(mod).toLlvm(); + const payload_alignment = Builder.Alignment.fromInternPool(payload_ty.abiAlignment(mod)); if (isByRef(payload_ty, mod)) { if (can_elide_load) return payload_ptr; @@ -6235,7 +6235,7 @@ pub const FuncGen = struct { if (self.canElideLoad(body_tail)) return ptr; - const elem_alignment = elem_ty.abiAlignment(mod).toLlvm(); + const elem_alignment = Builder.Alignment.fromInternPool(elem_ty.abiAlignment(mod)); return self.loadByRef(ptr, elem_ty, elem_alignment, .normal); } @@ -6275,7 +6275,7 @@ pub const FuncGen = struct { const elem_ptr = try self.wip.gep(.inbounds, array_llvm_ty, array_llvm_val, &indices, ""); if (canElideLoad(self, body_tail)) return elem_ptr; - const elem_alignment = elem_ty.abiAlignment(mod).toLlvm(); + const elem_alignment = Builder.Alignment.fromInternPool(elem_ty.abiAlignment(mod)); return self.loadByRef(elem_ptr, elem_ty, elem_alignment, .normal); } else { if (Air.refToIndex(bin_op.lhs)) |lhs_index| { @@ -6334,7 +6334,7 @@ pub const FuncGen = struct { &.{rhs}, ""); if (isByRef(elem_ty, mod)) { if (self.canElideLoad(body_tail)) return ptr; - const elem_alignment = elem_ty.abiAlignment(mod).toLlvm(); + const elem_alignment = Builder.Alignment.fromInternPool(elem_ty.abiAlignment(mod)); return self.loadByRef(ptr, elem_ty, elem_alignment, .normal); } @@ -6464,7 +6464,7 @@ pub const FuncGen = struct { return field_ptr; assert(alignment != .none); - const field_alignment = alignment.toLlvm(); + const field_alignment = Builder.Alignment.fromInternPool(alignment); return self.loadByRef(field_ptr, field_ty, field_alignment, .normal); } else { return self.load(field_ptr, field_ptr_ty); @@ -6476,7 +6476,7 @@ pub const FuncGen = struct { const payload_index = @intFromBool(layout.tag_align.compare(.gte, layout.payload_align)); const field_ptr = try self.wip.gepStruct(union_llvm_ty, struct_llvm_val, payload_index, ""); - const payload_alignment = layout.payload_align.toLlvm(); + const payload_alignment = Builder.Alignment.fromInternPool(layout.payload_align); if (isByRef(field_ty, mod)) { if (canElideLoad(self, body_tail)) return field_ptr; return self.loadByRef(field_ptr, field_ty, payload_alignment, .normal); @@ -6682,7 +6682,7 @@ pub const FuncGen = struct { if (isByRef(operand_ty, mod)) { _ = dib.insertDeclareAtEnd(operand.toLlvm(&self.wip), di_local_var, debug_loc, insert_block); } else if (o.module.comp.bin_file.options.optimize_mode == .Debug) { - const alignment = operand_ty.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(operand_ty.abiAlignment(mod)); const alloca = try self.buildAlloca(operand.typeOfWip(&self.wip), alignment); _ = try self.wip.store(.normal, operand, alloca, alignment); _ = dib.insertDeclareAtEnd(alloca.toLlvm(&self.wip), di_local_var, debug_loc, insert_block); @@ -6837,7 +6837,7 @@ pub const FuncGen = struct { llvm_param_values[llvm_param_i] = arg_llvm_value; llvm_param_types[llvm_param_i] = arg_llvm_value.typeOfWip(&self.wip); } else { - const alignment = arg_ty.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(arg_ty.abiAlignment(mod)); const arg_llvm_ty = try o.lowerType(arg_ty); const load_inst = try self.wip.load(.normal, arg_llvm_ty, arg_llvm_value, alignment, ""); @@ -6849,7 +6849,7 @@ pub const FuncGen = struct { llvm_param_values[llvm_param_i] = arg_llvm_value; llvm_param_types[llvm_param_i] = arg_llvm_value.typeOfWip(&self.wip); } else { - const alignment = arg_ty.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(arg_ty.abiAlignment(mod)); const arg_ptr = try self.buildAlloca(arg_llvm_value.typeOfWip(&self.wip), alignment); _ = try self.wip.store(.normal, arg_llvm_value, arg_ptr, alignment); llvm_param_values[llvm_param_i] = arg_ptr; @@ -6901,7 +6901,7 @@ pub const FuncGen = struct { llvm_param_values[llvm_param_i] = llvm_rw_val; llvm_param_types[llvm_param_i] = llvm_rw_val.typeOfWip(&self.wip); } else { - const alignment = rw_ty.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(rw_ty.abiAlignment(mod)); const loaded = try self.wip.load(.normal, llvm_elem_ty, llvm_rw_val, alignment, ""); llvm_param_values[llvm_param_i] = loaded; llvm_param_types[llvm_param_i] = llvm_elem_ty; @@ -7062,7 +7062,7 @@ pub const FuncGen = struct { const output_ptr = try self.resolveInst(output); const output_ptr_ty = self.typeOf(output); - const alignment = output_ptr_ty.ptrAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(output_ptr_ty.ptrAlignment(mod)); _ = try self.wip.store(.normal, output_value, output_ptr, alignment); } else { ret_val = output_value; @@ -7256,7 +7256,7 @@ pub const FuncGen = struct { if (operand_is_ptr) { return self.wip.gepStruct(err_union_llvm_ty, operand, offset, ""); } else if (isByRef(err_union_ty, mod)) { - const payload_alignment = payload_ty.abiAlignment(mod).toLlvm(); + const payload_alignment = Builder.Alignment.fromInternPool(payload_ty.abiAlignment(mod)); const payload_ptr = try self.wip.gepStruct(err_union_llvm_ty, operand, offset, ""); if (isByRef(payload_ty, mod)) { if (self.canElideLoad(body_tail)) return payload_ptr; @@ -7321,7 +7321,7 @@ pub const FuncGen = struct { const err_union_llvm_ty = try o.lowerType(err_union_ty); { const err_int_ty = try mod.errorIntType(); - const error_alignment = err_int_ty.abiAlignment(mod).toLlvm(); + const error_alignment = Builder.Alignment.fromInternPool(err_int_ty.abiAlignment(mod)); const error_offset = try errUnionErrorOffset(payload_ty, mod); // First set the non-error value. const non_null_ptr = try self.wip.gepStruct(err_union_llvm_ty, operand, error_offset, ""); @@ -7407,7 +7407,7 @@ pub const FuncGen = struct { const optional_ptr = if (directReturn) self.ret_ptr else brk: { - const alignment = optional_ty.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(optional_ty.abiAlignment(mod)); const optional_ptr = try self.buildAllocaWorkaround(optional_ty, alignment); break :brk optional_ptr; }; @@ -7443,14 +7443,14 @@ pub const FuncGen = struct { const result_ptr = if (directReturn) self.ret_ptr else brk: { - const alignment = err_un_ty.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(err_un_ty.abiAlignment(mod)); const result_ptr = try self.buildAllocaWorkaround(err_un_ty, alignment); break :brk result_ptr; }; const err_ptr = try self.wip.gepStruct(err_un_llvm_ty, result_ptr, error_offset, ""); const err_int_ty = try mod.errorIntType(); - const error_alignment = err_int_ty.abiAlignment(mod).toLlvm(); + const error_alignment = Builder.Alignment.fromInternPool(err_int_ty.abiAlignment(mod)); _ = try self.wip.store(.normal, ok_err_code, err_ptr, error_alignment); const payload_ptr = try self.wip.gepStruct(err_un_llvm_ty, result_ptr, payload_offset, ""); const payload_ptr_ty = try mod.singleMutPtrType(payload_ty); @@ -7481,14 +7481,14 @@ pub const FuncGen = struct { const result_ptr = if (directReturn) self.ret_ptr else brk: { - const alignment = err_un_ty.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(err_un_ty.abiAlignment(mod)); const result_ptr = try self.buildAllocaWorkaround(err_un_ty, alignment); break :brk result_ptr; }; const err_ptr = try self.wip.gepStruct(err_un_llvm_ty, result_ptr, error_offset, ""); const err_int_ty = try mod.errorIntType(); - const error_alignment = err_int_ty.abiAlignment(mod).toLlvm(); + const error_alignment = Builder.Alignment.fromInternPool(err_int_ty.abiAlignment(mod)); _ = try self.wip.store(.normal, operand, err_ptr, error_alignment); const payload_ptr = try self.wip.gepStruct(err_un_llvm_ty, result_ptr, payload_offset, ""); const payload_ptr_ty = try mod.singleMutPtrType(payload_ty); @@ -7535,7 +7535,7 @@ pub const FuncGen = struct { const access_kind: Builder.MemoryAccessKind = if (vector_ptr_ty.isVolatilePtr(mod)) .@"volatile" else .normal; const elem_llvm_ty = try o.lowerType(vector_ptr_ty.childType(mod)); - const alignment = vector_ptr_ty.ptrAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(vector_ptr_ty.ptrAlignment(mod)); const loaded = try self.wip.load(access_kind, elem_llvm_ty, vector_ptr, alignment, ""); const new_vector = try self.wip.insertElement(loaded, operand, index, ""); @@ -7965,7 +7965,7 @@ pub const FuncGen = struct { const overflow_index = o.llvmFieldIndex(inst_ty, 1).?; if (isByRef(inst_ty, mod)) { - const result_alignment = inst_ty.abiAlignment(mod).toLlvm(); + const result_alignment = Builder.Alignment.fromInternPool(inst_ty.abiAlignment(mod)); const alloca_inst = try self.buildAllocaWorkaround(inst_ty, result_alignment); { const field_ptr = try self.wip.gepStruct(llvm_inst_ty, alloca_inst, result_index, ""); @@ -8323,7 +8323,7 @@ pub const FuncGen = struct { const overflow_index = o.llvmFieldIndex(dest_ty, 1).?; if (isByRef(dest_ty, mod)) { - const result_alignment = dest_ty.abiAlignment(mod).toLlvm(); + const result_alignment = Builder.Alignment.fromInternPool(dest_ty.abiAlignment(mod)); const alloca_inst = try self.buildAllocaWorkaround(dest_ty, result_alignment); { const field_ptr = try self.wip.gepStruct(llvm_dest_ty, alloca_inst, result_index, ""); @@ -8618,7 +8618,7 @@ pub const FuncGen = struct { const array_ptr = try self.buildAllocaWorkaround(inst_ty, .default); const bitcast_ok = elem_ty.bitSize(mod) == elem_ty.abiSize(mod) * 8; if (bitcast_ok) { - const alignment = inst_ty.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(inst_ty.abiAlignment(mod)); _ = try self.wip.store(.normal, operand, array_ptr, alignment); } else { // If the ABI size of the element type is not evenly divisible by size in bits; @@ -8646,7 +8646,7 @@ pub const FuncGen = struct { if (bitcast_ok) { // The array is aligned to the element's alignment, while the vector might have a completely // different alignment. This means we need to enforce the alignment of this load. - const alignment = elem_ty.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(elem_ty.abiAlignment(mod)); return self.wip.load(.normal, llvm_vector_ty, operand, alignment, ""); } else { // If the ABI size of the element type is not evenly divisible by size in bits; @@ -8671,12 +8671,12 @@ pub const FuncGen = struct { } if (operand_is_ref) { - const alignment = operand_ty.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(operand_ty.abiAlignment(mod)); return self.wip.load(.normal, llvm_dest_ty, operand, alignment, ""); } if (result_is_ref) { - const alignment = operand_ty.abiAlignment(mod).max(inst_ty.abiAlignment(mod)).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(operand_ty.abiAlignment(mod).max(inst_ty.abiAlignment(mod))); const result_ptr = try self.buildAllocaWorkaround(inst_ty, alignment); _ = try self.wip.store(.normal, operand, result_ptr, alignment); return result_ptr; @@ -8688,7 +8688,7 @@ pub const FuncGen = struct { // Both our operand and our result are values, not pointers, // but LLVM won't let us bitcast struct values or vectors with padding bits. // Therefore, we store operand to alloca, then load for result. - const alignment = operand_ty.abiAlignment(mod).max(inst_ty.abiAlignment(mod)).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(operand_ty.abiAlignment(mod).max(inst_ty.abiAlignment(mod))); const result_ptr = try self.buildAllocaWorkaround(inst_ty, alignment); _ = try self.wip.store(.normal, operand, result_ptr, alignment); return self.wip.load(.normal, llvm_dest_ty, result_ptr, alignment, ""); @@ -8734,7 +8734,7 @@ pub const FuncGen = struct { if (isByRef(inst_ty, mod)) { _ = dib.insertDeclareAtEnd(arg_val.toLlvm(&self.wip), di_local_var, debug_loc, insert_block); } else if (o.module.comp.bin_file.options.optimize_mode == .Debug) { - const alignment = inst_ty.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(inst_ty.abiAlignment(mod)); const alloca = try self.buildAlloca(arg_val.typeOfWip(&self.wip), alignment); _ = try self.wip.store(.normal, arg_val, alloca, alignment); _ = dib.insertDeclareAtEnd(alloca.toLlvm(&self.wip), di_local_var, debug_loc, insert_block); @@ -8755,7 +8755,7 @@ pub const FuncGen = struct { return (try o.lowerPtrToVoid(ptr_ty)).toValue(); //const pointee_llvm_ty = try o.lowerType(pointee_type); - const alignment = ptr_ty.ptrAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(ptr_ty.ptrAlignment(mod)); return self.buildAllocaWorkaround(pointee_type, alignment); } @@ -8768,7 +8768,7 @@ pub const FuncGen = struct { return (try o.lowerPtrToVoid(ptr_ty)).toValue(); if (self.ret_ptr != .none) return self.ret_ptr; //const ret_llvm_ty = try o.lowerType(ret_ty); - const alignment = ptr_ty.ptrAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(ptr_ty.ptrAlignment(mod)); return self.buildAllocaWorkaround(ret_ty, alignment); } @@ -8818,7 +8818,7 @@ pub const FuncGen = struct { const len = try o.builder.intValue(try o.lowerType(Type.usize), operand_ty.abiSize(mod)); _ = try self.wip.callMemSet( dest_ptr, - ptr_ty.ptrAlignment(mod).toLlvm(), + Builder.Alignment.fromInternPool(ptr_ty.ptrAlignment(mod)), if (safety) try o.builder.intValue(.i8, 0xaa) else try o.builder.undefValue(.i8), len, if (ptr_ty.isVolatilePtr(mod)) .@"volatile" else .normal, @@ -8949,7 +8949,7 @@ pub const FuncGen = struct { self.sync_scope, toLlvmAtomicOrdering(extra.successOrder()), toLlvmAtomicOrdering(extra.failureOrder()), - ptr_ty.ptrAlignment(mod).toLlvm(), + Builder.Alignment.fromInternPool(ptr_ty.ptrAlignment(mod)), "", ); @@ -8988,7 +8988,7 @@ pub const FuncGen = struct { const access_kind: Builder.MemoryAccessKind = if (ptr_ty.isVolatilePtr(mod)) .@"volatile" else .normal; - const ptr_alignment = ptr_ty.ptrAlignment(mod).toLlvm(); + const ptr_alignment = Builder.Alignment.fromInternPool(ptr_ty.ptrAlignment(mod)); if (llvm_abi_ty != .none) { // operand needs widening and truncating or bitcasting. @@ -9044,10 +9044,10 @@ pub const FuncGen = struct { if (!elem_ty.hasRuntimeBitsIgnoreComptime(mod)) return .none; const ordering = toLlvmAtomicOrdering(atomic_load.order); const llvm_abi_ty = try o.getAtomicAbiType(elem_ty, false); - const ptr_alignment = (if (info.flags.alignment != .none) + const ptr_alignment = Builder.Alignment.fromInternPool(if (info.flags.alignment != .none) @as(InternPool.Alignment, info.flags.alignment) else - Type.fromInterned(info.child).abiAlignment(mod)).toLlvm(); + Type.fromInterned(info.child).abiAlignment(mod)); const access_kind: Builder.MemoryAccessKind = if (info.flags.is_volatile) .@"volatile" else .normal; const elem_llvm_ty = try o.lowerType(elem_ty); @@ -9111,7 +9111,7 @@ pub const FuncGen = struct { const dest_slice = try self.resolveInst(bin_op.lhs); const ptr_ty = self.typeOf(bin_op.lhs); const elem_ty = self.typeOf(bin_op.rhs); - const dest_ptr_align = ptr_ty.ptrAlignment(mod).toLlvm(); + const dest_ptr_align = Builder.Alignment.fromInternPool(ptr_ty.ptrAlignment(mod)); const dest_ptr = try self.sliceOrArrayPtr(dest_slice, ptr_ty); const access_kind: Builder.MemoryAccessKind = if (ptr_ty.isVolatilePtr(mod)) .@"volatile" else .normal; @@ -9215,13 +9215,13 @@ pub const FuncGen = struct { self.wip.cursor = .{ .block = body_block }; const elem_abi_align = elem_ty.abiAlignment(mod); - const it_ptr_align = InternPool.Alignment.fromLlvm(dest_ptr_align).min(elem_abi_align).toLlvm(); + const it_ptr_align = Builder.Alignment.fromInternPool(Builder.Alignment.toInternPool(dest_ptr_align).min(elem_abi_align)); if (isByRef(elem_ty, mod)) { _ = try self.wip.callMemCpy( it_ptr.toValue(), it_ptr_align, value, - elem_abi_align.toLlvm(), + Builder.Alignment.fromInternPool(elem_abi_align), try o.builder.intValue(llvm_usize_ty, elem_abi_size), access_kind, ); @@ -9287,9 +9287,9 @@ pub const FuncGen = struct { self.wip.cursor = .{ .block = memcpy_block }; _ = try self.wip.callMemCpy( dest_ptr, - dest_ptr_ty.ptrAlignment(mod).toLlvm(), + Builder.Alignment.fromInternPool(dest_ptr_ty.ptrAlignment(mod)), src_ptr, - src_ptr_ty.ptrAlignment(mod).toLlvm(), + Builder.Alignment.fromInternPool(src_ptr_ty.ptrAlignment(mod)), len, access_kind, ); @@ -9300,9 +9300,9 @@ pub const FuncGen = struct { _ = try self.wip.callMemCpy( dest_ptr, - dest_ptr_ty.ptrAlignment(mod).toLlvm(), + Builder.Alignment.fromInternPool(dest_ptr_ty.ptrAlignment(mod)), src_ptr, - src_ptr_ty.ptrAlignment(mod).toLlvm(), + Builder.Alignment.fromInternPool(src_ptr_ty.ptrAlignment(mod)), len, access_kind, ); @@ -9958,7 +9958,7 @@ pub const FuncGen = struct { if (isByRef(result_ty, mod)) { // TODO in debug builds init to undef so that the padding will be 0xaa // even if we fully populate the fields. - const alignment = result_ty.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(result_ty.abiAlignment(mod)); const alloca_inst = try self.buildAllocaWorkaround(result_ty, alignment); for (elements, 0..) |elem, i| { @@ -9995,7 +9995,7 @@ pub const FuncGen = struct { const llvm_usize = try o.lowerType(Type.usize); const usize_zero = try o.builder.intValue(llvm_usize, 0); - const alignment = result_ty.abiAlignment(mod).toLlvm(); + const alignment = Builder.Alignment.fromInternPool(result_ty.abiAlignment(mod)); const alloca_inst = try self.buildAllocaWorkaround(result_ty, alignment); const array_info = result_ty.arrayInfo(mod); @@ -10071,7 +10071,7 @@ pub const FuncGen = struct { // necessarily match the format that we need, depending on which tag is active. // We must construct the correct unnamed struct type here, in order to then set // the fields appropriately. - const alignment = layout.abi_align.toLlvm(); + const alignment = Builder.Alignment.fromInternPool(layout.abi_align); const result_ptr = try self.buildAllocaWorkaround(union_ty, alignment); const llvm_payload = try self.resolveInst(extra.init); const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]); @@ -10142,7 +10142,7 @@ pub const FuncGen = struct { const field_ptr = try self.wip.gep(.inbounds, llvm_union_ty, result_ptr, &indices, ""); const tag_ty = try o.lowerType(Type.fromInterned(union_obj.enum_tag_ty)); const llvm_tag = try o.builder.intValue(tag_ty, tag_int); - const tag_alignment = Type.fromInterned(union_obj.enum_tag_ty).abiAlignment(mod).toLlvm(); + const tag_alignment = Builder.Alignment.fromInternPool(Type.fromInterned(union_obj.enum_tag_ty).abiAlignment(mod)); _ = try self.wip.store(.normal, llvm_tag, field_ptr, tag_alignment); } @@ -10279,7 +10279,7 @@ pub const FuncGen = struct { variable_index.setMutability(.constant, &o.builder); variable_index.setUnnamedAddr(.unnamed_addr, &o.builder); variable_index.setAlignment( - Type.slice_const_u8_sentinel_0.abiAlignment(mod).toLlvm(), + Builder.Alignment.fromInternPool(Type.slice_const_u8_sentinel_0.abiAlignment(mod)), &o.builder, ); @@ -10324,7 +10324,7 @@ pub const FuncGen = struct { // We have a pointer and we need to return a pointer to the first field. const payload_ptr = try fg.wip.gepStruct(opt_llvm_ty, opt_handle, 0, ""); - const payload_alignment = payload_ty.abiAlignment(mod).toLlvm(); + const payload_alignment = Builder.Alignment.fromInternPool(payload_ty.abiAlignment(mod)); if (isByRef(payload_ty, mod)) { if (can_elide_load) return payload_ptr; @@ -10350,7 +10350,7 @@ pub const FuncGen = struct { const mod = o.module; if (isByRef(optional_ty, mod)) { - const payload_alignment = optional_ty.abiAlignment(mod).toLlvm(); + const payload_alignment = Builder.Alignment.fromInternPool(optional_ty.abiAlignment(mod)); const alloca_inst = try self.buildAllocaWorkaround(optional_ty, payload_alignment); { @@ -10493,7 +10493,7 @@ pub const FuncGen = struct { const o = fg.dg.object; const mod = o.module; //const pointee_llvm_ty = try o.lowerType(pointee_type); - const result_align = InternPool.Alignment.fromLlvm(ptr_alignment).max(pointee_type.abiAlignment(mod)).toLlvm(); + const result_align = Builder.Alignment.fromInternPool(Builder.Alignment.toInternPool(ptr_alignment).max(pointee_type.abiAlignment(mod))); const result_ptr = try fg.buildAllocaWorkaround(pointee_type, result_align); const size_bytes = pointee_type.abiSize(mod); _ = try fg.wip.callMemCpy( @@ -10517,10 +10517,10 @@ pub const FuncGen = struct { const elem_ty = Type.fromInterned(info.child); if (!elem_ty.hasRuntimeBitsIgnoreComptime(mod)) return .none; - const ptr_alignment = (if (info.flags.alignment != .none) + const ptr_alignment = Builder.Alignment.fromInternPool(if (info.flags.alignment != .none) @as(InternPool.Alignment, info.flags.alignment) else - elem_ty.abiAlignment(mod)).toLlvm(); + elem_ty.abiAlignment(mod)); const access_kind: Builder.MemoryAccessKind = if (info.flags.is_volatile) .@"volatile" else .normal; @@ -10552,7 +10552,7 @@ pub const FuncGen = struct { const elem_llvm_ty = try o.lowerType(elem_ty); if (isByRef(elem_ty, mod)) { - const result_align = elem_ty.abiAlignment(mod).toLlvm(); + const result_align = Builder.Alignment.fromInternPool(elem_ty.abiAlignment(mod)); const result_ptr = try self.buildAllocaWorkaround(elem_ty, result_align); const same_size_int = try o.builder.intType(@intCast(elem_bits)); @@ -10590,7 +10590,7 @@ pub const FuncGen = struct { if (!elem_ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) { return; } - const ptr_alignment = ptr_ty.ptrAlignment(mod).toLlvm(); + const ptr_alignment = Builder.Alignment.fromInternPool(ptr_ty.ptrAlignment(mod)); const access_kind: Builder.MemoryAccessKind = if (info.flags.is_volatile) .@"volatile" else .normal; @@ -10656,7 +10656,7 @@ pub const FuncGen = struct { ptr, ptr_alignment, elem, - elem_ty.abiAlignment(mod).toLlvm(), + Builder.Alignment.fromInternPool(elem_ty.abiAlignment(mod)), try o.builder.intValue(try o.lowerType(Type.usize), elem_ty.abiSize(mod)), access_kind, ); @@ -10688,7 +10688,7 @@ pub const FuncGen = struct { if (!target_util.hasValgrindSupport(target)) return default_value; const llvm_usize = try o.lowerType(Type.usize); - const usize_alignment = Type.usize.abiAlignment(mod).toLlvm(); + const usize_alignment = Builder.Alignment.fromInternPool(Type.usize.abiAlignment(mod)); const array_llvm_ty = try o.builder.arrayType(6, llvm_usize); const array_ptr = if (fg.valgrind_client_request_array == .none) a: { diff --git a/src/codegen/llvm/Builder.zig b/src/codegen/llvm/Builder.zig index b3c39f336272..227e385029b3 100644 --- a/src/codegen/llvm/Builder.zig +++ b/src/codegen/llvm/Builder.zig @@ -1970,6 +1970,14 @@ pub const Alignment = enum(u6) { return if (self == .default) null else @as(u64, 1) << @intFromEnum(self); } + pub fn fromInternPool(alignment: InternPool.Alignment) Alignment { + return @enumFromInt(@intFromEnum(alignment)); + } + + pub fn toInternPool(other: Alignment) InternPool.Alignment { + return @enumFromInt(@intFromEnum(other)); + } + pub fn format( self: Alignment, comptime prefix: []const u8, @@ -11722,6 +11730,7 @@ else @compileError("LLVM unavailable"); const log = std.log.scoped(.llvm); const std = @import("std"); +const InternPool = std.zig.InternPool; const Allocator = std.mem.Allocator; const Builder = @This(); diff --git a/src/codegen/spirv.zig b/src/codegen/spirv.zig index 92e4b9b704f6..ce9b9acea059 100644 --- a/src/codegen/spirv.zig +++ b/src/codegen/spirv.zig @@ -10,9 +10,9 @@ const Type = @import("../type.zig").Type; const Value = @import("../value.zig").Value; const LazySrcLoc = Module.LazySrcLoc; const Air = @import("../Air.zig"); -const Zir = @import("../Zir.zig"); +const Zir = std.zig.Zir; const Liveness = @import("../Liveness.zig"); -const InternPool = @import("../InternPool.zig"); +const InternPool = std.zig.InternPool; const spec = @import("spirv/spec.zig"); const Opcode = spec.Opcode; diff --git a/src/codegen/spirv/Cache.zig b/src/codegen/spirv/Cache.zig index 93921204dbf0..41116a931540 100644 --- a/src/codegen/spirv/Cache.zig +++ b/src/codegen/spirv/Cache.zig @@ -22,7 +22,7 @@ const Opcode = spec.Opcode; const IdResult = spec.IdResult; const StorageClass = spec.StorageClass; -const InternPool = @import("../../InternPool.zig"); +const InternPool = std.zig.InternPool; const Self = @This(); diff --git a/src/crash_report.zig b/src/crash_report.zig index cedce84d94bb..0c2354af4e3d 100644 --- a/src/crash_report.zig +++ b/src/crash_report.zig @@ -8,7 +8,7 @@ const native_os = builtin.os.tag; const Module = @import("Module.zig"); const Sema = @import("Sema.zig"); -const Zir = @import("Zir.zig"); +const Zir = std.zig.Zir; const Decl = Module.Decl; pub const is_enabled = builtin.mode == .Debug; diff --git a/src/link.zig b/src/link.zig index 2c5b0f66569f..8e5b8e635246 100644 --- a/src/link.zig +++ b/src/link.zig @@ -16,7 +16,7 @@ const Compilation = @import("Compilation.zig"); const LibCInstallation = @import("libc_installation.zig").LibCInstallation; const Liveness = @import("Liveness.zig"); const Module = @import("Module.zig"); -const InternPool = @import("InternPool.zig"); +const InternPool = std.zig.InternPool; const Type = @import("type.zig").Type; const TypedValue = @import("TypedValue.zig"); diff --git a/src/link/C.zig b/src/link/C.zig index a8721a0c028b..554dcf066d6c 100644 --- a/src/link/C.zig +++ b/src/link/C.zig @@ -6,7 +6,7 @@ const fs = std.fs; const C = @This(); const Module = @import("../Module.zig"); -const InternPool = @import("../InternPool.zig"); +const InternPool = std.zig.InternPool; const Alignment = InternPool.Alignment; const Compilation = @import("../Compilation.zig"); const codegen = @import("../codegen/c.zig"); diff --git a/src/link/Coff.zig b/src/link/Coff.zig index 44b329d5b9e3..285957d8fb87 100644 --- a/src/link/Coff.zig +++ b/src/link/Coff.zig @@ -2663,7 +2663,7 @@ const ImportTable = @import("Coff/ImportTable.zig"); const Liveness = @import("../Liveness.zig"); const LlvmObject = @import("../codegen/llvm.zig").Object; const Module = @import("../Module.zig"); -const InternPool = @import("../InternPool.zig"); +const InternPool = std.zig.InternPool; const Object = @import("Coff/Object.zig"); const Relocation = @import("Coff/Relocation.zig"); const TableSection = @import("table_section.zig").TableSection; diff --git a/src/link/Dwarf.zig b/src/link/Dwarf.zig index ef803a45f18b..e923151b6ee1 100644 --- a/src/link/Dwarf.zig +++ b/src/link/Dwarf.zig @@ -2829,7 +2829,7 @@ const LinkBlock = File.LinkBlock; const LinkFn = File.LinkFn; const LinkerLoad = @import("../codegen.zig").LinkerLoad; const Module = @import("../Module.zig"); -const InternPool = @import("../InternPool.zig"); +const InternPool = std.zig.InternPool; const StringTable = @import("StringTable.zig"); const Type = @import("../type.zig").Type; const Value = @import("../value.zig").Value; diff --git a/src/link/Elf.zig b/src/link/Elf.zig index 7c1e46dd8931..46ca413c3d63 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -6452,7 +6452,7 @@ const Liveness = @import("../Liveness.zig"); const LlvmObject = @import("../codegen/llvm.zig").Object; const Module = @import("../Module.zig"); const Object = @import("Elf/Object.zig"); -const InternPool = @import("../InternPool.zig"); +const InternPool = std.zig.InternPool; const PltSection = synthetic_sections.PltSection; const PltGotSection = synthetic_sections.PltGotSection; const SharedObject = @import("Elf/SharedObject.zig"); diff --git a/src/link/Elf/Atom.zig b/src/link/Elf/Atom.zig index ec12f177212d..d89700b91ac4 100644 --- a/src/link/Elf/Atom.zig +++ b/src/link/Elf/Atom.zig @@ -39,7 +39,7 @@ fde_end: u32 = 0, prev_index: Index = 0, next_index: Index = 0, -pub const Alignment = @import("../../InternPool.zig").Alignment; +pub const Alignment = std.zig.InternPool.Alignment; pub fn name(self: Atom, elf_file: *Elf) []const u8 { const file_ptr = self.file(elf_file).?; diff --git a/src/link/Elf/ZigObject.zig b/src/link/Elf/ZigObject.zig index ef029c7702f6..483d8ff66edf 100644 --- a/src/link/Elf/ZigObject.zig +++ b/src/link/Elf/ZigObject.zig @@ -1607,7 +1607,7 @@ const Atom = @import("Atom.zig"); const Dwarf = @import("../Dwarf.zig"); const Elf = @import("../Elf.zig"); const File = @import("file.zig").File; -const InternPool = @import("../../InternPool.zig"); +const InternPool = std.zig.InternPool; const Liveness = @import("../../Liveness.zig"); const Module = @import("../../Module.zig"); const Object = @import("Object.zig"); diff --git a/src/link/MachO.zig b/src/link/MachO.zig index 61446b3300d6..1adaf983e8c3 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -5800,7 +5800,7 @@ const Liveness = @import("../Liveness.zig"); const LlvmObject = @import("../codegen/llvm.zig").Object; const Md5 = std.crypto.hash.Md5; const Module = @import("../Module.zig"); -const InternPool = @import("../InternPool.zig"); +const InternPool = std.zig.InternPool; const Platform = load_commands.Platform; const Relocation = @import("MachO/Relocation.zig"); const StringTable = @import("StringTable.zig"); diff --git a/src/link/MachO/Atom.zig b/src/link/MachO/Atom.zig index 290c67c45e2e..a9f346bd6368 100644 --- a/src/link/MachO/Atom.zig +++ b/src/link/MachO/Atom.zig @@ -35,7 +35,7 @@ alignment: Alignment = .@"1", next_index: ?Index = null, prev_index: ?Index = null, -pub const Alignment = @import("../../InternPool.zig").Alignment; +pub const Alignment = std.zig.InternPool.Alignment; pub const Index = u32; diff --git a/src/link/NvPtx.zig b/src/link/NvPtx.zig index 606c5f123754..781a4c20c15a 100644 --- a/src/link/NvPtx.zig +++ b/src/link/NvPtx.zig @@ -13,7 +13,7 @@ const assert = std.debug.assert; const log = std.log.scoped(.link); const Module = @import("../Module.zig"); -const InternPool = @import("../InternPool.zig"); +const InternPool = std.zig.InternPool; const Compilation = @import("../Compilation.zig"); const link = @import("../link.zig"); const trace = @import("../tracy.zig").trace; diff --git a/src/link/Plan9.zig b/src/link/Plan9.zig index b608b291615e..479eaa1ffa10 100644 --- a/src/link/Plan9.zig +++ b/src/link/Plan9.zig @@ -4,7 +4,7 @@ const Plan9 = @This(); const link = @import("../link.zig"); const Module = @import("../Module.zig"); -const InternPool = @import("../InternPool.zig"); +const InternPool = std.zig.InternPool; const Compilation = @import("../Compilation.zig"); const aout = @import("Plan9/aout.zig"); const codegen = @import("../codegen.zig"); diff --git a/src/link/SpirV.zig b/src/link/SpirV.zig index ac36a391ecdd..dab1c0de985e 100644 --- a/src/link/SpirV.zig +++ b/src/link/SpirV.zig @@ -29,7 +29,7 @@ const assert = std.debug.assert; const log = std.log.scoped(.link); const Module = @import("../Module.zig"); -const InternPool = @import("../InternPool.zig"); +const InternPool = std.zig.InternPool; const Compilation = @import("../Compilation.zig"); const link = @import("../link.zig"); const codegen = @import("../codegen/spirv.zig"); diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index 82f9f9f20d66..6d5de2bb78ec 100644 --- a/src/link/Wasm.zig +++ b/src/link/Wasm.zig @@ -12,7 +12,7 @@ const log = std.log.scoped(.link); pub const Atom = @import("Wasm/Atom.zig"); const Dwarf = @import("Dwarf.zig"); const Module = @import("../Module.zig"); -const InternPool = @import("../InternPool.zig"); +const InternPool = std.zig.InternPool; const Compilation = @import("../Compilation.zig"); const CodeGen = @import("../arch/wasm/CodeGen.zig"); const codegen = @import("../codegen.zig"); diff --git a/src/link/Wasm/types.zig b/src/link/Wasm/types.zig index ebb2ddf89579..95fbf8a1cc0c 100644 --- a/src/link/Wasm/types.zig +++ b/src/link/Wasm/types.zig @@ -109,7 +109,7 @@ pub const SubsectionType = enum(u8) { WASM_SYMBOL_TABLE = 8, }; -pub const Alignment = @import("../../InternPool.zig").Alignment; +pub const Alignment = std.zig.InternPool.Alignment; pub const Segment = struct { /// Segment's name, encoded as UTF-8 bytes. diff --git a/src/main.zig b/src/main.zig index bcc7860e357a..bd4cb86a6774 100644 --- a/src/main.zig +++ b/src/main.zig @@ -26,7 +26,7 @@ const Cache = std.Build.Cache; const target_util = @import("target.zig"); const crash_report = @import("crash_report.zig"); const Module = @import("Module.zig"); -const AstGen = @import("AstGen.zig"); +const AstGen = std.zig.AstGen; const mingw = @import("mingw.zig"); const Server = std.zig.Server; @@ -6363,7 +6363,7 @@ pub fn cmdAstCheck( arena: Allocator, args: []const []const u8, ) !void { - const Zir = @import("Zir.zig"); + const Zir = std.zig.Zir; var color: Color = .auto; var want_output_text = false; @@ -6525,7 +6525,7 @@ pub fn cmdDumpZir( args: []const []const u8, ) !void { _ = arena; - const Zir = @import("Zir.zig"); + const Zir = std.zig.Zir; const cache_file = args[0]; @@ -6585,7 +6585,7 @@ pub fn cmdChangelist( args: []const []const u8, ) !void { const color: Color = .auto; - const Zir = @import("Zir.zig"); + const Zir = std.zig.Zir; const old_source_file = args[0]; const new_source_file = args[1]; diff --git a/src/print_air.zig b/src/print_air.zig index 1fdecb394705..7874a64dc721 100644 --- a/src/print_air.zig +++ b/src/print_air.zig @@ -7,7 +7,7 @@ const Value = @import("value.zig").Value; const Type = @import("type.zig").Type; const Air = @import("Air.zig"); const Liveness = @import("Liveness.zig"); -const InternPool = @import("InternPool.zig"); +const InternPool = std.zig.InternPool; pub fn write(stream: anytype, module: *Module, air: Air, liveness: ?Liveness) void { const instruction_bytes = air.instructions.len * diff --git a/src/print_zir.zig b/src/print_zir.zig index 3f2334e18d7e..b71bed2b615a 100644 --- a/src/print_zir.zig +++ b/src/print_zir.zig @@ -3,9 +3,9 @@ const mem = std.mem; const Allocator = std.mem.Allocator; const assert = std.debug.assert; const Ast = std.zig.Ast; -const InternPool = @import("InternPool.zig"); +const InternPool = std.zig.InternPool; -const Zir = @import("Zir.zig"); +const Zir = std.zig.Zir; const Module = @import("Module.zig"); const LazySrcLoc = Module.LazySrcLoc; @@ -643,7 +643,7 @@ const Writer = struct { const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].un_node; try self.writeInstRef(stream, inst_data.operand); try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromUnNode(inst_data)); } fn writeUnTok( @@ -654,7 +654,7 @@ const Writer = struct { const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].un_tok; try self.writeInstRef(stream, inst_data.operand); try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromUnTok(inst_data)); } fn writeValidateDestructure( @@ -668,7 +668,7 @@ const Writer = struct { try stream.print(", {d}) (destructure=", .{extra.expect_len}); try self.writeSrc(stream, LazySrcLoc.nodeOffset(extra.destructure_node)); try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeValidateArrayInitTy( @@ -680,7 +680,7 @@ const Writer = struct { const extra = self.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data; try self.writeInstRef(stream, extra.ty); try stream.print(", {d}) ", .{extra.init_count}); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeArrayTypeSentinel( @@ -696,7 +696,7 @@ const Writer = struct { try stream.writeAll(", "); try self.writeInstRef(stream, extra.elem_type); try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writePtrType( @@ -776,7 +776,7 @@ const Writer = struct { fn writeFloat128(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const extra = self.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const number = extra.get(); // TODO improve std.format to be able to print f128 values try stream.print("{d}) ", .{@as(f64, @floatCast(number))}); @@ -800,7 +800,7 @@ const Writer = struct { try stream.writeAll(", "); try self.writeInstRef(stream, extra.start); try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeSliceEnd(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { @@ -812,7 +812,7 @@ const Writer = struct { try stream.writeAll(", "); try self.writeInstRef(stream, extra.end); try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeSliceSentinel(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { @@ -826,7 +826,7 @@ const Writer = struct { try stream.writeAll(", "); try self.writeInstRef(stream, extra.sentinel); try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeSliceLength(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { @@ -842,7 +842,7 @@ const Writer = struct { try self.writeInstRef(stream, extra.sentinel); } try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeUnionInit(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { @@ -854,7 +854,7 @@ const Writer = struct { try stream.writeAll(", "); try self.writeInstRef(stream, extra.init); try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeShuffle(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { @@ -868,7 +868,7 @@ const Writer = struct { try stream.writeAll(", "); try self.writeInstRef(stream, extra.mask); try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeSelect(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void { @@ -893,7 +893,7 @@ const Writer = struct { try stream.writeAll(", "); try self.writeInstRef(stream, extra.addend); try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeBuiltinCall(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { @@ -909,7 +909,7 @@ const Writer = struct { try stream.writeAll(", "); try self.writeInstRef(stream, extra.args); try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeFieldParentPtr(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { @@ -921,7 +921,7 @@ const Writer = struct { try stream.writeAll(", "); try self.writeInstRef(stream, extra.field_ptr); try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeBuiltinAsyncCall(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void { @@ -952,7 +952,7 @@ const Writer = struct { } try self.writeBracedBody(stream, body); try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlTok(inst_data)); } fn writePlNodeBin(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { @@ -962,7 +962,7 @@ const Writer = struct { try stream.writeAll(", "); try self.writeInstRef(stream, extra.rhs); try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writePlNodeMultiOp(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { @@ -975,7 +975,7 @@ const Writer = struct { try self.writeInstRef(stream, arg); } try stream.writeAll("}) "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeArrayMul(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { @@ -987,7 +987,7 @@ const Writer = struct { try stream.writeAll(", "); try self.writeInstRef(stream, extra.rhs); try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeElemValImm(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { @@ -1002,7 +1002,7 @@ const Writer = struct { try self.writeInstRef(stream, extra.ptr); try stream.print(", {d}) ", .{extra.index}); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writePlNodeExport(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { @@ -1014,7 +1014,7 @@ const Writer = struct { try stream.print(", {}, ", .{std.zig.fmtId(decl_name)}); try self.writeInstRef(stream, extra.options); try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writePlNodeExportValue(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { @@ -1025,7 +1025,7 @@ const Writer = struct { try stream.writeAll(", "); try self.writeInstRef(stream, extra.options); try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeValidateArrayInitRefTy(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { @@ -1035,7 +1035,7 @@ const Writer = struct { try self.writeInstRef(stream, extra.ptr_ty); try stream.writeAll(", "); try stream.print(", {}) ", .{extra.elem_count}); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeStructInit(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { @@ -1059,7 +1059,7 @@ const Writer = struct { try stream.writeAll("]"); } try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeCmpxchg(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void { @@ -1116,7 +1116,7 @@ const Writer = struct { try stream.writeAll(", "); try self.writeInstRef(stream, extra.ordering); try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeAtomicStore(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { @@ -1129,7 +1129,7 @@ const Writer = struct { try stream.writeAll(", "); try self.writeInstRef(stream, extra.ordering); try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeAtomicRmw(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { @@ -1144,7 +1144,7 @@ const Writer = struct { try stream.writeAll(", "); try self.writeInstRef(stream, extra.ordering); try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeStructInitAnon(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { @@ -1165,7 +1165,7 @@ const Writer = struct { try stream.writeAll("]"); } try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeStructInitFieldType(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { @@ -1174,7 +1174,7 @@ const Writer = struct { try self.writeInstRef(stream, extra.container_type); const field_name = self.code.nullTerminatedString(extra.name_start); try stream.print(", {s}) ", .{field_name}); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeFieldTypeRef(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { @@ -1184,7 +1184,7 @@ const Writer = struct { try stream.writeAll(", "); try self.writeInstRef(stream, extra.field_name); try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeNodeMultiOp(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void { @@ -1208,7 +1208,7 @@ const Writer = struct { const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].inst_node; try self.writeInstIndex(stream, inst_data.inst); try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromInstNode(inst_data)); } fn writeAsm( @@ -1353,13 +1353,13 @@ const Writer = struct { } try stream.writeAll("]) "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeBlock(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; try self.writePlNodeBlockWithoutSrc(stream, inst); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writePlNodeBlockWithoutSrc(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { @@ -1381,7 +1381,7 @@ const Writer = struct { try stream.writeAll(", "); try self.writeBracedBody(stream, else_body); try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeTry(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { @@ -1392,7 +1392,7 @@ const Writer = struct { try stream.writeAll(", "); try self.writeBracedBody(stream, body); try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeStructDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void { @@ -1832,7 +1832,7 @@ const Writer = struct { self.parent_decl_node = self.relativeToNodeIndex(sub_decl_node_off); try self.writePlNodeBlockWithoutSrc(stream, decl_index); self.parent_decl_node = parent_decl_node; - try self.writeSrc(stream, decl_block_inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(decl_block_inst_data)); try stream.writeAll("\n"); } else { try stream.print(" line({d}) hash({}): %{d} = ...\n", .{ @@ -2023,7 +2023,7 @@ const Writer = struct { try stream.writeByteNTimes(' ', self.indent); try stream.writeAll("}) "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeSwitchBlock(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { @@ -2153,7 +2153,7 @@ const Writer = struct { self.indent -= 2; try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writePlNodeField(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { @@ -2162,7 +2162,7 @@ const Writer = struct { const name = self.code.nullTerminatedString(extra.field_name_start); try self.writeInstRef(stream, extra.lhs); try stream.print(", \"{}\") ", .{std.zig.fmtEscapes(name)}); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writePlNodeFieldNamed(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { @@ -2172,7 +2172,7 @@ const Writer = struct { try stream.writeAll(", "); try self.writeInstRef(stream, extra.field_name); try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeAs(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { @@ -2182,7 +2182,7 @@ const Writer = struct { try stream.writeAll(", "); try self.writeInstRef(stream, extra.operand); try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeNode( @@ -2204,7 +2204,7 @@ const Writer = struct { const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str_tok; const str = inst_data.get(self.code); try stream.print("\"{}\") ", .{std.zig.fmtEscapes(str)}); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromStrTok(inst_data)); } fn writeStrOp(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { @@ -2221,7 +2221,7 @@ const Writer = struct { inferred_error_set: bool, ) !void { const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); const extra = self.code.extraData(Zir.Inst.Func, inst_data.payload_index); var extra_index = extra.end; @@ -2277,7 +2277,7 @@ const Writer = struct { fn writeFuncFancy(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const extra = self.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index); - const src = inst_data.src(); + const src = LazySrcLoc.fromPlNode(inst_data); var extra_index: usize = extra.end; var align_ref: Zir.Inst.Ref = .none; @@ -2462,7 +2462,7 @@ const Writer = struct { .unsigned => 'u', }; try stream.print("{c}{d}) ", .{ prefix, int_type.bit_count }); - try self.writeSrc(stream, int_type.src()); + try self.writeSrc(stream, LazySrcLoc.fromIntType(int_type)); } fn writeSaveErrRetIndex(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { @@ -2505,7 +2505,7 @@ const Writer = struct { try self.writeInstRef(stream, arg); } try stream.writeAll("}) "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeArrayInitAnon(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { @@ -2520,7 +2520,7 @@ const Writer = struct { try self.writeInstRef(stream, arg); } try stream.writeAll("}) "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeArrayInitSent(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { @@ -2540,13 +2540,13 @@ const Writer = struct { try self.writeInstRef(stream, elem); } try stream.writeAll("}) "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromPlNode(inst_data)); } fn writeUnreachable(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].@"unreachable"; try stream.writeAll(") "); - try self.writeSrc(stream, inst_data.src()); + try self.writeSrc(stream, LazySrcLoc.fromUnreachable(inst_data)); } fn writeFuncCommon( diff --git a/src/reduce.zig b/src/reduce.zig index a0b1bc8a1895..c7d1f2123195 100644 --- a/src/reduce.zig +++ b/src/reduce.zig @@ -5,8 +5,8 @@ const assert = std.debug.assert; const fatal = @import("./main.zig").fatal; const Ast = std.zig.Ast; const Walk = @import("reduce/Walk.zig"); -const AstGen = @import("AstGen.zig"); -const Zir = @import("Zir.zig"); +const AstGen = std.zig.AstGen; +const Zir = std.zig.Zir; const usage = \\zig reduce [options] ./checker root_source_file.zig [-- [argv]] diff --git a/src/target.zig b/src/target.zig index cac9aa11b064..83e6b2478613 100644 --- a/src/target.zig +++ b/src/target.zig @@ -1,7 +1,7 @@ const std = @import("std"); const Type = @import("type.zig").Type; const AddressSpace = std.builtin.AddressSpace; -const Alignment = @import("InternPool.zig").Alignment; +const Alignment = std.zig.InternPool.Alignment; pub const ArchOsAbi = struct { arch: std.Target.Cpu.Arch, diff --git a/src/type.zig b/src/type.zig index dbf73c0eb2db..2aba3dc9d9e8 100644 --- a/src/type.zig +++ b/src/type.zig @@ -8,7 +8,7 @@ const log = std.log.scoped(.Type); const target_util = @import("target.zig"); const TypedValue = @import("TypedValue.zig"); const Sema = @import("Sema.zig"); -const InternPool = @import("InternPool.zig"); +const InternPool = std.zig.InternPool; const Alignment = InternPool.Alignment; /// Both types and values are canonically represented by a single 32-bit integer diff --git a/src/value.zig b/src/value.zig index f046b9ae3d75..dd84fe6ce3b1 100644 --- a/src/value.zig +++ b/src/value.zig @@ -10,7 +10,7 @@ const Allocator = std.mem.Allocator; const Module = @import("Module.zig"); const TypedValue = @import("TypedValue.zig"); const Sema = @import("Sema.zig"); -const InternPool = @import("InternPool.zig"); +const InternPool = std.zig.InternPool; pub const Value = struct { /// We are migrating towards using this for every Value object. However, many diff --git a/tools/lldb_pretty_printers.py b/tools/lldb_pretty_printers.py index 975edb7d0ea9..1da78e98f22d 100644 --- a/tools/lldb_pretty_printers.py +++ b/tools/lldb_pretty_printers.py @@ -709,8 +709,8 @@ def __lldb_init_module(debugger, _=None): add(debugger, category='zig.stage2', type='Air.Inst::Air.Inst.Ref', identifier='InstRef', summary=True) add(debugger, category='zig.stage2', regex=True, type=MultiArrayList_Entry('Air\\.Inst'), identifier='TagAndPayload', synth=True, inline_children=True, summary=True) add(debugger, category='zig.stage2', regex=True, type='^Air\\.Inst\\.Data\\.Data__struct_[1-9][0-9]*$', inline_children=True, summary=True) - add(debugger, category='zig.stage2', type='Module.Decl::Module.Decl.Index', synth=True) - add(debugger, category='zig.stage2', type='Module.Namespace::Module.Namespace.Index', synth=True) + add(debugger, category='zig.stage2', type='Module.Decl::InternPool.DeclIndex', synth=True) + add(debugger, category='zig.stage2', type='Module.Namespace::InternPool.NamespaceIndex', synth=True) add(debugger, category='zig.stage2', type='Module.LazySrcLoc', identifier='zig_TaggedUnion', synth=True) add(debugger, category='zig.stage2', type='InternPool.Index', synth=True) add(debugger, category='zig.stage2', type='InternPool.NullTerminatedString', summary=True)