Skip to content

Commit 420f9a3

Browse files
committed
move processing of source_scope_data into MutVisitor's impl of Integrator when inline mir-opt
1 parent 56d540e commit 420f9a3

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

compiler/rustc_mir_transform/src/inline.rs

+27-28
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,8 @@ impl<'tcx> Inliner<'tcx> {
555555
new_scopes: SourceScope::new(caller_body.source_scopes.len())..,
556556
new_blocks: BasicBlock::new(caller_body.basic_blocks().len())..,
557557
destination: dest,
558-
return_block: callsite.target,
558+
callsite_scope: caller_body.source_scopes[callsite.source_info.scope].clone(),
559+
callsite,
559560
cleanup_block: cleanup,
560561
in_cleanup_block: false,
561562
tcx: self.tcx,
@@ -567,31 +568,6 @@ impl<'tcx> Inliner<'tcx> {
567568
// (or existing ones, in a few special cases) in the caller.
568569
integrator.visit_body(&mut callee_body);
569570

570-
for scope in &mut callee_body.source_scopes {
571-
// FIXME(eddyb) move this into a `fn visit_scope_data` in `Integrator`.
572-
if scope.parent_scope.is_none() {
573-
let callsite_scope = &caller_body.source_scopes[callsite.source_info.scope];
574-
575-
// Attach the outermost callee scope as a child of the callsite
576-
// scope, via the `parent_scope` and `inlined_parent_scope` chains.
577-
scope.parent_scope = Some(callsite.source_info.scope);
578-
assert_eq!(scope.inlined_parent_scope, None);
579-
scope.inlined_parent_scope = if callsite_scope.inlined.is_some() {
580-
Some(callsite.source_info.scope)
581-
} else {
582-
callsite_scope.inlined_parent_scope
583-
};
584-
585-
// Mark the outermost callee scope as an inlined one.
586-
assert_eq!(scope.inlined, None);
587-
scope.inlined = Some((callsite.callee, callsite.source_info.span));
588-
} else if scope.inlined_parent_scope.is_none() {
589-
// Make it easy to find the scope with `inlined` set above.
590-
scope.inlined_parent_scope =
591-
Some(integrator.map_scope(OUTERMOST_SOURCE_SCOPE));
592-
}
593-
}
594-
595571
// If there are any locals without storage markers, give them storage only for the
596572
// duration of the call.
597573
for local in callee_body.vars_and_temps_iter() {
@@ -787,7 +763,8 @@ struct Integrator<'a, 'tcx> {
787763
new_scopes: RangeFrom<SourceScope>,
788764
new_blocks: RangeFrom<BasicBlock>,
789765
destination: Place<'tcx>,
790-
return_block: Option<BasicBlock>,
766+
callsite_scope: SourceScopeData<'tcx>,
767+
callsite: &'a CallSite<'tcx>,
791768
cleanup_block: Option<BasicBlock>,
792769
in_cleanup_block: bool,
793770
tcx: TyCtxt<'tcx>,
@@ -833,6 +810,28 @@ impl<'tcx> MutVisitor<'tcx> for Integrator<'_, 'tcx> {
833810
*local = self.map_local(*local);
834811
}
835812

813+
fn visit_source_scope_data(&mut self, scope_data: &mut SourceScopeData<'tcx>) {
814+
self.super_source_scope_data(scope_data);
815+
if scope_data.parent_scope.is_none() {
816+
// Attach the outermost callee scope as a child of the callsite
817+
// scope, via the `parent_scope` and `inlined_parent_scope` chains.
818+
scope_data.parent_scope = Some(self.callsite.source_info.scope);
819+
assert_eq!(scope_data.inlined_parent_scope, None);
820+
scope_data.inlined_parent_scope = if self.callsite_scope.inlined.is_some() {
821+
Some(self.callsite.source_info.scope)
822+
} else {
823+
self.callsite_scope.inlined_parent_scope
824+
};
825+
826+
// Mark the outermost callee scope as an inlined one.
827+
assert_eq!(scope_data.inlined, None);
828+
scope_data.inlined = Some((self.callsite.callee, self.callsite.source_info.span));
829+
} else if scope_data.inlined_parent_scope.is_none() {
830+
// Make it easy to find the scope with `inlined` set above.
831+
scope_data.inlined_parent_scope = Some(self.map_scope(OUTERMOST_SOURCE_SCOPE));
832+
}
833+
}
834+
836835
fn visit_source_scope(&mut self, scope: &mut SourceScope) {
837836
*scope = self.map_scope(*scope);
838837
}
@@ -939,7 +938,7 @@ impl<'tcx> MutVisitor<'tcx> for Integrator<'_, 'tcx> {
939938
}
940939
}
941940
TerminatorKind::Return => {
942-
terminator.kind = if let Some(tgt) = self.return_block {
941+
terminator.kind = if let Some(tgt) = self.callsite.target {
943942
TerminatorKind::Goto { target: tgt }
944943
} else {
945944
TerminatorKind::Unreachable

0 commit comments

Comments
 (0)