Skip to content

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

Closed
@carl-eastlund

Description

@carl-eastlund

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions