Sema: factor out NeededComptimeReason from comptime value resolution
This makes the call sites easier to read, reduces the number of `catch` expressions required, and prepares for comptime reasons to appear earlier in the list of notes.
This commit is contained in:
@@ -4147,7 +4147,9 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
|
||||
const address_space_src: LazySrcLoc = .{ .node_offset_var_decl_addrspace = 0 };
|
||||
const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = 0 };
|
||||
const init_src: LazySrcLoc = .{ .node_offset_var_decl_init = 0 };
|
||||
const decl_tv = try sema.resolveInstValue(&block_scope, init_src, result_ref, "global variable initializer must be comptime-known");
|
||||
const decl_tv = try sema.resolveInstValue(&block_scope, init_src, result_ref, .{
|
||||
.needed_comptime_reason = "global variable initializer must be comptime-known",
|
||||
});
|
||||
|
||||
// Note this resolves the type of the Decl, not the value; if this Decl
|
||||
// is a struct, for example, this resolves `type` (which needs no resolution),
|
||||
@@ -4257,7 +4259,9 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
|
||||
decl.@"linksection" = blk: {
|
||||
const linksection_ref = decl.zirLinksectionRef(mod);
|
||||
if (linksection_ref == .none) break :blk .none;
|
||||
const bytes = try sema.resolveConstString(&block_scope, section_src, linksection_ref, "linksection must be comptime-known");
|
||||
const bytes = try sema.resolveConstString(&block_scope, section_src, linksection_ref, .{
|
||||
.needed_comptime_reason = "linksection must be comptime-known",
|
||||
});
|
||||
if (mem.indexOfScalar(u8, bytes, 0) != null) {
|
||||
return sema.fail(&block_scope, section_src, "linksection cannot contain null bytes", .{});
|
||||
} else if (bytes.len == 0) {
|
||||
|
||||
565
src/Sema.zig
565
src/Sema.zig
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user