authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-12-26 18:34:20-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-01-15 15:11:36-08:00
logeb943890d975a50618db8ca7593563fcf8b107da
tree54b7dc26c3f354e4a5059670aaba6e5450ec1d58
parentaebccb06e774107d18c4259eafbf5eb3c642237a

resolve merge conflicts

with 497592c9b45a94fb7b6028bf45b80f183e395a9b

3 files changed, 35 insertions(+), 44 deletions(-)

src/InternPool.zig+18-15
......@@ -552,6 +552,15 @@ pub const Nav = struct {
552552 };
553553 }
554554
555 /// This function is intended to be used by code generation, since semantic
556 /// analysis will ensure that any `Nav` which is potentially `extern` is
557 /// fully resolved.
558 /// Asserts that `status == .fully_resolved`.
559 pub fn getResolvedExtern(nav: Nav, ip: *const InternPool) ?Key.Extern {
560 assert(nav.status == .fully_resolved);
561 return nav.getExtern(ip);
562 }
563
555564 /// Always returns `null` for `status == .type_resolved`. This function is inteded
556565 /// to be used by code generation, since semantic analysis will ensure that any `Nav`
557566 /// which is potentially `extern` is fully resolved.
......@@ -585,6 +594,15 @@ pub const Nav = struct {
585594 };
586595 }
587596
597 /// Asserts that `status != .unresolved`.
598 pub fn getLinkSection(nav: Nav) OptionalNullTerminatedString {
599 return switch (nav.status) {
600 .unresolved => unreachable,
601 .type_resolved => |r| r.@"linksection",
602 .fully_resolved => |r| r.@"linksection",
603 };
604 }
605
588606 /// Asserts that `status != .unresolved`.
589607 pub fn isThreadlocal(nav: Nav, ip: *const InternPool) bool {
590608 return switch (nav.status) {
......@@ -620,21 +638,6 @@ pub const Nav = struct {
620638 };
621639 }
622640
623 /// Asserts that `status == .resolved`.
624 pub fn toExtern(nav: *const Nav, ip: *const InternPool) ?Key.Extern {
625 return switch (ip.indexToKey(nav.status.resolved.val)) {
626 .@"extern" => |ext| ext,
627 else => null,
628 };
629 }
630
631 /// Asserts that `status == .resolved`.
632 pub fn isThreadLocal(nav: Nav, ip: *const InternPool) bool {
633 const val = nav.status.resolved.val;
634 if (!isVariable(ip, val)) return false;
635 return ip.indexToKey(val).variable.is_threadlocal;
636 }
637
638641 /// Get the ZIR instruction corresponding to this `Nav`, used to resolve source locations.
639642 /// This is a `declaration`.
640643 pub fn srcInst(nav: Nav, ip: *const InternPool) TrackedInst.Index {
src/arch/wasm/CodeGen.zig+1-1
......@@ -1025,7 +1025,7 @@ fn emitWValue(cg: *CodeGen, value: WValue) InnerError!void {
10251025 const comp = wasm.base.comp;
10261026 const zcu = comp.zcu.?;
10271027 const ip = &zcu.intern_pool;
1028 const ip_index = ip.getNav(nav_ref.nav_index).status.resolved.val;
1028 const ip_index = ip.getNav(nav_ref.nav_index).status.fully_resolved.val;
10291029 if (ip.isFunctionType(ip.typeOf(ip_index))) {
10301030 assert(nav_ref.offset == 0);
10311031 const gop = try wasm.indirect_function_table.getOrPut(comp.gpa, ip_index);
src/link/Wasm.zig+16-28
......@@ -366,7 +366,7 @@ pub const OutputFunctionIndex = enum(u32) {
366366 const zcu = wasm.base.comp.zcu.?;
367367 const ip = &zcu.intern_pool;
368368 const nav = ip.getNav(nav_index);
369 return fromIpIndex(wasm, nav.status.resolved.val);
369 return fromIpIndex(wasm, nav.status.fully_resolved.val);
370370 }
371371
372372 pub fn fromTagNameType(wasm: *const Wasm, tag_type: InternPool.Index) OutputFunctionIndex {
......@@ -758,9 +758,9 @@ const ZcuDataStarts = struct {
758758 while (true) {
759759 while (navs_i < wasm.navs_obj.entries.len) : (navs_i += 1) {
760760 const elem_nav = ip.getNav(wasm.navs_obj.keys()[navs_i]);
761 const elem_nav_init = switch (ip.indexToKey(elem_nav.status.resolved.val)) {
761 const elem_nav_init = switch (ip.indexToKey(elem_nav.status.fully_resolved.val)) {
762762 .variable => |variable| variable.init,
763 else => elem_nav.status.resolved.val,
763 else => elem_nav.status.fully_resolved.val,
764764 };
765765 // Call to `lowerZcuData` here possibly creates more entries in these tables.
766766 wasm.navs_obj.values()[navs_i] = try lowerZcuData(wasm, pt, elem_nav_init);
......@@ -781,9 +781,9 @@ const ZcuDataStarts = struct {
781781 while (true) {
782782 while (navs_i < wasm.navs_exe.entries.len) : (navs_i += 1) {
783783 const elem_nav = ip.getNav(wasm.navs_exe.keys()[navs_i]);
784 const elem_nav_init = switch (ip.indexToKey(elem_nav.status.resolved.val)) {
784 const elem_nav_init = switch (ip.indexToKey(elem_nav.status.fully_resolved.val)) {
785785 .variable => |variable| variable.init,
786 else => elem_nav.status.resolved.val,
786 else => elem_nav.status.fully_resolved.val,
787787 };
788788 // Call to `lowerZcuData` here possibly creates more entries in these tables.
789789 const zcu_data = try lowerZcuData(wasm, pt, elem_nav_init);
......@@ -930,7 +930,7 @@ pub const FunctionImport = extern struct {
930930 pub fn fromIpNav(wasm: *const Wasm, nav_index: InternPool.Nav.Index) Resolution {
931931 const zcu = wasm.base.comp.zcu.?;
932932 const ip = &zcu.intern_pool;
933 return fromIpIndex(wasm, ip.getNav(nav_index).status.resolved.val);
933 return fromIpIndex(wasm, ip.getNav(nav_index).status.fully_resolved.val);
934934 }
935935
936936 pub fn fromIpIndex(wasm: *const Wasm, ip_index: InternPool.Index) Resolution {
......@@ -1507,7 +1507,7 @@ pub const DataId = enum(u32) {
15071507 const zcu = wasm.base.comp.zcu.?;
15081508 const ip = &zcu.intern_pool;
15091509 const nav = ip.getNav(i.key(wasm).*);
1510 if (nav.isThreadLocal(ip)) return .tls;
1510 if (nav.isThreadlocal(ip)) return .tls;
15111511 const code = i.value(wasm).code;
15121512 return if (code.off == .none) .zero else .data;
15131513 },
......@@ -1523,7 +1523,7 @@ pub const DataId = enum(u32) {
15231523 const zcu = wasm.base.comp.zcu.?;
15241524 const ip = &zcu.intern_pool;
15251525 const nav = ip.getNav(i.key(wasm).*);
1526 return nav.isThreadLocal(ip);
1526 return nav.isThreadlocal(ip);
15271527 },
15281528 };
15291529 }
......@@ -1540,7 +1540,7 @@ pub const DataId = enum(u32) {
15401540 const zcu = wasm.base.comp.zcu.?;
15411541 const ip = &zcu.intern_pool;
15421542 const nav = ip.getNav(i.key(wasm).*);
1543 return nav.status.resolved.@"linksection".toSlice(ip) orelse ".data";
1543 return nav.getLinkSection().toSlice(ip) orelse ".data";
15441544 },
15451545 };
15461546 }
......@@ -1563,7 +1563,7 @@ pub const DataId = enum(u32) {
15631563 const zcu = wasm.base.comp.zcu.?;
15641564 const ip = &zcu.intern_pool;
15651565 const nav = ip.getNav(i.key(wasm).*);
1566 const explicit = nav.status.resolved.alignment;
1566 const explicit = nav.getAlignment();
15671567 if (explicit != .none) return explicit;
15681568 const ty: ZcuType = .fromInterned(nav.typeOf(ip));
15691569 const result = ty.abiAlignment(zcu);
......@@ -1820,11 +1820,7 @@ pub const ZcuImportIndex = enum(u32) {
18201820 const zcu = wasm.base.comp.zcu.?;
18211821 const ip = &zcu.intern_pool;
18221822 const nav_index = index.ptr(wasm).*;
1823 const nav = ip.getNav(nav_index);
1824 const ext = switch (ip.indexToKey(nav.status.resolved.val)) {
1825 .@"extern" => |*ext| ext,
1826 else => unreachable,
1827 };
1823 const ext = ip.getNav(nav_index).getResolvedExtern(ip).?;
18281824 const name_slice = ext.name.toSlice(ip);
18291825 return wasm.getExistingString(name_slice).?;
18301826 }
......@@ -1833,11 +1829,7 @@ pub const ZcuImportIndex = enum(u32) {
18331829 const zcu = wasm.base.comp.zcu.?;
18341830 const ip = &zcu.intern_pool;
18351831 const nav_index = index.ptr(wasm).*;
1836 const nav = ip.getNav(nav_index);
1837 const ext = switch (ip.indexToKey(nav.status.resolved.val)) {
1838 .@"extern" => |*ext| ext,
1839 else => unreachable,
1840 };
1832 const ext = ip.getNav(nav_index).getResolvedExtern(ip).?;
18411833 const lib_name = ext.lib_name.toSlice(ip) orelse return .none;
18421834 return wasm.getExistingString(lib_name).?.toOptional();
18431835 }
......@@ -1848,11 +1840,7 @@ pub const ZcuImportIndex = enum(u32) {
18481840 const zcu = comp.zcu.?;
18491841 const ip = &zcu.intern_pool;
18501842 const nav_index = index.ptr(wasm).*;
1851 const nav = ip.getNav(nav_index);
1852 const ext = switch (ip.indexToKey(nav.status.resolved.val)) {
1853 .@"extern" => |*ext| ext,
1854 else => unreachable,
1855 };
1843 const ext = ip.getNav(nav_index).getResolvedExtern(ip).?;
18561844 const fn_info = zcu.typeToFunc(.fromInterned(ext.ty)).?;
18571845 return getExistingFunctionType(wasm, fn_info.cc, fn_info.param_types.get(ip), .fromInterned(fn_info.return_type), target).?;
18581846 }
......@@ -1944,7 +1932,7 @@ pub const FunctionImportId = enum(u32) {
19441932 .zcu_import => |i| {
19451933 const zcu = wasm.base.comp.zcu.?;
19461934 const ip = &zcu.intern_pool;
1947 const ext = ip.getNav(i.ptr(wasm).*).toExtern(ip).?;
1935 const ext = ip.getNav(i.ptr(wasm).*).getResolvedExtern(ip).?;
19481936 return !ext.is_weak_linkage and ext.lib_name != .none;
19491937 },
19501938 };
......@@ -2588,7 +2576,7 @@ pub fn updateNav(wasm: *Wasm, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index
25882576 const is_obj = comp.config.output_mode == .Obj;
25892577 const target = &comp.root_mod.resolved_target.result;
25902578
2591 const nav_init, const chased_nav_index = switch (ip.indexToKey(nav.status.resolved.val)) {
2579 const nav_init, const chased_nav_index = switch (ip.indexToKey(nav.status.fully_resolved.val)) {
25922580 .func => return, // global const which is a function alias
25932581 .@"extern" => |ext| {
25942582 if (is_obj) {
......@@ -2612,7 +2600,7 @@ pub fn updateNav(wasm: *Wasm, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index
26122600 return;
26132601 },
26142602 .variable => |variable| .{ variable.init, variable.owner_nav },
2615 else => .{ nav.status.resolved.val, nav_index },
2603 else => .{ nav.status.fully_resolved.val, nav_index },
26162604 };
26172605 //log.debug("updateNav {} {}", .{ nav.fqn.fmt(ip), chased_nav_index });
26182606 assert(!wasm.imports.contains(chased_nav_index));