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

compiler diverges without error message when generic function has infinite instantiations #8727

Closed
carl-eastlund opened this issue Aug 24, 2013 · 6 comments
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@carl-eastlund
Copy link

The program below causes the compiler to diverge because instantiating generic requires an unbounded number of instantiations. Unfortunately, divergence provides no information to the user about what went wrong. Hopefully there is some way for the compiler to detect this scenario and report it.

// If the definition of Data is simpler, the compiler attempts to inline
// generic<T>, fails, and produces an error.
struct Data(~Option<Data>);

fn generic<T>( _ : ~[(Data,T)] ) {
    // The important detail is substituting (bool,T) for T on each
    // recursive call so the number of representations necessary to compile
    // this function is infinite.
    let rec : ~[(Data,(bool,T))] = ~[];
    generic( rec );
}

fn main () {
    // Use generic<T> at least once to trigger instantiation.
    let input : ~[(Data,())] = ~[];
    generic(input);
}
@huonw
Copy link
Member

huonw commented Aug 24, 2013

This looks like polymorphic recursion, and so is covered by #4287.

Closing, feel free to reopen if I've misinterpreted.

@huonw huonw closed this as completed Aug 24, 2013
@nikomatsakis
Copy link
Contributor

If there is no error message, this is a bug.

@nikomatsakis nikomatsakis reopened this Aug 24, 2013
@nikomatsakis
Copy link
Contributor

That is, a separate bug.

@alexcrichton
Copy link
Member

This now emits a reasonable error:

foo.rs:5:1: 11:2 error: reached the recursion limit during monomorphization

Flagging as needstest.

@thestinger
Copy link
Contributor

26398b4 fixed this and included a test for it, although I don't know if it covers enough.

@ghost
Copy link

ghost commented Aug 17, 2014

The original example from this issue is also already included in the test suite: https://github.com/rust-lang/rust/blob/776c17f476c4be92f6cfe4dab528886973ea8c03/src/test/compile-fail/issue-8727.rs so I think this can be closed.

@huonw huonw closed this as completed Aug 18, 2014
flip1995 pushed a commit to flip1995/rust that referenced this issue May 5, 2022
…dnet

Add `large_include_file` lint

changelog: Add [`large_include_file`] lint
closes rust-lang#7005
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants