let result: Double = -(1 + 1) + -(1 + 1) - 1
Swift 6 takes 6.2 seconds to compile this one line.That's crazy...
Swift programmers: do you face this kind of issues often?
let result: Double = -(1 + 1) + -(1 + 1) - 1
Swift 6 takes 6.2 seconds to compile this one line.That's crazy...
Swift programmers: do you face this kind of issues often?
OCaml does have +. for floats to make type checking easier, but Standard ML does not. Also, if Swift has operator overloading, why isn't it instantly clear that the RHS is an int, which can be assigned to a double?
This just looks like a performance bug in the type checker, and nothing that is inherent to HM.
Am I seeing this correctly? Is HM + polymorphic literals + implicit type conversion the cause of Swift’s exploding compile time in such cases?
In C++ terms, if you have int& operator+(const int&x, const int& y) then (1 + 1) is not ambiguous and can be selected fast. Same for unary minus etc.
The Swift devs should then blog about this example and explain step by step what is going on. If the literal "1" can be both an int and a float, that of course would be insane. Is that what you meant by "polymorphic literals"?
let result:Double = -(1 + 1) + -(1 + 1) - 1 // 10.829s
let result:Double = -(1 + 1) + -(1 + 1) // 1.724s
let result:Double = (1 + 1) + (1 + 1) - 1 // 1.721s
let result:Double = -(1 + 1) - 1 // 0.763s
let result:Int = -(1 + 1) + -(1 + 1) - 1 // 0.571s
let result:Double = -(1 + 1) + -(1 + 1) + 1
//error: the compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressionsThen there's this fucker for whenever you make a programming error involving types:
>The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions
Basically, your code has a type error somewhere in it, and you need to figure out where and how it's wrong.
Xcode is still awful too.
So every edit you need to take a minute to see how it renders?
In my personal experience, no. That doesn't mean it's not a weakness of the language, but in practice you very rarely write a real expression with more than one or two type inferences in it. And when you do, you can just add explicit typing.
let x: Double = 2
let y = 5 / x
y is a Double with a value of 2.5. let x: Int = 2
let y = 5 / x
y is an Int with a value of 2. let x: Int = 2
let y: Double = 5 / x
Code doesn't compile.