commit 436c72e89a6e402b6920ab03207b95d0ca709ee9 (tree)
parent fec4b7ef5c6a9fc2da1708be6e5be0a619d4b948
Author: Veikka Tuominen <git@vexu.eu>
Date: Sun, 17 Mar 2024 13:31:28 +0200
Sema: allow param instructions to clobber inst_map
Closes #18840
Diffstat:
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/src/Sema.zig b/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());
}
}
diff --git a/test/behavior/generics.zig b/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;
+}