Swift: Optional generic variable in NSObject subclass crashes compiler

Originator:joachimb
Number:rdar://18505295 Date Originated:30-Sep-2014 10:33 PM
Status:Closed Resolved:01-Jul-2015 10:18 AM (Xcode 7 beta)
Product:OS X DevTools Product Version:Xcode 6.1/6A1042b, OS X 10.10/14A343f
Classification:Crash Reproducible:Always
 
Summary:
class A<T> : NSObject {	
	var v : T? = nil // crash
}

Doesn't crash if I don't subclass NSObject.

Steps to Reproduce:
1. Subclass NSObject
2. Make the class generic with <T>
3. Add an optional ivar of the generic type


Expected Results:
4. Does not crash compiler


Actual Results:
4. Crashes compiler


Version:
Xcode 6.1/6A1042b
OS X 10.10/14A343f

Log output:

CompileSwift normal x86_64 /Users/nevyn/Desktop/RecursiveGenericCompilerCrash/RecursiveGenericCompilerCrash/main.swift
    cd /Users/nevyn/Desktop/RecursiveGenericCompilerCrash
    /Applications/Xcode61.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/nevyn/Desktop/RecursiveGenericCompilerCrash/RecursiveGenericCompilerCrash/main.swift -target x86_64-apple-macosx10.10 -target-cpu core2 -sdk /Applications/Xcode61.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -I /Users/nevyn/Library/Developer/Xcode/DerivedData/RecursiveGenericCompilerCrash-fxirwxyeyecaqsdcmvjsbomnrnhn/Build/Products/Debug -F /Users/nevyn/Library/Developer/Xcode/DerivedData/RecursiveGenericCompilerCrash-fxirwxyeyecaqsdcmvjsbomnrnhn/Build/Products/Debug -g -module-cache-path /Users/nevyn/Library/Developer/Xcode/DerivedData/ModuleCache -Xcc -I/Users/nevyn/Library/Developer/Xcode/DerivedData/RecursiveGenericCompilerCrash-fxirwxyeyecaqsdcmvjsbomnrnhn/Build/Intermediates/RecursiveGenericCompilerCrash.build/Debug/RecursiveGenericCompilerCrash.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/nevyn/Library/Developer/Xcode/DerivedData/RecursiveGenericCompilerCrash-fxirwxyeyecaqsdcmvjsbomnrnhn/Build/Intermediates/RecursiveGenericCompilerCrash.build/Debug/RecursiveGenericCompilerCrash.build/RecursiveGenericCompilerCrash-generated-files.hmap -Xcc -I/Users/nevyn/Library/Developer/Xcode/DerivedData/RecursiveGenericCompilerCrash-fxirwxyeyecaqsdcmvjsbomnrnhn/Build/Intermediates/RecursiveGenericCompilerCrash.build/Debug/RecursiveGenericCompilerCrash.build/RecursiveGenericCompilerCrash-own-target-headers.hmap -Xcc -I/Users/nevyn/Library/Developer/Xcode/DerivedData/RecursiveGenericCompilerCrash-fxirwxyeyecaqsdcmvjsbomnrnhn/Build/Intermediates/RecursiveGenericCompilerCrash.build/Debug/RecursiveGenericCompilerCrash.build/RecursiveGenericCompilerCrash-all-target-headers.hmap -Xcc -iquote -Xcc /Users/nevyn/Library/Developer/Xcode/DerivedData/RecursiveGenericCompilerCrash-fxirwxyeyecaqsdcmvjsbomnrnhn/Build/Intermediates/RecursiveGenericCompilerCrash.build/Debug/RecursiveGenericCompilerCrash.build/RecursiveGenericCompilerCrash-project-headers.hmap -Xcc -I/Users/nevyn/Library/Developer/Xcode/DerivedData/RecursiveGenericCompilerCrash-fxirwxyeyecaqsdcmvjsbomnrnhn/Build/Products/Debug/include -Xcc -I/Applications/Xcode61.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Xcc -I/Users/nevyn/Library/Developer/Xcode/DerivedData/RecursiveGenericCompilerCrash-fxirwxyeyecaqsdcmvjsbomnrnhn/Build/Intermediates/RecursiveGenericCompilerCrash.build/Debug/RecursiveGenericCompilerCrash.build/DerivedSources/x86_64 -Xcc -I/Users/nevyn/Library/Developer/Xcode/DerivedData/RecursiveGenericCompilerCrash-fxirwxyeyecaqsdcmvjsbomnrnhn/Build/Intermediates/RecursiveGenericCompilerCrash.build/Debug/RecursiveGenericCompilerCrash.build/DerivedSources -Xcc -DDEBUG=1 -emit-module-doc-path /Users/nevyn/Library/Developer/Xcode/DerivedData/RecursiveGenericCompilerCrash-fxirwxyeyecaqsdcmvjsbomnrnhn/Build/Intermediates/RecursiveGenericCompilerCrash.build/Debug/RecursiveGenericCompilerCrash.build/Objects-normal/x86_64/main~partial.swiftdoc -Onone -module-name RecursiveGenericCompilerCrash -emit-module-path /Users/nevyn/Library/Developer/Xcode/DerivedData/RecursiveGenericCompilerCrash-fxirwxyeyecaqsdcmvjsbomnrnhn/Build/Intermediates/RecursiveGenericCompilerCrash.build/Debug/RecursiveGenericCompilerCrash.build/Objects-normal/x86_64/main~partial.swiftmodule -serialize-diagnostics-path /Users/nevyn/Library/Developer/Xcode/DerivedData/RecursiveGenericCompilerCrash-fxirwxyeyecaqsdcmvjsbomnrnhn/Build/Intermediates/RecursiveGenericCompilerCrash.build/Debug/RecursiveGenericCompilerCrash.build/Objects-normal/x86_64/main.dia -emit-dependencies-path /Users/nevyn/Library/Developer/Xcode/DerivedData/RecursiveGenericCompilerCrash-fxirwxyeyecaqsdcmvjsbomnrnhn/Build/Intermediates/RecursiveGenericCompilerCrash.build/Debug/RecursiveGenericCompilerCrash.build/Objects-normal/x86_64/main.d -o /Users/nevyn/Library/Developer/Xcode/DerivedData/RecursiveGenericCompilerCrash-fxirwxyeyecaqsdcmvjsbomnrnhn/Build/Intermediates/RecursiveGenericCompilerCrash.build/Debug/RecursiveGenericCompilerCrash.build/Objects-normal/x86_64/main.o

0  swift                    0x000000010b0b3f68 llvm::sys::PrintStackTrace(__sFILE*) + 40
1  swift                    0x000000010b0b4454 SignalHandler(int) + 452
2  libsystem_platform.dylib 0x00007fff8adcdf1a _sigtramp + 26
3  libsystem_platform.dylib 0x00007fff55805b28 _sigtramp + 3399711784
4  swift                    0x000000010a44aa58 swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType) + 280
5  swift                    0x000000010a44b320 llvm::Value* swift::CanTypeVisitor<(anonymous namespace)::EmitTypeMetadataRefForLayout, llvm::Value*>::visit<>(swift::CanType) + 64
6  swift                    0x000000010a44b2d9 swift::irgen::IRGenFunction::emitTypeMetadataRefForLayout(swift::SILType) + 25
7  swift                    0x000000010a483528 (anonymous namespace)::OpaqueArchetypeTypeInfo::destroy(swift::irgen::IRGenFunction&, swift::irgen::Address, swift::SILType) const + 24
8  swift                    0x000000010a4bc2e2 swift::SILVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::ValueBase*) + 13266
9  swift                    0x000000010a4b82cb swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 9179
10 swift                    0x000000010a431810 swift::irgen::IRGenModule::emitGlobalTopLevel() + 208
11 swift                    0x000000010a4a4ffc performIRGeneration(swift::IRGenOptions&, swift::Module*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, unsigned int) + 1900
12 swift                    0x000000010a4a5a03 swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, unsigned int) + 51
13 swift                    0x000000010a3facf4 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 5444
14 swift                    0x000000010a3f806d main + 1677
15 libdyld.dylib            0x00007fff8bfb25c9 start + 1
Stack dump:
0.	Program arguments: /Applications/Xcode61.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/nevyn/Desktop/RecursiveGenericCompilerCrash/RecursiveGenericCompilerCrash/main.swift -target x86_64-apple-macosx10.10 -target-cpu core2 -sdk /Applications/Xcode61.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -I /Users/nevyn/Library/Developer/Xcode/DerivedData/RecursiveGenericCompilerCrash-fxirwxyeyecaqsdcmvjsbomnrnhn/Build/Products/Debug -F /Users/nevyn/Library/Developer/Xcode/DerivedData/RecursiveGenericCompilerCrash-fxirwxyeyecaqsdcmvjsbomnrnhn/Build/Products/Debug -g -module-cache-path /Users/nevyn/Library/Developer/Xcode/DerivedData/ModuleCache -Xcc -I/Users/nevyn/Library/Developer/Xcode/DerivedData/RecursiveGenericCompilerCrash-fxirwxyeyecaqsdcmvjsbomnrnhn/Build/Intermediates/RecursiveGenericCompilerCrash.build/Debug/RecursiveGenericCompilerCrash.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/nevyn/Library/Developer/Xcode/DerivedData/RecursiveGenericCompilerCrash-fxirwxyeyecaqsdcmvjsbomnrnhn/Build/Intermediates/RecursiveGenericCompilerCrash.build/Debug/RecursiveGenericCompilerCrash.build/RecursiveGenericCompilerCrash-generated-files.hmap -Xcc -I/Users/nevyn/Library/Developer/Xcode/DerivedData/RecursiveGenericCompilerCrash-fxirwxyeyecaqsdcmvjsbomnrnhn/Build/Intermediates/RecursiveGenericCompilerCrash.build/Debug/RecursiveGenericCompilerCrash.build/RecursiveGenericCompilerCrash-own-target-headers.hmap -Xcc -I/Users/nevyn/Library/Developer/Xcode/DerivedData/RecursiveGenericCompilerCrash-fxirwxyeyecaqsdcmvjsbomnrnhn/Build/Intermediates/RecursiveGenericCompilerCrash.build/Debug/RecursiveGenericCompilerCrash.build/RecursiveGenericCompilerCrash-all-target-headers.hmap -Xcc -iquote -Xcc /Users/nevyn/Library/Developer/Xcode/DerivedData/RecursiveGenericCompilerCrash-fxirwxyeyecaqsdcmvjsbomnrnhn/Build/Intermediates/RecursiveGenericCompilerCrash.build/Debug/RecursiveGenericCompilerCrash.build/RecursiveGenericCompilerCrash-project-headers.hmap -Xcc -I/Users/nevyn/Library/Developer/Xcode/DerivedData/RecursiveGenericCompilerCrash-fxirwxyeyecaqsdcmvjsbomnrnhn/Build/Products/Debug/include -Xcc -I/Applications/Xcode61.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Xcc -I/Users/nevyn/Library/Developer/Xcode/DerivedData/RecursiveGenericCompilerCrash-fxirwxyeyecaqsdcmvjsbomnrnhn/Build/Intermediates/RecursiveGenericCompilerCrash.build/Debug/RecursiveGenericCompilerCrash.build/DerivedSources/x86_64 -Xcc -I/Users/nevyn/Library/Developer/Xcode/DerivedData/RecursiveGenericCompilerCrash-fxirwxyeyecaqsdcmvjsbomnrnhn/Build/Intermediates/RecursiveGenericCompilerCrash.build/Debug/RecursiveGenericCompilerCrash.build/DerivedSources -Xcc -DDEBUG=1 -emit-module-doc-path /Users/nevyn/Library/Developer/Xcode/DerivedData/RecursiveGenericCompilerCrash-fxirwxyeyecaqsdcmvjsbomnrnhn/Build/Intermediates/RecursiveGenericCompilerCrash.build/Debug/RecursiveGenericCompilerCrash.build/Objects-normal/x86_64/main~partial.swiftdoc -Onone -module-name RecursiveGenericCompilerCrash -emit-module-path /Users/nevyn/Library/Developer/Xcode/DerivedData/RecursiveGenericCompilerCrash-fxirwxyeyecaqsdcmvjsbomnrnhn/Build/Intermediates/RecursiveGenericCompilerCrash.build/Debug/RecursiveGenericCompilerCrash.build/Objects-normal/x86_64/main~partial.swiftmodule -serialize-diagnostics-path /Users/nevyn/Library/Developer/Xcode/DerivedData/RecursiveGenericCompilerCrash-fxirwxyeyecaqsdcmvjsbomnrnhn/Build/Intermediates/RecursiveGenericCompilerCrash.build/Debug/RecursiveGenericCompilerCrash.build/Objects-normal/x86_64/main.dia -emit-dependencies-path /Users/nevyn/Library/Developer/Xcode/DerivedData/RecursiveGenericCompilerCrash-fxirwxyeyecaqsdcmvjsbomnrnhn/Build/Intermediates/RecursiveGenericCompilerCrash.build/Debug/RecursiveGenericCompilerCrash.build/Objects-normal/x86_64/main.d -o /Users/nevyn/Library/Developer/Xcode/DerivedData/RecursiveGenericCompilerCrash-fxirwxyeyecaqsdcmvjsbomnrnhn/Build/Intermediates/RecursiveGenericCompilerCrash.build/Debug/RecursiveGenericCompilerCrash.build/Objects-normal/x86_64/main.o 
1.	While emitting IR SIL function @_TToFC29RecursiveGenericCompilerCrash1AE for 'deinit' at /Users/nevyn/Desktop/RecursiveGenericCompilerCrash/RecursiveGenericCompilerCrash/main.swift:11:7

Comments

Fixed in Xcode 7

Apple Developer Relations 01-Jul-2015 10:18 AM

We believe this issue has been addressed in the latest Xcode 7 beta. This release includes the Xcode IDE, Swift 2 compiler, Instruments, Simulator, and latest SDKs for OS X, iOS, and watchOS.

Please test with this release. If you still have issues, please provide any relevant logs or information that could help us investigate.

Xcode 7 beta https://developer.apple.com/xcode/downloads/


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!