|
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; |
@@ -323,24 +324,19 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { |
323 | 324 | if ty.is_zst() { |
324 | 325 | ImmTy::uninit(ty).into() |
325 | 326 | } else if matches!(ty.abi, Abi::Scalar(..) | Abi::ScalarPair(..)) { |
326 | | - let alloc_id = self |
327 | | - .ecx |
328 | | - .intern_with_temp_alloc(ty, |ecx, dest| { |
329 | | - let variant_dest = if let Some(variant) = variant { |
330 | | - ecx.project_downcast(dest, variant)? |
331 | | - } else { |
332 | | - dest.clone() |
333 | | - }; |
334 | | - for (field_index, op) in fields.into_iter().enumerate() { |
335 | | - let field_dest = ecx.project_field(&variant_dest, field_index)?; |
336 | | - ecx.copy_op(op, &field_dest, /*allow_transmute*/ false)?; |
337 | | - } |
338 | | - ecx.write_discriminant(variant.unwrap_or(FIRST_VARIANT), dest) |
339 | | - }) |
340 | | - .ok()?; |
341 | | - let mplace = |
342 | | - self.ecx.raw_const_to_mplace(ConstAlloc { alloc_id, ty: ty.ty }).ok()?; |
343 | | - mplace.into() |
| 327 | + let dest = self.ecx.allocate(ty, MemoryKind::Stack).ok()?; |
| 328 | + let variant_dest = if let Some(variant) = variant { |
| 329 | + self.ecx.project_downcast(&dest, variant).ok()? |
| 330 | + } else { |
| 331 | + dest.clone() |
| 332 | + }; |
| 333 | + for (field_index, op) in fields.into_iter().enumerate() { |
| 334 | + let field_dest = self.ecx.project_field(&variant_dest, field_index).ok()?; |
| 335 | + self.ecx.copy_op(op, &field_dest, /*allow_transmute*/ false).ok()?; |
| 336 | + } |
| 337 | + self.ecx.write_discriminant(variant.unwrap_or(FIRST_VARIANT), &dest).ok()?; |
| 338 | + self.ecx.alloc_mark_immutable(dest.ptr().provenance.unwrap()).ok()?; |
| 339 | + dest.into() |
344 | 340 | } else { |
345 | 341 | return None; |
346 | 342 | } |
@@ -846,10 +842,8 @@ fn op_to_prop_const<'tcx>( |
846 | 842 | { |
847 | 843 | let pointer = mplace.ptr().into_pointer_or_addr().ok()?; |
848 | 844 | let (alloc_id, offset) = pointer.into_parts(); |
849 | | - return if matches!(ecx.tcx.global_alloc(alloc_id), GlobalAlloc::Memory(_)) { |
850 | | - Some(ConstValue::Indirect { alloc_id, offset }) |
851 | | - } else { |
852 | | - None |
| 845 | + if matches!(ecx.tcx.try_get_global_alloc(alloc_id), Some(GlobalAlloc::Memory(_))) { |
| 846 | + return Some(ConstValue::Indirect { alloc_id, offset }) |
853 | 847 | } |
854 | 848 | } |
855 | 849 |
|
|
0 commit comments