exponential compile times for simple function compositions #119503
Open
Description
opened on Jan 1, 2024
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