exponential compile times for simple function compositions
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the exponential compile-time growth with the nested Apply and drop example, then investigate how Rust handles early- and late-bound function generics. Done means the composition no longer causes exponential type growth or compilation time, with a regression test or benchmark covering the example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers, performance
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100