Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upWhere clauses increase compilation time and memory use dramatically. #26325
Comments
This comment has been minimized.
This comment has been minimized.
|
It actually has nothing to do with the presence/absence of a method, this compiles in a similar amount of time: https://play.rust-lang.org/?gist=d9c18a3c48d6c0584579&version=nightly It's the where clause, which, yes, is required in this case, but only due to the method returning |
Aatch
changed the title
The compiler requires more information and can take much longer to compile when implementing a trait with a member function vs. one without.
Where clauses increase compilation time and memory use dramatically.
Jun 16, 2015
Aatch
added
the
I-slow
label
Jun 16, 2015
This comment has been minimized.
This comment has been minimized.
|
@Aatch I didn't think to specifically test whether it was the added information in the The big question to me is why does the function having output type In the Similarly, here is another example that I've just stumbled across: trait Marker {}
struct Bob;
impl Marker for Bob {}
trait DoNothing {
type Output;
}
impl DoNothing for Bob {
type Output = Bob;
}
struct Dude<M: Marker>(M);
// Conflicting implementation with this line uncommented,
// Marker not implemented for <Bob as DoNothing>::Output error with it commented
impl Marker for <Bob as DoNothing>::Output {}
const b: Dude<<Bob as DoNothing>::Output> = Dude(Bob);
fn main() {
}The compiler is able to check that |
This comment has been minimized.
This comment has been minimized.
|
The Your last example is another (separate) bug. |
This comment has been minimized.
This comment has been minimized.
|
The final example no longer compiles. When you write programs in the type system the type checker has to execute said programs via type checking so it is expected that it would impact compilation performance. Overall we have a lot of room for optimization in the where clause implementation but I'm not sure if this issue has a directly actionable solution. |
This comment has been minimized.
This comment has been minimized.
|
This is really hurting us freaks who try to implement any type-level shenanigans – I believe this also affects compile times for others in the wild.
Currently having those where clauses in the code means compilation time is growing exponentially with the number of types used. I'm not completely privvy to the details of the type checker implementation, but I'm quite certain the search space could use a good bit of pruning. |
This comment has been minimized.
This comment has been minimized.
|
If Rust is anything like ML, then typechecking is EXP-complete and provably intractable in the worst case. However, this involves cases where types turn out to be exponentially large and so probably does not apply here. |
This comment has been minimized.
This comment has been minimized.
|
Adding the same where-clause to the |
DemiMarie
referenced this issue
Jan 4, 2017
Closed
Unsound projection when late-bound-region appears only in return type #32330
brson
added
the
T-compiler
label
Mar 23, 2017
nikomatsakis
added
the
A-traits
label
Mar 23, 2017
This comment has been minimized.
This comment has been minimized.
|
This hasn't been updated in a long time. Anybody have new numbers? |
brson
added
the
P-low
label
Mar 23, 2017
This comment has been minimized.
This comment has been minimized.
|
It seems fixed; the example that used to timeout and gobble ram now has no problems compiling. |
paholg commentedJun 15, 2015
When implementing a trait with a member function (vs. one without), the compiler requires more information and takes much longer to compile.
Consider the following two implementations of addition over Peano numbers as types:
First, using
std::ops::Add: http://is.gd/7tO1cKSecond, using a custom trait for addition,
AddPeano, that has only an associated type and no member functions: http://is.gd/byhqSnThe key difference is here:
Using
AddPeano,Using
std::ops::Add,Without the
whereclause, the compiler gives the errorIn
main()for both of those examples, theAddtraits are used for successive doubling until the number32is reached. UsingAddPeano, playpen finishes in moments, whereas usingAddit triggers playpen's timeout and fails to compile.I have had similar results locally ... even using up 8 GB of ram in the case of the
std::opsversion while the version without a function would compile virtually instantly.