2 Replies
      Latest reply on Sep 7, 2015 8:50 PM by jp.rider
      jp.rider Level 1 Level 1 (0 points)

        I just submitted a bug request about this (22470476), but I was wondering if anyone else has experienced this or has any solutions.

         

        import Foundation
        func test( t : FromJSON) {
            FromJSON.fromJSON()
        }
        protocol FromJSON {
            static func fromJSON () -> FromJSON
        }
        

         

        Here is a copy of the bug report:

         

        Summary:

        The swift compiler crashes with a segmentation fault under certain conditions. I believe I have attached a minified example. This seems to occur when code calls a static protocol function.


        Steps to Reproduce:

        1. Install XCode 6.4 (6E35b)

        2. Create a new Swift project

        3. Add the attached (P.swift) file to the project

        4. Build the project (command-b)

         

        Expected Results:

        Swift compiler should compile project or produce error messages.

         

        Actual Results:

        Swift compiler crashes with 'Segmentation fault: 11'. Here is the log:


        CompileSwift normal x86_64 /Users/james/Desktop/Test/Test/P.swift cd /Users/james/Desktop/Test /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/james/Desktop/Test/Test/P.swift /Users/james/Desktop/Test/Test/ViewController.swift /Users/james/Desktop/Test/Test/AppDelegate.swift -target x86_64-apple-ios8.4 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.4.sdk -I /Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Products/Debug-iphonesimulator -F /Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Products/Debug-iphonesimulator -g -module-cache-path /Users/james/Library/Developer/Xcode/DerivedData/ModuleCache -serialize-debugging-options -Xcc -I/Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Intermediates/Test.build/Debug-iphonesimulator/Test.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Intermediates/Test.build/Debug-iphonesimulator/Test.build/Test-generated-files.hmap -Xcc -I/Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Intermediates/Test.build/Debug-iphonesimulator/Test.build/Test-own-target-headers.hmap -Xcc -I/Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Intermediates/Test.build/Debug-iphonesimulator/Test.build/Test-all-target-headers.hmap -Xcc -iquote -Xcc /Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Intermediates/Test.build/Debug-iphonesimulator/Test.build/Test-project-headers.hmap -Xcc -I/Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Products/Debug-iphonesimulator/include -Xcc -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Xcc -I/Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Intermediates/Test.build/Debug-iphonesimulator/Test.build/DerivedSources/x86_64 -Xcc -I/Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Intermediates/Test.build/Debug-iphonesimulator/Test.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/Users/james/Desktop/Test -emit-module-doc-path /Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Intermediates/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/x86_64/P~partial.swiftdoc -Onone -module-name Test -emit-module-path /Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Intermediates/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/x86_64/P~partial.swiftmodule -serialize-diagnostics-path /Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Intermediates/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/x86_64/P.dia -emit-dependencies-path /Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Intermediates/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/x86_64/P.d -emit-reference-dependencies-path /Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Intermediates/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/x86_64/P.swiftdeps -o /Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Intermediates/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/x86_64/P.o 0 swift 0x0000000108e7d2b8 llvm::sys::PrintStackTrace(__sFILE*) + 40 1 swift 0x0000000108e7d794 SignalHandler(int) + 452 2 libsystem_platform.dylib 0x00007fff99aaef1a _sigtramp + 26 3 swift 0x000000010a23af51 llvm::AttributeSet::get(llvm::LLVMContext&, llvm::ArrayRef<std::__1::pair<unsigned int, llvm::Attribute> >) + 449 4 swift 0x0000000108801306 getProtocolWitnessTable(swift::irgen::IRGenFunction&, swift::CanType, swift::irgen::TypeInfo const&, (anonymous namespace)::ProtocolEntry, swift::ProtocolConformance*) + 70 5 swift 0x0000000108801211 swift::irgen::emitWitnessMethodValue(swift::irgen::IRGenFunction&, swift::CanType, swift::SILDeclRef, swift::ProtocolConformance*, swift::irgen::Explosion&) + 113 6 swift 0x00000001088454be swift::SILVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::ValueBase*) + 17678 7 swift 0x000000010884039d swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 9901 8 swift 0x00000001087aaf4f swift::irgen::IRGenModule::emitGlobalTopLevel() + 159 9 swift 0x000000010882ac59 performIRGeneration(swift::IRGenOptions&, swift::Module*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, unsigned int) + 2121 10 swift 0x000000010882b693 swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, unsigned int) + 51 11 swift 0x0000000108767087 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 6647 12 swift 0x00000001087654e6 main + 1814 13 libdyld.dylib 0x00007fff9910d5c9 start + 1 Stack dump: 0. Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/james/Desktop/Test/Test/P.swift /Users/james/Desktop/Test/Test/ViewController.swift /Users/james/Desktop/Test/Test/AppDelegate.swift -target x86_64-apple-ios8.4 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.4.sdk -I /Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Products/Debug-iphonesimulator -F /Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Products/Debug-iphonesimulator -g -module-cache-path /Users/james/Library/Developer/Xcode/DerivedData/ModuleCache -serialize-debugging-options -Xcc -I/Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Intermediates/Test.build/Debug-iphonesimulator/Test.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Intermediates/Test.build/Debug-iphonesimulator/Test.build/Test-generated-files.hmap -Xcc -I/Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Intermediates/Test.build/Debug-iphonesimulator/Test.build/Test-own-target-headers.hmap -Xcc -I/Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Intermediates/Test.build/Debug-iphonesimulator/Test.build/Test-all-target-headers.hmap -Xcc -iquote -Xcc /Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Intermediates/Test.build/Debug-iphonesimulator/Test.build/Test-project-headers.hmap -Xcc -I/Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Products/Debug-iphonesimulator/include -Xcc -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Xcc -I/Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Intermediates/Test.build/Debug-iphonesimulator/Test.build/DerivedSources/x86_64 -Xcc -I/Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Intermediates/Test.build/Debug-iphonesimulator/Test.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/Users/james/Desktop/Test -emit-module-doc-path /Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Intermediates/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/x86_64/P~partial.swiftdoc -Onone -module-name Test -emit-module-path /Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Intermediates/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/x86_64/P~partial.swiftmodule -serialize-diagnostics-path /Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Intermediates/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/x86_64/P.dia -emit-dependencies-path /Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Intermediates/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/x86_64/P.d -emit-reference-dependencies-path /Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Intermediates/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/x86_64/P.swiftdeps -o /Users/james/Library/Developer/Xcode/DerivedData/Test-ebqoiqmakfhfhrbooasmjvhamzkz/Build/Intermediates/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/x86_64/P.o 1. While emitting IR SIL function @_TF4Test4testFPS_8FromJSON_T_ for 'test' at /Users/james/Desktop/Test/Test/P.swift:11:1

        • Re: Swift compiler crashes when calling a protocol's static function
          Jens Level 3 Level 3 (230 points)

          In latest beta (Xcode 7 beta 6) there's this compile time error instead:

          import Foundation
          func test( t : FromJSON) {
              FromJSON.fromJSON() // Error: Static member 'fromJSON' cannot be used on instance of type 'FromJSON.Protocol'
          }
          protocol FromJSON {
              static func fromJSON () -> FromJSON
          }
          
          

           

          Not sure what you want, but for example this will compile (in latest beta):

          func test( t : FromJSON) {
              t.dynamicType.fromJSON()
          }
          protocol FromJSON {
              static func fromJSON () -> FromJSON
          }
          

           

          And so will this:

          func test<T: FromJSON>(t : T) {
              T.fromJSON()
          }
          protocol FromJSON {
              static func fromJSON () -> FromJSON
          }