1
Fork 0

use AllocId instead of Allocation in ConstValue::ByRef

This commit is contained in:
Ralf Jung 2023-09-11 20:01:48 +02:00
parent c728bf3963
commit 551f481ffb
15 changed files with 80 additions and 63 deletions

View file

@ -535,7 +535,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
}
trace!("replacing {:?} with {:?}", place, value);
// FIXME> figure out what to do when read_immediate_raw fails
// FIXME: figure out what to do when read_immediate_raw fails
let imm = self.ecx.read_immediate_raw(&value).ok()?;
let Right(imm) = imm else { return None };
@ -544,7 +544,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
Some(ConstantKind::from_scalar(self.tcx, scalar, value.layout.ty))
}
Immediate::ScalarPair(l, r) if l.try_to_int().is_ok() && r.try_to_int().is_ok() => {
let alloc = self
let alloc_id = self
.ecx
.intern_with_temp_alloc(value.layout, |ecx, dest| {
ecx.write_immediate(*imm, dest)
@ -552,7 +552,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
.ok()?;
Some(ConstantKind::Val(
ConstValue::ByRef { alloc, offset: Size::ZERO },
ConstValue::ByRef { alloc_id, offset: Size::ZERO },
value.layout.ty,
))
}

View file

@ -139,7 +139,6 @@ impl EnumSizeOpt {
let (adt_def, num_variants, alloc_id) =
self.candidate(tcx, param_env, ty, &mut alloc_cache)?;
let alloc = tcx.global_alloc(alloc_id).unwrap_memory();
let tmp_ty = Ty::new_array(tcx, tcx.types.usize, num_variants as u64);
@ -154,7 +153,7 @@ impl EnumSizeOpt {
span,
user_ty: None,
literal: ConstantKind::Val(
interpret::ConstValue::ByRef { alloc, offset: Size::ZERO },
interpret::ConstValue::ByRef { alloc_id, offset: Size::ZERO },
tmp_ty,
),
};