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-14678] [Sema] Crash on type checking tuple contextual mismatch in generic context #57029

Closed
LucianoPAlmeida opened this issue May 31, 2021 · 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 type checker Area → compiler: Semantic analysis

Comments

@LucianoPAlmeida
Copy link
Collaborator

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

main @8576aae5f44c2b51b0918bfa90ed78fadfce1dda

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

md5: f42b428706a88e4ee66ff143206c188c

Issue Description:

While working on SR-13239 I found that we have a crash on the compiler on main only in this case

func call<T>(_ : Int, _ f: () -> (T, Int)) -> (T, Int) {
  f()
}

func test() -> (Int, Int) {
  call(1) {
     (print("hello"), 0)
  }
}

Hit an assertion on main

: 'RUN: at line 1';   .../swift-lang/build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift-frontend -target x86_64-apple-macosx10.9  -module-cache-path .../swift-lang/build/Ninja-ReleaseAssert/swift-macosx-x86_64/swift-test-results/x86_64-apple-macosx10.9/clang-module-cache -sdk '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk'  -swift-version 4  -define-availability 'SwiftStdlib 5.5:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999' -typo-correction-limit 10  -typecheck -verify -disable-objc-attr-requires-foundation-module .../swift-lang/swift/test/Sema/test-tc.swift
--
Exit Code: 134

Command Output (stderr):
--
Assertion failed: (getFromType()->is<TupleType>() && getToType()->is<TupleType>()), function TupleContextualFailure, file .../swift-lang/swift/lib/Sema/CSDiagnostics.h, line 961.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
Stack dump:
0.  Program arguments: .../swift-lang/build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift-frontend -target x86_64-apple-macosx10.9 -module-cache-path .../swift-lang/build/Ninja-ReleaseAssert/swift-macosx-x86_64/swift-test-results/x86_64-apple-macosx10.9/clang-module-cache -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -swift-version 4 -define-availability "SwiftStdlib 5.5:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999" -typo-correction-limit 10 -typecheck -verify -disable-objc-attr-requires-foundation-module .../swift-lang/swift/test/Sema/test-tc.swift
1.  Swift version 5.5-dev (LLVM f24579dc63dffad, Swift 8576aae5f44c2b5)
2.  While evaluating request TypeCheckSourceFileRequest(source_file ".../swift-lang/swift/test/Sema/test-tc.swift")
3.  While evaluating request TypeCheckFunctionBodyRequest(main.(file).test()@.../swift-lang/swift/test/Sema/test-tc.swift:7:6)
4.  While type-checking statement at [.../swift-lang/swift/test/Sema/test-tc.swift:7:27 - line:11:1] RangeText="{
  call(1) {
     (print("hello"), 0)// expected-error {{cannot convert value of type '()' to closure result type 'Int'}}
  }
"
5.  While type-checking statement at [.../swift-lang/swift/test/Sema/test-tc.swift:8:3 - line:10:3] RangeText="call(1) {
     (print("hello"), 0)// expected-error {{cannot convert value of type '()' to closure result type 'Int'}}
  "
6.  While type-checking expression at [.../swift-lang/swift/test/Sema/test-tc.swift:8:3 - line:10:3] RangeText="call(1) {
     (print("hello"), 0)// expected-error {{cannot convert value of type '()' to closure result type 'Int'}}
  "
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x000000010aa062b7 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
1  swift-frontend           0x000000010aa05228 llvm::sys::RunSignalHandlers() + 248
2  swift-frontend           0x000000010aa068e6 SignalHandler(int) + 262
3  libsystem_platform.dylib 0x00007fff203a2d7d _sigtramp + 29
4  libsystem_platform.dylib 0x0000000000005530 _sigtramp + 18446603339975501776
5  libsystem_c.dylib        0x00007fff202b2411 abort + 120
6  libsystem_c.dylib        0x00007fff202b17e8 err + 0
7  swift-frontend           0x000000010ae37d53 swift::constraints::TupleContextualFailure::TupleContextualFailure(swift::constraints::Solution const&, swift::ContextualTypePurpose, swift::Type, swift::Type, llvm::ArrayRef<unsigned int>, swift::constraints::ConstraintLocator*) (.cold.7) + 35
8  swift-frontend           0x0000000106a5260f swift::constraints::TupleContextualFailure::TupleContextualFailure(swift::constraints::Solution const&, swift::ContextualTypePurpose, swift::Type, swift::Type, llvm::ArrayRef<unsigned int>, swift::constraints::ConstraintLocator*) + 319
9  swift-frontend           0x0000000106a482b2 swift::constraints::AllowTupleTypeMismatch::coalesceAndDiagnose(swift::constraints::Solution const&, llvm::ArrayRef<swift::constraints::ConstraintFix*>, bool) const + 642
10 swift-frontend           0x0000000106999fa3 swift::constraints::ConstraintSystem::applySolutionFixes(swift::constraints::Solution const&) + 2067
11 swift-frontend           0x000000010699a771 swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::constraints::SolutionApplicationTarget) + 65
12 swift-frontend           0x0000000106b5d1bf swift::TypeChecker::typeCheckExpression(swift::constraints::SolutionApplicationTarget&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 527
13 swift-frontend           0x0000000106b5cf2e swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::constraints::ContextualTypeInfo, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 78
14 swift-frontend           0x0000000106c1b2d1 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 4721
15 swift-frontend           0x0000000106c1a020 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::Stmt>(swift::Stmt*&) + 128
16 swift-frontend           0x0000000106c180ad (anonymous namespace)::StmtChecker::typeCheckASTNode(swift::ASTNode&) + 125
17 swift-frontend           0x0000000106c1a0ed swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 141
18 swift-frontend           0x0000000106c19430 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 128
19 swift-frontend           0x0000000106c188bc swift::TypeCheckFunctionBodyRequest::evaluate(swift::Evaluator&, swift::AbstractFunctionDecl*) const + 924
20 swift-frontend           0x0000000106ee442e llvm::Expected<swift::TypeCheckFunctionBodyRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckFunctionBodyRequest>(swift::TypeCheckFunctionBodyRequest const&) + 414
21 swift-frontend           0x0000000106ee41cb llvm::Expected<swift::TypeCheckFunctionBodyRequest::OutputType> swift::Evaluator::getResultCached<swift::TypeCheckFunctionBodyRequest, (void*)0>(swift::TypeCheckFunctionBodyRequest const&) + 107
22 swift-frontend           0x0000000106e42c35 swift::TypeCheckFunctionBodyRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckFunctionBodyRequest>(swift::Evaluator&, swift::TypeCheckFunctionBodyRequest, swift::TypeCheckFunctionBodyRequest::OutputType) + 37
23 swift-frontend           0x0000000106c4c5d8 swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const + 328
24 swift-frontend           0x0000000106c4d42f llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckSourceFileRequest>(swift::TypeCheckSourceFileRequest const&) + 415
25 swift-frontend           0x0000000106c4d1e4 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultCached<swift::TypeCheckSourceFileRequest, (void*)0>(swift::TypeCheckSourceFileRequest const&) + 100
26 swift-frontend           0x0000000106c4c3b0 swift::TypeCheckSourceFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckSourceFileRequest>(swift::Evaluator&, swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType) + 32
27 swift-frontend           0x0000000105f2070e swift::CompilerInstance::forEachFileToTypeCheck(llvm::function_ref<void (swift::SourceFile&)>) + 158
28 swift-frontend           0x0000000105f205ba swift::CompilerInstance::performSema() + 74
29 swift-frontend           0x0000000105df0561 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6225
30 swift-frontend           0x0000000105d47892 main + 514
31 libdyld.dylib            0x00007fff20378f5d start + 1
.../swift-lang/build/Ninja-ReleaseAssert/swift-macosx-x86_64/test-macosx-x86_64/Sema/Output/test-tc.swift.script: line 1: 53714 Abort trap: 6           .../swift-lang/build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift-frontend -target x86_64-apple-macosx10.9 -module-cache-path .../swift-lang/build/Ninja-ReleaseAssert/swift-macosx-x86_64/swift-test-results/x86_64-apple-macosx10.9/clang-module-cache -sdk '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk' -swift-version 4 -define-availability 'SwiftStdlib 5.5:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999' -typo-correction-limit 10 -typecheck -verify -disable-objc-attr-requires-foundation-module .../swift-lang/swift/test/Sema/test-tc.swift

Assertion we are hitting:

assert(getFromType()->is<TupleType>() && getToType()->is<TupleType>());

@LucianoPAlmeida
Copy link
Collaborator Author

cc @xedin

@LucianoPAlmeida
Copy link
Collaborator Author

Fixed by #37707

@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

2 participants