Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-10656] Compiler crashes when using protocols with associated type #53056

Closed
swift-ci opened this issue May 10, 2019 · 2 comments
Closed

[SR-10656] Compiler crashes when using protocols with associated type #53056

swift-ci opened this issue May 10, 2019 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-10656
Radar rdar://problem/50664742
Original Reporter VitoMata (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Xcode 10.2.1 and Swift 5

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash
Assignee None
Priority Medium

md5: f6ab078a1d3f0a86b6399f6c50f3c745

relates to:

  • SR-8814 GenericSignatureBuilder should re-introduce conformance requirements when adding a superclass requirement

Issue Description:

I have a project in which I created several protocols that have an associatedType, implemented by some generic classes. In particular, there is a protocol with a method requirement and an associatedType, and this type conforms to another protocol that has another associatedType. A generic class conforms to the first protocol, assigning its generic parameter to the associatedType. When I try to build the project, the compiler crashes, giving a Segmentation fault error when trying to build the method I mentioned before but without explaining the reason.
Of course the code is more complex than this, but I managed to reproduce the issue in a short playground:

protocol Eatable {
  associatedtype Ingredient
}


protocol Person {
  associatedtype Food: Eatable
  
  func eat()
}


extension Person {
  func eat() {
    print("Eating")
  }
}


class MyFood: Eatable {
  typealias Ingredient = String
}


class MyPerson<T>: Person where T: Eatable {
  typealias Food = T
}


let c = MyPerson<MyFood>()

I'm not sure of what should be the issue in this code, but anyway the compiler should report it instead of crashing.

@belkadan
Copy link
Contributor

Weird. That code looks fine to me. What am I missing, @slavapestov?

@belkadan
Copy link
Contributor

With master:

Assertion failed: (!isInvalid()), function getRequirement, file /Volumes/Data/swift-public/swift/lib/AST/ProtocolConformance.cpp, line 77.
Stack dump:
0.  Program arguments: /Volumes/Data/swift-public/build/ninja/swift-macosx-x86_64/bin/swift -frontend -c -primary-file - -emit-module-path /var/folders/_d/dmrgv26d3bs6lkrks9z825_w0000gn/T/--3f3d9c.swiftmodule -emit-module-doc-path /var/folders/_d/dmrgv26d3bs6lkrks9z825_w0000gn/T/--3f3d9c.swiftdoc -target x86_64-apple-darwin18.6.0 -enable-objc-interop -sdk /Volumes/Data/Applications/Xcode10.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -g -enable-anonymous-context-mangled-names -color-diagnostics -module-name main -o /var/folders/_d/dmrgv26d3bs6lkrks9z825_w0000gn/T/--3f3d9c.o 
1.  Swift version 5.0-dev (LLVM f0b886e419, Swift b44d3490dc)
2.  While emitting IR SIL function "@$s4main8MyPersonCyqd__GAA0C0A2aEP3eatyyFTW".
 for 'eat()' (at <stdin>:14:3)
0  swift                    0x000000010818f415 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x000000010818e6d5 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x000000010818f9f8 SignalHandler(int) + 264
3  libsystem_platform.dylib 0x00007fff5b240b5d _sigtramp + 29
4  libsystem_platform.dylib 0x00007ffeeb53a120 _sigtramp + 2419037664
5  libsystem_c.dylib        0x00007fff5b0fa6a6 abort + 127
6  libsystem_c.dylib        0x00007fff5b0c320d basename_r + 0
7  swift                    0x000000010552428f swift::ProtocolConformanceRef::getRequirement() const + 63
8  swift                    0x0000000104774666 void llvm::function_ref<void (unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)>::callback_fn<swift::irgen::FulfillmentMap::searchNominalTypeMetadata(swift::irgen::IRGenModule&, swift::CanType, swift::MetadataState, unsigned int, swift::irgen::MetadataPath&&, swift::irgen::FulfillmentMap::InterestingKeysCallback const&)::$_1>(long, unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>) + 1142
9  swift                    0x000000010485100f swift::irgen::GenericTypeRequirements::enumerateFulfillments(swift::irgen::IRGenModule&, swift::SubstitutionMap, llvm::function_ref<void (unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)>) + 239
10 swift                    0x0000000104773765 swift::irgen::FulfillmentMap::searchNominalTypeMetadata(swift::irgen::IRGenModule&, swift::CanType, swift::MetadataState, unsigned int, swift::irgen::MetadataPath&&, swift::irgen::FulfillmentMap::InterestingKeysCallback const&) + 245
11 swift                    0x00000001047734b8 swift::irgen::FulfillmentMap::searchTypeMetadata(swift::irgen::IRGenModule&, swift::CanType, swift::irgen::IsExact_t, swift::MetadataState, unsigned int, swift::irgen::MetadataPath&&, swift::irgen::FulfillmentMap::InterestingKeysCallback const&) + 840
12 swift                    0x00000001048e7bc2 swift::irgen::LocalTypeDataCache::addAbstractForTypeMetadata(swift::irgen::IRGenFunction&, swift::CanType, swift::irgen::IsExact_t, swift::irgen::MetadataResponse) + 114
13 swift                    0x00000001048e7b10 swift::irgen::IRGenFunction::bindLocalTypeDataFromTypeMetadata(swift::CanType, swift::irgen::IsExact_t, llvm::Value*, swift::MetadataState) + 272
14 swift                    0x000000010484f7e2 swift::irgen::emitPolymorphicParameters(swift::irgen::IRGenFunction&, swift::SILFunction&, swift::irgen::Explosion&, swift::irgen::WitnessMetadata*, llvm::function_ref<llvm::Value* (unsigned int)> const&) + 786
15 swift                    0x00000001048b0e50 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 6032
16 swift                    0x00000001047bbd6b swift::irgen::IRGenerator::emitLazyDefinitions() + 1099

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software
Projects
None yet
Development

No branches or pull requests

3 participants