Auto merge of #47802 - bobtwinkles:loop_false_edge, r=nikomatsakis

[NLL] Add false edges out of infinite loops

Resolves #46036 by adding a `cleanup` member to the `FalseEdges` terminator kind. There's also a small doc fix to one of the other comments in `into.rs` which I can pull out in to another PR if desired =)

This PR should pass CI but the test suite has been relatively unstable on my system so I'm not 100% sure.

r? @nikomatsakis
This commit is contained in:
bors 2018-02-09 13:04:17 +00:00
commit 3bcda48a30
29 changed files with 263 additions and 76 deletions

View file

@ -0,0 +1,23 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Issue 46036: [NLL] false edges on infinite loops
// Infinite loops should create false edges to the cleanup block.
#![feature(nll)]
struct Foo { x: &'static u32 }
fn foo() {
let a = 3;
let foo = Foo { x: &a }; //~ ERROR E0597
loop { }
}
fn main() { }

View file

@ -179,7 +179,7 @@ pub fn change_continue_label() {
}
#[cfg(not(cfail1))]
#[rustc_clean(cfg="cfail2", except="HirBody, TypeckTables")]
#[rustc_clean(cfg="cfail2", except="HirBody, MirValidated, TypeckTables")]
#[rustc_clean(cfg="cfail3")]
pub fn change_continue_label() {
let mut _x = 0;

View file

@ -40,15 +40,21 @@ fn main() {
// goto -> bb1;
// }
// bb1: {
// falseUnwind -> [real: bb2, cleanup: bb3];
// }
// bb2: {
// StorageLive(_2);
// _2 = const true;
// StorageLive(_3);
// _3 = &'23_1rs _2;
// StorageLive(_5);
// _5 = _2;
// switchInt(move _5) -> [0u8: bb3, otherwise: bb2];
// switchInt(move _5) -> [0u8: bb5, otherwise: bb4];
// }
// bb2: {
// bb3: {
// ...
// }
// bb4: {
// _0 = ();
// StorageDead(_5);
// EndRegion('23_1rs);
@ -56,7 +62,7 @@ fn main() {
// StorageDead(_2);
// return;
// }
// bb3: {
// bb5: {
// _4 = ();
// StorageDead(_5);
// StorageLive(_7);

View file

@ -43,14 +43,20 @@ fn main() {
// goto -> bb1;
// }
// bb1: {
// falseUnwind -> [real: bb2, cleanup: bb3];
// }
// bb2: {
// _1 = const true;
// StorageLive(_3);
// _3 = &'26_1rs _1;
// StorageLive(_5);
// _5 = _1;
// switchInt(move _5) -> [0u8: bb3, otherwise: bb2];
// switchInt(move _5) -> [0u8: bb5, otherwise: bb4];
// }
// bb2: {
// bb3: {
// ...
// }
// bb4: {
// _0 = ();
// StorageDead(_5);
// EndRegion('26_1rs);
@ -58,7 +64,7 @@ fn main() {
// StorageDead(_1);
// return;
// }
// bb3: {
// bb5: {
// _4 = ();
// StorageDead(_5);
// StorageLive(_7);

View file

@ -57,16 +57,24 @@ fn main() {
// _1 = const false;
// StorageLive(_2);
// _2 = const 3i32;
// StorageLive(_4);
// goto -> bb1;
// falseUnwind -> [real: bb2, cleanup: bb1];
// }
//
// bb1: {
// StorageLive(_7);
// _7 = _1;
// switchInt(move _7) -> [0u8: bb3, otherwise: bb2];
// ...
// }
// bb2: {
// StorageLive(_4);
// goto -> bb3;
// }
// bb3: {
// falseUnwind -> [real: bb4, cleanup: bb1];
// }
// bb4: {
// StorageLive(_7);
// _7 = _1;
// switchInt(move _7) -> [0u8: bb6, otherwise: bb5];
// }
// bb5: {
// _0 = ();
// StorageDead(_7);
// EndRegion('33_0rs);
@ -75,13 +83,13 @@ fn main() {
// StorageDead(_1);
// return;
// }
// bb3: {
// bb6: {
// _4 = &'33_0rs _2;
// _6 = ();
// StorageDead(_7);
// _1 = const true;
// _3 = ();
// goto -> bb1;
// goto -> bb3;
// }
// }
// END rustc.main.SimplifyCfg-qualify-consts.after.mir

View file

@ -67,16 +67,19 @@ fn query() -> bool { true }
// goto -> bb1;
// }
// bb1: {
// falseUnwind -> [real: bb2, cleanup: bb3];
// }
// bb2: {
// StorageLive(_2);
// StorageLive(_3);
// StorageLive(_4);
// _4 = std::option::Option<&'35_0rs S<'35_0rs>>::None;
// _3 = const <std::cell::Cell<T>>::new(move _4) -> [return: bb3, unwind: bb2];
// }
// bb2: {
// resume;
// _3 = const <std::cell::Cell<T>>::new(move _4) -> [return: bb4, unwind: bb3];
// }
// bb3: {
// resume;
// }
// bb4: {
// StorageDead(_4);
// _2 = S<'35_0rs> { r: move _3 };
// StorageDead(_3);
@ -89,27 +92,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 <std::cell::Cell<T>>::set(move _6, move _7) -> [return: bb4, unwind: bb2];
// _5 = const <std::cell::Cell<T>>::set(move _6, move _7) -> [return: bb5, unwind: bb3];
// }
// bb4: {
// bb5: {
// EndRegion('16s);
// StorageDead(_7);
// StorageDead(_6);
// StorageDead(_9);
// StorageLive(_11);
// _11 = const query() -> [return: bb5, unwind: bb2];
// }
// bb5: {
// switchInt(move _11) -> [0u8: bb7, otherwise: bb6];
// _11 = const query() -> [return: bb6, unwind: bb3];
// }
// bb6: {
// switchInt(move _11) -> [0u8: bb8, otherwise: bb7];
// }
// bb7: {
// _0 = ();
// StorageDead(_11);
// EndRegion('35_0rs);
// StorageDead(_2);
// return;
// }
// bb7: {
// bb8: {
// _10 = ();
// StorageDead(_11);
// StorageLive(_14);
@ -121,9 +124,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 <std::cell::Cell<T>>::set(move _14, move _15) -> [return: bb8, unwind: bb2];
// _13 = const <std::cell::Cell<T>>::set(move _14, move _15) -> [return: bb9, unwind: bb3];
// }
// bb8: {
// bb9: {
// EndRegion('33s);
// StorageDead(_15);
// StorageDead(_14);

View file

@ -25,27 +25,30 @@ fn main() {
// bb0: {
// StorageLive(_1);
// _1 = const false;
// goto -> bb1;
// goto -> bb2;
// }
//
// bb1: {
// resume;
// }
// bb2: {
// falseUnwind -> [real: bb3, cleanup: bb1];
// }
// bb3: {
// StorageLive(_4);
// _4 = _1;
// switchInt(move _4) -> [0u8: bb3, otherwise: bb2];
// switchInt(move _4) -> [0u8: bb5, otherwise: bb4];
// }
//
// bb2: {
// bb4: {
// _0 = ();
// StorageDead(_4);
// StorageDead(_1);
// return;
// }
//
// bb3: {
// bb5: {
// _3 = ();
// StorageDead(_4);
// _1 = const true;
// _2 = ();
// goto -> bb1;
// goto -> bb2;
// }
// END rustc.main.SimplifyCfg-initial.after.mir

View file

@ -0,0 +1,49 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// compile-flags: -Z identify_regions -Z emit-end-regions
// Tests to make sure we correctly generate falseUnwind edges in loops
fn main() {
// Exit early at runtime. Since only care about the generated MIR
// and not the runtime behavior (which is exercised by other tests)
// we just bail early. Without this the test just loops infinitely.
if true {
return;
}
loop {
let x = 1;
continue;
}
}
// END RUST SOURCE
// START rustc.main.SimplifyCfg-qualify-consts.after.mir
// ...
// bb1: { // The cleanup block
// resume;
// }
// ...
// bb3: { // Entry into the loop
// _1 = ();
// goto -> bb4;
// }
// bb4: { // The loop_block
// falseUnwind -> [real: bb5, cleanup: bb1];
// }
// bb5: { // The loop body (body_block)
// StorageLive(_5);
// _5 = const 1i32;
// StorageDead(_5);
// goto -> bb4;
// }
// ...
// END rustc.main.SimplifyCfg-qualify-consts.after.mir

View file

@ -25,17 +25,17 @@ fn main() {
// END RUST SOURCE
// START rustc.main.nll.0.mir
// | Live variables on entry to bb2: []
// bb2: {
// | Live variables on entry to bb2[0]: []
// | Live variables on entry to bb3: []
// bb3: {
// | Live variables on entry to bb3[0]: []
// _1 = const 55usize;
// | Live variables on entry to bb2[1]: [_1]
// | Live variables on entry to bb3[1]: [_1]
// StorageLive(_3);
// | Live variables on entry to bb2[2]: [_1]
// | Live variables on entry to bb3[2]: [_1]
// StorageLive(_4);
// | Live variables on entry to bb2[3]: [_1]
// | Live variables on entry to bb3[3]: [_1]
// _4 = _1;
// | Live variables on entry to bb2[4]: [_4]
// _3 = const use_x(move _4) -> [return: bb3, unwind: bb1];
// | Live variables on entry to bb3[4]: [_4]
// _3 = const use_x(move _4) -> [return: bb4, unwind: bb1];
// }
// END rustc.main.nll.0.mir