Avoid mono collection hangs from recursive type growth#156993
Avoid mono collection hangs from recursive type growth#156993naganohara-yoshino wants to merge 3 commits into
Conversation
|
rustbot has assigned @dingxiangfei2009. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
|
With this change, the code now terminates and reports the recursion-limit diagnostic: #![allow(dead_code)]
enum Foo<A> {
Fst,
Snd(Box<dyn Fn() -> Foo<(A, A)>>),
}
fn recursive<A>(x: Foo<A>) {
match x {
Foo::Fst => (),
Foo::Snd(f) => recursive(f()),
}
}
fn main() {
let p0: Foo<()> = Foo::Fst;
recursive(p0);
}UI test is added accordingly. |
|
This PR modifies |
This comment has been minimized.
This comment has been minimized.
|
Some changes occurred in compiler/rustc_attr_parsing cc @jdonszelmann, @JonathanBrouwer
cc @bjorn3 Some changes occurred in compiler/rustc_ast/src/expand/typetree.rs cc @ZuseZ4 Some changes occurred in check-cfg diagnostics cc @Urgau Some changes occurred in compiler/rustc_codegen_llvm/src/builder/autodiff.rs cc @ZuseZ4 Some changes occurred in compiler/rustc_builtin_macros/src/autodiff.rs cc @ZuseZ4 Some changes occurred in compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs cc @ZuseZ4 Some changes occurred to diagnostic attributes. cc @mejrs This PR modifies If appropriate, please update These commits modify the If this was unintentional then you should revert the changes before this PR is merged. |
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
Looks like you made a mistake with rebasing. Try |
080295f to
0d1dcce
Compare
Thanks for your reminder. I think I have fixed it now. |
0d1dcce to
501b0ab
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
a788f4e to
c09dfb5
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
Description
The mono item collector currently detects infinite recursive monomorphization
with a depth-based recursion limit. This can be too late for non-regular
recursive instantiations, where each recursive step produces much larger
instance arguments.
This PR starts checking the structural length of
instance.argsonce recursiveinstantiation is partway to the recursion limit. If the arguments already exceed
the type length limit, rustc emits the recursion limit diagnostic instead of continuing to process enormous types.
This keeps the diagnostic consistent with the error produced when the same code
is compiled with a smaller
#![recursion_limit].Related Issue
Fixes #156272.