ctfe interning: don't walk allocations that don't need it

The interning of const allocations visits the mplace looking for references
to intern. Walking big aggregates like big static arrays can be costly,
so we only do it if the allocation we're interning contains references
or interior mutability.

Walking ZSTs was avoided before, and this optimization is now applied
to cases where there are no references/relocations either.
This commit is contained in:
Rémy Rakic
2022-05-31 12:36:48 +02:00
parent 94e93749ab
commit 97a0b2e2d0
2 changed files with 25 additions and 3 deletions

View File

@@ -942,6 +942,11 @@ impl<'tcx, 'a, Tag: Provenance, Extra> AllocRef<'a, 'tcx, Tag, Extra> {
.check_bytes(&self.tcx, self.range.subrange(range), allow_uninit, allow_ptr)
.map_err(|e| e.to_interp_error(self.alloc_id))?)
}
/// Returns whether the allocation has relocations for the entire range of the `AllocRef`.
pub(crate) fn has_relocations(&self) -> bool {
!self.alloc.get_relocations(&self.tcx, self.range).is_empty()
}
}
impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {