diff options
| author | bors <bors@rust-lang.org> | 2021-09-16 16:46:02 +0000 |
|---|---|---|
| committer | Eric Huss <eric@huss.org> | 2021-10-04 12:12:47 -0700 |
| commit | d2e10d5cc60eab699f7ae0f11fe5be4c7ccf1b53 (patch) | |
| tree | ef6ebd8db52b4f535433ed4dbd64228da4e9e3b2 | |
| parent | c0f9379260531ae3780c71cc924b4c997abd12c2 (diff) | |
| download | rust-d2e10d5cc60eab699f7ae0f11fe5be4c7ccf1b53.tar.gz rust-d2e10d5cc60eab699f7ae0f11fe5be4c7ccf1b53.zip | |
Auto merge of #88979 - tmiasko:no-remove-zsts-in-generators, 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 #88972.
| -rw-r--r-- | compiler/rustc_mir/src/transform/remove_zsts.rs | 4 | ||||
| -rw-r--r-- | src/test/ui/mir/remove-zsts-query-cycle.rs | 16 |
2 files changed, 20 insertions, 0 deletions
diff --git a/compiler/rustc_mir/src/transform/remove_zsts.rs b/compiler/rustc_mir/src/transform/remove_zsts.rs index 03277b1b2e0..5876ac22c66 100644 --- a/compiler/rustc_mir/src/transform/remove_zsts.rs +++ b/compiler/rustc_mir/src/transform/remove_zsts.rs @@ -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() { diff --git a/src/test/ui/mir/remove-zsts-query-cycle.rs b/src/test/ui/mir/remove-zsts-query-cycle.rs new file mode 100644 index 00000000000..8f93c6cadff --- /dev/null +++ b/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() +} |
