Skip to content

Commit

Permalink
Rollup merge of rust-lang#88979 - tmiasko:no-remove-zsts-in-generator…
Browse files Browse the repository at this point in the history
…s, r=oli-obk

Disable RemoveZsts in generators to avoid query cycles

Querying layout of a generator requires its optimized MIR. Thus
computing layout during MIR optimization of a generator might create a
query cycle. Disable RemoveZsts in generators to avoid the issue
(similar approach is used in ConstProp transform already).

Fixes rust-lang#88972.
  • Loading branch information
Manishearth authored Sep 16, 2021
2 parents 34aaf54 + c39d759 commit f7a6ae6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_mir_transform/src/remove_zsts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ pub struct RemoveZsts;

impl<'tcx> MirPass<'tcx> for RemoveZsts {
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
// Avoid query cycles (generators require optimized MIR for layout).
if tcx.type_of(body.source.def_id()).is_generator() {
return;
}
let param_env = tcx.param_env(body.source.def_id());
let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut();
for block in basic_blocks.iter_mut() {
Expand Down
16 changes: 16 additions & 0 deletions src/test/ui/mir/remove-zsts-query-cycle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Regression test for #88972. Used to cause a query cycle:
// optimized mir -> remove zsts -> layout of a generator -> optimized mir.
//
// edition:2018
// compile-flags: --crate-type=lib
// build-pass

pub async fn listen() -> Result<(), std::io::Error> {
let f = do_async();
std::mem::forget(f);
Ok(())
}

pub async fn do_async() {
listen().await.unwrap()
}

0 comments on commit f7a6ae6

Please sign in to comment.