Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inlined recursive type error can be dodged, leading to compiler overflowing its stack #98842

Closed
danielhenrymantilla opened this issue Jul 3, 2022 · 5 comments · Fixed by #122895
Labels
A-codegen Area: Code generation C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@danielhenrymantilla
Copy link
Contributor

danielhenrymantilla commented Jul 3, 2022

// If the inner `Foo` is named through an associated type, the "infinite size" error does not occur.
struct Foo(<&'static Foo as ::core::ops::Deref>::Target);
// But Rust will be unable to know whether `Foo` is sized or not,
// and it will infinitely recurse somewhere trying to figure out the size of this pointer (is my guess):
const _: *const Foo = 0 as _;

This happens on 1.0.0, stable, and nightly (haven't checked the others).

Error

image

On older toolchains, it succintly says:

thread rustc has overflowed its stack

On newer ones, it yields:

/opt/compiler-explorer/rust-nightly/bin/../lib/librustc_driver-82e4545cc4765a53.so(+0x519703)[0x7f215aa83703]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x143c0)[0x7f215a1ca3c0]
/opt/compiler-explorer/rust-nightly/bin/../lib/librustc_driver-82e4545cc4765a53.so(_RNvXNtNtNtCslVMVSX5WZa3_21rustc_trait_selection6traits5query19evaluate_obligationNtNtCskKqV9GDjbtg_11rustc_infer5infer9InferCtxtNtB2_12InferCtxtExt34predicate_must_hold_modulo_regions+0x26)[0x7f215c91e606]
/opt/compiler-explorer/rust-nightly/bin/../lib/librustc_driver-82e4545cc4765a53.so(_RNvNtCslVMVSX5WZa3_21rustc_trait_selection6traits39type_known_to_meet_bound_modulo_regions+0x122)[0x7f215c980332]
/opt/compiler-explorer/rust-nightly/bin/../lib/librustc_driver-82e4545cc4765a53.so(+0x2939da2)[0x7f215cea3da2]
/opt/compiler-explorer/rust-nightly/bin/../lib/librustc_driver-82e4545cc4765a53.so(+0x2939e5a)[0x7f215cea3e5a]

/opt/compiler-explorer/rust-nightly/bin/../lib/librustc_driver-82e4545cc4765a53.so(+0x2939e5a)[0x7f215cea3e5a]

Demo

@danielhenrymantilla danielhenrymantilla added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 3, 2022
@danielhenrymantilla
Copy link
Contributor Author

Note that if no *const Foo tries to make it to codegen then the:

struct Foo(<&'static Foo as ::core::ops::Deref>::Target);

part, alone, compiles Just Fine™ 😅

matthiaskrgr added a commit to matthiaskrgr/glacier that referenced this issue Jul 3, 2022
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jul 3, 2022
@Iron-E
Copy link

Iron-E commented Jul 3, 2022

Possibly related: #39959

@compiler-errors
Copy link
Member

This works for any associated type, right? Or just Deref::Target?

@danielhenrymantilla
Copy link
Contributor Author

Yeah any associated type of any trait; I just went for a dyn Deref to keep the snippet short thanks to the convenience of the already present impl, provided the associated type has : ?Sized (otherwise the Sized bound will cause errors for Foo)

@Alexendoo
Copy link
Member

No longer ICEs since #104293, I would guess #100386

@Alexendoo Alexendoo added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Nov 14, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 22, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 23, 2024
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Mar 24, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 24, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Mar 24, 2024
RenjiSann pushed a commit to RenjiSann/rust that referenced this issue Mar 25, 2024
RenjiSann pushed a commit to RenjiSann/rust that referenced this issue Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants