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-11913] Protocol requirements implemented solely in an extension crash the compiler #54331

Closed
gwynne opened this issue Dec 6, 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

@gwynne
Copy link
Contributor

gwynne commented Dec 6, 2019

Previous ID SR-11913
Radar rdar://problem/57691182
Original Reporter @gwynne
Type Bug
Status Resolved
Resolution Duplicate

Attachment: Download

Environment

$ swift --version
Apple Swift version 5.1.2 (swiftlang-1100.0.278 clang-1100.0.33.9)
Target: x86_64-apple-darwin19.2.0
$ xcodebuild -version
Xcode 11.2.1
Build version 11B500

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

md5: 3a1a978742f96364708bff92cc51695f

duplicates:

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

Issue Description:

The following code will reliably crash swiftc with a failure to emit SIL:

public protocol Something {
    associatedtype McGuffin: BinaryInteger
    func whatever() throws -> [String]
}

extension Something {
    func whatever() throws -> [String] { [] }
}

class Thing<McGuffin: BinaryInteger>: Something {}

Notes:

  • The crash goes away if I change class to struct.

  • It also goes away if the func takes any parameters.

  • BinaryInteger and [String] are just the random types I pulled out of the air; changing them has no effect.

Hit this in real code when I tried to use an extension to provide implementations for KeyedDecodingContainer. Full crash trace attached. Initial crash info:

1.  While emitting IR SIL function "@$s3foo5ThingCyqd__GAA9SomethingA2aEP4doItSaySSGyKFTW".
 for 'doIt()' (at /foo/Sources/foo/main.swift:7:5)
0  swift                    0x000000010e3a9a13 PrintStackTraceSignalHandler(void*) + 51
1  swift                    0x000000010e3a91e6 SignalHandler(int) + 358
2  libsystem_platform.dylib 0x00007fff68d3f42d _sigtramp + 29
3  libsystem_platform.dylib 0x00007f9c4e823028 _sigtramp + 3853401112
4  swift                    0x000000010a062e61 swift::irgen::FulfillmentMap::searchWitnessTable(swift::irgen::IRGenModule&, swift::CanType, swift::ProtocolDecl*, unsigned int, swift::irgen::MetadataPath&&, swift::irgen::FulfillmentMap::InterestingKeysCallback const&, llvm::SmallPtrSetImpl<swift::ProtocolDecl*>*) + 65
5  swift                    0x000000010a062dd2 swift::irgen::FulfillmentMap::searchWitnessTable(swift::irgen::IRGenModule&, swift::CanType, swift::ProtocolDecl*, unsigned int, swift::irgen::MetadataPath&&, swift::irgen::FulfillmentMap::InterestingKeysCallback const&) + 450
6  swift                    0x000000010a062bd8 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>) + 1656
7  swift                    0x000000010a1c3b5f swift::irgen::GenericTypeRequirements::enumerateFulfillments(swift::irgen::IRGenModule&, swift::SubstitutionMap, llvm::function_ref<void (unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)>) + 335
8  swift                    0x000000010a061d9e swift::irgen::FulfillmentMap::searchNominalTypeMetadata(swift::irgen::IRGenModule&, swift::CanType, swift::MetadataState, unsigned int, swift::irgen::MetadataPath&&, swift::irgen::FulfillmentMap::InterestingKeysCallback const&) + 478
9  swift                    0x000000010a061b80 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&) + 912
10 swift                    0x000000010a274acd swift::irgen::IRGenFunction::bindLocalTypeDataFromTypeMetadata(swift::CanType, swift::irgen::IsExact_t, llvm::Value*, swift::MetadataState) + 317
11 swift                    0x000000010a1c1ab4 swift::irgen::emitPolymorphicParameters(swift::irgen::IRGenFunction&, swift::SILFunction&, swift::irgen::Explosion&, swift::irgen::WitnessMetadata*, llvm::function_ref<llvm::Value* (unsigned int)> const&) + 596
12 swift                    0x000000010a22bb25 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 6293
13 swift                    0x000000010a0dbe97 swift::irgen::IRGenerator::emitLazyDefinitions() + 9303
14 swift                    0x000000010a209710 performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, swift::SourceFile*, llvm::GlobalVariable**) + 1344
15 swift                    0x0000000109ff5e31 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 36673
16 swift                    0x0000000109fe96e4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6820
17 swift                    0x0000000109f76be3 main + 1219
18 libdyld.dylib            0x00007fff68b467fd start + 1
error: Segmentation fault: 11 (in target 'foo' from project 'foo')
@weissi
Copy link
Member

weissi commented Dec 6, 2019

@swift-ci create

@swift-ci
Copy link
Collaborator

Comment by William A Vabrinskas (JIRA)

Can confirm this issue still appears in Xcode 11.3.1

Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
Target: x86_64-apple-darwin19.3.0

switching the class type to struct fixes the issue.

@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

4 participants