Skip to content

Commit

Permalink
Auto merge of #88979 - tmiasko:no-remove-zsts-in-generators, r=oli-obk
Browse files Browse the repository at this point in the history
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 #88972.
  • Loading branch information
bors committed Sep 16, 2021
2 parents d1d8145 + c39d759 commit 237bb5e
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 237bb5e

Please sign in to comment.