authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2024-03-17 13:31:28+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2024-03-17 14:42:12+02:00
log436c72e89a6e402b6920ab03207b95d0ca709ee9
treea3388f0414101b608f48e54420c9ef3254b5d423
parentfec4b7ef5c6a9fc2da1708be6e5be0a619d4b948

Sema: allow param instructions to clobber inst_map

Closes #18840

2 files changed, 10 insertions(+), 4 deletions(-)

src/Sema.zig+4-4
......@@ -9919,7 +9919,7 @@ fn zirParam(
99199919 .is_comptime = comptime_syntax,
99209920 .name = param_name,
99219921 });
9922 sema.inst_map.putAssumeCapacityNoClobber(inst, .generic_poison);
9922 sema.inst_map.putAssumeCapacity(inst, .generic_poison);
99239923 return;
99249924 },
99259925 else => |e| return e,
......@@ -9936,7 +9936,7 @@ fn zirParam(
99369936 .is_comptime = comptime_syntax,
99379937 .name = param_name,
99389938 });
9939 sema.inst_map.putAssumeCapacityNoClobber(inst, .generic_poison);
9939 sema.inst_map.putAssumeCapacity(inst, .generic_poison);
99409940 return;
99419941 },
99429942 else => |e| return e,
......@@ -9951,7 +9951,7 @@ fn zirParam(
99519951 if (is_comptime) {
99529952 // If this is a comptime parameter we can add a constant generic_poison
99539953 // since this is also a generic parameter.
9954 sema.inst_map.putAssumeCapacityNoClobber(inst, .generic_poison);
9954 sema.inst_map.putAssumeCapacity(inst, .generic_poison);
99559955 } else {
99569956 // Otherwise we need a dummy runtime instruction.
99579957 const result_index: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);
......@@ -9959,7 +9959,7 @@ fn zirParam(
99599959 .tag = .alloc,
99609960 .data = .{ .ty = param_ty },
99619961 });
9962 sema.inst_map.putAssumeCapacityNoClobber(inst, result_index.toRef());
9962 sema.inst_map.putAssumeCapacity(inst, result_index.toRef());
99639963 }
99649964}
99659965
test/behavior/generics.zig+6
......@@ -578,3 +578,9 @@ test "call generic function that uses capture from function declaration's scope"
578578 const s = S.foo(123);
579579 try expectEqual(123.0, s[0]);
580580}
581
582comptime {
583 // The same function parameter instruction being analyzed multiple times
584 // should override the result of the previous analysis.
585 for (0..2) |_| _ = fn (void) void;
586}