简体   繁体   中英

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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM