|
53 | 53 | //! _c = *_b // replaced by _c = _a
|
54 | 54 | //! ```
|
55 | 55 |
|
| 56 | +use rustc_const_eval::interpret::MemoryKind; |
56 | 57 | use rustc_const_eval::interpret::{ImmTy, InterpCx, MemPlaceMeta, OpTy, Projectable, Scalar};
|
57 | 58 | use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
|
58 | 59 | use rustc_data_structures::graph::dominators::Dominators;
|
@@ -316,24 +317,19 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
|
316 | 317 | if ty.is_zst() {
|
317 | 318 | ImmTy::uninit(ty).into()
|
318 | 319 | } else if matches!(ty.abi, Abi::Scalar(..) | Abi::ScalarPair(..)) {
|
319 |
| - let alloc_id = self |
320 |
| - .ecx |
321 |
| - .intern_with_temp_alloc(ty, |ecx, dest| { |
322 |
| - let variant_dest = if let Some(variant) = variant { |
323 |
| - ecx.project_downcast(dest, variant)? |
324 |
| - } else { |
325 |
| - dest.clone() |
326 |
| - }; |
327 |
| - for (field_index, op) in fields.into_iter().enumerate() { |
328 |
| - let field_dest = ecx.project_field(&variant_dest, field_index)?; |
329 |
| - ecx.copy_op(op, &field_dest, /*allow_transmute*/ false)?; |
330 |
| - } |
331 |
| - ecx.write_discriminant(variant.unwrap_or(FIRST_VARIANT), dest) |
332 |
| - }) |
333 |
| - .ok()?; |
334 |
| - let mplace = |
335 |
| - self.ecx.raw_const_to_mplace(ConstAlloc { alloc_id, ty: ty.ty }).ok()?; |
336 |
| - mplace.into() |
| 320 | + let dest = self.ecx.allocate(ty, MemoryKind::Stack).ok()?; |
| 321 | + let variant_dest = if let Some(variant) = variant { |
| 322 | + self.ecx.project_downcast(&dest, variant).ok()? |
| 323 | + } else { |
| 324 | + dest.clone() |
| 325 | + }; |
| 326 | + for (field_index, op) in fields.into_iter().enumerate() { |
| 327 | + let field_dest = self.ecx.project_field(&variant_dest, field_index).ok()?; |
| 328 | + self.ecx.copy_op(op, &field_dest, /*allow_transmute*/ false).ok()?; |
| 329 | + } |
| 330 | + self.ecx.write_discriminant(variant.unwrap_or(FIRST_VARIANT), &dest).ok()?; |
| 331 | + self.ecx.alloc_mark_immutable(dest.ptr().provenance.unwrap()).ok()?; |
| 332 | + dest.into() |
337 | 333 | } else {
|
338 | 334 | return None;
|
339 | 335 | }
|
@@ -839,10 +835,8 @@ fn op_to_prop_const<'tcx>(
|
839 | 835 | {
|
840 | 836 | let pointer = mplace.ptr().into_pointer_or_addr().ok()?;
|
841 | 837 | let (alloc_id, offset) = pointer.into_parts();
|
842 |
| - return if matches!(ecx.tcx.global_alloc(alloc_id), GlobalAlloc::Memory(_)) { |
843 |
| - Some(ConstValue::Indirect { alloc_id, offset }) |
844 |
| - } else { |
845 |
| - None |
| 838 | + if matches!(ecx.tcx.try_get_global_alloc(alloc_id), Some(GlobalAlloc::Memory(_))) { |
| 839 | + return Some(ConstValue::Indirect { alloc_id, offset }) |
846 | 840 | }
|
847 | 841 | }
|
848 | 842 |
|
|
0 commit comments