]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #97142 - SparrowLii:inline, r=tmiasko
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>
Thu, 19 May 2022 15:22:48 +0000 (17:22 +0200)
committerGitHub <noreply@github.com>
Thu, 19 May 2022 15:22:48 +0000 (17:22 +0200)
move processing of `source_scope_data` into `MutVisitor`'s impl of `Integrator` when inline

This PR fixes the FIXME in the inline mir-opt which moves processing of `source_scope_data` into `MutVisitor`'s impl of `Integrator` when inline

1  2 
compiler/rustc_mir_transform/src/inline.rs

index a73fd13ce2d0ea13471570a4ef4f74c88ac76055,4193c5779f96d4f1458d1cc1c5244464c5489170..85b7fb5eb25fc1a6a58c4796d73255c9eac540b6
@@@ -418,7 -418,8 +418,7 @@@ impl<'tcx> Inliner<'tcx> 
                              }
                          }
                          // Don't give intrinsics the extra penalty for calls
 -                        let f = tcx.fn_sig(def_id);
 -                        if f.abi() == Abi::RustIntrinsic || f.abi() == Abi::PlatformIntrinsic {
 +                        if tcx.is_intrinsic(def_id) {
                              cost += INSTR_COST;
                          } else {
                              cost += CALL_PENALTY;
              }
  
              if !is_drop {
 -                for &succ in term.successors() {
 +                for succ in term.successors() {
                      work_list.push(succ);
                  }
              }
                      new_scopes: SourceScope::new(caller_body.source_scopes.len())..,
                      new_blocks: BasicBlock::new(caller_body.basic_blocks().len())..,
                      destination: dest,
-                     return_block: callsite.target,
+                     callsite_scope: caller_body.source_scopes[callsite.source_info.scope].clone(),
+                     callsite,
                      cleanup_block: cleanup,
                      in_cleanup_block: false,
                      tcx: self.tcx,
                  // (or existing ones, in a few special cases) in the caller.
                  integrator.visit_body(&mut callee_body);
  
-                 for scope in &mut callee_body.source_scopes {
-                     // FIXME(eddyb) move this into a `fn visit_scope_data` in `Integrator`.
-                     if scope.parent_scope.is_none() {
-                         let callsite_scope = &caller_body.source_scopes[callsite.source_info.scope];
-                         // Attach the outermost callee scope as a child of the callsite
-                         // scope, via the `parent_scope` and `inlined_parent_scope` chains.
-                         scope.parent_scope = Some(callsite.source_info.scope);
-                         assert_eq!(scope.inlined_parent_scope, None);
-                         scope.inlined_parent_scope = if callsite_scope.inlined.is_some() {
-                             Some(callsite.source_info.scope)
-                         } else {
-                             callsite_scope.inlined_parent_scope
-                         };
-                         // Mark the outermost callee scope as an inlined one.
-                         assert_eq!(scope.inlined, None);
-                         scope.inlined = Some((callsite.callee, callsite.source_info.span));
-                     } else if scope.inlined_parent_scope.is_none() {
-                         // Make it easy to find the scope with `inlined` set above.
-                         scope.inlined_parent_scope =
-                             Some(integrator.map_scope(OUTERMOST_SOURCE_SCOPE));
-                     }
-                 }
                  // If there are any locals without storage markers, give them storage only for the
                  // duration of the call.
                  for local in callee_body.vars_and_temps_iter() {
@@@ -786,7 -763,8 +762,8 @@@ struct Integrator<'a, 'tcx> 
      new_scopes: RangeFrom<SourceScope>,
      new_blocks: RangeFrom<BasicBlock>,
      destination: Place<'tcx>,
-     return_block: Option<BasicBlock>,
+     callsite_scope: SourceScopeData<'tcx>,
+     callsite: &'a CallSite<'tcx>,
      cleanup_block: Option<BasicBlock>,
      in_cleanup_block: bool,
      tcx: TyCtxt<'tcx>,
@@@ -832,6 -810,28 +809,28 @@@ impl<'tcx> MutVisitor<'tcx> for Integra
          *local = self.map_local(*local);
      }
  
+     fn visit_source_scope_data(&mut self, scope_data: &mut SourceScopeData<'tcx>) {
+         self.super_source_scope_data(scope_data);
+         if scope_data.parent_scope.is_none() {
+             // Attach the outermost callee scope as a child of the callsite
+             // scope, via the `parent_scope` and `inlined_parent_scope` chains.
+             scope_data.parent_scope = Some(self.callsite.source_info.scope);
+             assert_eq!(scope_data.inlined_parent_scope, None);
+             scope_data.inlined_parent_scope = if self.callsite_scope.inlined.is_some() {
+                 Some(self.callsite.source_info.scope)
+             } else {
+                 self.callsite_scope.inlined_parent_scope
+             };
+             // Mark the outermost callee scope as an inlined one.
+             assert_eq!(scope_data.inlined, None);
+             scope_data.inlined = Some((self.callsite.callee, self.callsite.source_info.span));
+         } else if scope_data.inlined_parent_scope.is_none() {
+             // Make it easy to find the scope with `inlined` set above.
+             scope_data.inlined_parent_scope = Some(self.map_scope(OUTERMOST_SOURCE_SCOPE));
+         }
+     }
      fn visit_source_scope(&mut self, scope: &mut SourceScope) {
          *scope = self.map_scope(*scope);
      }
                  }
              }
              TerminatorKind::Return => {
-                 terminator.kind = if let Some(tgt) = self.return_block {
+                 terminator.kind = if let Some(tgt) = self.callsite.target {
                      TerminatorKind::Goto { target: tgt }
                  } else {
                      TerminatorKind::Unreachable