Auto merge of #118336 - saethlin:const-to-op-cache, r=RalfJung
Return a finite number of AllocIds per ConstAllocation in Miri Before this, every evaluation of a const slice would produce a new AllocId. So in Miri, this program used to have unbounded memory use: ```rust fn main() { loop { helper(); } } fn helper() { "ouch"; } ``` Every trip around the loop creates a new AllocId which we need to keep track of a base address for. And the provenance GC can never clean up that AllocId -> u64 mapping, because the AllocId is for a const allocation which will never be deallocated. So this PR moves the logic of producing an AllocId for a ConstAllocation to the Machine trait, and the implementation that Miri provides will only produce 16 AllocIds for each allocation. The cache is also keyed on the Instance that the const is evaluated in, so that equal consts evaluated in two functions will have disjoint base addresses. r? RalfJung
This commit is contained in:
commit
cd6d8f2a04
4 changed files with 119 additions and 9 deletions
|
@ -1131,13 +1131,15 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
span: Option<Span>,
|
||||
layout: Option<TyAndLayout<'tcx>>,
|
||||
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
|
||||
let const_val = val.eval(*self.tcx, self.param_env, span).map_err(|err| {
|
||||
// FIXME: somehow this is reachable even when POST_MONO_CHECKS is on.
|
||||
// Are we not always populating `required_consts`?
|
||||
err.emit_note(*self.tcx);
|
||||
err
|
||||
})?;
|
||||
self.const_val_to_op(const_val, val.ty(), layout)
|
||||
M::eval_mir_constant(self, *val, span, layout, |ecx, val, span, layout| {
|
||||
let const_val = val.eval(*ecx.tcx, ecx.param_env, span).map_err(|err| {
|
||||
// FIXME: somehow this is reachable even when POST_MONO_CHECKS is on.
|
||||
// Are we not always populating `required_consts`?
|
||||
err.emit_note(*ecx.tcx);
|
||||
err
|
||||
})?;
|
||||
ecx.const_val_to_op(const_val, val.ty(), layout)
|
||||
})
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue