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 {...@@ -552,6 +552,15 @@ pub const Nav = struct {
552 };552 };
553 }553 }
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
555 /// Always returns `null` for `status == .type_resolved`. This function is inteded564 /// Always returns `null` for `status == .type_resolved`. This function is inteded
556 /// to be used by code generation, since semantic analysis will ensure that any `Nav`565 /// to be used by code generation, since semantic analysis will ensure that any `Nav`
557 /// which is potentially `extern` is fully resolved.566 /// which is potentially `extern` is fully resolved.
...@@ -585,6 +594,15 @@ pub const Nav = struct {...@@ -585,6 +594,15 @@ pub const Nav = struct {
585 };594 };
586 }595 }
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
588 /// Asserts that `status != .unresolved`.606 /// Asserts that `status != .unresolved`.
589 pub fn isThreadlocal(nav: Nav, ip: *const InternPool) bool {607 pub fn isThreadlocal(nav: Nav, ip: *const InternPool) bool {
590 return switch (nav.status) {608 return switch (nav.status) {
...@@ -620,21 +638,6 @@ pub const Nav = struct {...@@ -620,21 +638,6 @@ pub const Nav = struct {
620 };638 };
621 }639 }
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
638 /// Get the ZIR instruction corresponding to this `Nav`, used to resolve source locations.641 /// Get the ZIR instruction corresponding to this `Nav`, used to resolve source locations.
639 /// This is a `declaration`.642 /// This is a `declaration`.
640 pub fn srcInst(nav: Nav, ip: *const InternPool) TrackedInst.Index {643 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 {...@@ -1025,7 +1025,7 @@ fn emitWValue(cg: *CodeGen, value: WValue) InnerError!void {
1025 const comp = wasm.base.comp;1025 const comp = wasm.base.comp;
1026 const zcu = comp.zcu.?;1026 const zcu = comp.zcu.?;
1027 const ip = &zcu.intern_pool;1027 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;
1029 if (ip.isFunctionType(ip.typeOf(ip_index))) {1029 if (ip.isFunctionType(ip.typeOf(ip_index))) {
1030 assert(nav_ref.offset == 0);1030 assert(nav_ref.offset == 0);
1031 const gop = try wasm.indirect_function_table.getOrPut(comp.gpa, ip_index);1031 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) {...@@ -366,7 +366,7 @@ pub const OutputFunctionIndex = enum(u32) {
366 const zcu = wasm.base.comp.zcu.?;366 const zcu = wasm.base.comp.zcu.?;
367 const ip = &zcu.intern_pool;367 const ip = &zcu.intern_pool;
368 const nav = ip.getNav(nav_index);368 const nav = ip.getNav(nav_index);
369 return fromIpIndex(wasm, nav.status.resolved.val);369 return fromIpIndex(wasm, nav.status.fully_resolved.val);
370 }370 }
371371
372 pub fn fromTagNameType(wasm: *const Wasm, tag_type: InternPool.Index) OutputFunctionIndex {372 pub fn fromTagNameType(wasm: *const Wasm, tag_type: InternPool.Index) OutputFunctionIndex {
...@@ -758,9 +758,9 @@ const ZcuDataStarts = struct {...@@ -758,9 +758,9 @@ const ZcuDataStarts = struct {
758 while (true) {758 while (true) {
759 while (navs_i < wasm.navs_obj.entries.len) : (navs_i += 1) {759 while (navs_i < wasm.navs_obj.entries.len) : (navs_i += 1) {
760 const elem_nav = ip.getNav(wasm.navs_obj.keys()[navs_i]);760 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)) {
762 .variable => |variable| variable.init,762 .variable => |variable| variable.init,
763 else => elem_nav.status.resolved.val,763 else => elem_nav.status.fully_resolved.val,
764 };764 };
765 // Call to `lowerZcuData` here possibly creates more entries in these tables.765 // Call to `lowerZcuData` here possibly creates more entries in these tables.
766 wasm.navs_obj.values()[navs_i] = try lowerZcuData(wasm, pt, elem_nav_init);766 wasm.navs_obj.values()[navs_i] = try lowerZcuData(wasm, pt, elem_nav_init);
...@@ -781,9 +781,9 @@ const ZcuDataStarts = struct {...@@ -781,9 +781,9 @@ const ZcuDataStarts = struct {
781 while (true) {781 while (true) {
782 while (navs_i < wasm.navs_exe.entries.len) : (navs_i += 1) {782 while (navs_i < wasm.navs_exe.entries.len) : (navs_i += 1) {
783 const elem_nav = ip.getNav(wasm.navs_exe.keys()[navs_i]);783 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)) {
785 .variable => |variable| variable.init,785 .variable => |variable| variable.init,
786 else => elem_nav.status.resolved.val,786 else => elem_nav.status.fully_resolved.val,
787 };787 };
788 // Call to `lowerZcuData` here possibly creates more entries in these tables.788 // Call to `lowerZcuData` here possibly creates more entries in these tables.
789 const zcu_data = try lowerZcuData(wasm, pt, elem_nav_init);789 const zcu_data = try lowerZcuData(wasm, pt, elem_nav_init);
...@@ -930,7 +930,7 @@ pub const FunctionImport = extern struct {...@@ -930,7 +930,7 @@ pub const FunctionImport = extern struct {
930 pub fn fromIpNav(wasm: *const Wasm, nav_index: InternPool.Nav.Index) Resolution {930 pub fn fromIpNav(wasm: *const Wasm, nav_index: InternPool.Nav.Index) Resolution {
931 const zcu = wasm.base.comp.zcu.?;931 const zcu = wasm.base.comp.zcu.?;
932 const ip = &zcu.intern_pool;932 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);
934 }934 }
935935
936 pub fn fromIpIndex(wasm: *const Wasm, ip_index: InternPool.Index) Resolution {936 pub fn fromIpIndex(wasm: *const Wasm, ip_index: InternPool.Index) Resolution {
...@@ -1507,7 +1507,7 @@ pub const DataId = enum(u32) {...@@ -1507,7 +1507,7 @@ pub const DataId = enum(u32) {
1507 const zcu = wasm.base.comp.zcu.?;1507 const zcu = wasm.base.comp.zcu.?;
1508 const ip = &zcu.intern_pool;1508 const ip = &zcu.intern_pool;
1509 const nav = ip.getNav(i.key(wasm).*);1509 const nav = ip.getNav(i.key(wasm).*);
1510 if (nav.isThreadLocal(ip)) return .tls;1510 if (nav.isThreadlocal(ip)) return .tls;
1511 const code = i.value(wasm).code;1511 const code = i.value(wasm).code;
1512 return if (code.off == .none) .zero else .data;1512 return if (code.off == .none) .zero else .data;
1513 },1513 },
...@@ -1523,7 +1523,7 @@ pub const DataId = enum(u32) {...@@ -1523,7 +1523,7 @@ pub const DataId = enum(u32) {
1523 const zcu = wasm.base.comp.zcu.?;1523 const zcu = wasm.base.comp.zcu.?;
1524 const ip = &zcu.intern_pool;1524 const ip = &zcu.intern_pool;
1525 const nav = ip.getNav(i.key(wasm).*);1525 const nav = ip.getNav(i.key(wasm).*);
1526 return nav.isThreadLocal(ip);1526 return nav.isThreadlocal(ip);
1527 },1527 },
1528 };1528 };
1529 }1529 }
...@@ -1540,7 +1540,7 @@ pub const DataId = enum(u32) {...@@ -1540,7 +1540,7 @@ pub const DataId = enum(u32) {
1540 const zcu = wasm.base.comp.zcu.?;1540 const zcu = wasm.base.comp.zcu.?;
1541 const ip = &zcu.intern_pool;1541 const ip = &zcu.intern_pool;
1542 const nav = ip.getNav(i.key(wasm).*);1542 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";
1544 },1544 },
1545 };1545 };
1546 }1546 }
...@@ -1563,7 +1563,7 @@ pub const DataId = enum(u32) {...@@ -1563,7 +1563,7 @@ pub const DataId = enum(u32) {
1563 const zcu = wasm.base.comp.zcu.?;1563 const zcu = wasm.base.comp.zcu.?;
1564 const ip = &zcu.intern_pool;1564 const ip = &zcu.intern_pool;
1565 const nav = ip.getNav(i.key(wasm).*);1565 const nav = ip.getNav(i.key(wasm).*);
1566 const explicit = nav.status.resolved.alignment;1566 const explicit = nav.getAlignment();
1567 if (explicit != .none) return explicit;1567 if (explicit != .none) return explicit;
1568 const ty: ZcuType = .fromInterned(nav.typeOf(ip));1568 const ty: ZcuType = .fromInterned(nav.typeOf(ip));
1569 const result = ty.abiAlignment(zcu);1569 const result = ty.abiAlignment(zcu);
...@@ -1820,11 +1820,7 @@ pub const ZcuImportIndex = enum(u32) {...@@ -1820,11 +1820,7 @@ pub const ZcuImportIndex = enum(u32) {
1820 const zcu = wasm.base.comp.zcu.?;1820 const zcu = wasm.base.comp.zcu.?;
1821 const ip = &zcu.intern_pool;1821 const ip = &zcu.intern_pool;
1822 const nav_index = index.ptr(wasm).*;1822 const nav_index = index.ptr(wasm).*;
1823 const nav = ip.getNav(nav_index);1823 const ext = ip.getNav(nav_index).getResolvedExtern(ip).?;
1824 const ext = switch (ip.indexToKey(nav.status.resolved.val)) {
1825 .@"extern" => |*ext| ext,
1826 else => unreachable,
1827 };
1828 const name_slice = ext.name.toSlice(ip);1824 const name_slice = ext.name.toSlice(ip);
1829 return wasm.getExistingString(name_slice).?;1825 return wasm.getExistingString(name_slice).?;
1830 }1826 }
...@@ -1833,11 +1829,7 @@ pub const ZcuImportIndex = enum(u32) {...@@ -1833,11 +1829,7 @@ pub const ZcuImportIndex = enum(u32) {
1833 const zcu = wasm.base.comp.zcu.?;1829 const zcu = wasm.base.comp.zcu.?;
1834 const ip = &zcu.intern_pool;1830 const ip = &zcu.intern_pool;
1835 const nav_index = index.ptr(wasm).*;1831 const nav_index = index.ptr(wasm).*;
1836 const nav = ip.getNav(nav_index);1832 const ext = ip.getNav(nav_index).getResolvedExtern(ip).?;
1837 const ext = switch (ip.indexToKey(nav.status.resolved.val)) {
1838 .@"extern" => |*ext| ext,
1839 else => unreachable,
1840 };
1841 const lib_name = ext.lib_name.toSlice(ip) orelse return .none;1833 const lib_name = ext.lib_name.toSlice(ip) orelse return .none;
1842 return wasm.getExistingString(lib_name).?.toOptional();1834 return wasm.getExistingString(lib_name).?.toOptional();
1843 }1835 }
...@@ -1848,11 +1840,7 @@ pub const ZcuImportIndex = enum(u32) {...@@ -1848,11 +1840,7 @@ pub const ZcuImportIndex = enum(u32) {
1848 const zcu = comp.zcu.?;1840 const zcu = comp.zcu.?;
1849 const ip = &zcu.intern_pool;1841 const ip = &zcu.intern_pool;
1850 const nav_index = index.ptr(wasm).*;1842 const nav_index = index.ptr(wasm).*;
1851 const nav = ip.getNav(nav_index);1843 const ext = ip.getNav(nav_index).getResolvedExtern(ip).?;
1852 const ext = switch (ip.indexToKey(nav.status.resolved.val)) {
1853 .@"extern" => |*ext| ext,
1854 else => unreachable,
1855 };
1856 const fn_info = zcu.typeToFunc(.fromInterned(ext.ty)).?;1844 const fn_info = zcu.typeToFunc(.fromInterned(ext.ty)).?;
1857 return getExistingFunctionType(wasm, fn_info.cc, fn_info.param_types.get(ip), .fromInterned(fn_info.return_type), target).?;1845 return getExistingFunctionType(wasm, fn_info.cc, fn_info.param_types.get(ip), .fromInterned(fn_info.return_type), target).?;
1858 }1846 }
...@@ -1944,7 +1932,7 @@ pub const FunctionImportId = enum(u32) {...@@ -1944,7 +1932,7 @@ pub const FunctionImportId = enum(u32) {
1944 .zcu_import => |i| {1932 .zcu_import => |i| {
1945 const zcu = wasm.base.comp.zcu.?;1933 const zcu = wasm.base.comp.zcu.?;
1946 const ip = &zcu.intern_pool;1934 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).?;
1948 return !ext.is_weak_linkage and ext.lib_name != .none;1936 return !ext.is_weak_linkage and ext.lib_name != .none;
1949 },1937 },
1950 };1938 };
...@@ -2588,7 +2576,7 @@ pub fn updateNav(wasm: *Wasm, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index...@@ -2588,7 +2576,7 @@ pub fn updateNav(wasm: *Wasm, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index
2588 const is_obj = comp.config.output_mode == .Obj;2576 const is_obj = comp.config.output_mode == .Obj;
2589 const target = &comp.root_mod.resolved_target.result;2577 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)) {
2592 .func => return, // global const which is a function alias2580 .func => return, // global const which is a function alias
2593 .@"extern" => |ext| {2581 .@"extern" => |ext| {
2594 if (is_obj) {2582 if (is_obj) {
...@@ -2612,7 +2600,7 @@ pub fn updateNav(wasm: *Wasm, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index...@@ -2612,7 +2600,7 @@ pub fn updateNav(wasm: *Wasm, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index
2612 return;2600 return;
2613 },2601 },
2614 .variable => |variable| .{ variable.init, variable.owner_nav },2602 .variable => |variable| .{ variable.init, variable.owner_nav },
2615 else => .{ nav.status.resolved.val, nav_index },2603 else => .{ nav.status.fully_resolved.val, nav_index },
2616 };2604 };
2617 //log.debug("updateNav {} {}", .{ nav.fqn.fmt(ip), chased_nav_index });2605 //log.debug("updateNav {} {}", .{ nav.fqn.fmt(ip), chased_nav_index });
2618 assert(!wasm.imports.contains(chased_nav_index));2606 assert(!wasm.imports.contains(chased_nav_index));