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-6760] Compiler crash when using conditional conformance with generic func #49309

Closed
ffried opened this issue Jan 15, 2018 · 3 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself conditional conformances Feature → protocol → conformances: conditional conformances crash Bug: A crash, i.e., an abnormal termination of software

Comments

@ffried
Copy link
Contributor

ffried commented Jan 15, 2018

Previous ID SR-6760
Radar None
Original Reporter @ffried
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Apple Swift version 4.1-dev (LLVM b623e863a9, Clang 27a368e018, Swift edecd95)
Target: x86_64-apple-darwin17.3.0

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

md5: 2f8ebaa20aeb226faabfe7a7d718d201

Issue Description:

The following code crashes the Swift 4.1 compiler:

protocol Resolver {
   func value<T>(forKey key: String) throws -> T
}

extension Dictionary: Resolver where Key == String {
   func value<T>(forKey key: String) throws -> T {
      fatalError("Implementation is irrelevant...")
   }
}

It seems to me as if the generic method in the protocol causes some problems. The compiler crashes while type-checking the extension on Dictionary. When I don't have a generic func in the protocol, the generic extension works fine. Also, the implementation of the func seems irrelevant.

Output:

$> swift -v s41_unrelatedConditionalContainerConformance.swift 
Apple Swift version 4.1-dev (LLVM b623e863a9, Clang 27a368e018, Swift edecd95413)
Target: x86_64-apple-darwin17.3.0
/Library/Developer/Toolchains/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-01-11-a.xctoolchain/usr/bin/swift -frontend -interpret s41_unrelatedConditionalContainerConformance.swift -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -color-diagnostics -module-name s41_unrelatedConditionalContainerConformance
Assertion failed: (isa<X>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file /Users/buildnode/jenkins/workspace/oss-swift-4.1-package-osx/llvm/include/llvm/Support/Casting.h, line 255.
0  swift                    0x00000001111bdc18 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x00000001111bcb66 llvm::sys::RunSignalHandlers() + 86
2  swift                    0x00000001111be1de SignalHandler(int) + 366
3  libsystem_platform.dylib 0x00007fff6d8c6f5a _sigtramp + 26
4  libsystem_platform.dylib 0x000000011418d600 _sigtramp + 2794219200
5  libsystem_c.dylib        0x00007fff6d6f1312 abort + 127
6  libsystem_c.dylib        0x00007fff6d6b9368 basename_r + 0
7  swift                    0x000000010ee6cab2 swift::RequirementEnvironment::RequirementEnvironment(swift::DeclContext*, swift::GenericSignature*, swift::ProtocolDecl*, swift::ClassDecl*, swift::ProtocolConformance*) + 2450
8  swift                    0x000000010eb30a61 swift::matchWitness(swift::TypeChecker&, swift::ProtocolDecl*, swift::ProtocolConformance*, swift::DeclContext*, swift::ValueDecl*, swift::ValueDecl*) + 369
9  swift                    0x000000010eb317b0 swift::WitnessChecker::findBestWitness(swift::ValueDecl*, bool*, swift::NormalProtocolConformance*, llvm::SmallVectorImpl<swift::RequirementMatch>&, unsigned int&, unsigned int&, bool&) + 736
10 swift                    0x000000010eb37c53 swift::ConformanceChecker::resolveWitnessViaLookup(swift::ValueDecl*) + 675
11 swift                    0x000000010eb3451b swift::ConformanceChecker::checkConformance(swift::MissingWitnessDiagnosisKind) + 699
12 swift                    0x000000010eb32dde swift::MultiConformanceChecker::checkIndividualConformance(swift::NormalProtocolConformance*, bool) + 1390
13 swift                    0x000000010eb326b8 swift::MultiConformanceChecker::checkAllConformances() + 136
14 swift                    0x000000010eb3b9a8 swift::TypeChecker::checkConformancesInContext(swift::DeclContext*, swift::IterableDeclContext*) + 2952
15 swift                    0x000000010eb04d1c (anonymous namespace)::DeclChecker::visitExtensionDecl(swift::ExtensionDecl*) + 604
16 swift                    0x000000010eaf4371 (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 369
17 swift                    0x000000010eaf41f4 swift::TypeChecker::typeCheckDecl(swift::Decl*, bool) + 100
18 swift                    0x000000010eb8620a swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int) + 1738
19 swift                    0x000000010e808283 swift::CompilerInstance::parseAndTypeCheckMainFile(swift::PersistentParserState&, swift::DelayedParsingCallbacks*, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>) + 435
20 swift                    0x000000010e8070ef swift::CompilerInstance::parseAndCheckTypes(swift::CompilerInstance::ImplicitImports const&) + 767
21 swift                    0x000000010e806898 swift::CompilerInstance::performSema() + 520
22 swift                    0x000000010dd4ff05 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 1781
23 swift                    0x000000010dd4e84a swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3210
24 swift                    0x000000010dd0f5c0 main + 3360
25 libdyld.dylib            0x00007fff6d645115 start + 1
Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-01-11-a.xctoolchain/usr/bin/swift -frontend -interpret s41_unrelatedConditionalContainerConformance.swift -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -color-diagnostics -module-name s41_unrelatedConditionalContainerConformance 
1.  While type-checking extension of Dictionary<String, Value> at s41_unrelatedConditionalContainerConformance.swift:5:1
fish: 'swift -v s41_unrelatedCondition…' terminated by signal SIGABRT (Abort)
@ffried
Copy link
Contributor Author

ffried commented Jan 15, 2018

Is this maybe related to SR-6724?

@belkadan
Copy link
Contributor

Maybe? cc @DougGregor

@huonw
Copy link
Mannequin

huonw mannequin commented Apr 5, 2018

This no longer seems to crash, but I'm not sure of the specific patch that fixed it. Thanks for filing!

@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 conditional conformances Feature → protocol → conformances: conditional conformances crash Bug: A crash, i.e., an abnormal termination of software
Projects
None yet
Development

No branches or pull requests

3 participants