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

Self-referential templated trait overflows the stack #15477

Closed
lee-b opened this issue Jul 6, 2014 · 6 comments
Closed

Self-referential templated trait overflows the stack #15477

lee-b opened this issue Jul 6, 2014 · 6 comments
Labels
A-type-system Area: Type system I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@lee-b
Copy link

lee-b commented Jul 6, 2014

Compiling the following:

trait Chromosome<C: Chromosome> {
    fn random() -> C;
}

Causes the following output:

task 'rustc' has overflowed its stack
Illegal instruction

The code was an unintentional typo, and probably isn't valid, but I think the compiler should handle this a lot better, as there's no indication of what the problem is, or where it lies. In large compilation units with complex templating etc., that could be a big roadblock.

@pnkfelix
Copy link
Member

pnkfelix commented Jul 6, 2014

Indeed, even a "corrected" version (in that I provided an argument for the type param in the trait in the bound) still overflows the stack:

#![crate_type="lib"]
trait Chromosome<C: Chromosome<C>> {
    fn random() -> C;
}

(I just note this because while I agree that the original example was not valid, I believe the variant I have written is valid and should be accepted by the compiler. But we can wait for post 1.0 for it to be accepted. For 1.0 itself, I would be okay with rejecting this program; we should just do it properly.)

Make sure that we test this variant too:

#![crate_type="lib"]
trait X<C: Y<C>> {}
trait Y<C: X<C>> {}

@huonw
Copy link
Member

huonw commented Jul 6, 2014

Almost certainly related to #8762, #9095, #12511 and/or #12644. (Don't have time to dig through them right now, sorry for the link dump.)

@pnkfelix
Copy link
Member

pnkfelix commented Jul 6, 2014

hmm, indeed, from reading #8762, I guess the consensus tends to be that this code should not be accepted, though for some reason I had thought that the variant I had written with proper instantaations was sound. Perhaps just not compatible with our monomorphizaton model, though I would have thought that for trait definitions this would still be fine.

@pnkfelix
Copy link
Member

pnkfelix commented Jul 6, 2014

Note that I regard this issue and likewise #8762 (trait X<C: X<C>> {}) as being very different from #12511 (trait t : t {}). For some reason in my mind the former are entirely acceptable definitions while the latter is nonsense, (again, that is in my head).

@steveklabnik
Copy link
Member

This still overflows the stack today.

@jdm jdm added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jan 23, 2015
@tamird
Copy link
Contributor

tamird commented Apr 21, 2015

No longer reproducible.

bors added a commit to rust-lang-ci/rust that referenced this issue Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

6 participants