@@ -431,49 +431,6 @@ impl Inliner<'tcx> {
431431 TerminatorKind :: Call { args, destination : Some ( destination) , cleanup, .. } => {
432432 debug ! ( "inlined {:?} into {:?}" , callsite. callee, caller_body. source) ;
433433
434- let mut local_map = IndexVec :: with_capacity ( callee_body. local_decls . len ( ) ) ;
435- let mut scope_map = IndexVec :: with_capacity ( callee_body. source_scopes . len ( ) ) ;
436-
437- for mut scope in callee_body. source_scopes . iter ( ) . cloned ( ) {
438- // Map the callee scopes into the caller.
439- // FIXME(eddyb) this may ICE if the scopes are out of order.
440- scope. parent_scope = scope. parent_scope . map ( |s| scope_map[ s] ) ;
441- scope. inlined_parent_scope = scope. inlined_parent_scope . map ( |s| scope_map[ s] ) ;
442-
443- if scope. parent_scope . is_none ( ) {
444- let callsite_scope = & caller_body. source_scopes [ callsite. source_info . scope ] ;
445-
446- // Attach the outermost callee scope as a child of the callsite
447- // scope, via the `parent_scope` and `inlined_parent_scope` chains.
448- scope. parent_scope = Some ( callsite. source_info . scope ) ;
449- assert_eq ! ( scope. inlined_parent_scope, None ) ;
450- scope. inlined_parent_scope = if callsite_scope. inlined . is_some ( ) {
451- Some ( callsite. source_info . scope )
452- } else {
453- callsite_scope. inlined_parent_scope
454- } ;
455-
456- // Mark the outermost callee scope as an inlined one.
457- assert_eq ! ( scope. inlined, None ) ;
458- scope. inlined = Some ( ( callsite. callee , callsite. source_info . span ) ) ;
459- } else if scope. inlined_parent_scope . is_none ( ) {
460- // Make it easy to find the scope with `inlined` set above.
461- scope. inlined_parent_scope = Some ( scope_map[ OUTERMOST_SOURCE_SCOPE ] ) ;
462- }
463-
464- let idx = caller_body. source_scopes . push ( scope) ;
465- scope_map. push ( idx) ;
466- }
467-
468- for loc in callee_body. vars_and_temps_iter ( ) {
469- let mut local = callee_body. local_decls [ loc] . clone ( ) ;
470-
471- local. source_info . scope = scope_map[ local. source_info . scope ] ;
472-
473- let idx = caller_body. local_decls . push ( local) ;
474- local_map. push ( idx) ;
475- }
476-
477434 // If the call is something like `a[*i] = f(i)`, where
478435 // `i : &mut usize`, then just duplicating the `a[*i]`
479436 // Place could result in two different locations if `f`
@@ -524,15 +481,57 @@ impl Inliner<'tcx> {
524481 let mut integrator = Integrator {
525482 block_idx : bb_len,
526483 args : & args,
527- local_map,
528- scope_map,
484+ local_map : IndexVec :: with_capacity ( callee_body . local_decls . len ( ) ) ,
485+ scope_map : IndexVec :: with_capacity ( callee_body . source_scopes . len ( ) ) ,
529486 destination : dest,
530487 return_block,
531488 cleanup_block : cleanup,
532489 in_cleanup_block : false ,
533490 tcx : self . tcx ,
534491 } ;
535492
493+ for mut scope in callee_body. source_scopes . iter ( ) . cloned ( ) {
494+ // Map the callee scopes into the caller.
495+ // FIXME(eddyb) this may ICE if the scopes are out of order.
496+ scope. parent_scope = scope. parent_scope . map ( |s| integrator. scope_map [ s] ) ;
497+ scope. inlined_parent_scope =
498+ scope. inlined_parent_scope . map ( |s| integrator. scope_map [ s] ) ;
499+
500+ if scope. parent_scope . is_none ( ) {
501+ let callsite_scope = & caller_body. source_scopes [ callsite. source_info . scope ] ;
502+
503+ // Attach the outermost callee scope as a child of the callsite
504+ // scope, via the `parent_scope` and `inlined_parent_scope` chains.
505+ scope. parent_scope = Some ( callsite. source_info . scope ) ;
506+ assert_eq ! ( scope. inlined_parent_scope, None ) ;
507+ scope. inlined_parent_scope = if callsite_scope. inlined . is_some ( ) {
508+ Some ( callsite. source_info . scope )
509+ } else {
510+ callsite_scope. inlined_parent_scope
511+ } ;
512+
513+ // Mark the outermost callee scope as an inlined one.
514+ assert_eq ! ( scope. inlined, None ) ;
515+ scope. inlined = Some ( ( callsite. callee , callsite. source_info . span ) ) ;
516+ } else if scope. inlined_parent_scope . is_none ( ) {
517+ // Make it easy to find the scope with `inlined` set above.
518+ scope. inlined_parent_scope =
519+ Some ( integrator. scope_map [ OUTERMOST_SOURCE_SCOPE ] ) ;
520+ }
521+
522+ let idx = caller_body. source_scopes . push ( scope) ;
523+ integrator. scope_map . push ( idx) ;
524+ }
525+
526+ for loc in callee_body. vars_and_temps_iter ( ) {
527+ let mut local = callee_body. local_decls [ loc] . clone ( ) ;
528+
529+ local. source_info . scope = integrator. scope_map [ local. source_info . scope ] ;
530+
531+ let idx = caller_body. local_decls . push ( local) ;
532+ integrator. local_map . push ( idx) ;
533+ }
534+
536535 for mut var_debug_info in callee_body. var_debug_info . drain ( ..) {
537536 integrator. visit_var_debug_info ( & mut var_debug_info) ;
538537 caller_body. var_debug_info . push ( var_debug_info) ;
0 commit comments