Uploaded image for project: 'Swift'
  1. Swift
  2. SR-1939

Swift 3 crashes conforming class to protocol with generic type constraints

    XMLWordPrintable

    Details

      Description

      This example case cause crash of Swift 3 compiler.

      protocol P1 {
          associatedtype A1: Equatable
      }
      
      class C1<T, U: P1 where U.A1 == T>: P1 {
          typealias A1 = T
      }
      
      % /Users/banjun/Downloads/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift ~/Downloads/swift3crash-2.swift
      0  swift                    0x0000000108f0d34b llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 43
      1  swift                    0x0000000108f0c636 llvm::sys::RunSignalHandlers() + 70
      2  swift                    0x0000000108f0d99f SignalHandler(int) + 287
      3  libsystem_platform.dylib 0x00007fff8cc6f52a _sigtramp + 26
      4  libsystem_platform.dylib 0x00007fff59268df0 _sigtramp + 3428817120
      5  swift                    0x00000001069e8dab swift::irgen::emitAssociatedTypeWitnessTableRef(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::ArchetypeType>, swift::AssociatedTypeDecl*, llvm::Value*, swift::ProtocolDecl*) + 43
      6  swift                    0x00000001069ea9a9 llvm::Value* llvm::function_ref<llvm::Value* (unsigned int)>::callback_fn<swift::irgen::emitArchetypeWitnessTableRef(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::ArchetypeType>, swift::ProtocolDecl*)::$_0>(long, unsigned int) + 361
      7  swift                    0x0000000106a78450 swift::irgen::emitImpliedWitnessTableRef(swift::irgen::IRGenFunction&, llvm::ArrayRef<swift::irgen::ProtocolEntry>, swift::ProtocolDecl*, llvm::function_ref<llvm::Value* (unsigned int)> const&) + 240
      8  swift                    0x00000001069e8d72 swift::irgen::emitArchetypeWitnessTableRef(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::ArchetypeType>, swift::ProtocolDecl*) + 130
      9  swift                    0x0000000106a7b4df swift::SILWitnessVisitor<(anonymous namespace)::WitnessTableBuilder>::visitProtocolDecl(swift::ProtocolDecl*) + 4847
      10 swift                    0x0000000106a7613e swift::irgen::IRGenModule::emitSILWitnessTable(swift::SILWitnessTable*) + 414
      11 swift                    0x0000000106a138ad swift::irgen::IRGenerator::emitGlobalTopLevel() + 909
      12 swift                    0x0000000106aa097b performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, unsigned int) + 1131
      13 swift                    0x0000000106a9f83d swift::performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&) + 621
      14 swift                    0x00000001069dcc4a swift::RunImmediately(swift::CompilerInstance&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, swift::IRGenOptions&, swift::SILOptions const&) + 154
      15 swift                    0x00000001069ce2e4 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) + 15732
      16 swift                    0x00000001069c9619 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2873
      17 swift                    0x00000001069976c4 main + 2852
      18 libdyld.dylib            0x00007fff8e9955ad start + 1
      19 libdyld.dylib            0x000000000000000c start + 1902553696
      Stack dump:
      0.	Program arguments: /Users/banjun/Downloads/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret /Users/banjun/Downloads/swift3crash-2.swift -target x86_64-apple-macosx10.9 -enable-objc-interop -sdk /Users/banjun/Downloads/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -color-diagnostics -module-name main 
      zsh: segmentation fault   ~/Downloads/swift3crash-2.swift
      

      and locally built toolchain (on commit of https://github.com/apple/swift/pull/3093 ) prints error message before backtrace below:

      no relation found that declares conformance to target
      UNREACHABLE executed at /Users/banjun/projects/swift-source/swift/lib/IRGen/GenArchetype.cpp:140!
      

      For reproducing the issue, it is not required that `C1` and `U` have same protocol comformance to `P1`.
      i.e. using another protocol `P2` reproduce the same error message and crash.

      protocol P1 {
          associatedtype A1: Equatable
      }
      
      protocol P2 {
          associatedtype A2: Equatable
      }
      
      class C1<T, U: P1 where U.A1 == T>: P2 {
          typealias A2 = T
      }
      

      This issue might be related to SR-1426, but I'm not sure this duplicates.
      This issue does not reproduce with swift of Xcode 7.3.1.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                banjun BAN Jun
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: