Compiler crash - relates to protocol and protocol extension


(Jasl) #1

Hi,

I found a piece of code that could made the compiler crash, It’s can reproduce on Xcode 7.2(7C68) with Apple Swift version 2.1.1 (swiftlang-700.1.101.15 clang-700.1.81) Target: x86_64-apple-darwin15.2.0

the code is simply like:

protocol FooType {
func bar(b: Int)
}

extension FooType {
func bar(a: Int, b: Int) {
}
}

struct Foo: FooType {

}

Even the function’s default implementation signature in protocol extension is different with its definition in protocol, it can compiling successful with no error, but when compiling Foo, the compiler will crash, the stack is like:

0 swift 0x0000000110dbcfbb llvm::sys::PrintStackTrace(__sFILE*) + 43
1 swift 0x0000000110dbd6fb SignalHandler(int) + 379
2 libsystem_platform.dylib 0x00007fff996feeaa _sigtramp + 26
3 libsystem_platform.dylib 0x00007f9fa3aa12a8 _sigtramp + 171582488
4 swift 0x000000010f083707 swift::SILWitnessVisitor<(anonymous namespace)::SILGenConformance>::visitProtocolDecl(swift::ProtocolDecl*) + 999
5 swift 0x000000010f080ee5 swift::Lowering::SILGenModule::getWitnessTable(swift::ProtocolConformance*) + 277
6 swift 0x000000010f0d05b0 (anonymous namespace)::SILGenType::emitType() + 1264
7 swift 0x000000010f0d12d1 SILGenExtension::visitNominalTypeDecl(swift::NominalTypeDecl*) + 33
8 swift 0x000000010f0d0d4b SILGenExtension::emitExtension(swift::ExtensionDecl*) + 59
9 swift 0x000000010f0d06f5 swift::Lowering::SILGenModule::visitExtensionDecl(swift::ExtensionDecl*) + 21
10 swift 0x000000010f058bdb swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 779
11 swift 0x000000010f059790 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool, bool) + 928
12 swift 0x000000010f059b3d swift::performSILGeneration(swift::FileUnit&, swift::SILOptions&, llvm::Optional<unsigned int>, bool) + 109
13 swift 0x000000010eead992 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&) + 11442
14 swift 0x000000010eeaaad3 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 2691
15 swift 0x000000010eea7154 main + 2324
16 libdyld.dylib 0x00007fff8c66c5ad start + 1

Please check.

thank you!

···

--
Jasl
Sent with Airmail


(Dmitri Gribenko) #2

Hi Jasl,

This example does not seem to crash in current master branch:

swiftc a.swift
a.swift:10:8: error: type 'Foo' does not conform to protocol 'FooType'
struct Foo: FooType {
       ^
a.swift:2:8: note: protocol requires function 'bar' with type '(Int) -> ()'
  func bar(b: Int)
       ^
a.swift:6:8: note: candidate has non-matching type '<Self> (Int, b: Int) ->
()' (aka '<τ_0_0> (Int, b: Int) -> ()')
  func bar(a: Int, b: Int) {
       ^

Dmitri

···

On Sun, Dec 20, 2015 at 4:42 AM, Jasl via swift-dev <swift-dev@swift.org> wrote:

Hi,

I found a piece of code that could made the compiler crash, It’s can
reproduce on Xcode 7.2(7C68) with Apple Swift version 2.1.1
(swiftlang-700.1.101.15 clang-700.1.81) Target: x86_64-apple-darwin15.2.0

the code is simply like:

protocol FooType {
  func bar(b: Int)
}

extension FooType {
  func bar(a: Int, b: Int) {
  }
}

struct Foo: FooType {

}

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/