Skip to content

Commit cd68293

Browse files
authored
Rollup merge of #76245 - tmiasko:inline-generators, r=ecstatic-morse
inliner: Avoid query cycles when optimizing generators The HIR Id trick is insufficient to prevent query cycles when optimizing generators, since merely requesting a layout of a generator also computes its `optimized_mir`. Make no attempts to inline functions into generators within the same crate to avoid query cycles. Fixes #76181.
2 parents 3368f5c + 6c51ec9 commit cd68293

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

compiler/rustc_mir/src/transform/inline.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,14 @@ impl Inliner<'tcx> {
107107
// Avoid a cycle here by only using `optimized_mir` only if we have
108108
// a lower `HirId` than the callee. This ensures that the callee will
109109
// not inline us. This trick only works without incremental compilation.
110-
// So don't do it if that is enabled.
111-
if !self.tcx.dep_graph.is_fully_enabled() && self_hir_id < callee_hir_id {
110+
// So don't do it if that is enabled. Also avoid inlining into generators,
111+
// since their `optimized_mir` is used for layout computation, which can
112+
// create a cycle, even when no attempt is made to inline the function
113+
// in the other direction.
114+
if !self.tcx.dep_graph.is_fully_enabled()
115+
&& self_hir_id < callee_hir_id
116+
&& caller_body.generator_kind.is_none()
117+
{
112118
self.tcx.optimized_mir(callsite.callee)
113119
} else {
114120
continue;
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Checks that inliner doesn't introduce cycles when optimizing generators.
2+
// The outcome of optimization is not verfied, just the absence of the cycle.
3+
// Regression test for #76181.
4+
//
5+
// edition:2018
6+
7+
#![crate_type = "lib"]
8+
9+
pub struct S;
10+
11+
impl S {
12+
pub async fn g(&mut self) {
13+
self.h();
14+
}
15+
pub fn h(&mut self) {
16+
let _ = self.g();
17+
}
18+
}

0 commit comments

Comments
 (0)