diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index d990d72e3fb42..c32e3457d73a1 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -803,7 +803,6 @@ pub(crate) struct MirBorrowckCtxt<'a, 'diag, 'tcx> { impl<'a, 'tcx> ResultsVisitor<'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<'a, '_, 'tcx> { fn visit_after_early_statement_effect( &mut self, - _analysis: &Borrowck<'a, 'tcx>, state: &BorrowckDomain, stmt: &Statement<'tcx>, location: Location, @@ -878,7 +877,6 @@ impl<'a, 'tcx> ResultsVisitor<'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<'a, fn visit_after_early_terminator_effect( &mut self, - _analysis: &Borrowck<'a, 'tcx>, state: &BorrowckDomain, term: &Terminator<'tcx>, loc: Location, @@ -991,7 +989,6 @@ impl<'a, 'tcx> ResultsVisitor<'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<'a, fn visit_after_primary_terminator_effect( &mut self, - _analysis: &Borrowck<'a, 'tcx>, state: &BorrowckDomain, term: &Terminator<'tcx>, loc: Location, diff --git a/compiler/rustc_mir_dataflow/src/framework/direction.rs b/compiler/rustc_mir_dataflow/src/framework/direction.rs index 7b577c2b9df4c..74962a809247b 100644 --- a/compiler/rustc_mir_dataflow/src/framework/direction.rs +++ b/compiler/rustc_mir_dataflow/src/framework/direction.rs @@ -144,16 +144,16 @@ impl Direction for Backward { let loc = Location { block, statement_index: block_data.statements.len() }; let term = block_data.terminator(); analysis.apply_early_terminator_effect(state, term, loc); - vis.visit_after_early_terminator_effect(analysis, state, term, loc); + vis.visit_after_early_terminator_effect(state, term, loc); analysis.apply_primary_terminator_effect(state, term, loc); - vis.visit_after_primary_terminator_effect(analysis, state, term, loc); + vis.visit_after_primary_terminator_effect(state, term, loc); for (statement_index, stmt) in block_data.statements.iter().enumerate().rev() { let loc = Location { block, statement_index }; analysis.apply_early_statement_effect(state, stmt, loc); - vis.visit_after_early_statement_effect(analysis, state, stmt, loc); + vis.visit_after_early_statement_effect(state, stmt, loc); analysis.apply_primary_statement_effect(state, stmt, loc); - vis.visit_after_primary_statement_effect(analysis, state, stmt, loc); + vis.visit_after_primary_statement_effect(state, stmt, loc); } } } @@ -259,16 +259,16 @@ impl Direction for Forward { for (statement_index, stmt) in block_data.statements.iter().enumerate() { let loc = Location { block, statement_index }; analysis.apply_early_statement_effect(state, stmt, loc); - vis.visit_after_early_statement_effect(analysis, state, stmt, loc); + vis.visit_after_early_statement_effect(state, stmt, loc); analysis.apply_primary_statement_effect(state, stmt, loc); - vis.visit_after_primary_statement_effect(analysis, state, stmt, loc); + vis.visit_after_primary_statement_effect(state, stmt, loc); } let loc = Location { block, statement_index: block_data.statements.len() }; let term = block_data.terminator(); analysis.apply_early_terminator_effect(state, term, loc); - vis.visit_after_early_terminator_effect(analysis, state, term, loc); + vis.visit_after_early_terminator_effect(state, term, loc); analysis.apply_primary_terminator_effect(state, term, loc); - vis.visit_after_primary_terminator_effect(analysis, state, term, loc); + vis.visit_after_primary_terminator_effect(state, term, loc); } } diff --git a/compiler/rustc_mir_dataflow/src/framework/graphviz.rs b/compiler/rustc_mir_dataflow/src/framework/graphviz.rs index a95ab44c951d6..4996841703d16 100644 --- a/compiler/rustc_mir_dataflow/src/framework/graphviz.rs +++ b/compiler/rustc_mir_dataflow/src/framework/graphviz.rs @@ -287,7 +287,7 @@ where fn write_node_label( &mut self, block: BasicBlock, - diffs: StateDiffCollector, + diffs: StateDiffCollector<'_, 'tcx, A>, ) -> io::Result> { use std::io::Write; @@ -527,7 +527,7 @@ where &mut self, w: &mut impl io::Write, block: BasicBlock, - diffs: StateDiffCollector, + diffs: StateDiffCollector<'_, 'tcx, A>, ) -> io::Result<()> { let mut diffs_before = diffs.before.map(|v| v.into_iter()); let mut diffs_after = diffs.after.into_iter(); @@ -627,24 +627,25 @@ where } } -struct StateDiffCollector { - prev_state: D, +struct StateDiffCollector<'a, 'tcx, A: Analysis<'tcx>> { + analysis: &'a A, + prev_state: A::Domain, before: Option>, after: Vec, } -impl StateDiffCollector { - fn run<'tcx, A>( +impl<'a, 'tcx, A: Analysis<'tcx>> StateDiffCollector<'a, 'tcx, A> { + fn run( body: &Body<'tcx>, block: BasicBlock, - results: &Results<'tcx, A>, + results: &'a Results<'tcx, A>, style: OutputStyle, ) -> Self where - A: Analysis<'tcx, Domain = D>, - D: DebugWithContext, + A::Domain: DebugWithContext, { let mut collector = StateDiffCollector { + analysis: &results.analysis, prev_state: results.entry_states[block].clone(), after: vec![], before: (style == OutputStyle::BeforeAndAfter).then_some(vec![]), @@ -655,56 +656,52 @@ impl StateDiffCollector { } } -impl<'tcx, A> ResultsVisitor<'tcx, A> for StateDiffCollector +impl<'a, 'tcx, A: Analysis<'tcx>> ResultsVisitor<'tcx, A> for StateDiffCollector<'a, 'tcx, A> where A: Analysis<'tcx>, A::Domain: DebugWithContext, { fn visit_after_early_statement_effect( &mut self, - analysis: &A, state: &A::Domain, _statement: &mir::Statement<'tcx>, _location: Location, ) { if let Some(before) = self.before.as_mut() { - before.push(diff_pretty(state, &self.prev_state, analysis)); + before.push(diff_pretty(state, &self.prev_state, self.analysis)); self.prev_state.clone_from(state) } } fn visit_after_primary_statement_effect( &mut self, - analysis: &A, state: &A::Domain, _statement: &mir::Statement<'tcx>, _location: Location, ) { - self.after.push(diff_pretty(state, &self.prev_state, analysis)); + self.after.push(diff_pretty(state, &self.prev_state, self.analysis)); self.prev_state.clone_from(state) } fn visit_after_early_terminator_effect( &mut self, - analysis: &A, state: &A::Domain, _terminator: &mir::Terminator<'tcx>, _location: Location, ) { if let Some(before) = self.before.as_mut() { - before.push(diff_pretty(state, &self.prev_state, analysis)); + before.push(diff_pretty(state, &self.prev_state, self.analysis)); self.prev_state.clone_from(state) } } fn visit_after_primary_terminator_effect( &mut self, - analysis: &A, state: &A::Domain, _terminator: &mir::Terminator<'tcx>, _location: Location, ) { - self.after.push(diff_pretty(state, &self.prev_state, analysis)); + self.after.push(diff_pretty(state, &self.prev_state, self.analysis)); self.prev_state.clone_from(state) } } diff --git a/compiler/rustc_mir_dataflow/src/framework/visitor.rs b/compiler/rustc_mir_dataflow/src/framework/visitor.rs index b511477020088..e4b840a73e502 100644 --- a/compiler/rustc_mir_dataflow/src/framework/visitor.rs +++ b/compiler/rustc_mir_dataflow/src/framework/visitor.rs @@ -37,7 +37,6 @@ where /// Called after the "early" effect of the given statement is applied to `state`. fn visit_after_early_statement_effect( &mut self, - _analysis: &A, _state: &A::Domain, _statement: &mir::Statement<'tcx>, _location: Location, @@ -47,7 +46,6 @@ where /// Called after the "primary" effect of the given statement is applied to `state`. fn visit_after_primary_statement_effect( &mut self, - _analysis: &A, _state: &A::Domain, _statement: &mir::Statement<'tcx>, _location: Location, @@ -57,7 +55,6 @@ where /// Called after the "early" effect of the given terminator is applied to `state`. fn visit_after_early_terminator_effect( &mut self, - _analysis: &A, _state: &A::Domain, _terminator: &mir::Terminator<'tcx>, _location: Location, @@ -69,7 +66,6 @@ where /// The `call_return_effect` (if one exists) will *not* be applied to `state`. fn visit_after_primary_terminator_effect( &mut self, - _analysis: &A, _state: &A::Domain, _terminator: &mir::Terminator<'tcx>, _location: Location, diff --git a/compiler/rustc_mir_transform/src/coroutine/layout.rs b/compiler/rustc_mir_transform/src/coroutine/layout.rs index b460c1e82b7e9..030620fee57bf 100644 --- a/compiler/rustc_mir_transform/src/coroutine/layout.rs +++ b/compiler/rustc_mir_transform/src/coroutine/layout.rs @@ -301,7 +301,6 @@ struct StorageConflictVisitor<'a> { impl<'a, 'tcx> ResultsVisitor<'tcx, MaybeRequiresStorage> for StorageConflictVisitor<'a> { fn visit_after_early_statement_effect( &mut self, - _analysis: &MaybeRequiresStorage, state: &DenseBitSet, _statement: &Statement<'tcx>, _loc: Location, @@ -311,7 +310,6 @@ impl<'a, 'tcx> ResultsVisitor<'tcx, MaybeRequiresStorage> for StorageConflictVis fn visit_after_early_terminator_effect( &mut self, - _analysis: &MaybeRequiresStorage, state: &DenseBitSet, _terminator: &Terminator<'tcx>, _loc: Location, diff --git a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs index 5659157937005..2af68a9046e5a 100644 --- a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs +++ b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs @@ -71,7 +71,7 @@ impl<'tcx> crate::MirPass<'tcx> for DataflowConstProp { .in_scope(|| ConstAnalysis::new(tcx, body, map).iterate_to_fixpoint(tcx, body, None)); // Collect results and patch the body afterwards. - let mut visitor = Collector::new(tcx, body); + let mut visitor = Collector::new(tcx, body, &const_.analysis.map); debug_span!("collect").in_scope(|| { visit_results(body, traversal::reachable(body).map(|(bb, _)| bb), &const_, &mut visitor) }); @@ -767,23 +767,24 @@ struct Collector<'a, 'tcx> { patch: Patch<'tcx>, local_decls: &'a LocalDecls<'tcx>, ecx: InterpCx<'tcx, DummyMachine>, + map: &'a Map<'tcx>, } impl<'a, 'tcx> Collector<'a, 'tcx> { - pub(crate) fn new(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>) -> Self { + pub(crate) fn new(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, map: &'a Map<'tcx>) -> Self { Self { patch: Patch::new(tcx), local_decls: &body.local_decls, ecx: InterpCx::new(tcx, DUMMY_SP, body.typing_env(tcx), DummyMachine), + map, } } - #[instrument(level = "trace", skip(self, map), ret)] + #[instrument(level = "trace", skip(self), ret)] fn try_make_constant( &mut self, place: Place<'tcx>, state: &State>, - map: &Map<'tcx>, ) -> Option> { let ty = place.ty(self.local_decls, self.patch.tcx).ty; let layout = self.ecx.layout_of(ty).ok()?; @@ -796,9 +797,9 @@ impl<'a, 'tcx> Collector<'a, 'tcx> { return None; } - let place = map.find(place.as_ref())?; + let place = self.map.find(place.as_ref())?; if layout.backend_repr.is_scalar() - && let Some(value) = propagatable_scalar(place, state, map) + && let Some(value) = propagatable_scalar(place, state, self.map) { return Some(Const::Val(ConstValue::Scalar(value), ty)); } @@ -807,7 +808,7 @@ impl<'a, 'tcx> Collector<'a, 'tcx> { let alloc_id = self .ecx .intern_with_temp_alloc(layout, |ecx, dest| { - try_write_constant(ecx, dest, place, ty, state, map) + try_write_constant(ecx, dest, place, ty, state, self.map) }) .discard_err()?; return Some(Const::Val(ConstValue::Indirect { alloc_id, offset: Size::ZERO }, ty)); @@ -940,27 +941,24 @@ fn try_write_constant<'tcx>( } impl<'tcx> ResultsVisitor<'tcx, ConstAnalysis<'_, 'tcx>> for Collector<'_, 'tcx> { - #[instrument(level = "trace", skip(self, analysis, statement))] + #[instrument(level = "trace", skip(self, statement))] fn visit_after_early_statement_effect( &mut self, - analysis: &ConstAnalysis<'_, 'tcx>, state: &State>, statement: &Statement<'tcx>, location: Location, ) { match &statement.kind { StatementKind::Assign((_, rvalue)) => { - OperandCollector { state, visitor: self, map: &analysis.map } - .visit_rvalue(rvalue, location); + OperandCollector { state, visitor: self }.visit_rvalue(rvalue, location); } _ => (), } } - #[instrument(level = "trace", skip(self, analysis, statement))] + #[instrument(level = "trace", skip(self, statement))] fn visit_after_primary_statement_effect( &mut self, - analysis: &ConstAnalysis<'_, 'tcx>, state: &State>, statement: &Statement<'tcx>, location: Location, @@ -970,7 +968,7 @@ impl<'tcx> ResultsVisitor<'tcx, ConstAnalysis<'_, 'tcx>> for Collector<'_, 'tcx> // Don't overwrite the assignment if it already uses a constant (to keep the span). } StatementKind::Assign((place, _)) => { - if let Some(value) = self.try_make_constant(place, state, &analysis.map) { + if let Some(value) = self.try_make_constant(place, state) { self.patch.assignments.insert(location, value); } } @@ -980,13 +978,11 @@ impl<'tcx> ResultsVisitor<'tcx, ConstAnalysis<'_, 'tcx>> for Collector<'_, 'tcx> fn visit_after_early_terminator_effect( &mut self, - analysis: &ConstAnalysis<'_, 'tcx>, state: &State>, terminator: &Terminator<'tcx>, location: Location, ) { - OperandCollector { state, visitor: self, map: &analysis.map } - .visit_terminator(terminator, location); + OperandCollector { state, visitor: self }.visit_terminator(terminator, location); } } @@ -1045,7 +1041,6 @@ impl<'tcx> MutVisitor<'tcx> for Patch<'tcx> { struct OperandCollector<'a, 'b, 'tcx> { state: &'a State>, visitor: &'a mut Collector<'b, 'tcx>, - map: &'a Map<'tcx>, } impl<'tcx> Visitor<'tcx> for OperandCollector<'_, '_, 'tcx> { @@ -1057,7 +1052,7 @@ impl<'tcx> Visitor<'tcx> for OperandCollector<'_, '_, 'tcx> { location: Location, ) { if let PlaceElem::Index(local) = elem - && let Some(value) = self.visitor.try_make_constant(local.into(), self.state, self.map) + && let Some(value) = self.visitor.try_make_constant(local.into(), self.state) { self.visitor.patch.before_effect.insert((location, local.into()), value); } @@ -1065,7 +1060,7 @@ impl<'tcx> Visitor<'tcx> for OperandCollector<'_, '_, 'tcx> { fn visit_operand(&mut self, operand: &Operand<'tcx>, location: Location) { if let Some(place) = operand.place() { - if let Some(value) = self.visitor.try_make_constant(place, self.state, self.map) { + if let Some(value) = self.visitor.try_make_constant(place, self.state) { self.visitor.patch.before_effect.insert((location, place), value); } else if !place.projection.is_empty() { // Try to propagate into `Index` projections.