diff --git a/src/librustc_mir/build/expr/into.rs b/src/librustc_mir/build/expr/into.rs index 1d724d7b4e6df..ed339110537f6 100644 --- a/src/librustc_mir/build/expr/into.rs +++ b/src/librustc_mir/build/expr/into.rs @@ -255,7 +255,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { this.cfg.terminate(block, source_info, TerminatorKind::Call { func: fun, args, - cleanup, + cleanup: Some(cleanup), destination: if diverges { None } else { diff --git a/src/librustc_mir/build/matches/test.rs b/src/librustc_mir/build/matches/test.rs index 7c9f190670ba8..b2357b771572f 100644 --- a/src/librustc_mir/build/matches/test.rs +++ b/src/librustc_mir/build/matches/test.rs @@ -315,7 +315,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { }), args: vec![val, expect], destination: Some((eq_result.clone(), eq_block)), - cleanup, + cleanup: Some(cleanup), }); // check the result diff --git a/src/librustc_mir/build/scope.rs b/src/librustc_mir/build/scope.rs index 3814dde17bb67..630d0bf179294 100644 --- a/src/librustc_mir/build/scope.rs +++ b/src/librustc_mir/build/scope.rs @@ -383,7 +383,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { assert_eq!(scope.region_scope, region_scope.0); self.cfg.push_end_region(self.hir.tcx(), block, region_scope.1, scope.region_scope); + let resume_block = self.resume_block(); unpack!(block = build_scope_drops(&mut self.cfg, + resume_block, &scope, &self.scopes, block, @@ -422,6 +424,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { } { + let resume_block = self.resume_block(); let mut rest = &mut self.scopes[(len - scope_count)..]; while let Some((scope, rest_)) = {rest}.split_last_mut() { rest = rest_; @@ -441,6 +444,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { self.cfg.push_end_region(self.hir.tcx(), block, region_scope.1, scope.region_scope); unpack!(block = build_scope_drops(&mut self.cfg, + resume_block, scope, rest, block, @@ -468,6 +472,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { let src_info = self.scopes[0].source_info(self.fn_span); let mut block = self.cfg.start_new_block(); let result = block; + let resume_block = self.resume_block(); let mut rest = &mut self.scopes[..]; while let Some((scope, rest_)) = {rest}.split_last_mut() { @@ -491,6 +496,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { self.cfg.push_end_region(self.hir.tcx(), block, src_info, scope.region_scope); unpack!(block = build_scope_drops(&mut self.cfg, + resume_block, scope, rest, block, @@ -701,18 +707,31 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { /// This path terminates in Resume. Returns the start of the path. /// See module comment for more details. None indicates there’s no /// cleanup to do at this point. - pub fn diverge_cleanup(&mut self) -> Option { + pub fn diverge_cleanup(&mut self) -> BasicBlock { self.diverge_cleanup_gen(false) } - fn diverge_cleanup_gen(&mut self, generator_drop: bool) -> Option { - if !self.scopes.iter().any(|scope| scope.needs_cleanup) { - return None; + fn resume_block(&mut self) -> BasicBlock { + if let Some(target) = self.cached_resume_block { + target + } else { + let resumeblk = self.cfg.start_new_cleanup_block(); + self.cfg.terminate(resumeblk, + SourceInfo { + scope: ARGUMENT_VISIBILITY_SCOPE, + span: self.fn_span + }, + TerminatorKind::Resume); + self.cached_resume_block = Some(resumeblk); + resumeblk } - assert!(!self.scopes.is_empty()); // or `any` above would be false + } + + fn diverge_cleanup_gen(&mut self, generator_drop: bool) -> BasicBlock { + // To start, create the resume terminator. + let mut target = self.resume_block(); - let Builder { ref mut cfg, ref mut scopes, - ref mut cached_resume_block, .. } = *self; + let Builder { ref mut cfg, ref mut scopes, .. } = *self; // Build up the drops in **reverse** order. The end result will // look like: @@ -725,23 +744,14 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { // store caches. If everything is cached, we'll just walk right // to left reading the cached results but never created anything. - // To start, create the resume terminator. - let mut target = if let Some(target) = *cached_resume_block { - target - } else { - let resumeblk = cfg.start_new_cleanup_block(); - cfg.terminate(resumeblk, - scopes[0].source_info(self.fn_span), - TerminatorKind::Resume); - *cached_resume_block = Some(resumeblk); - resumeblk - }; - - for scope in scopes.iter_mut() { - target = build_diverge_scope(self.hir.tcx(), cfg, scope.region_scope_span, - scope, target, generator_drop); + if scopes.iter().any(|scope| scope.needs_cleanup) { + for scope in scopes.iter_mut() { + target = build_diverge_scope(self.hir.tcx(), cfg, scope.region_scope_span, + scope, target, generator_drop); + } } - Some(target) + + target } /// Utility function for *non*-scope code to build their own drops @@ -760,7 +770,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { TerminatorKind::Drop { location, target: next_target, - unwind: diverge_target, + unwind: Some(diverge_target), }); next_target.unit() } @@ -779,7 +789,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { location, value, target: next_target, - unwind: diverge_target, + unwind: Some(diverge_target), }); next_target.unit() } @@ -804,7 +814,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { expected, msg, target: success_block, - cleanup, + cleanup: Some(cleanup), }); success_block @@ -813,6 +823,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { /// Builds drops for pop_scope and exit_scope. fn build_scope_drops<'tcx>(cfg: &mut CFG<'tcx>, + resume_block: BasicBlock, scope: &Scope<'tcx>, earlier_scopes: &[Scope<'tcx>], mut block: BasicBlock, @@ -868,7 +879,7 @@ fn build_scope_drops<'tcx>(cfg: &mut CFG<'tcx>, cfg.terminate(block, source_info, TerminatorKind::Drop { location: drop_data.location.clone(), target: next, - unwind: on_diverge + unwind: Some(on_diverge.unwrap_or(resume_block)) }); block = next; } diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index 64ba5ae3e8bd7..830838c603758 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -260,6 +260,7 @@ fn optimized_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx deaggregator::Deaggregator, copy_prop::CopyPropagation, remove_noop_landing_pads::RemoveNoopLandingPads, + simplify::SimplifyCfg::new("final"), simplify::SimplifyLocals, generator::StateTransform, diff --git a/src/librustc_mir/transform/simplify.rs b/src/librustc_mir/transform/simplify.rs index 2e7c3714ffe12..e7675b4ceaf29 100644 --- a/src/librustc_mir/transform/simplify.rs +++ b/src/librustc_mir/transform/simplify.rs @@ -124,8 +124,6 @@ impl<'a, 'tcx: 'a> CfgSimplifier<'a, 'tcx> { self.collapse_goto_chain(successor, &mut changed); } - changed |= self.simplify_unwind(&mut terminator); - let mut new_stmts = vec![]; let mut inner_changed = true; while inner_changed { @@ -238,38 +236,6 @@ impl<'a, 'tcx: 'a> CfgSimplifier<'a, 'tcx> { true } - // turn an unwind branch to a resume block into a None - fn simplify_unwind(&mut self, terminator: &mut Terminator<'tcx>) -> bool { - let unwind = match terminator.kind { - TerminatorKind::Drop { ref mut unwind, .. } | - TerminatorKind::DropAndReplace { ref mut unwind, .. } | - TerminatorKind::Call { cleanup: ref mut unwind, .. } | - TerminatorKind::Assert { cleanup: ref mut unwind, .. } => - unwind, - _ => return false - }; - - if let &mut Some(unwind_block) = unwind { - let is_resume_block = match self.basic_blocks[unwind_block] { - BasicBlockData { - ref statements, - terminator: Some(Terminator { - kind: TerminatorKind::Resume, .. - }), .. - } if statements.is_empty() => true, - _ => false - }; - if is_resume_block { - debug!("simplifying unwind to {:?} from {:?}", - unwind_block, terminator.source_info); - *unwind = None; - } - return is_resume_block; - } - - false - } - fn strip_nops(&mut self) { for blk in self.basic_blocks.iter_mut() { blk.statements.retain(|stmt| if let StatementKind::Nop = stmt.kind { diff --git a/src/test/mir-opt/basic_assignment.rs b/src/test/mir-opt/basic_assignment.rs index a8b87a273bfd5..321c05c490356 100644 --- a/src/test/mir-opt/basic_assignment.rs +++ b/src/test/mir-opt/basic_assignment.rs @@ -50,16 +50,16 @@ fn main() { // StorageLive(_5); // StorageLive(_6); // _6 = move _4; -// replace(_5 <- move _6) -> [return: bb1, unwind: bb5]; +// replace(_5 <-move _6) -> [return: bb2, unwind: bb5]; // } // bb1: { -// drop(_6) -> [return: bb6, unwind: bb4]; +// resume; // } // bb2: { -// resume; +// drop(_6) -> [return: bb6, unwind: bb4]; // } // bb3: { -// drop(_4) -> bb2; +// drop(_4) -> bb1; // } // bb4: { // drop(_5) -> bb3; @@ -74,7 +74,7 @@ fn main() { // } // bb7: { // StorageDead(_5); -// drop(_4) -> bb8; +// drop(_4) -> [return: bb8, unwind: bb1]; // } // bb8: { // StorageDead(_4); diff --git a/src/test/mir-opt/box_expr.rs b/src/test/mir-opt/box_expr.rs index 74e07d5e86475..ed9c303a16fd4 100644 --- a/src/test/mir-opt/box_expr.rs +++ b/src/test/mir-opt/box_expr.rs @@ -44,20 +44,20 @@ impl Drop for S { // StorageLive(_1); // StorageLive(_2); // _2 = Box(S); -// (*_2) = const S::new() -> [return: bb1, unwind: bb3]; +// (*_2) = const S::new() -> [return: bb2, unwind: bb3]; // } // // bb1: { -// _1 = move _2; -// drop(_2) -> bb4; +// resume; // } // // bb2: { -// resume; +// _1 = move _2; +// drop(_2) -> bb4; // } // // bb3: { -// drop(_2) -> bb2; +// drop(_2) -> bb1; // } // // bb4: { @@ -72,7 +72,7 @@ impl Drop for S { // } // // bb6: { -// drop(_1) -> bb2; +// drop(_1) -> bb1; // } // // bb7: { diff --git a/src/test/mir-opt/end_region_4.rs b/src/test/mir-opt/end_region_4.rs index d9456ef1563d3..ded818688d72f 100644 --- a/src/test/mir-opt/end_region_4.rs +++ b/src/test/mir-opt/end_region_4.rs @@ -51,9 +51,12 @@ fn foo(i: i32) { // _3 = &'26_2rs _2; // StorageLive(_5); // _5 = (*_3); -// _4 = const foo(move _5) -> [return: bb1, unwind: bb3]; +// _4 = const foo(move _5) -> [return: bb2, unwind: bb3]; // } // bb1: { +// resume; +// } +// bb2: { // StorageDead(_5); // StorageLive(_6); // _6 = &'26_4rs _2; @@ -63,14 +66,11 @@ fn foo(i: i32) { // EndRegion('26_2rs); // StorageDead(_3); // StorageDead(_2); -// drop(_1) -> bb4; -// } -// bb2: { -// resume; +// drop(_1) -> [return: bb4, unwind: bb1]; // } // bb3: { // EndRegion('26_2rs); -// drop(_1) -> bb2; +// drop(_1) -> bb1; // } // bb4: { // StorageDead(_1); diff --git a/src/test/mir-opt/end_region_5.rs b/src/test/mir-opt/end_region_5.rs index c2ee2d62b98e8..1da97a997a19c 100644 --- a/src/test/mir-opt/end_region_5.rs +++ b/src/test/mir-opt/end_region_5.rs @@ -43,20 +43,20 @@ fn foo(f: F) where F: FnOnce() -> i32 { // _4 = &'14s _1; // _3 = [closure@NodeId(18)] { d: move _4 }; // StorageDead(_4); -// _2 = const foo(move _3) -> [return: bb1, unwind: bb3]; +// _2 = const foo(move _3) -> [return: bb2, unwind: bb3]; // } // bb1: { +// resume; +// } +// bb2: { // EndRegion('14s); // StorageDead(_3); // _0 = (); -// drop(_1) -> bb4; -// } -// bb2: { -// resume; +// drop(_1) -> [return: bb4, unwind: bb1]; // } // bb3: { // EndRegion('14s); -// drop(_1) -> bb2; +// drop(_1) -> bb1; // } // bb4: { // StorageDead(_1); diff --git a/src/test/mir-opt/end_region_6.rs b/src/test/mir-opt/end_region_6.rs index 34675e8842f4c..dadc755eb8c57 100644 --- a/src/test/mir-opt/end_region_6.rs +++ b/src/test/mir-opt/end_region_6.rs @@ -43,20 +43,20 @@ fn foo(f: F) where F: FnOnce() -> i32 { // _4 = &'19s _1; // _3 = [closure@NodeId(22)] { d: move _4 }; // StorageDead(_4); -// _2 = const foo(move _3) -> [return: bb1, unwind: bb3]; +// _2 = const foo(move _3) -> [return: bb2, unwind: bb3]; // } // bb1: { +// resume; +// } +// bb2: { // EndRegion('19s); // StorageDead(_3); // _0 = (); -// drop(_1) -> bb4; -// } -// bb2: { -// resume; +// drop(_1) -> [return: bb4, unwind: bb1]; // } // bb3: { // EndRegion('19s); -// drop(_1) -> bb2; +// drop(_1) -> bb1; // } // bb4: { // StorageDead(_1); diff --git a/src/test/mir-opt/end_region_7.rs b/src/test/mir-opt/end_region_7.rs index a9b6d2196fc7e..1426174b482b6 100644 --- a/src/test/mir-opt/end_region_7.rs +++ b/src/test/mir-opt/end_region_7.rs @@ -63,7 +63,7 @@ fn foo(f: F) where F: FnOnce() -> i32 { // bb6: { // StorageDead(_3); // _0 = (); -// drop(_1) -> bb7; +// drop(_1) -> [return: bb7, unwind: bb1]; // } // bb7: { // StorageDead(_1); @@ -88,9 +88,12 @@ fn foo(f: F) where F: FnOnce() -> i32 { // StorageDead(_3); // EndRegion('15_0rs); // StorageDead(_2); -// drop(_1) -> bb1; +// drop(_1) -> [return: bb2, unwind: bb1]; // } // bb1: { +// resume; +// } +// bb2: { // return; // } // } diff --git a/src/test/mir-opt/end_region_8.rs b/src/test/mir-opt/end_region_8.rs index 4c1ec4b102629..405864aba9436 100644 --- a/src/test/mir-opt/end_region_8.rs +++ b/src/test/mir-opt/end_region_8.rs @@ -48,21 +48,21 @@ fn foo(f: F) where F: FnOnce() -> i32 { // _5 = _2; // _4 = [closure@NodeId(22)] { r: move _5 }; // StorageDead(_5); -// _3 = const foo(move _4) -> [return: bb1, unwind: bb3]; +// _3 = const foo(move _4) -> [return: bb2, unwind: bb3]; // } // bb1: { +// resume; +// } +// bb2: { // StorageDead(_4); // _0 = (); // EndRegion('21_1rs); // StorageDead(_2); -// drop(_1) -> bb4; -// } -// bb2: { -// resume; +// drop(_1) -> [return: bb4, unwind: bb1]; // } // bb3: { // EndRegion('21_1rs); -// drop(_1) -> bb2; +// drop(_1) -> bb1; // } // bb4: { // StorageDead(_1); diff --git a/src/test/mir-opt/end_region_cyclic.rs b/src/test/mir-opt/end_region_cyclic.rs index b8dabada18eab..37a6229febabb 100644 --- a/src/test/mir-opt/end_region_cyclic.rs +++ b/src/test/mir-opt/end_region_cyclic.rs @@ -62,6 +62,7 @@ fn query() -> bool { true } // let mut _15: std::option::Option<&'35_0rs S<'35_0rs>>; // let mut _16: &'35_0rs S<'35_0rs>; // let mut _17: &'35_0rs S<'35_0rs>; +// // bb0: { // goto -> bb1; // } @@ -70,9 +71,12 @@ fn query() -> bool { true } // StorageLive(_3); // StorageLive(_4); // _4 = std::option::Option<&'35_0rs S<'35_0rs>>::None; -// _3 = const >::new(move _4) -> bb2; +// _3 = const >::new(move _4) -> [return: bb3, unwind: bb2]; // } // bb2: { +// resume; +// } +// bb3: { // StorageDead(_4); // _2 = S<'35_0rs> { r: move _3 }; // StorageDead(_3); @@ -85,27 +89,27 @@ fn query() -> bool { true } // _8 = &'35_0rs (*_9); // _7 = std::option::Option<&'35_0rs S<'35_0rs>>::Some(move _8,); // StorageDead(_8); -// _5 = const >::set(move _6, move _7) -> bb3; +// _5 = const >::set(move _6, move _7) -> [return: bb4, unwind: bb2]; // } -// bb3: { +// bb4: { // EndRegion('16s); // StorageDead(_7); // StorageDead(_6); // StorageDead(_9); // StorageLive(_11); -// _11 = const query() -> bb4; -// } -// bb4: { -// switchInt(move _11) -> [0u8: bb6, otherwise: bb5]; +// _11 = const query() -> [return: bb5, unwind: bb2]; // } // bb5: { +// switchInt(move _11) -> [0u8: bb7, otherwise: bb6]; +// } +// bb6: { // _0 = (); // StorageDead(_11); // EndRegion('35_0rs); // StorageDead(_2); // return; // } -// bb6: { +// bb7: { // _10 = (); // StorageDead(_11); // StorageLive(_14); @@ -117,9 +121,9 @@ fn query() -> bool { true } // _16 = &'35_0rs (*_17); // _15 = std::option::Option<&'35_0rs S<'35_0rs>>::Some(move _16,); // StorageDead(_16); -// _13 = const >::set(move _14, move_15) -> bb7; +// _13 = const >::set(move _14, move _15) -> [return: bb8, unwind: bb2]; // } -// bb7: { +// bb8: { // EndRegion('33s); // StorageDead(_15); // StorageDead(_14); diff --git a/src/test/mir-opt/end_region_destruction_extents_1.rs b/src/test/mir-opt/end_region_destruction_extents_1.rs index aebe0a1ff6a91..69c5cdccf49d7 100644 --- a/src/test/mir-opt/end_region_destruction_extents_1.rs +++ b/src/test/mir-opt/end_region_destruction_extents_1.rs @@ -99,10 +99,14 @@ unsafe impl<'a, #[may_dangle] 'b> Drop for D1<'a, 'b> { // _2 = (_3.0: &'12ds S1); // _1 = move _2; // StorageDead(_2); -// drop(_3) -> bb1; +// drop(_3) -> [return: bb2, unwind: bb1]; // } // // bb1: { +// resume; +// } +// +// bb2: { // StorageDead(_3); // StorageDead(_8); // StorageDead(_9); @@ -146,10 +150,14 @@ unsafe impl<'a, #[may_dangle] 'b> Drop for D1<'a, 'b> { // _2 = (_3.0: &'12ds S1); // _1 = move _2; // StorageDead(_2); -// drop(_3) -> bb1; +// drop(_3) -> [return: bb2, unwind: bb1]; // } // // bb1: { +// resume; +// } +// +// bb2: { // StorageDead(_3); // StorageDead(_8); // StorageDead(_5); diff --git a/src/test/mir-opt/match_false_edges.rs b/src/test/mir-opt/match_false_edges.rs index b0adbd6ba89e6..0e86eae22e5ea 100644 --- a/src/test/mir-opt/match_false_edges.rs +++ b/src/test/mir-opt/match_false_edges.rs @@ -54,56 +54,59 @@ fn main() { // ... // _2 = std::option::Option::Some(const 42i32,); // _5 = discriminant(_2); -// switchInt(move _5) -> [0isize: bb5, 1isize: bb3, otherwise: bb7]; +// switchInt(move _5) -> [0isize: bb6, 1isize: bb4, otherwise: bb8]; // } -// bb1: { // arm1 +// bb1: { +// resume; +// } +// bb2: { // arm1 // StorageLive(_7); // _7 = _3; // _1 = (const 1i32, move _7); // StorageDead(_7); -// goto -> bb12; +// goto -> bb13; // } -// bb2: { // binding3(empty) and arm3 +// bb3: { // binding3(empty) and arm3 // _1 = (const 3i32, const 3i32); -// goto -> bb12; -// } -// bb3: { -// falseEdges -> [real: bb8, imaginary: bb4]; //pre_binding1 +// goto -> bb13; // } // bb4: { -// falseEdges -> [real: bb11, imaginary: bb5]; //pre_binding2 +// falseEdges -> [real: bb9, imaginary: bb5]; //pre_binding1 // } // bb5: { -// falseEdges -> [real: bb2, imaginary: bb6]; //pre_binding3 +// falseEdges -> [real: bb12, imaginary: bb6]; //pre_binding2 // } // bb6: { -// unreachable; +// falseEdges -> [real: bb3, imaginary: bb7]; //pre_binding3 // } // bb7: { // unreachable; // } -// bb8: { // binding1 and guard +// bb8: { +// unreachable; +// } +// bb9: { // binding1 and guard // StorageLive(_3); // _3 = ((_2 as Some).0: i32); // StorageLive(_6); -// _6 = const guard() -> bb9; +// _6 = const guard() -> [return: bb10, unwind: bb1]; // } -// bb9: { // end of guard -// switchInt(move _6) -> [0u8: bb10, otherwise: bb1]; +// bb10: { // end of guard +// switchInt(move _6) -> [0u8: bb11, otherwise: bb2]; // } -// bb10: { // to pre_binding2 -// falseEdges -> [real: bb4, imaginary: bb4]; +// bb11: { // to pre_binding2 +// falseEdges -> [real: bb5, imaginary: bb5]; // } -// bb11: { // bindingNoLandingPads.before.mir2 and arm2 +// bb12: { // bindingNoLandingPads.before.mir2 and arm2 // StorageLive(_4); // _4 = ((_2 as Some).0: i32); // StorageLive(_8); // _8 = _4; // _1 = (const 2i32, move _8); // StorageDead(_8); -// goto -> bb12; +// goto -> bb13; // } -// bb12: { +// bb13: { // ... // return; // } @@ -114,56 +117,59 @@ fn main() { // ... // _2 = std::option::Option::Some(const 42i32,); // _5 = discriminant(_2); -// switchInt(move _5) -> [0isize: bb4, 1isize: bb3, otherwise: bb7]; +// switchInt(move _5) -> [0isize: bb5, 1isize: bb4, otherwise: bb8]; +// } +// bb1: { +// resume; // } -// bb1: { // arm1 +// bb2: { // arm1 // StorageLive(_7); // _7 = _3; // _1 = (const 1i32, move _7); // StorageDead(_7); -// goto -> bb12; +// goto -> bb13; // } -// bb2: { // binding3(empty) and arm3 +// bb3: { // binding3(empty) and arm3 // _1 = (const 3i32, const 3i32); -// goto -> bb12; -// } -// bb3: { -// falseEdges -> [real: bb8, imaginary: bb4]; //pre_binding1 +// goto -> bb13; // } // bb4: { -// falseEdges -> [real: bb2, imaginary: bb5]; //pre_binding2 +// falseEdges -> [real: bb9, imaginary: bb5]; //pre_binding1 // } // bb5: { -// falseEdges -> [real: bb11, imaginary: bb6]; //pre_binding3 +// falseEdges -> [real: bb3, imaginary: bb6]; //pre_binding2 // } // bb6: { -// unreachable; +// falseEdges -> [real: bb12, imaginary: bb7]; //pre_binding3 // } // bb7: { // unreachable; // } -// bb8: { // binding1 and guard +// bb8: { +// unreachable; +// } +// bb9: { // binding1 and guard // StorageLive(_3); // _3 = ((_2 as Some).0: i32); // StorageLive(_6); -// _6 = const guard() -> bb9; +// _6 = const guard() -> [return: bb10, unwind: bb1]; // } -// bb9: { // end of guard -// switchInt(move _6) -> [0u8: bb10, otherwise: bb1]; +// bb10: { // end of guard +// switchInt(move _6) -> [0u8: bb11, otherwise: bb2]; // } -// bb10: { // to pre_binding2 -// falseEdges -> [real: bb5, imaginary: bb4]; +// bb11: { // to pre_binding2 +// falseEdges -> [real: bb6, imaginary: bb5]; // } -// bb11: { // binding2 and arm2 +// bb12: { // binding2 and arm2 // StorageLive(_4); // _4 = ((_2 as Some).0: i32); // StorageLive(_8); // _8 = _4; // _1 = (const 2i32, move _8); // StorageDead(_8); -// goto -> bb12; +// goto -> bb13; // } -// bb12: { +// bb13: { // ... // return; // } @@ -174,72 +180,75 @@ fn main() { // ... // _2 = std::option::Option::Some(const 1i32,); // _7 = discriminant(_2); -// switchInt(move _7) -> [1isize: bb3, otherwise: bb4]; +// switchInt(move _7) -> [1isize: bb4, otherwise: bb5]; +// } +// bb1: { +// resume; // } -// bb1: { // arm1 -// _1 = const 1i32; -// goto -> bb16; +// bb2: { // arm1 +// _1 = const 1i32; +// goto -> bb17; // } -// bb2: { // arm3 +// bb3: { // arm3 // _1 = const 3i32; -// goto -> bb16; +// goto -> bb17; // } // -// bb3: { -// falseEdges -> [real: bb8, imaginary: bb4]; //pre_binding1 -// } -// bb4: { -// falseEdges -> [real: bb11, imaginary: bb5]; //pre_binding2 -// } -// bb5: { -// falseEdges -> [real: bb12, imaginary: bb6]; //pre_binding3 -// } -// bb6: { -// falseEdges -> [real: bb15, imaginary: bb7]; //pre_binding4 -// } -// bb7: { -// unreachable; -// } -// bb8: { // binding1: Some(w) if guard() -// StorageLive(_3); -// _3 = ((_2 as Some).0: i32); -// StorageLive(_8); -// _8 = const guard() -> bb9; -// } -// bb9: { //end of guard -// switchInt(move _8) -> [0u8: bb10, otherwise: bb1]; -// } -// bb10: { // to pre_binding2 -// falseEdges -> [real: bb4, imaginary: bb4]; -// } -// bb11: { // binding2 & arm2 -// StorageLive(_4); -// _4 = _2; -// _1 = const 2i32; -// goto -> bb16; -// } -// bb12: { // binding3: Some(y) if guard2(y) -// StorageLive(_5); -// _5 = ((_2 as Some).0: i32); -// StorageLive(_10); -// StorageLive(_11); -// _11 = _5; -// _10 = const guard2(move _11) -> bb13; -// } -// bb13: { // end of guard2 -// StorageDead(_11); -// switchInt(move _10) -> [0u8: bb14, otherwise: bb2]; -// } -// bb14: { // to pre_binding4 -// falseEdges -> [real: bb6, imaginary: bb6]; -// } -// bb15: { // binding4 & arm4 -// StorageLive(_6); -// _6 = _2; -// _1 = const 4i32; -// goto -> bb16; -// } -// bb16: { +// bb4: { +// falseEdges -> [real: bb9, imaginary: bb5]; //pre_binding1 +// } +// bb5: { +// falseEdges -> [real: bb12, imaginary: bb6]; //pre_binding2 +// } +// bb6: { +// falseEdges -> [real: bb13, imaginary: bb7]; //pre_binding3 +// } +// bb7: { +// falseEdges -> [real: bb16, imaginary: bb8]; //pre_binding4 +// } +// bb8: { +// unreachable; +// } +// bb9: { // binding1: Some(w) if guard() +// StorageLive(_3); +// _3 = ((_2 as Some).0: i32); +// StorageLive(_8); +// _8 = const guard() -> [return: bb10, unwind: bb1]; +// } +// bb10: { //end of guard +// switchInt(move _8) -> [0u8: bb11, otherwise: bb2]; +// } +// bb11: { // to pre_binding2 +// falseEdges -> [real: bb5, imaginary: bb5]; +// } +// bb12: { // binding2 & arm2 +// StorageLive(_4); +// _4 = _2; +// _1 = const 2i32; +// goto -> bb17; +// } +// bb13: { // binding3: Some(y) if guard2(y) +// StorageLive(_5); +// _5 = ((_2 as Some).0: i32); +// StorageLive(_10); +// StorageLive(_11); +// _11 = _5; +// _10 = const guard2(move _11) -> [return: bb14, unwind: bb1]; +// } +// bb14: { // end of guard2 +// StorageDead(_11); +// switchInt(move _10) -> [0u8: bb15, otherwise: bb3]; +// } +// bb15: { // to pre_binding4 +// falseEdges -> [real: bb7, imaginary: bb7]; +// } +// bb16: { // binding4 & arm4 +// StorageLive(_6); +// _6 = _2; +// _1 = const 4i32; +// goto -> bb17; +// } +// bb17: { // ... // return; // } diff --git a/src/test/mir-opt/nll/liveness-call-subtlety.rs b/src/test/mir-opt/nll/liveness-call-subtlety.rs index 59a1d4891f66f..e4dd99f5a1e75 100644 --- a/src/test/mir-opt/nll/liveness-call-subtlety.rs +++ b/src/test/mir-opt/nll/liveness-call-subtlety.rs @@ -31,15 +31,15 @@ fn main() { // | Live variables at bb0[0]: [] // StorageLive(_1); // | Live variables at bb0[1]: [] -// _1 = const >::new(const 22usize) -> bb1; +// _1 = const >::new(const 22usize) -> [return: bb2, unwind: bb1]; // } // END rustc.main.nll.0.mir // START rustc.main.nll.0.mir -// | Live variables on entry to bb1: [_1 (drop)] -// bb1: { -// | Live variables at bb1[0]: [_1 (drop)] +// | Live variables on entry to bb2: [_1 (drop)] +// bb2: { +// | Live variables at bb2[0]: [_1 (drop)] // StorageLive(_2); -// | Live variables at bb1[1]: [_1 (drop)] -// _2 = const can_panic() -> [return: bb2, unwind: bb4]; +// | Live variables at bb2[1]: [_1 (drop)] +// _2 = const can_panic() -> [return: bb3, unwind: bb4]; // } // END rustc.main.nll.0.mir diff --git a/src/test/mir-opt/nll/liveness-drop-intra-block.rs b/src/test/mir-opt/nll/liveness-drop-intra-block.rs index 3e86677956f0b..8dae773806718 100644 --- a/src/test/mir-opt/nll/liveness-drop-intra-block.rs +++ b/src/test/mir-opt/nll/liveness-drop-intra-block.rs @@ -25,17 +25,17 @@ fn main() { // END RUST SOURCE // START rustc.main.nll.0.mir -// | Live variables on entry to bb1: [] -// bb1: { -// | Live variables at bb1[0]: [] +// | Live variables on entry to bb2: [] +// bb2: { +// | Live variables at bb2[0]: [] // _1 = const 55usize; -// | Live variables at bb1[1]: [_1] +// | Live variables at bb2[1]: [_1] // StorageLive(_3); -// | Live variables at bb1[2]: [_1] +// | Live variables at bb2[2]: [_1] // StorageLive(_4); -// | Live variables at bb1[3]: [_1] +// | Live variables at bb2[3]: [_1] // _4 = _1; -// | Live variables at bb1[4]: [_4] -// _3 = const use_x(move _4) -> bb2; +// | Live variables at bb2[4]: [_4] +// _3 = const use_x(move _4) -> [return: bb3, unwind: bb1]; // } // END rustc.main.nll.0.mir diff --git a/src/test/mir-opt/nll/liveness-interblock.rs b/src/test/mir-opt/nll/liveness-interblock.rs index 32a38a5cd5e35..5d799d3d90b41 100644 --- a/src/test/mir-opt/nll/liveness-interblock.rs +++ b/src/test/mir-opt/nll/liveness-interblock.rs @@ -29,22 +29,20 @@ fn main() { // END RUST SOURCE // START rustc.main.nll.0.mir -// | Live variables on entry to bb2: [_1] -// bb2: { -// | Live variables at bb2[0]: [_1] +// | Live variables on entry to bb3: [_1] +// bb3: { +// | Live variables at bb3[0]: [_1] // StorageLive(_4); -// | Live variables at bb2[1]: [_1] +// | Live variables at bb3[1]: [_1] // _4 = _1; -// | Live variables at bb2[2]: [_4] -// _3 = const make_live(move _4) -> bb4; +// | Live variables at bb3[2]: [_4] +// _3 = const make_live(move _4) -> [return: bb5, unwind: bb1]; // } // END rustc.main.nll.0.mir // START rustc.main.nll.0.mir -// | Live variables on entry to bb3: [] -// bb3: { -// | Live variables at bb3[0]: [] -// _5 = const make_dead() -> bb5; +// | Live variables on entry to bb4: [] +// bb4: { +// | Live variables at bb4[0]: [] +// _5 = const make_dead() -> [return: bb6, unwind: bb1]; // } // END rustc.main.nll.0.mir - - diff --git a/src/test/mir-opt/nll/region-liveness-basic.rs b/src/test/mir-opt/nll/region-liveness-basic.rs index 3aba3ac86aea4..36dedeebd538a 100644 --- a/src/test/mir-opt/nll/region-liveness-basic.rs +++ b/src/test/mir-opt/nll/region-liveness-basic.rs @@ -31,26 +31,26 @@ fn main() { // END RUST SOURCE // START rustc.main.nll.0.mir -// | '_#1r: {bb1[1], bb2[0], bb2[1]} -// | '_#2r: {bb1[1], bb2[0], bb2[1]} +// | '_#1r: {bb2[1], bb3[0], bb3[1]} +// | '_#2r: {bb2[1], bb3[0], bb3[1]} // ... // let _2: &'_#2r usize; // END rustc.main.nll.0.mir // START rustc.main.nll.0.mir -// bb1: { -// | Live variables at bb1[0]: [_1, _3] +// bb2: { +// | Live variables at bb2[0]: [_1, _3] // _2 = &'_#1r _1[_3]; -// | Live variables at bb1[1]: [_2] -// switchInt(const true) -> [0u8: bb3, otherwise: bb2]; +// | Live variables at bb2[1]: [_2] +// switchInt(const true) -> [0u8: bb4, otherwise: bb3]; // } // END rustc.main.nll.0.mir // START rustc.main.nll.0.mir -// bb2: { -// | Live variables at bb2[0]: [_2] +// bb3: { +// | Live variables at bb3[0]: [_2] // StorageLive(_7); -// | Live variables at bb2[1]: [_2] +// | Live variables at bb3[1]: [_2] // _7 = (*_2); -// | Live variables at bb2[2]: [_7] -// _6 = const use_x(move _7) -> bb4; +// | Live variables at bb3[2]: [_7] +// _6 = const use_x(move _7) -> [return: bb5, unwind: bb1]; // } // END rustc.main.nll.0.mir diff --git a/src/test/mir-opt/nll/region-liveness-drop-may-dangle.rs b/src/test/mir-opt/nll/region-liveness-drop-may-dangle.rs index 6d7aa0a26c8a8..04a30dc284d77 100644 --- a/src/test/mir-opt/nll/region-liveness-drop-may-dangle.rs +++ b/src/test/mir-opt/nll/region-liveness-drop-may-dangle.rs @@ -44,5 +44,5 @@ unsafe impl<#[may_dangle] T> Drop for Wrap { // END RUST SOURCE // START rustc.main.nll.0.mir -// | '_#5r: {bb1[3], bb1[4], bb1[5], bb2[0], bb2[1]} +// | '_#5r: {bb2[3], bb2[4], bb2[5], bb3[0], bb3[1]} // END rustc.main.nll.0.mir diff --git a/src/test/mir-opt/nll/region-liveness-two-disjoint-uses.rs b/src/test/mir-opt/nll/region-liveness-two-disjoint-uses.rs index 5c28746126a64..de2b18fe4afa3 100644 --- a/src/test/mir-opt/nll/region-liveness-two-disjoint-uses.rs +++ b/src/test/mir-opt/nll/region-liveness-two-disjoint-uses.rs @@ -36,10 +36,10 @@ fn main() { // END RUST SOURCE // START rustc.main.nll.0.mir -// | '_#1r: {bb1[1], bb2[0], bb2[1]} +// | '_#1r: {bb2[1], bb3[0], bb3[1]} // ... -// | '_#3r: {bb7[2], bb7[3], bb7[4]} -// | '_#4r: {bb1[1], bb2[0], bb2[1], bb7[2], bb7[3], bb7[4]} +// | '_#3r: {bb8[2], bb8[3], bb8[4]} +// | '_#4r: {bb2[1], bb3[0], bb3[1], bb8[2], bb8[3], bb8[4]} // ... // let mut _2: &'_#4r usize; // ... diff --git a/src/test/mir-opt/nll/region-subtyping-basic.rs b/src/test/mir-opt/nll/region-subtyping-basic.rs index 3570107673052..6a2a7cc714997 100644 --- a/src/test/mir-opt/nll/region-subtyping-basic.rs +++ b/src/test/mir-opt/nll/region-subtyping-basic.rs @@ -32,9 +32,9 @@ fn main() { // END RUST SOURCE // START rustc.main.nll.0.mir -// | '_#1r: {bb1[1], bb1[2], bb1[3], bb1[4], bb1[5], bb1[6], bb2[0], bb2[1]} -// | '_#2r: {bb1[1], bb1[2], bb1[3], bb1[4], bb1[5], bb1[6], bb2[0], bb2[1]} -// | '_#3r: {bb1[5], bb1[6], bb2[0], bb2[1]} +// | '_#1r: {bb2[1], bb2[2], bb2[3], bb2[4], bb2[5], bb2[6], bb3[0], bb3[1]} +// | '_#2r: {bb2[1], bb2[2], bb2[3], bb2[4], bb2[5], bb2[6], bb3[0], bb3[1]} +// | '_#3r: {bb2[5], bb2[6], bb3[0], bb3[1]} // END rustc.main.nll.0.mir // START rustc.main.nll.0.mir // let _2: &'_#2r usize; diff --git a/src/test/mir-opt/packed-struct-drop-aligned.rs b/src/test/mir-opt/packed-struct-drop-aligned.rs index 0706f185d3163..1b114419448f1 100644 --- a/src/test/mir-opt/packed-struct-drop-aligned.rs +++ b/src/test/mir-opt/packed-struct-drop-aligned.rs @@ -64,7 +64,7 @@ impl Drop for Droppy { // (_1.0: Aligned) = move _4; // StorageDead(_4); // _0 = (); -// drop(_1) -> bb2; +// drop(_1) -> [return: bb2, unwind: bb1]; // } // } // END rustc.main.EraseRegions.before.mir diff --git a/src/test/mir-opt/simplify_if.rs b/src/test/mir-opt/simplify_if.rs index ad3bbba8d08df..35786643648eb 100644 --- a/src/test/mir-opt/simplify_if.rs +++ b/src/test/mir-opt/simplify_if.rs @@ -17,11 +17,11 @@ fn main() { // END RUST SOURCE // START rustc.main.SimplifyBranches-initial.before.mir // bb0: { -// switchInt(const false) -> [0u8: bb2, otherwise: bb1]; +// switchInt(const false) -> [0u8: bb3, otherwise: bb2]; // } // END rustc.main.SimplifyBranches-initial.before.mir // START rustc.main.SimplifyBranches-initial.after.mir // bb0: { -// goto -> bb2; +// goto -> bb3; // } // END rustc.main.SimplifyBranches-initial.after.mir diff --git a/src/test/mir-opt/validate_2.rs b/src/test/mir-opt/validate_2.rs index 5b8ba4d8d0632..309558ed5b327 100644 --- a/src/test/mir-opt/validate_2.rs +++ b/src/test/mir-opt/validate_2.rs @@ -28,7 +28,7 @@ fn main() { // StorageDead(_3); // _0 = (); // Validate(Release, [_1: std::boxed::Box<[i32]>]); -// drop(_1) -> bb2; +// drop(_1) -> [return: bb2, unwind: bb3]; // } // ... // }