swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.57k stars 10.35k forks source link

[SR-1083] Compiler crash (associated types + generics) #43696

Closed swift-ci closed 7 years ago

swift-ci commented 8 years ago
Previous ID SR-1083
Radar None
Original Reporter maniacus_gd (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, CompilerCrash | |Assignee | @slavapestov | |Priority | Medium | md5: 4515febbcda2ecc0029895829892d939

Issue Description:

I apologise for not providing any insight to what might be the cause but this code crashes compiler reliably:
(compiler version: Apple Swift version 2.2 (swiftlang-703.0.18.1 clang-703.0.29) Target: x86_64-apple-macosx10.9)

protocol Meal {
    associatedtype Food
    func getFood() -> Food
}

protocol Animal {
    func feed<T: Meal>(food: T.Food)
}

struct SomeAnimal<T: Meal>: Animal {
    func feed<T : Meal>(food: T.Food) {}
}

Stacktrace is:

0  swift                    0x00000001092684eb llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 43
1  swift                    0x00000001092677d6 llvm::sys::RunSignalHandlers() + 70
2  swift                    0x0000000109268b4f SignalHandler(int) + 287
3  libsystem_platform.dylib 0x00007fff87ea552a _sigtramp + 26
4  libsystem_platform.dylib 0xfffffffffffffff8 _sigtramp + 2014685928
5  swift                    0x000000010776f22d std::__1::__function::__func<swift::Type::subst(swift::ModuleDecl*, llvm::DenseMap<swift::TypeBase*, swift::Type, llvm::DenseMapInfo<swift::TypeBase*>, llvm::detail::DenseMapPair<swift::TypeBase*, swift::Type> >&, swift::OptionSet<swift::SubstFlags, unsigned int>) const::$_6, std::__1::allocator<swift::Type::subst(swift::ModuleDecl*, llvm::DenseMap<swift::TypeBase*, swift::Type, llvm::DenseMapInfo<swift::TypeBase*>, llvm::detail::DenseMapPair<swift::TypeBase*, swift::Type> >&, swift::OptionSet<swift::SubstFlags, unsigned int>) const::$_6>, swift::Type (swift::Type)>::operator()(swift::Type&&) + 541
6  swift                    0x000000010776aad7 swift::Type::transform(std::__1::function<swift::Type (swift::Type)> const&) const + 55
7  swift                    0x000000010776b087 swift::Type::transform(std::__1::function<swift::Type (swift::Type)> const&) const + 1511
8  swift                    0x0000000107769b8e swift::PolymorphicFunctionType::substGenericArgs(swift::ModuleDecl*, llvm::ArrayRef<swift::Substitution>) + 142
9  swift                    0x00000001072039a0 swift::Lowering::SILGenFunction::emitProtocolWitness(swift::ProtocolConformance*, swift::SILDeclRef, swift::SILDeclRef, llvm::ArrayRef<swift::Substitution>, swift::Lowering::IsFreeFunctionWitness_t) + 624
10 swift                    0x00000001071c2c38 swift::Lowering::SILGenModule::emitProtocolWitness(swift::ProtocolConformance*, swift::SILLinkage, swift::SILDeclRef, swift::SILDeclRef, swift::Lowering::IsFreeFunctionWitness_t, llvm::ArrayRef<swift::Substitution>) + 3112
11 swift                    0x00000001071c4822 (anonymous namespace)::SILGenConformance::addMethod(swift::FuncDecl*, swift::ValueDecl*, llvm::ArrayRef<swift::Substitution>) + 242
12 swift                    0x00000001071c4499 swift::SILWitnessVisitor<(anonymous namespace)::SILGenConformance>::visitProtocolDecl(swift::ProtocolDecl*) + 1641
13 swift                    0x00000001071c1566 swift::Lowering::SILGenModule::getWitnessTable(swift::ProtocolConformance*) + 278
14 swift                    0x0000000107213901 (anonymous namespace)::SILGenType::emitType() + 1441
15 swift                    0x00000001072132ee swift::Lowering::SILGenModule::visitNominalTypeDecl(swift::NominalTypeDecl*) + 30
16 swift                    0x000000010719851b swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 731
17 swift                    0x0000000107199069 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool, bool) + 793
18 swift                    0x00000001071994d3 swift::performSILGeneration(swift::FileUnit&, swift::SILOptions&, llvm::Optional<unsigned int>, bool) + 115
19 swift                    0x0000000106fbd0d3 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&) + 12627
20 swift                    0x0000000106fb941d frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 2781
21 swift                    0x0000000106fb4e3c main + 1932
22 libdyld.dylib            0x00007fff9203f5ad start + 1
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file c3.swift -target x86_64-apple-macosx10.9 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -color-diagnostics -module-name c3 -o /var/folders/vz/rx8w_fgx1fsdqsxl5dz4f5bc0000gn/T/c3-206920.o
<unknown>:0: error: unable to execute command: Segmentation fault: 11
<unknown>:0: error: compile command failed due to signal (use -v to see invocation)
slavapestov commented 7 years ago

No longer crashes in Swift 3.1.