Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
jruderman opened this issue Nov 6, 2023 · 2 comments
Open

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

jruderman opened this issue Nov 6, 2023 · 2 comments
Labels
C-bug Category: This is a bug. I-compiletime Issue: Problems and improvements with respect to compile times. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@jruderman
Copy link
Contributor

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

@jruderman jruderman added the C-bug Category: This is a bug. label Nov 6, 2023
@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. I-compiletime Issue: Problems and improvements with respect to compile times. labels Nov 6, 2023
@saethlin saethlin added T-types Relevant to the types team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Nov 18, 2023
@saethlin
Copy link
Member

Can you try with -Ztrait-solver=next? The new solver is definitely not done, but it has (I'm told accidentally) fixed a handful of other bugs that have been reported recently.

@jruderman
Copy link
Contributor Author

Using -Z trait-solver=next does not help, but instead makes it moderately slower. Tested with rustc 1.76.0-nightly (2f8d81f9d 2023-11-21).

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: This is a bug. I-compiletime Issue: Problems and improvements with respect to compile times. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants