Skip to content

exponential compile times for simple function compositions #119503

Open
@aliemjay

Description

Each additional statement let x = Apply(x, drop); surprisingly increases the compilation time by a factor of two:

struct Apply<X, F: Fn(X)>(X, F);

pub fn main() {
    let x = &();
    let x = Apply(x, drop);
    let x = Apply(x, drop);
    let x = Apply(x, drop);
    let x = Apply(x, drop);
    let x = Apply(x, drop);
    let x = Apply(x, drop);
    let x = Apply(x, drop);
    let x = Apply(x, drop);
    let x = Apply(x, drop);
    let x = Apply(x, drop);
    let x = Apply(x, drop);
    let x = Apply(x, drop);
    let x = Apply(x, drop);
    let x = Apply(x, drop);
    let x = Apply(x, drop);
    let x = Apply(x, drop);
    let _ = x;
}

The reason behind this exponential blowup is that the function drop has an "early-bound" generic parameter (drop::<_>), making the types of x grow exponentially with each level of nesting type X2 = Apply<X1, drop::<X1>>;

This should be fixed by removing the distinction between early- and late-bound function generics.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.I-compiletimeIssue: Problems and improvements with respect to compile times.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions