Navigation Menu

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-10992] Compiler crash on function conversion reliant on conditional conformance #53382

Closed
hamishknight opened this issue Jun 21, 2019 · 8 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 type checker Area → compiler: Semantic analysis

Comments

@hamishknight
Copy link
Collaborator

Previous ID SR-10992
Radar None
Original Reporter @hamishknight
Type Bug
Status Closed
Resolution Done
Environment

Swift version 5.1-dev (LLVM af1f73e9e9, Swift 7e8ce6c)
Target: x86_64-apple-darwin18.5.0

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

md5: d1eb1aecca7002c25f705f5cb12b054b

Issue Description:

The following trips an assertion:

protocol P {}
struct S<T> {}
extension S : P where T : P {}

func foo(_ fn: (S<String>) -> Void) {}

func bar(_ fn: (P) -> Void) {
  foo(fn)
}
Assertion failed: (summaryFlags == ConstraintLocator::getSummaryFlagsForPath(path)), function getConstraintLocator, file /Users/hamishknight/Desktop/swift-dev/swift/lib/Sema/ConstraintSystem.cpp, line 381.
Stack dump:
0.  Program arguments: ./swift -frontend -typecheck /Users/hamishknight/Desktop/Stochastic Projects/newnew/newnew/main.swift -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
1.  Swift version 5.1-dev (LLVM af1f73e9e9, Swift 7e8ce6ce4a)
2.  While type-checking 'bar(_:)' (at /Users/hamishknight/Desktop/Stochastic Projects/newnew/newnew/main.swift:213:1)
3.  While type-checking statement at [/Users/hamishknight/Desktop/Stochastic Projects/newnew/newnew/main.swift:213:29 - line:215:1] RangeText="{
  foo(fn)
"
4.  While type-checking expression at [/Users/hamishknight/Desktop/Stochastic Projects/newnew/newnew/main.swift:214:3 - line:214:9] RangeText="foo(fn"
0  swift                    0x0000000111a8c005 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x0000000111a8b008 llvm::sys::RunSignalHandlers() + 248
2  swift                    0x0000000111a8c608 SignalHandler(int) + 264
3  libsystem_platform.dylib 0x00007fff649e3b5d _sigtramp + 29
4  swift                    0x00000001130ffda0 cmark_strbuf__initbuf + 133515
5  libsystem_c.dylib        0x00007fff648a36a6 abort + 127
6  libsystem_c.dylib        0x00007fff6486c20d basename_r + 0
7  swift                    0x0000000111da1de3 swift::constraints::ConstraintSystem::getConstraintLocator(swift::Expr*, llvm::ArrayRef<swift::constraints::ConstraintLocator::PathElement>, unsigned int) (.cold.2) + 35
8  swift                    0x000000010e6a8080 swift::constraints::ConstraintSystem::getConstraintLocator(swift::Expr*, llvm::ArrayRef<swift::constraints::ConstraintLocator::PathElement>, unsigned int) + 544
9  swift                    0x000000010e640975 fixRequirementFailure(swift::constraints::ConstraintSystem&, swift::Type, swift::Type, swift::Expr*, llvm::ArrayRef<swift::constraints::ConstraintLocator::PathElement>) + 677
10 swift                    0x000000010e63f1f7 swift::constraints::ConstraintSystem::simplifyConformsToConstraint(swift::Type, swift::ProtocolDecl*, swift::constraints::ConstraintKind, swift::constraints::ConstraintLocatorBuilder, swift::OptionSet<swift::constraints::ConstraintSystem::TypeMatchFlags, unsigned int>) + 983
11 swift                    0x000000010e64e10b swift::constraints::ConstraintSystem::addConstraint(swift::Requirement, swift::constraints::ConstraintLocatorBuilder, bool) + 203
12 swift                    0x000000010e6417e0 swift::constraints::ConstraintSystem::simplifyConformsToConstraint(swift::Type, swift::ProtocolDecl*, swift::constraints::ConstraintKind, swift::constraints::ConstraintLocatorBuilder, swift::OptionSet<swift::constraints::ConstraintSystem::TypeMatchFlags, unsigned int>)::$_23::operator()(swift::ProtocolConformanceRef) const + 288
13 swift                    0x000000010e63f019 swift::constraints::ConstraintSystem::simplifyConformsToConstraint(swift::Type, swift::ProtocolDecl*, swift::constraints::ConstraintKind, swift::constraints::ConstraintLocatorBuilder, swift::OptionSet<swift::constraints::ConstraintSystem::TypeMatchFlags, unsigned int>) + 505
14 swift                    0x000000010e63ed3d swift::constraints::ConstraintSystem::matchExistentialTypes(swift::Type, swift::Type, swift::constraints::ConstraintKind, swift::OptionSet<swift::constraints::ConstraintSystem::TypeMatchFlags, unsigned int>, swift::constraints::ConstraintLocatorBuilder) + 1357
15 swift                    0x000000010e64d102 swift::constraints::ConstraintSystem::simplifyRestrictedConstraintImpl(swift::constraints::ConversionRestrictionKind, swift::Type, swift::Type, swift::constraints::ConstraintKind, swift::OptionSet<swift::constraints::ConstraintSystem::TypeMatchFlags, unsigned int>, swift::constraints::ConstraintLocatorBuilder) + 4066
16 swift                    0x000000010e640ab8 swift::constraints::ConstraintSystem::simplifyRestrictedConstraint(swift::constraints::ConversionRestrictionKind, swift::Type, swift::Type, swift::constraints::ConstraintKind, swift::OptionSet<swift::constraints::ConstraintSystem::TypeMatchFlags, unsigned int>, swift::constraints::ConstraintLocatorBuilder) + 56
17 swift                    0x000000010e63b9d9 swift::constraints::ConstraintSystem::matchTypes(swift::Type, swift::Type, swift::constraints::ConstraintKind, swift::OptionSet<swift::constraints::ConstraintSystem::TypeMatchFlags, unsigned int>, swift::constraints::ConstraintLocatorBuilder) + 11977
18 swift                    0x000000010e63d1d9 swift::constraints::ConstraintSystem::matchFunctionTypes(swift::FunctionType*, swift::FunctionType*, swift::constraints::ConstraintKind, swift::OptionSet<swift::constraints::ConstraintSystem::TypeMatchFlags, unsigned int>, swift::constraints::ConstraintLocatorBuilder) + 3609
19 swift                    0x000000010e6395c7 swift::constraints::ConstraintSystem::matchTypes(swift::Type, swift::Type, swift::constraints::ConstraintKind, swift::OptionSet<swift::constraints::ConstraintSystem::TypeMatchFlags, unsigned int>, swift::constraints::ConstraintLocatorBuilder) + 2743
20 swift                    0x000000010e64d867 swift::constraints::ConstraintSystem::addConstraintImpl(swift::constraints::ConstraintKind, swift::Type, swift::Type, swift::constraints::ConstraintLocatorBuilder, bool) + 103
21 swift                    0x000000010e637fa0 swift::constraints::matchCallArguments(swift::constraints::ConstraintSystem&, llvm::ArrayRef<swift::AnyFunctionType::Param>, llvm::ArrayRef<swift::AnyFunctionType::Param>, swift::constraints::ConstraintKind, swift::constraints::ConstraintLocatorBuilder) + 1776
22 swift                    0x000000010e64a6da swift::constraints::ConstraintSystem::simplifyApplicableFnConstraint(swift::Type, swift::Type, swift::OptionSet<swift::constraints::ConstraintSystem::TypeMatchFlags, unsigned int>, swift::constraints::ConstraintLocatorBuilder) + 2186
23 swift                    0x000000010e63875f swift::constraints::ConstraintSystem::addConstraint(swift::constraints::ConstraintKind, swift::Type, swift::Type, swift::constraints::ConstraintLocatorBuilder, bool) + 63
24 swift                    0x000000010e62c19f (anonymous namespace)::ConstraintGenerator::visitApplyExpr(swift::ApplyExpr*) + 447
25 swift                    0x000000010e624322 (anonymous namespace)::ConstraintWalker::walkToExprPost(swift::Expr*) + 450
26 swift                    0x000000010ea11e13 swift::Expr::walk(swift::ASTWalker&) + 115
27 swift                    0x000000010e6200da swift::constraints::ConstraintSystem::generateConstraints(swift::Expr*, swift::DeclContext*) + 426
28 swift                    0x000000010e65a16d swift::constraints::ConstraintSystem::solveImpl(swift::Expr*&, swift::Type, swift::ExprTypeCheckListener*, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 477
29 swift                    0x000000010e659d3b swift::constraints::ConstraintSystem::solve(swift::Expr*&, swift::Type, swift::ExprTypeCheckListener*, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 475
30 swift                    0x000000010e716574 swift::TypeChecker::typeCheckExpressionImpl(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener&, swift::constraints::ConstraintSystem*) + 964
31 swift                    0x000000010e71619f swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 63
32 swift                    0x000000010e7afa46 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 614
33 swift                    0x000000010e7aeb68 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 136
34 swift                    0x000000010e7ad73d swift::TypeChecker::typeCheckFunctionBodyUntil(swift::FuncDecl*, swift::SourceLoc) + 493
35 swift                    0x000000010e7ae24e swift::TypeChecker::typeCheckAbstractFunctionBody(swift::AbstractFunctionDecl*) + 334
36 swift                    0x000000010e7ce9b3 typeCheckFunctionsAndExternalDecls(swift::SourceFile&, swift::TypeChecker&) + 275
37 swift                    0x000000010e7cf13d swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) + 1005
38 swift                    0x000000010df83f76 swift::CompilerInstance::parseAndTypeCheckMainFileUpTo(swift::SourceFile::ASTStage_t, swift::PersistentParserState&, swift::DelayedParsingCallbacks*, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>) + 502
39 swift                    0x000000010df82d86 swift::CompilerInstance::parseAndCheckTypesUpTo(swift::CompilerInstance::ImplicitImports const&, swift::SourceFile::ASTStage_t) + 342
40 swift                    0x000000010df8272a swift::CompilerInstance::performSemaUpTo(swift::SourceFile::ASTStage_t) + 618
41 swift                    0x000000010dd725f2 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 1730
42 swift                    0x000000010dd70f51 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3025
43 swift                    0x000000010dd193e9 main + 729
44 libdyld.dylib            0x00007fff647fe3d5 start + 1
fish: './swift -frontend -typecheck /U…' terminated by signal SIGABRT (Abort)
@theblixguy
Copy link
Collaborator

Ah I see, we should be passing the value of `ConstraintLocator::getSummaryFlagsForPath(path);` instead of always passing `0`. Is that correct @xedin? We need to do this in `fixRequirementFailure` and `getConformanceForConditionalReq`.

@xedin
Copy link
Member

xedin commented Jun 24, 2019

Yeah, that seems to be the right solution.

@xedin
Copy link
Member

xedin commented Jun 24, 2019

Or we could just modify existing getConstraintLocator or add a new overload and use getSummaryFlagsForPath internally. With could probably be less error prone.

@theblixguy
Copy link
Collaborator

Yeah, I think using it internally makes sense. I'll create a PR for this.

@xedin
Copy link
Member

xedin commented Jun 24, 2019

Great, thank you!

@theblixguy
Copy link
Collaborator

@xedin I have created a PR here: #25721

@theblixguy
Copy link
Collaborator

Fixed on master and Swift 5.1 branch.

@hamishknight
Copy link
Collaborator Author

Thanks Suyash!

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

No branches or pull requests

4 participants