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-12072] Compiler crashes when protocols have associated types with lower bounds #54508

Closed
swift-ci opened this issue Jan 23, 2020 · 10 comments
Assignees
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 regression swift 5.1 type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-12072
Radar rdar://58941114
Original Reporter koher (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)

Target: x86_64-apple-darwin18.7.0

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 5.1Regression, CompilerCrash, TypeChecker
Assignee @CodaFi
Priority Medium

md5: d2311401b679cc6e44d3366d1b6415f3

Issue Description:

The following code makes the compiler crash.

class C1 {}
class C2: C1 {}

protocol Foo {
    associatedtype X where C2: X
}
@theblixguy
Copy link
Collaborator

Stack trace on master:

Assertion failed: (isa<X>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file /Users/suyashsrijan/Documents/swift-src/llvm/include/llvm/Support/Casting.h, line 264.
Stack dump:
0.  Program arguments: ./swiftc -frontend -typecheck /Users/suyashsrijan/Desktop/test.swift -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
1.  Swift version 5.2-dev
2.  While evaluating request TypeCheckSourceFileRequest(source_file "/Users/suyashsrijan/Desktop/test.swift", 0)
3.  While type-checking 'Foo' (at /Users/suyashsrijan/Desktop/test.swift:4:1)
4.  While evaluating request RequirementSignatureRequest(test.(file).Foo@/Users/suyashsrijan/Desktop/test.swift:4:10)
0  swiftc                   0x0000000110d356c5 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swiftc                   0x0000000110d348d5 llvm::sys::RunSignalHandlers() + 85
2  swiftc                   0x0000000110d35cb6 SignalHandler(int) + 278
3  libsystem_platform.dylib 0x00007fff682fab1d _sigtramp + 29
4  libdyld.dylib            0x00007fff680ea065 dyldGlobalLockRelease() + 0
5  libsystem_c.dylib        0x00007fff681d0a1c abort + 120
6  libsystem_c.dylib        0x00007fff681cfcd6 err + 0
7  swiftc                   0x0000000111214113 formProtocolRelativeType(swift::ProtocolDecl*, swift::Type, swift::Type) (.cold.2) + 35
8  swiftc                   0x000000010dff7ba6 formProtocolRelativeType(swift::ProtocolDecl*, swift::Type, swift::Type) + 182
9  swiftc                   0x000000010dff7a26 swift::GenericSignatureBuilder::FloatingRequirementSource::getSource(swift::GenericSignatureBuilder&, swift::Type) const + 182
10 swiftc                   0x000000010e007f81 swift::GenericSignatureBuilder::addTypeRequirement(llvm::PointerUnion<swift::GenericSignatureBuilder::PotentialArchetype*, swift::Type>, llvm::PointerUnion<swift::GenericSignatureBuilder::PotentialArchetype*, swift::Type>, swift::GenericSignatureBuilder::FloatingRequirementSource, swift::GenericSignatureBuilder::UnresolvedHandlingKind, swift::ModuleDecl*) + 1793
11 swiftc                   0x000000010dffb40d swift::GenericSignatureBuilder::addRequirement(swift::Requirement const&, swift::RequirementRepr const*, swift::GenericSignatureBuilder::FloatingRequirementSource, swift::SubstitutionMap const*, swift::ModuleDecl*) + 909
12 swiftc                   0x000000010e020b28 bool llvm::function_ref<bool (swift::Requirement, swift::RequirementRepr*)>::callback_fn<swift::GenericSignatureBuilder::expandConformanceRequirement(swift::GenericSignatureBuilder::ResolvedType, swift::ProtocolDecl*, swift::GenericSignatureBuilder::RequirementSource const*, bool)::$_27>(long, swift::Requirement, swift::RequirementRepr*) + 184
13 swiftc                   0x000000010e0955f3 swift::WhereClauseOwner::visitRequirements(swift::TypeResolutionStage, llvm::function_ref<bool (swift::Requirement, swift::RequirementRepr*)>) const && + 419
14 swiftc                   0x000000010e0046d4 swift::GenericSignatureBuilder::expandConformanceRequirement(swift::GenericSignatureBuilder::ResolvedType, swift::ProtocolDecl*, swift::GenericSignatureBuilder::RequirementSource const*, bool) + 1124
15 swiftc                   0x000000010e007b7e swift::GenericSignatureBuilder::addTypeRequirement(llvm::PointerUnion<swift::GenericSignatureBuilder::PotentialArchetype*, swift::Type>, llvm::PointerUnion<swift::GenericSignatureBuilder::PotentialArchetype*, swift::Type>, swift::GenericSignatureBuilder::FloatingRequirementSource, swift::GenericSignatureBuilder::UnresolvedHandlingKind, swift::ModuleDecl*) + 766
16 swiftc                   0x000000010dffb40d swift::GenericSignatureBuilder::addRequirement(swift::Requirement const&, swift::RequirementRepr const*, swift::GenericSignatureBuilder::FloatingRequirementSource, swift::SubstitutionMap const*, swift::ModuleDecl*) + 909
17 swiftc                   0x000000010db9a588 swift::RequirementSignatureRequest::evaluate(swift::Evaluator&, swift::ProtocolDecl*) const + 968
18 swiftc                   0x000000010dc207f1 swift::SimpleRequest<swift::RequirementSignatureRequest, llvm::ArrayRef<swift::Requirement> (swift::ProtocolDecl*), (swift::CacheKind)2>::evaluateRequest(swift::RequirementSignatureRequest const&, swift::Evaluator&) + 17
19 swiftc                   0x000000010df9bd0f llvm::Expected<swift::RequirementSignatureRequest::OutputType> swift::Evaluator::getResultUncached<swift::RequirementSignatureRequest>(swift::RequirementSignatureRequest const&) + 463
20 swiftc                   0x000000010df9ba85 llvm::Expected<swift::RequirementSignatureRequest::OutputType> swift::Evaluator::getResultCached<swift::RequirementSignatureRequest, (void*)0>(swift::RequirementSignatureRequest const&) + 85
21 swiftc                   0x000000010df56918 swift::RequirementSignatureRequest::OutputType swift::evaluateOrDefault<swift::RequirementSignatureRequest>(swift::Evaluator&, swift::RequirementSignatureRequest, swift::RequirementSignatureRequest::OutputType) + 40
22 swiftc                   0x000000010dbc03aa (anonymous namespace)::DeclChecker::visitProtocolDecl(swift::ProtocolDecl*) + 2122
23 swiftc                   0x000000010dbbaf53 (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 2435
24 swiftc                   0x000000010dbba5bf swift::TypeChecker::typeCheckDecl(swift::Decl*) + 63
25 swiftc                   0x000000010dc51118 swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*, unsigned int) const + 408
26 swiftc                   0x000000010dc20b55 swift::SimpleRequest<swift::TypeCheckSourceFileRequest, bool (swift::SourceFile*, unsigned int), (swift::CacheKind)2>::evaluateRequest(swift::TypeCheckSourceFileRequest const&, swift::Evaluator&) + 21
27 swiftc                   0x000000010dc5325b llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckSourceFileRequest>(swift::TypeCheckSourceFileRequest const&) + 459
28 swiftc                   0x000000010dc52fb8 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultCached<swift::TypeCheckSourceFileRequest, (void*)0>(swift::TypeCheckSourceFileRequest const&) + 56
29 swiftc                   0x000000010dc50e75 swift::TypeCheckSourceFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckSourceFileRequest>(swift::Evaluator&, swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType) + 37
30 swiftc                   0x000000010d356715 swift::CompilerInstance::parseAndTypeCheckMainFileUpTo(swift::SourceFile::ASTStage_t) + 533
31 swiftc                   0x000000010d355382 swift::CompilerInstance::parseAndCheckTypesUpTo(swift::CompilerInstance::ImplicitImports const&, swift::SourceFile::ASTStage_t) + 418
32 swiftc                   0x000000010d354b61 swift::CompilerInstance::performSemaUpTo(swift::SourceFile::ASTStage_t) + 625
33 swiftc                   0x000000010d115701 performCompile(swift::CompilerInstance&, swift::CompilerInvocation const&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 1905
34 swiftc                   0x000000010d114003 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 5139
35 swiftc                   0x000000010d0ae25e main + 734
36 libdyld.dylib            0x00007fff680f92e5 start + 1

@theblixguy
Copy link
Collaborator

Slightly smaller reproducer:

class C {}
protocol Foo {
  associatedtype X where C: X
}

This looks like a regression because we used to correctly diagnose this in Swift 5, but since 5.1 this is crashing.

@theblixguy
Copy link
Collaborator

Another reproducer:

class C {}
protocol Foo {
  associatedtype W
  associatedtype X where Foo: W
}

@beccadax
Copy link
Contributor

@swift-ci create

@CodaFi
Copy link
Member

CodaFi commented Jan 27, 2020

Calling FloatingRequirementSource::getSource on a bogus type is going to crash as expected. We need to throw an ErrorType somewhere.

@CodaFi
Copy link
Member

CodaFi commented Jan 27, 2020

@swift-ci create

@theblixguy
Copy link
Collaborator

Yeah. I also think we have a strange diagnostic (=<Swift 5), for example type 'Foo' constrained to non-protocol, non-class type 'Self.X' instead of type 'Foo' in conformance requirement does not refer to a generic parameter or associated type. I don't think we've ever emitted that inside a protocol though.

@CodaFi
Copy link
Member

CodaFi commented Jan 27, 2020

I think I have a 3-line patch that'll fix this. I'll tag you as a reviewer when I get a radar number to associate it with.

@CodaFi
Copy link
Member

CodaFi commented Jan 28, 2020

Okay, sync isn't listening to me. rdar://58941114 has been filed. We'll dupe when/if it wakes up.

@CodaFi
Copy link
Member

CodaFi commented Jan 28, 2020

Merged to master #29491

@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 regression swift 5.1 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

5 participants