Skip to content

Commit 784d444

Browse files
committed
Auto merge of rust-lang#129714 - saethlin:half-a-recursion, r=compiler-errors
Use a reduced recursion limit in the MIR inliner's cycle breaker This probably papers over rust-lang#128887, but primarily I'm opening this PR because multiple compiler people have thought about making this change which probably means it's a good idea. r? compiler-errors
2 parents 6cf068d + 950437a commit 784d444

File tree

1 file changed

+9
-1
lines changed
  • compiler/rustc_mir_transform/src/inline

1 file changed

+9
-1
lines changed

compiler/rustc_mir_transform/src/inline/cycle.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ pub(crate) fn mir_callgraph_reachable<'tcx>(
135135
}
136136
false
137137
}
138+
// FIXME(-Znext-solver): Remove this hack when trait solver overflow can return an error.
139+
// In code like that pointed out in #128887, the type complexity we ask the solver to deal with
140+
// grows as we recurse into the call graph. If we use the same recursion limit here and in the
141+
// solver, the solver hits the limit first and emits a fatal error. But if we use a reduced
142+
// limit, we will hit the limit first and give up on looking for inlining. And in any case,
143+
// the default recursion limits are quite generous for us. If we need to recurse 64 times
144+
// into the call graph, we're probably not going to find any useful MIR inlining.
145+
let recursion_limit = tcx.recursion_limit() / 2;
138146
process(
139147
tcx,
140148
param_env,
@@ -143,7 +151,7 @@ pub(crate) fn mir_callgraph_reachable<'tcx>(
143151
&mut Vec::new(),
144152
&mut FxHashSet::default(),
145153
&mut FxHashMap::default(),
146-
tcx.recursion_limit(),
154+
recursion_limit,
147155
)
148156
}
149157

0 commit comments

Comments
 (0)