Sema: allow param instructions to clobber inst_map

Closes #18840
This commit is contained in:
Veikka Tuominen 2024-03-17 13:31:28 +02:00
parent fec4b7ef5c
commit 436c72e89a
2 changed files with 10 additions and 4 deletions

View File

@ -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());
}
}

View File

@ -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;
}