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-14399] Compiler crash with Self as closure parameter #56757

Open
theblixguy opened this issue Mar 24, 2021 · 1 comment
Open

[SR-14399] Compiler crash with Self as closure parameter #56757

theblixguy opened this issue Mar 24, 2021 · 1 comment

Comments

@theblixguy
Copy link
Collaborator

@theblixguy theblixguy commented Mar 24, 2021

Previous ID SR-14399
Radar rdar://problem/75839792
Original Reporter @theblixguy
Type Bug
Environment

Swift version 5.4-dev (LLVM bd2476a, Swift 14c1853)
Target: x86_64-apple-darwin20.3.0
OS: macOS Big Sur 11.2.3

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

md5: 5d60f820e589fc287538e4bf6877aec7

Issue Description:

The following code crashes in the CSApply:

class A {}

extension A {
  func closure(_: @escaping (Self) -> Void) {}
}

let a = A()
_ = a.closure({ _ in })
Unhandled coercion
UNREACHABLE executed at /Users/suyashsrijan/Documents/swift-project/swift/lib/Sema/CSApply.cpp:7041!
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
Stack dump:
0.  Program arguments: /Users/suyashsrijan/Documents/swift-project/build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/bin/swift-frontend -frontend -interpret /Users/suyashsrijan/Desktop/test.swift -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk -color-diagnostics -target-sdk-version 11.1 -module-name test
1.  Swift version 5.4-dev (LLVM bd2476a8056e227, Swift 14c18531a3b3d95)
2.  While evaluating request TypeCheckSourceFileRequest(source_file "/Users/suyashsrijan/Desktop/test.swift")
3.  While type-checking statement at [/Users/suyashsrijan/Desktop/test.swift:8:1 - line:8:23] RangeText="_ = a.closure({ _ in }"
4.  While type-checking expression at [/Users/suyashsrijan/Desktop/test.swift:8:1 - line:8:23] RangeText="_ = a.closure({ _ in }"
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           0x0000000110937d37 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
1  swift-frontend           0x0000000110936e05 llvm::sys::RunSignalHandlers() + 85
2  swift-frontend           0x0000000110938366 SignalHandler(int) + 262
3  libsystem_platform.dylib 0x00007fff20487d7d _sigtramp + 29
4  libsystem_platform.dylib 0x0000000000000046 _sigtramp + 18446603339974542054
5  libsystem_c.dylib        0x00007fff20396720 abort + 120
6  swift-frontend           0x0000000110889652 llvm::llvm_unreachable_internal(char const*, char const*, unsigned int) + 482
7  swift-frontend           0x000000010c7bf208 (anonymous namespace)::ExprRewriter::coerceToType(swift::Expr*, swift::Type, swift::constraints::ConstraintLocatorBuilder, llvm::Optional<swift::Pattern*>) + 12184
8  swift-frontend           0x000000010c7c4c30 swift::ASTVisitor<(anonymous namespace)::ExprRewriter, swift::Expr*, void, void, void, void, void>::visit(swift::Expr*) + 9648
9  swift-frontend           0x000000010c7c09d6 (anonymous namespace)::ExprWalker::walkToExprPost(swift::Expr*) + 22
10 swift-frontend           0x000000010cc22fd3 swift::Expr::walk(swift::ASTWalker&) + 115
11 swift-frontend           0x000000010c7b9ee8 (anonymous namespace)::ExprWalker::rewriteTarget(swift::constraints::SolutionApplicationTarget) + 136
12 swift-frontend           0x000000010c7b9cae swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::constraints::SolutionApplicationTarget) + 622
13 swift-frontend           0x000000010c980c79 swift::TypeChecker::typeCheckExpression(swift::constraints::SolutionApplicationTarget&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 633
14 swift-frontend           0x000000010c98097d swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::constraints::ContextualTypeInfo, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 77
15 swift-frontend           0x000000010ca4157b (anonymous namespace)::StmtChecker::typeCheckASTNode(swift::ASTNode&) + 235
16 swift-frontend           0x000000010ca4350c swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 124
17 swift-frontend           0x000000010ca42880 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 128
18 swift-frontend           0x000000010ca42902 swift::TypeChecker::typeCheckTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 50
19 swift-frontend           0x000000010ca7673f swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const + 223
20 swift-frontend           0x000000010ca778ff llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckSourceFileRequest>(swift::TypeCheckSourceFileRequest const&) + 415
21 swift-frontend           0x000000010ca776b4 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultCached<swift::TypeCheckSourceFileRequest, (void*)0>(swift::TypeCheckSourceFileRequest const&) + 100
22 swift-frontend           0x000000010ca76580 swift::TypeCheckSourceFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckSourceFileRequest>(swift::Evaluator&, swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType) + 32
23 swift-frontend           0x000000010bcc6a4e swift::CompilerInstance::forEachFileToTypeCheck(llvm::function_ref<void (swift::SourceFile&)>) + 174
24 swift-frontend           0x000000010bcc68ea swift::CompilerInstance::performSema() + 74
25 swift-frontend           0x000000010bb58d74 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4724
26 swift-frontend           0x000000010baa9847 main + 519
27 libdyld.dylib            0x00007fff2045e621 start + 1
28 libdyld.dylib            0x000000000000000c start + 18446603339974711788
zsh: abort      ./swift ~/Desktop/test.swift

If you remove the discard assignment, then it crashes in SIL:

class A {}

extension A {
  func closure(_: @escaping (Self) -> Void) {}
}

let a = A()
a.closure({ _ in })
Assertion failed: (hasDynamicSelfMetadata() && "This method can only be called if the " "SILFunction has a self-metadata parameter"), function getDynamicSelfMetadata, file /Users/suyashsrijan/Documents/swift-project/swift/include/swift/SIL/SILFunction.h, line 1138.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
Stack dump:
0.  Program arguments: /Users/suyashsrijan/Documents/swift-project/build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/bin/swift-frontend -frontend -interpret /Users/suyashsrijan/Desktop/test.swift -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk -color-diagnostics -target-sdk-version 11.1 -module-name test
1.  Swift version 5.4-dev (LLVM bd2476a8056e227, Swift 14c18531a3b3d95)
2.  While evaluating request ASTLoweringRequest(Lowering AST to SIL for module test)
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           0x000000010a50ad37 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
1  swift-frontend           0x000000010a509e05 llvm::sys::RunSignalHandlers() + 85
2  swift-frontend           0x000000010a50b366 SignalHandler(int) + 262
3  libsystem_platform.dylib 0x00007fff20487d7d _sigtramp + 29
4  swift-frontend           0x000000010d947748 cmark_strbuf__initbuf + 215043
5  libsystem_c.dylib        0x00007fff20396720 abort + 120
6  libsystem_c.dylib        0x00007fff203959d6 err + 0
7  swift-frontend           0x000000010a5c1003 collectTypeDependentOperands(llvm::SmallVectorImpl<swift::SILValue>&, swift::SILOpenedArchetypesState&, swift::SILFunction&, swift::CanType, swift::SubstitutionMap) (.cold.4) + 35
8  swift-frontend           0x00000001059248f7 collectTypeDependentOperands(llvm::SmallVectorImpl<swift::SILValue>&, swift::SILOpenedArchetypesState&, swift::SILFunction&, swift::CanType, swift::SubstitutionMap) + 951
9  swift-frontend           0x0000000105934039 swift::MetatypeInst::create(swift::SILDebugLocation, swift::SILType, swift::SILFunction*, swift::SILOpenedArchetypesState&) + 201
10 swift-frontend           0x0000000105e486d8 swift::Lowering::SILGenFunction::emitCaptures(swift::SILLocation, swift::SILDeclRef, swift::Lowering::CaptureEmission, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&) + 824
11 swift-frontend           0x0000000105e499d7 swift::Lowering::SILGenFunction::emitClosureValue(swift::SILLocation, swift::SILDeclRef, swift::CanType, swift::SubstitutionMap) + 1079
12 swift-frontend           0x0000000105e406e7 (anonymous namespace)::RValueEmitter::visitAbstractClosureExpr(swift::AbstractClosureExpr*, swift::Lowering::SGFContext) + 295
13 swift-frontend           0x0000000105e341d5 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 133
14 swift-frontend           0x0000000105e2adf7 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 55
15 swift-frontend           0x0000000105deb958 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 2008
16 swift-frontend           0x0000000105dda437 (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 679
17 swift-frontend           0x0000000105dead23 (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern) + 147
18 swift-frontend           0x0000000105df419d (anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::SmallVectorImpl<(anonymous namespace)::DelayedArgument>&, swift::Lowering::CalleeTypeInfo::ForeignInfo const&) && + 909
19 swift-frontend           0x0000000105df3969 (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, swift::Lowering::CalleeTypeInfo::ForeignInfo const&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::Optional<swift::SILLocation>&) + 1561
20 swift-frontend           0x0000000105dde553 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 2755
21 swift-frontend           0x0000000105ddc25f swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 1935
22 swift-frontend           0x0000000105e341bb swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 107
23 swift-frontend           0x0000000105e2b1a1 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 849
24 swift-frontend           0x0000000105dd0721 swift::Lowering::SILGenModule::visitTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 321
25 swift-frontend           0x0000000105dd1077 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 1943
26 swift-frontend           0x0000000105e97970 swift::SimpleRequest<swift::ASTLoweringRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> > (swift::ASTLoweringDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) + 128
27 swift-frontend           0x0000000105dd4ff3 llvm::Expected<swift::ASTLoweringRequest::OutputType> swift::Evaluator::getResultUncached<swift::ASTLoweringRequest>(swift::ASTLoweringRequest const&) + 403
28 swift-frontend           0x0000000105dd20c5 swift::performASTLowering(swift::ModuleDecl*, swift::Lowering::TypeConverter&, swift::SILOptions const&) + 165
29 swift-frontend           0x0000000105737731 performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 545
30 swift-frontend           0x000000010572bdf4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4852
31 swift-frontend           0x000000010567c847 main + 519
32 libdyld.dylib            0x00007fff2045e621 start + 1
33 libdyld.dylib            0x000000000000000c start + 18446603339974711788
zsh: abort      ./swift ~/Desktop/test.swift
@typesanitizer
Copy link

@typesanitizer typesanitizer commented Mar 25, 2021

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants