Haagenti
Haagenti

Reputation: 8144

Swift type-check takes long time

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.

Upvotes: 8

Views: 3869

Answers (1)

zaitsman
zaitsman

Reputation: 9499

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!

Upvotes: 1

Related Questions