authorgravatar for jtwambolt@gmail.comJackson Wambolt <jtwambolt@gmail.com> 2025-06-28 19:33:38-05:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-07-31 22:28:46+01:00
log264bd7053edb948d0f96525b54b859c0422e12a2
tree35ea671688ad92693f4579c6de89f9a1f6e3b98e
parentac1e73e249f8ce06bc7c89d2bdc4359b0399236c

Sema: remove incorrect `requireRuntimeBlock` calls

Part of #22353 Resolves: #24273 Co-Authored-By: Matthew Lugg <mlugg@mlugg.co.uk>

3 files changed, 30 insertions(+), 12 deletions(-)

src/Sema.zig+2-12
...@@ -19572,7 +19572,7 @@ fn structInitAnon(...@@ -19572,7 +19572,7 @@ fn structInitAnon(
19572 try sema.declareDependency(.{ .interned = struct_ty });19572 try sema.declareDependency(.{ .interned = struct_ty });
19573 try sema.addTypeReferenceEntry(src, struct_ty);19573 try sema.addTypeReferenceEntry(src, struct_ty);
1957419574
19575 const runtime_index = opt_runtime_index orelse {19575 _ = opt_runtime_index orelse {
19576 const struct_val = try pt.intern(.{ .aggregate = .{19576 const struct_val = try pt.intern(.{ .aggregate = .{
19577 .ty = struct_ty,19577 .ty = struct_ty,
19578 .storage = .{ .elems = values },19578 .storage = .{ .elems = values },
...@@ -19580,11 +19580,6 @@ fn structInitAnon(...@@ -19580,11 +19580,6 @@ fn structInitAnon(
19580 return sema.addConstantMaybeRef(struct_val, is_ref);19580 return sema.addConstantMaybeRef(struct_val, is_ref);
19581 };19581 };
1958219582
19583 try sema.requireRuntimeBlock(block, LazySrcLoc.unneeded, block.src(.{ .init_elem = .{
19584 .init_node_offset = src.offset.node_offset.x,
19585 .elem_index = @intCast(runtime_index),
19586 } }));
19587
19588 if (is_ref) {19583 if (is_ref) {
19589 const target = zcu.getTarget();19584 const target = zcu.getTarget();
19590 const alloc_ty = try pt.ptrTypeSema(.{19585 const alloc_ty = try pt.ptrTypeSema(.{
...@@ -19713,7 +19708,7 @@ fn zirArrayInit(...@@ -19713,7 +19708,7 @@ fn zirArrayInit(
19713 if (!comptime_known) break @intCast(i);19708 if (!comptime_known) break @intCast(i);
19714 } else null;19709 } else null;
1971519710
19716 const runtime_index = opt_runtime_index orelse {19711 _ = opt_runtime_index orelse {
19717 const elem_vals = try sema.arena.alloc(InternPool.Index, resolved_args.len);19712 const elem_vals = try sema.arena.alloc(InternPool.Index, resolved_args.len);
19718 for (elem_vals, resolved_args) |*val, arg| {19713 for (elem_vals, resolved_args) |*val, arg| {
19719 // We checked that all args are comptime above.19714 // We checked that all args are comptime above.
...@@ -19728,11 +19723,6 @@ fn zirArrayInit(...@@ -19728,11 +19723,6 @@ fn zirArrayInit(
19728 return sema.addConstantMaybeRef(result_val.toIntern(), is_ref);19723 return sema.addConstantMaybeRef(result_val.toIntern(), is_ref);
19729 };19724 };
1973019725
19731 try sema.requireRuntimeBlock(block, LazySrcLoc.unneeded, block.src(.{ .init_elem = .{
19732 .init_node_offset = src.offset.node_offset.x,
19733 .elem_index = runtime_index,
19734 } }));
19735
19736 if (is_ref) {19726 if (is_ref) {
19737 const target = zcu.getTarget();19727 const target = zcu.getTarget();
19738 const alloc_ty = try pt.ptrTypeSema(.{19728 const alloc_ty = try pt.ptrTypeSema(.{
test/cases/compile_errors/runtime_value_in_comptime_array.zig created+14
...@@ -0,0 +1,14 @@
1fn comptimeArray(comptime _: []const u8) void {}
2fn bar() u8 {
3 return 123;
4}
5export fn entry() void {
6 const y = bar();
7 comptimeArray(&.{y});
8}
9
10// error
11//
12// :7:19: error: unable to resolve comptime value
13// :7:19: note: argument to comptime parameter must be comptime-known
14// :1:18: note: parameter declared comptime here
test/cases/compile_errors/runtime_value_in_comptime_struct.zig created+14
...@@ -0,0 +1,14 @@
1fn comptimeStruct(comptime _: anytype) void {}
2fn bar() u8 {
3 return 123;
4}
5export fn entry() void {
6 const y = bar();
7 comptimeStruct(.{ .foo = y });
8}
9
10// error
11//
12// :7:21: error: unable to resolve comptime value
13// :7:21: note: argument to comptime parameter must be comptime-known
14// :1:19: note: parameter declared comptime here