-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #69814 - jonas-schievink:gen-ret-unw, r=Zoxc
Smaller and more correct generator codegen This removes unnecessary panicking branches in the resume function when the generator can not return or unwind, respectively. Closes #66100 It also addresses the correctness concerns wrt poisoning on unwind. These are not currently a soundness issue because any operation *inside* a generator that could possibly unwind will result in a cleanup path for dropping it, ultimately reaching a `Resume` terminator, which we already handled correctly. Future MIR optimizations might optimize that out, though. r? @Zoxc
- Loading branch information
Showing
2 changed files
with
138 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//! Tests that generators that cannot return or unwind don't have unnecessary | ||
//! panic branches. | ||
// compile-flags: -Zno-landing-pads | ||
|
||
#![feature(generators, generator_trait)] | ||
|
||
struct HasDrop; | ||
|
||
impl Drop for HasDrop { | ||
fn drop(&mut self) {} | ||
} | ||
|
||
fn callee() {} | ||
|
||
fn main() { | ||
let _gen = |_x: u8| { | ||
let _d = HasDrop; | ||
loop { | ||
yield; | ||
callee(); | ||
} | ||
}; | ||
} | ||
|
||
// END RUST SOURCE | ||
|
||
// START rustc.main-{{closure}}.generator_resume.0.mir | ||
// bb0: { | ||
// ... | ||
// switchInt(move _11) -> [0u32: bb1, 3u32: bb5, otherwise: bb6]; | ||
// } | ||
// ... | ||
// END rustc.main-{{closure}}.generator_resume.0.mir |