From 8ef82e83551cfca60698eb82dc180118e64b8fde Mon Sep 17 00:00:00 2001 From: mlugg Date: Tue, 12 Aug 2025 22:36:58 +0100 Subject: [PATCH] what if we kissed by the extern source bit --- src/InternPool.zig | 13 ++++++++++--- src/Sema.zig | 1 + src/Zcu/PerThread.zig | 2 ++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/InternPool.zig b/src/InternPool.zig index 0aa664d611..5f108e3224 100644 --- a/src/InternPool.zig +++ b/src/InternPool.zig @@ -2257,6 +2257,7 @@ pub const Key = union(enum) { /// The `Nav` corresponding to this extern symbol. /// This is ignored by hashing and equality. owner_nav: Nav.Index, + source: Tag.Extern.Flags.Source, }; pub const Func = struct { @@ -2859,7 +2860,7 @@ pub const Key = union(enum) { asBytes(&e.is_threadlocal) ++ asBytes(&e.is_dll_import) ++ asBytes(&e.relocation) ++ asBytes(&e.is_const) ++ asBytes(&e.alignment) ++ asBytes(&e.@"addrspace") ++ - asBytes(&e.zir_index)), + asBytes(&e.zir_index) ++ &[1]u8{@intFromEnum(e.source)}), }; } @@ -2958,7 +2959,8 @@ pub const Key = union(enum) { a_info.is_const == b_info.is_const and a_info.alignment == b_info.alignment and a_info.@"addrspace" == b_info.@"addrspace" and - a_info.zir_index == b_info.zir_index; + a_info.zir_index == b_info.zir_index and + a_info.source == b_info.source; }, .func => |a_info| { const b_info = b.func; @@ -5967,7 +5969,10 @@ pub const Tag = enum(u8) { is_threadlocal: bool, is_dll_import: bool, relocation: std.builtin.ExternOptions.Relocation, - _: u25 = 0, + source: Source, + _: u24 = 0, + + pub const Source = enum(u1) { builtin, syntax }; }; }; @@ -7320,6 +7325,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { .@"addrspace" = nav.status.fully_resolved.@"addrspace", .zir_index = extra.zir_index, .owner_nav = extra.owner_nav, + .source = extra.flags.source, } }; }, .func_instance => .{ .func = ip.extraFuncInstance(unwrapped_index.tid, unwrapped_index.getExtra(ip), data) }, @@ -9212,6 +9218,7 @@ pub fn getExtern( .is_threadlocal = key.is_threadlocal, .is_dll_import = key.is_dll_import, .relocation = key.relocation, + .source = key.source, }, .zir_index = key.zir_index, .owner_nav = owner_nav, diff --git a/src/Sema.zig b/src/Sema.zig index 34e862dbbb..4d05441a83 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -25768,6 +25768,7 @@ fn zirBuiltinExtern( }, }, .owner_nav = undefined, // ignored by `getExtern` + .source = .builtin, }); const uncasted_ptr = try sema.analyzeNavRef(block, src, ip.indexToKey(extern_val).@"extern".owner_nav); diff --git a/src/Zcu/PerThread.zig b/src/Zcu/PerThread.zig index 6d2da7afa4..3c2bb27dab 100644 --- a/src/Zcu/PerThread.zig +++ b/src/Zcu/PerThread.zig @@ -1249,6 +1249,7 @@ fn analyzeNavVal(pt: Zcu.PerThread, nav_id: InternPool.Nav.Index) Zcu.CompileErr .@"addrspace" = modifiers.@"addrspace", .zir_index = old_nav.analysis.?.zir_index, // `declaration` instruction .owner_nav = undefined, // ignored by `getExtern` + .source = .syntax, })); }, }; @@ -3435,6 +3436,7 @@ pub fn getCoerced(pt: Zcu.PerThread, val: Value, new_ty: Type) Allocator.Error!V .@"addrspace" = e.@"addrspace", .zir_index = e.zir_index, .owner_nav = undefined, // ignored by `getExtern`. + .source = e.source, }); return Value.fromInterned(coerced); },