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

The compiler crashes when actor has borrowing func that contains nested @Sendable func involving self. #78967

Open
YOCKOW opened this issue Jan 28, 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

@YOCKOW
Copy link
Member

YOCKOW commented Jan 28, 2025

Description

The code below induces a compiler crash with the message:

  • swift-DEVELOPMENT-SNAPSHOT-2025-01-10-a: "Assertion failed: (!ActorIso), function emitUsingCoroutineAccessor, file SILGenLValue.cpp"
  • Swift 6.0.3: "Unhandled SIL Instruction: hop_to_executor %5 : $MyValue // id: %11"

(Needless to say, the code is just a reproducer which is non-sense and probably invalid.)

Reproduction

actor MyValue<T> where T: Sendable & ~Copyable {
  var value: T

  init(_ value: consuming T) {
    self.value = value
  }

  private func _setValue(_ newValue: consuming T) {
    self.value = newValue
  }

  borrowing func withValue() async {
    @Sendable func __nestedSendableFunction() async {
      await self._setValue(self.value)
    }
    await __nestedSendableFunction()
  }
}

Stack dump

swift-DEVELOPMENT-SNAPSHOT-2025-01-10-a

Assertion failed: (!ActorIso), function emitUsingCoroutineAccessor, file SILGenLValue.cpp, line 4030.
Stack dump:
0.	Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-01-10-a.xctoolchain/usr/bin/swift-frontend -frontend -interpret _borrowing-actor_.swift -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk -color-diagnostics -empty-abi-descriptor -resource-dir /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-01-10-a.xctoolchain/usr/lib/swift -module-name main -in-process-plugin-server-path /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-01-10-a.xctoolchain/usr/lib/swift/host/libSwiftInProcPluginServer.dylib -plugin-path /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-01-10-a.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-01-10-a.xctoolchain/usr/local/lib/swift/host/plugins -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
1.	Apple Swift version 6.2-dev (LLVM 81859ac55f8d09a, Swift 8ec8a1229a7ea14)
2.	Compiling with effective version 5.10
3.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for module main)
4.	While silgen emitFunction SIL function "@$s4main7MyValueCAARi_zrlE04withC0yyYaF".
 for 'withValue()' (at _borrowing-actor_.swift:12:13)
5.	While silgen emitFunction SIL function "@$s4main7MyValueCAARi_zrlE04withC0yyYaF24__nestedSendableFunctionL_yyYaYbs0F0RzRi_zlF".
 for '__nestedSendableFunction()' (at _borrowing-actor_.swift:13:15)
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           0x000000010b0edf60 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x000000010b0ec644 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x000000010b0ee5bc SignalHandler(int) + 304
3  libsystem_platform.dylib 0x000000018fe22e04 _sigtramp + 56
4  libsystem_pthread.dylib  0x000000018fdebf70 pthread_kill + 288
5  libsystem_c.dylib        0x000000018fcf8908 abort + 128
6  libsystem_c.dylib        0x000000018fcf7c1c err + 0
7  swift-frontend           0x000000010b223bf0 (anonymous namespace)::LogicalKeyPathApplicationComponent::set(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ArgumentSource&&, swift::Lowering::ManagedValue) && (.cold.1) + 0
8  swift-frontend           0x000000010595ddc0 (anonymous namespace)::AccessEmitter<swift::Lowering::LValue::addMemberVarComponent(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::VarDecl*, swift::SubstitutionMap, swift::Lowering::LValueOptions, bool, swift::Lowering::SGFAccessKind, swift::AccessStrategy, swift::CanType, bool, std::__1::optional<swift::ActorIsolation>)::MemberVarAccessEmitter, swift::VarDecl>::emitUsingAccessor(swift::AccessorKind, bool) + 1108
9  swift-frontend           0x000000010594905c swift::Lowering::LValue::addMemberVarComponent(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::VarDecl*, swift::SubstitutionMap, swift::Lowering::LValueOptions, bool, swift::Lowering::SGFAccessKind, swift::AccessStrategy, swift::CanType, bool, std::__1::optional<swift::ActorIsolation>) + 620
10 swift-frontend           0x000000010594e1f4 SILGenLValue::visitMemberRefExpr(swift::MemberRefExpr*, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions) + 924
11 swift-frontend           0x000000010594a144 swift::Lowering::SILGenFunction::emitLValue(swift::Expr*, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions) + 56
12 swift-frontend           0x00000001058b5358 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, bool, std::__1::optional<swift::AnyFunctionType::Param>) + 2312
13 swift-frontend           0x00000001058a6644 (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, bool, std::__1::optional<swift::AnyFunctionType::Param>) + 320
14 swift-frontend           0x00000001058b3eec (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern) + 220
15 swift-frontend           0x00000001058bf308 (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::ForeignInfo const&) && + 532
16 swift-frontend           0x00000001058beb68 (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, swift::ForeignInfo const&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, std::__1::optional<swift::SILLocation>&) + 1052
17 swift-frontend           0x00000001058aa0c4 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 1800
18 swift-frontend           0x00000001058a8744 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 2028
19 swift-frontend           0x0000000105908060 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 912
20 swift-frontend           0x000000010599e98c swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 4288
21 swift-frontend           0x000000010599d8c0 swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 24
22 swift-frontend           0x000000010592b550 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 436
23 swift-frontend           0x0000000105896040 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 6124
24 swift-frontend           0x0000000105897254 swift::Lowering::SILGenModule::emitOrDelayFunction(swift::SILDeclRef) + 268
25 swift-frontend           0x000000010589481c swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 184
26 swift-frontend           0x000000010599e900 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 4148
27 swift-frontend           0x000000010599d8c0 swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 24
28 swift-frontend           0x000000010592b550 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 436
29 swift-frontend           0x0000000105896040 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 6124
30 swift-frontend           0x0000000105897254 swift::Lowering::SILGenModule::emitOrDelayFunction(swift::SILDeclRef) + 268
31 swift-frontend           0x000000010589481c swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 184
32 swift-frontend           0x00000001059b2940 (anonymous namespace)::SILGenType::visitFuncDecl(swift::FuncDecl*) + 28
33 swift-frontend           0x00000001059af8f8 (anonymous namespace)::SILGenType::emitType() + 276
34 swift-frontend           0x00000001059af7d8 swift::Lowering::SILGenModule::visitNominalTypeDecl(swift::NominalTypeDecl*) + 24
35 swift-frontend           0x00000001058999f8 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 176
36 swift-frontend           0x0000000105899f14 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 632
37 swift-frontend           0x000000010599d280 swift::SimpleRequest<swift::ASTLoweringRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>> (swift::ASTLoweringDescriptor), (swift::RequestFlags)17>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) + 148
38 swift-frontend           0x000000010589f424 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'()) + 340
39 swift-frontend           0x000000010589a294 swift::performASTLowering(swift::ModuleDecl*, swift::Lowering::TypeConverter&, swift::SILOptions const&, swift::IRGenOptions const*) + 144
40 swift-frontend           0x000000010523591c swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1184
41 swift-frontend           0x00000001052416a4 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 160
42 swift-frontend           0x0000000105237418 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 716
43 swift-frontend           0x0000000105236c34 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2208
44 swift-frontend           0x0000000104fe91b8 swift::mainEntry(int, char const**) + 3100
45 dyld                     0x000000018fa6c274 start + 2840

Swift 6.0.3

Unhandled SIL Instruction:   hop_to_executor %5 : $MyValue<T>                // id: %11
Stack dump:
0.	Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -interpret _borrowing-actor_.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 -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 effective version 5.10
3.	While evaluating request ExecuteSILPipelineRequest(Run pipelines { Mandatory Diagnostic Passes + Enabling Optimization Passes } on SIL for main)
4.	While running pass #247 SILFunctionTransform "MoveOnlyTypeEliminator" on SILFunction "@$s4main7MyValueCAARi_zrlE04withC0yyYaF24__nestedSendableFunctionL_yyYaYbs0F0RzRi_zlF".
 for '__nestedSendableFunction()' (at _borrowing-actor_.swift:13:15)
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           0x000000010a37ea9c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x000000010a37ccf0 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x000000010a37f068 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x000000018fe22e04 _sigtramp + 56
4  swift-frontend           0x0000000105b5d708 swift::SILInstructionVisitor<(anonymous namespace)::SILMoveOnlyWrappedTypeEliminatorVisitor, bool>::visitAllocPackInst(swift::AllocPackInst*) + 40
5  swift-frontend           0x0000000105b5d108 (anonymous namespace)::SILMoveOnlyWrappedTypeEliminatorPass::run() + 6056
6  swift-frontend           0x0000000105b69b74 swift::SILPassManager::runFunctionPasses(unsigned int, unsigned int) + 3448
7  swift-frontend           0x0000000105b66158 swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 11968
8  swift-frontend           0x0000000105b9f6a4 swift::SimpleRequest<swift::ExecuteSILPipelineRequest, std::__1::tuple<> (swift::SILPipelineExecutionDescriptor), (swift::RequestFlags)1>::evaluateRequest(swift::ExecuteSILPipelineRequest const&, swift::Evaluator&) + 56
9  swift-frontend           0x0000000105b83008 swift::ExecuteSILPipelineRequest::OutputType swift::Evaluator::getResultUncached<swift::ExecuteSILPipelineRequest, swift::ExecuteSILPipelineRequest::OutputType swift::evaluateOrFatal<swift::ExecuteSILPipelineRequest>(swift::Evaluator&, swift::ExecuteSILPipelineRequest)::'lambda'()>(swift::ExecuteSILPipelineRequest const&, swift::ExecuteSILPipelineRequest::OutputType swift::evaluateOrFatal<swift::ExecuteSILPipelineRequest>(swift::Evaluator&, swift::ExecuteSILPipelineRequest)::'lambda'()) + 412
10 swift-frontend           0x0000000105b85784 swift::runSILDiagnosticPasses(swift::SILModule&) + 612
11 swift-frontend           0x00000001050fc0e4 swift::CompilerInstance::performSILProcessing(swift::SILModule*) + 84
12 swift-frontend           0x0000000104d269c4 performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 1376
13 swift-frontend           0x0000000104d26340 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 2888
14 swift-frontend           0x0000000104d29374 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 2944
15 swift-frontend           0x0000000104d27bb4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3572
16 swift-frontend           0x0000000104caea5c swift::mainEntry(int, char const**) + 3680
17 dyld                     0x000000018fa6c274 start + 2840

Expected behavior

The compiler emits a warning or an error. (Or compiles successfully?)

Environment

Apple Swift version 6.2-dev (LLVM 81859ac55f8d09a, Swift 8ec8a1229a7ea14)
Target: arm64-apple-macosx15.0
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

@YOCKOW YOCKOW 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 28, 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