Skip to content

Commit 515697e

Browse files
committed
Auto merge of rust-lang#145477 - cjgillot:codegen-mode, r=oli-obk
Introduce `TypingMode::Codegen` to avoid layout cycles on coroutines Computing layout of coroutines depends on their `optimized_mir`. At the same time, MIR opts can require using layouts to work. For instance to evaluate constants. This leads to cycles and clumsy workarounds. This PR creates a new typing mode for layout computations: - when a coroutine's layout is requested with `TypingMode::PostAnalysis` or earlier, return `LayourError::TooGeneric`; - when a coroutine's layout is requested with `TypingMode::Codegen`, actually compute it. `TypingMode::Codegen` is meant be be used by codegen code, and analyses that require coroutine layout, like transmute check and coroutine recursion check. With this PR, we can remove all `is_coroutine` checks from `rustc_mir_transform` and unlock simplifying coroutine MIR. Perf is not terrific. This PR causes recomputation of a few queries, and I had to insert workarounds.
2 parents a9a7ce5 + 7098a65 commit 515697e

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

clippy_lints/src/large_futures.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeFuture {
6464
&& let ty = cx.typeck_results().expr_ty(arg)
6565
&& let Some(future_trait_def_id) = cx.tcx.lang_items().future_trait()
6666
&& implements_trait(cx, ty, future_trait_def_id, &[])
67-
&& let Ok(layout) = cx.tcx.layout_of(cx.typing_env().as_query_input(ty))
67+
&& let Ok(layout) = cx.tcx.layout_of(cx.typing_env().with_codegen_normalized(cx.tcx).as_query_input(ty))
6868
&& let size = layout.layout.size()
6969
&& size >= Size::from_bytes(self.future_size_threshold)
7070
{

0 commit comments

Comments
 (0)