From acd35a1aa75c78dc24859fa658f6d3e25e330b8a Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Sat, 26 Aug 2023 16:55:32 -0400 Subject: 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. --- src/Module.zig | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/Module.zig') diff --git a/src/Module.zig b/src/Module.zig index c13be489bb..d1b1e9b357 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -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) { -- cgit v1.2.3