Optimized Swift program crashes in swift_getTupleTypeMetadata

Originator:kristopherdjohnson
Number:rdar://19349390 Date Originated:26-Dec-2014 01:17 PM
Status:Closed Resolved:Fixed in Xcode 6.3 beta
Product:Developer Tools Product Version:6.1.1 (6A2008a)
Classification:Crash/Hang/Data Loss Reproducible:Always
 
Summary:
I have an Xcode project with a Cocoa framework and unit tests. When I run the unit tests with a Debug configuration or with a Release configuration with [-Onone] set for the Swift optimizer option, then it works. However, if I use the [-O] (fastest) optimizer option, then the unit test crashes with an EXC_BAD_ACCESS exception in swift_getTupleTypeMetadata.

The stack trace is:

- libswiftCore.dylib`std::__1::__function::__func<swift::swift_getTupleTypeMetadata::$_2, std::__1::allocator<swift::swift_getTupleTypeMetadata::$_2>, (anonymous namespace)::TupleCacheEntry* ()>::operator()()

- libswiftCore.dylib`swift_getTupleTypeMetadata2

- finchlib`finchlib.parse (my code)

If I change the Swift optimizer setting to -Onone, then the crash doesn't happen.

If I put all the source code into a single .swift file, then the crash doesn't happen.

Steps to Reproduce:
The attached Xcode project demonstrates the issue. The project has two schemes: finchlib_Optimized and finchlib_Unoptimized. The only difference between the schemes is that the former specifies the "Fastest [-O]" Swift optimizer option and the latter specifies "None [-Onone]"

Open the project in Xcode and select the finchlib_Unoptimized scheme and run unit tests. The test will pass.

Then select the finchlib_Optimized scheme and run unit tests. It will crash with EXC_BAD_ACCESS in swift_getTupleTypeMetadata.

Expected Results:
Optimized code should run like unoptimized code

Actual Results:
Optimized code crashes

Version:
6.1.1 (6A2008a)

Notes:
As noted in the description, the crash won't happen if all the code is in a single file. That is, if you remove all the parse<>() functions from my parse.swift file and put them in Interpreter.swift, then the code seems to run fine when optimized.

Configuration:
OS X Yosemite

Attachments:
'finchbasic_crash_swift_getTupleTypeMetadata.zip' was successfully uploaded.

(Available at https://dl.dropboxusercontent.com/u/1437706/finchbasic_crash_swift_getTupleTypeMetadata.zip)

Comments

Swift compiler engineer says optimizer can't specialize generics across files yet

via Twitter:

jckarter: @OldManKris The optimizer specializes generics within a file, which eliminates most runtime calls. It can't specialize across files yet.

By kristopherdjohnson at Dec. 27, 2014, 3:38 a.m. (reply...)

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!