Skip to content

Commit

Permalink
resolve merge conflicts
Browse files Browse the repository at this point in the history
with 497592c
  • Loading branch information
andrewrk committed Dec 27, 2024
1 parent eb7d938 commit 9885cb1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 49 deletions.
34 changes: 14 additions & 20 deletions src/InternPool.zig
Original file line number Diff line number Diff line change
Expand Up @@ -527,14 +527,14 @@ pub const Nav = struct {
};
}

/// Always returns `null` for `status == .type_resolved`. This function is inteded
/// to be used by code generation, since semantic analysis will ensure that any `Nav`
/// which is potentially `extern` is fully resolved.
/// Asserts that `status != .unresolved`.
/// This function is intended to be used by code generation, since semantic
/// analysis will ensure that any `Nav` which is potentially `extern` is
/// fully resolved.
/// Asserts that `status == .fully_resolved`.
pub fn getExtern(nav: Nav, ip: *const InternPool) ?Key.Extern {
return switch (nav.status) {
.unresolved => unreachable,
.type_resolved => null,
.type_resolved => unreachable,
.fully_resolved => |r| switch (ip.indexToKey(r.val)) {
.@"extern" => |e| e,
else => null,
Expand All @@ -560,6 +560,15 @@ pub const Nav = struct {
};
}

/// Asserts that `status != .unresolved`.
pub fn getLinkSection(nav: Nav) OptionalNullTerminatedString {
return switch (nav.status) {
.unresolved => unreachable,
.type_resolved => |r| r.@"linksection",
.fully_resolved => |r| r.@"linksection",
};
}

/// Asserts that `status != .unresolved`.
pub fn isThreadlocal(nav: Nav, ip: *const InternPool) bool {
return switch (nav.status) {
Expand Down Expand Up @@ -595,21 +604,6 @@ pub const Nav = struct {
};
}

/// Asserts that `status == .resolved`.
pub fn toExtern(nav: *const Nav, ip: *const InternPool) ?Key.Extern {
return switch (ip.indexToKey(nav.status.resolved.val)) {
.@"extern" => |ext| ext,
else => null,
};
}

/// Asserts that `status == .resolved`.
pub fn isThreadLocal(nav: Nav, ip: *const InternPool) bool {
const val = nav.status.resolved.val;
if (!isVariable(ip, val)) return false;
return ip.indexToKey(val).variable.is_threadlocal;
}

/// Get the ZIR instruction corresponding to this `Nav`, used to resolve source locations.
/// This is a `declaration`.
pub fn srcInst(nav: Nav, ip: *const InternPool) TrackedInst.Index {
Expand Down
2 changes: 1 addition & 1 deletion src/arch/wasm/CodeGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ fn emitWValue(cg: *CodeGen, value: WValue) InnerError!void {
const comp = wasm.base.comp;
const zcu = comp.zcu.?;
const ip = &zcu.intern_pool;
const ip_index = ip.getNav(nav_ref.nav_index).status.resolved.val;
const ip_index = ip.getNav(nav_ref.nav_index).status.fully_resolved.val;
if (ip.isFunctionType(ip.typeOf(ip_index))) {
assert(nav_ref.offset == 0);
const gop = try wasm.indirect_function_table.getOrPut(comp.gpa, ip_index);
Expand Down
44 changes: 16 additions & 28 deletions src/link/Wasm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ pub const OutputFunctionIndex = enum(u32) {
const zcu = wasm.base.comp.zcu.?;
const ip = &zcu.intern_pool;
const nav = ip.getNav(nav_index);
return fromIpIndex(wasm, nav.status.resolved.val);
return fromIpIndex(wasm, nav.status.fully_resolved.val);
}

pub fn fromTagNameType(wasm: *const Wasm, tag_type: InternPool.Index) OutputFunctionIndex {
Expand Down Expand Up @@ -758,9 +758,9 @@ const ZcuDataStarts = struct {
while (true) {
while (navs_i < wasm.navs_obj.entries.len) : (navs_i += 1) {
const elem_nav = ip.getNav(wasm.navs_obj.keys()[navs_i]);
const elem_nav_init = switch (ip.indexToKey(elem_nav.status.resolved.val)) {
const elem_nav_init = switch (ip.indexToKey(elem_nav.status.fully_resolved.val)) {
.variable => |variable| variable.init,
else => elem_nav.status.resolved.val,
else => elem_nav.status.fully_resolved.val,
};
// Call to `lowerZcuData` here possibly creates more entries in these tables.
wasm.navs_obj.values()[navs_i] = try lowerZcuData(wasm, pt, elem_nav_init);
Expand All @@ -781,9 +781,9 @@ const ZcuDataStarts = struct {
while (true) {
while (navs_i < wasm.navs_exe.entries.len) : (navs_i += 1) {
const elem_nav = ip.getNav(wasm.navs_exe.keys()[navs_i]);
const elem_nav_init = switch (ip.indexToKey(elem_nav.status.resolved.val)) {
const elem_nav_init = switch (ip.indexToKey(elem_nav.status.fully_resolved.val)) {
.variable => |variable| variable.init,
else => elem_nav.status.resolved.val,
else => elem_nav.status.fully_resolved.val,
};
// Call to `lowerZcuData` here possibly creates more entries in these tables.
const zcu_data = try lowerZcuData(wasm, pt, elem_nav_init);
Expand Down Expand Up @@ -930,7 +930,7 @@ pub const FunctionImport = extern struct {
pub fn fromIpNav(wasm: *const Wasm, nav_index: InternPool.Nav.Index) Resolution {
const zcu = wasm.base.comp.zcu.?;
const ip = &zcu.intern_pool;
return fromIpIndex(wasm, ip.getNav(nav_index).status.resolved.val);
return fromIpIndex(wasm, ip.getNav(nav_index).status.fully_resolved.val);
}

pub fn fromIpIndex(wasm: *const Wasm, ip_index: InternPool.Index) Resolution {
Expand Down Expand Up @@ -1507,7 +1507,7 @@ pub const DataId = enum(u32) {
const zcu = wasm.base.comp.zcu.?;
const ip = &zcu.intern_pool;
const nav = ip.getNav(i.key(wasm).*);
if (nav.isThreadLocal(ip)) return .tls;
if (nav.isThreadlocal(ip)) return .tls;
const code = i.value(wasm).code;
return if (code.off == .none) .zero else .data;
},
Expand All @@ -1523,7 +1523,7 @@ pub const DataId = enum(u32) {
const zcu = wasm.base.comp.zcu.?;
const ip = &zcu.intern_pool;
const nav = ip.getNav(i.key(wasm).*);
return nav.isThreadLocal(ip);
return nav.isThreadlocal(ip);
},
};
}
Expand All @@ -1540,7 +1540,7 @@ pub const DataId = enum(u32) {
const zcu = wasm.base.comp.zcu.?;
const ip = &zcu.intern_pool;
const nav = ip.getNav(i.key(wasm).*);
return nav.status.resolved.@"linksection".toSlice(ip) orelse ".data";
return nav.getLinkSection().toSlice(ip) orelse ".data";
},
};
}
Expand All @@ -1563,7 +1563,7 @@ pub const DataId = enum(u32) {
const zcu = wasm.base.comp.zcu.?;
const ip = &zcu.intern_pool;
const nav = ip.getNav(i.key(wasm).*);
const explicit = nav.status.resolved.alignment;
const explicit = nav.getAlignment();
if (explicit != .none) return explicit;
const ty: ZcuType = .fromInterned(nav.typeOf(ip));
const result = ty.abiAlignment(zcu);
Expand Down Expand Up @@ -1820,11 +1820,7 @@ pub const ZcuImportIndex = enum(u32) {
const zcu = wasm.base.comp.zcu.?;
const ip = &zcu.intern_pool;
const nav_index = index.ptr(wasm).*;
const nav = ip.getNav(nav_index);
const ext = switch (ip.indexToKey(nav.status.resolved.val)) {
.@"extern" => |*ext| ext,
else => unreachable,
};
const ext = ip.getNav(nav_index).getExtern(ip).?;
const name_slice = ext.name.toSlice(ip);
return wasm.getExistingString(name_slice).?;
}
Expand All @@ -1833,11 +1829,7 @@ pub const ZcuImportIndex = enum(u32) {
const zcu = wasm.base.comp.zcu.?;
const ip = &zcu.intern_pool;
const nav_index = index.ptr(wasm).*;
const nav = ip.getNav(nav_index);
const ext = switch (ip.indexToKey(nav.status.resolved.val)) {
.@"extern" => |*ext| ext,
else => unreachable,
};
const ext = ip.getNav(nav_index).getExtern(ip).?;
const lib_name = ext.lib_name.toSlice(ip) orelse return .none;
return wasm.getExistingString(lib_name).?.toOptional();
}
Expand All @@ -1848,11 +1840,7 @@ pub const ZcuImportIndex = enum(u32) {
const zcu = comp.zcu.?;
const ip = &zcu.intern_pool;
const nav_index = index.ptr(wasm).*;
const nav = ip.getNav(nav_index);
const ext = switch (ip.indexToKey(nav.status.resolved.val)) {
.@"extern" => |*ext| ext,
else => unreachable,
};
const ext = ip.getNav(nav_index).getExtern(ip).?;
const fn_info = zcu.typeToFunc(.fromInterned(ext.ty)).?;
return getExistingFunctionType(wasm, fn_info.cc, fn_info.param_types.get(ip), .fromInterned(fn_info.return_type), target).?;
}
Expand Down Expand Up @@ -1944,7 +1932,7 @@ pub const FunctionImportId = enum(u32) {
.zcu_import => |i| {
const zcu = wasm.base.comp.zcu.?;
const ip = &zcu.intern_pool;
const ext = ip.getNav(i.ptr(wasm).*).toExtern(ip).?;
const ext = ip.getNav(i.ptr(wasm).*).getExtern(ip).?;
return !ext.is_weak_linkage and ext.lib_name != .none;
},
};
Expand Down Expand Up @@ -2588,7 +2576,7 @@ pub fn updateNav(wasm: *Wasm, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index
const is_obj = comp.config.output_mode == .Obj;
const target = &comp.root_mod.resolved_target.result;

const nav_init, const chased_nav_index = switch (ip.indexToKey(nav.status.resolved.val)) {
const nav_init, const chased_nav_index = switch (ip.indexToKey(nav.status.fully_resolved.val)) {
.func => return, // global const which is a function alias
.@"extern" => |ext| {
if (is_obj) {
Expand All @@ -2612,7 +2600,7 @@ pub fn updateNav(wasm: *Wasm, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index
return;
},
.variable => |variable| .{ variable.init, variable.owner_nav },
else => .{ nav.status.resolved.val, nav_index },
else => .{ nav.status.fully_resolved.val, nav_index },
};
//log.debug("updateNav {} {}", .{ nav.fqn.fmt(ip), chased_nav_index });
assert(!wasm.imports.contains(chased_nav_index));
Expand Down

0 comments on commit 9885cb1

Please sign in to comment.