Commit 436c72e89a

Veikka Tuominen <git@vexu.eu>
2024-03-17 12:31:28
Sema: allow param instructions to clobber inst_map
Closes #18840
1 parent fec4b7e
Changed files (2)
src
test
behavior
src/Sema.zig
@@ -9919,7 +9919,7 @@ fn zirParam(
                     .is_comptime = comptime_syntax,
                     .name = param_name,
                 });
-                sema.inst_map.putAssumeCapacityNoClobber(inst, .generic_poison);
+                sema.inst_map.putAssumeCapacity(inst, .generic_poison);
                 return;
             },
             else => |e| return e,
@@ -9936,7 +9936,7 @@ fn zirParam(
                 .is_comptime = comptime_syntax,
                 .name = param_name,
             });
-            sema.inst_map.putAssumeCapacityNoClobber(inst, .generic_poison);
+            sema.inst_map.putAssumeCapacity(inst, .generic_poison);
             return;
         },
         else => |e| return e,
@@ -9951,7 +9951,7 @@ fn zirParam(
     if (is_comptime) {
         // If this is a comptime parameter we can add a constant generic_poison
         // since this is also a generic parameter.
-        sema.inst_map.putAssumeCapacityNoClobber(inst, .generic_poison);
+        sema.inst_map.putAssumeCapacity(inst, .generic_poison);
     } else {
         // Otherwise we need a dummy runtime instruction.
         const result_index: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);
@@ -9959,7 +9959,7 @@ fn zirParam(
             .tag = .alloc,
             .data = .{ .ty = param_ty },
         });
-        sema.inst_map.putAssumeCapacityNoClobber(inst, result_index.toRef());
+        sema.inst_map.putAssumeCapacity(inst, result_index.toRef());
     }
 }
 
test/behavior/generics.zig
@@ -578,3 +578,9 @@ test "call generic function that uses capture from function declaration's scope"
     const s = S.foo(123);
     try expectEqual(123.0, s[0]);
 }
+
+comptime {
+    // The same function parameter instruction being analyzed multiple times
+    // should override the result of the previous analysis.
+    for (0..2) |_| _ = fn (void) void;
+}