I've added the flag -Xfrontend -warn-long-expression-type-checking=50
to my Swift project to see what is taking too long. I've the following
expression:
let s: String = "1234"
let t: Int? = Int(s)
On the Int(s)
I get the warning Expression took 52ms to type-check (limit: 50ms)
. I'm just wondering why this takes more than 50ms to figure out since I specified all types.
If we try to run this initializer:
let t: Int? = Int(s, radix: 10)
we can see that the typecheck is a lot faster.
Looking at Int
initializers in the code completion, i can see there are a couple that take a String
, so my guess is the compiler is just trying to resolve one based on arguments and returning Int?
and that takes longer
What we did when we supplied radix was limit the number of possible choices, which is why that code typecheck is faster. That's purely my speculation, of course!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With