Skip to content

Commit bc9586d

Browse files
committed
wip
1 parent ff0c6b7 commit bc9586d

File tree

1 file changed

+25
-2
lines changed
  • compiler/rustc_mir_transform/src

1 file changed

+25
-2
lines changed

compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,9 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
367367
#[instrument(level = "trace", skip(self), ret)]
368368
fn eval_to_const(&mut self, value: VnIndex) -> Option<OpTy<'tcx>> {
369369
use Value::*;
370-
let op = match *self.get(value) {
370+
let vvalue = self.get(value);
371+
debug!(?vvalue);
372+
let op = match *vvalue {
371373
Opaque(_) => return None,
372374
// Do not bother evaluating repeat expressions. This would uselessly consume memory.
373375
Repeat(..) => return None,
@@ -376,10 +378,11 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
376378
self.ecx.eval_mir_constant(value, DUMMY_SP, None).ok()?
377379
}
378380
Aggregate(kind, variant, ref fields) => {
381+
debug!(?kind, ?variant, ?fields);
379382
let fields = fields
380383
.iter()
381384
.map(|&f| self.evaluated[f].as_ref())
382-
.collect::<Option<Vec<_>>>()?;
385+
.collect::<Option<Vec<&OpTy<'_>>>>()?;
383386
let ty = match kind {
384387
AggregateTy::Array => {
385388
assert!(fields.len() > 0);
@@ -407,6 +410,24 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
407410
};
408411
let ptr_imm = Immediate::new_pointer_with_meta(data, meta, &self.ecx);
409412
ImmTy::from_immediate(ptr_imm, ty).into()
413+
} else if matches!(kind, AggregateTy::Array) {
414+
let mut mplace = None;
415+
let alloc_id = self.ecx.intern_with_temp_alloc(ty, |ecx, dest| {
416+
for (field_index, op) in fields.iter().copied().enumerate() {
417+
let field_dest = ecx.project_field(dest, field_index)?;
418+
ecx.copy_op(op, &field_dest)?;
419+
}
420+
421+
let place = dest.assert_mem_place();
422+
mplace.replace(place);
423+
Ok(())
424+
}).ok()?;
425+
let GlobalAlloc::Memory(_alloc) = self.tcx.global_alloc(alloc_id) else {
426+
bug!()
427+
};
428+
let mplace = mplace.unwrap();
429+
debug!(?mplace);
430+
return Some(mplace.into());
410431
} else if matches!(ty.abi, Abi::Scalar(..) | Abi::ScalarPair(..)) {
411432
let dest = self.ecx.allocate(ty, MemoryKind::Stack).ok()?;
412433
let variant_dest = if let Some(variant) = variant {
@@ -429,6 +450,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
429450
}
430451

431452
Projection(base, elem) => {
453+
debug!(?base, ?elem);
432454
let value = self.evaluated[base].as_ref()?;
433455
let elem = match elem {
434456
ProjectionElem::Deref => ProjectionElem::Deref,
@@ -450,6 +472,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
450472
self.ecx.project(value, elem).ok()?
451473
}
452474
Address { place, kind, provenance: _ } => {
475+
debug!(?place, ?kind);
453476
if !place.is_indirect_first_projection() {
454477
return None;
455478
}

0 commit comments

Comments
 (0)