From 5f4e4baddb104ee3e63d1db24a4c2a73e1a703cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Thu, 15 Feb 2024 00:00:00 +0000 Subject: [PATCH] Skip coroutines in jump threading to avoid query cycles --- compiler/rustc_mir_transform/src/jump_threading.rs | 6 ++++++ tests/ui/mir/mir_query_cycle.rs | 14 ++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tests/ui/mir/mir_query_cycle.rs diff --git a/compiler/rustc_mir_transform/src/jump_threading.rs b/compiler/rustc_mir_transform/src/jump_threading.rs index 78ba166ba43..ad8f21ffbda 100644 --- a/compiler/rustc_mir_transform/src/jump_threading.rs +++ b/compiler/rustc_mir_transform/src/jump_threading.rs @@ -68,6 +68,12 @@ impl<'tcx> MirPass<'tcx> for JumpThreading { let def_id = body.source.def_id(); debug!(?def_id); + // Optimizing coroutines creates query cycles. + if tcx.is_coroutine(def_id) { + trace!("Skipped for coroutine {:?}", def_id); + return; + } + let param_env = tcx.param_env_reveal_all_normalized(def_id); let map = Map::new(tcx, body, Some(MAX_PLACES)); let loop_headers = loop_headers(body); diff --git a/tests/ui/mir/mir_query_cycle.rs b/tests/ui/mir/mir_query_cycle.rs new file mode 100644 index 00000000000..22d1ccb6c6e --- /dev/null +++ b/tests/ui/mir/mir_query_cycle.rs @@ -0,0 +1,14 @@ +// Regression test for #121094. +// build-pass +// compile-flags: -O --crate-type=lib +// edition: 2021 +use std::{future::Future, pin::Pin}; + +pub async fn foo(count: u32) { + if count == 0 { + return + } else { + let fut: Pin>> = Box::pin(foo(count - 1)); + fut.await; + } +}