Skip to content

Exponential compile time with nested &dyn Fn type and lifetime #117624

@jruderman

Description

@jruderman

Found with a modified fuzz-rustc (variant of #104583 that is still slow)

Code

fn main() {}

fn q<'b>(_a: &'b u32) 
-> &dyn Fn(&dyn Fn(&dyn Fn(&dyn Fn(&dyn Fn(&dyn Fn(&dyn Fn(&dyn Fn(&dyn Fn(&dyn Fn(&dyn Fn(&dyn Fn(&dyn Fn(&'b u16)))))))))))))
{
    3_u8
}

Time complexity

Seems exponential:

Nesting level Time
9 0.4 sec
10 1.6 sec
11 6.7 sec
12 33 sec

Where it's slow

Version

rustc 1.75.0-nightly (a2f5f9691 2023-11-02)
binary: rustc
commit-hash: a2f5f9691b6ce64c1703feaf9363710dfd7a56cf
commit-date: 2023-11-02
host: x86_64-apple-darwin
release: 1.75.0-nightly
LLVM version: 17.0.4

@rustbot label +I-compiletime

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-compiletimeIssue: Problems and improvements with respect to compile times.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