Skip to content

Commit

Permalink
Disable RemoveZsts in generators to avoid query cycles
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
tmiasko committed Sep 15, 2021
1 parent 2c7bc5e commit c39d759
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
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
@@ -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 c39d759

Please sign in to comment.