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

withoutActuallyEscaping with sending @escaping causes crash #79078

Open
ph1ps opened this issue Jan 31, 2025 · 0 comments
Open

withoutActuallyEscaping with sending @escaping causes crash #79078

ph1ps opened this issue Jan 31, 2025 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels

Comments

@ph1ps
Copy link

ph1ps commented Jan 31, 2025

Description

This is pretty much a non-sensical use case. On accident, I tried to use an already @escaping closure in withoutActuallyEscaping. The crash does not happen with non-sending @escaping closures.

Reproduction

func send(
    operation: sending @escaping () async -> Void
) async {
  _ = await withoutActuallyEscaping(operation) { escapingClosure in
    await Task {
      await escapingClosure()
    }.value
  }
}

Stack dump

Stack dump:
0.	Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -interpret main.swift -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk -color-diagnostics -swift-version 6 -new-driver-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -empty-abi-descriptor -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -module-name main -disable-clang-spi -target-sdk-version 15.2 -target-sdk-name macosx15.2 -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins
1.	Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
2.	Compiling with the current language version
3.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for module main)
4.	While silgen emitFunction SIL function "@$s4main4send9operationyyyYacn_tYaF".
 for 'send(operation:)' (at main.swift:1:1)
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           0x000000010a696a9c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x000000010a694cf0 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x000000010a697068 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x0000000195daee04 _sigtramp + 56
4  swift-frontend           0x0000000105941770 (anonymous namespace)::TypeClassifierBase<(anonymous namespace)::LowerType, swift::Lowering::TypeLowering*>::visit(swift::CanType, swift::Lowering::AbstractionPattern, swift::Lowering::IsTypeExpansionSensitive_t) + 56
5  swift-frontend           0x00000001059415b4 swift::Lowering::TypeConverter::getTypeLowering(swift::Lowering::AbstractionPattern, swift::Type, swift::TypeExpansionContext) + 668
6  swift-frontend           0x0000000105b3ae3c swift::Lowering::SILGenFunction::emitRValueForNonMemberVarDecl(swift::SILLocation, swift::ConcreteDeclRef, swift::CanType, swift::AccessSemantics, swift::Lowering::SGFContext) + 1844
7  swift-frontend           0x0000000105af597c (anonymous namespace)::RValueEmitter::visitMakeTemporarilyEscapableExpr(swift::MakeTemporarilyEscapableExpr*, swift::Lowering::SGFContext) + 64
8  swift-frontend           0x0000000105adfc74 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 888
9  swift-frontend           0x0000000105aff53c (anonymous namespace)::RValueEmitter::visitAssignExpr(swift::AssignExpr*, swift::Lowering::SGFContext) + 568
10 swift-frontend           0x0000000105adfc74 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 888
11 swift-frontend           0x0000000105b97274 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 5512
12 swift-frontend           0x0000000105b0efc8 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 492
13 swift-frontend           0x0000000105a5ab1c swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 8420
14 swift-frontend           0x0000000105a5b3bc swift::Lowering::SILGenModule::emitOrDelayFunction(swift::SILDeclRef) + 216
15 swift-frontend           0x0000000105a589ec swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 364
16 swift-frontend           0x0000000105a5f038 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 1804
17 swift-frontend           0x0000000105b9592c 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&) + 196
18 swift-frontend           0x0000000105a63f14 swift::ASTLoweringRequest::OutputType swift::Evaluator::getResultUncached<swift::ASTLoweringRequest, swift::ASTLoweringRequest::OutputType swift::evaluateOrFatal<swift::ASTLoweringRequest>(swift::Evaluator&, swift::ASTLoweringRequest)::'lambda'()>(swift::ASTLoweringRequest const&, swift::ASTLoweringRequest::OutputType swift::evaluateOrFatal<swift::ASTLoweringRequest>(swift::Evaluator&, swift::ASTLoweringRequest)::'lambda'()) + 528
19 swift-frontend           0x000000010503e304 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 2828
20 swift-frontend           0x0000000105041374 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 2944
21 swift-frontend           0x000000010503fbb4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3572
22 swift-frontend           0x0000000104fc6a5c swift::mainEntry(int, char const**) + 3680
23 dyld                     0x00000001959f8274 start + 2840
zsh: trace trap  swift -swift-version 6 main.swift

Expected behavior

Firstly, I'd expect this to not crash. But secondly, I don't know what else to expect. Maybe a compiler warning or error that you are passing an @escaping closure to withoutActuallyEscaping, which does not make sense.

Environment

swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: arm64-apple-macosx15.0

Additional information

No response

@ph1ps ph1ps added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels labels Jan 31, 2025
@ph1ps ph1ps changed the title withoutActuallyEscaping and sending causes crash withoutActuallyEscaping with sending @escaping causes crash Feb 2, 2025
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. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant