Nil coalescing operator exponential compile times
Originator: | keithbsmiley | ||
Number: | rdar://23695200 | Date Originated: | 30-Nov-2015 02:45 PM |
Status: | Open | Resolved: | |
Product: | Developer Tools | Product Version: | Swift 2.1 |
Classification: | Other Bug | Reproducible: | Always |
Summary: When using Swift's nil coalescing operator, compile time seems to be exponential based on the number of uses in a statement. Steps to reproduce: 1. Attempt to compile the attached example OR 1. Create a swift file with a single function that returns an optional 2. Chain ~10 calls to the function separated by `??` Expected results: The file is compiled in a reasonable amount of time Actual results: The compile takes an insane amount of time (on my 2014 rMPB the process was killed after 59 minutes with 9 calls to the function). Seemingly this compile time is exponential.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
case where the issue doesn't happen
If the right hand side of
??
is non-optional, there is no compile time issue:So the workaround is only needed when the right-hand side of the operator is an optional.
workaround
Issue is still happening a year later with Xcode 8.1 and Swift 3.
Assigning each intermediate value to a constant will workaround compile speed issue.
https://github.com/keith/radars/tree/master/NilCoalescingOperatorExponentialCompile