3 ms·
In swift it's the type inference and operator overloading combination that causes long compile times. The operator + for example can have a lot of implementati
by woolvalley 8y ago
In swift it's the type inference and operator overloading combination that causes long compile times. The operator + for example can have a lot of implementations, and since types have to be inferred instead of being declared upfront, the combo creates slow compile times:
Ex, there is this infamous error in swift:
"Expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions"
for something like this:
matrix11 = (g(x23(x12+x32)+x13(-x22+x32)-(x12+x22)x33) * sin(a)) / (x13(x22x31-x21x32)+x12(-x23 * x31+x21 * x33)+x11 * (x23 * x32-x22 * x33))
C++ would have no problems compile that expression quickly.
Since rust and swift are similar languages, there is probably a similar issue.
- dman 8y agoInteresting, makes sense but not something I thought about (as a C++ user) before.
- eridius 8y ago> Since rust and swift are similar languages, there is probably a similar issue. Swift's type checker works quite differently than Rust's. I'm not aware of any exponential time complexity issues in type-checking Rust code.
- shepmaster 8y agoExponential performance cliff compiling associated types with equality constraints[1]. It was first opened in 2015 and was only recently addressed. Rust certainly has the potential for exponential times when performing large inference. [1]: https://github.com/rust-lang/rust/issues/22204 https://github.com/rust-lang/rust/issues/22204