Skip to content

Commit b62a9da

Browse files
committed
Handle aggregates in DataflowConstProp.
1 parent 20dd5e0 commit b62a9da

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

compiler/rustc_mir_transform/src/dataflow_const_prop.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use rustc_const_eval::const_eval::CheckAlignment;
66
use rustc_const_eval::interpret::{ConstValue, ImmTy, Immediate, InterpCx, Scalar};
77
use rustc_data_structures::fx::FxHashMap;
8+
use rustc_hir::def::DefKind;
89
use rustc_middle::mir::visit::{MutVisitor, Visitor};
910
use rustc_middle::mir::*;
1011
use rustc_middle::ty::{self, Ty, TyCtxt};
@@ -85,6 +86,30 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'tcx> {
8586
state: &mut State<Self::Value>,
8687
) {
8788
match rvalue {
89+
Rvalue::Aggregate(kind, operands) => {
90+
let target = self.map().find(target.as_ref());
91+
if let Some(target) = target {
92+
state.flood_idx_with(target, self.map(), FlatSet::Bottom);
93+
let field_based = match **kind {
94+
AggregateKind::Tuple | AggregateKind::Closure(..) => true,
95+
AggregateKind::Adt(def_id, ..) => {
96+
matches!(self.tcx.def_kind(def_id), DefKind::Struct)
97+
}
98+
_ => false,
99+
};
100+
if field_based {
101+
for (field_index, operand) in operands.iter().enumerate() {
102+
if let Some(field) = self
103+
.map()
104+
.apply(target, TrackElem::Field(Field::from_usize(field_index)))
105+
{
106+
let result = self.handle_operand(operand, state);
107+
state.assign_idx(field, result, self.map());
108+
}
109+
}
110+
}
111+
}
112+
}
88113
Rvalue::CheckedBinaryOp(op, box (left, right)) => {
89114
let target = self.map().find(target.as_ref());
90115
if let Some(target) = target {

0 commit comments

Comments
 (0)