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

Compiler crash when capturing optional isolated parameter in a closure #73197

Open
Jnosh opened this issue Apr 23, 2024 · 0 comments
Open

Compiler crash when capturing optional isolated parameter in a closure #73197

Jnosh opened this issue Apr 23, 2024 · 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

@Jnosh
Copy link
Contributor

Jnosh commented Apr 23, 2024

Description

The following snippet crashes the compiler with recent Swift 6.0 development snapshot toolchains.

Did not crash: swift-6.0-DEVELOPMENT-SNAPSHOT-2024-04-18-a
Does crash: swift-6.0-DEVELOPMENT-SNAPSHOT-2024-04-20-a and newer

The StrictConcurrency upcoming feature must be enabled for the crash to occur and I can only reproduce the crash when compiling via swift-frontend (as done by Xcode) not when invoking swiftc.

To reproduce, compile the snippet as follows:
<path to toolchain>/usr/bin/swift-frontend -frontend -c -enable-upcoming-feature StrictConcurrency Crash.swift

Reproduction

func f(f: () -> Void) {}

func main(isolation: isolated (any Actor)?) {
    f { isolation }
}

Stack dump

Assertion failed: ((!actorInstance || (actorIsolation.getKind() == ActorIsolation::ActorInstance && actorInstance->getType().isAnyActor())) && "actorInstance must be an actor if it is non-empty"), function SILIsolationInfo, file PartitionUtils.h, line 134.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /Users/<user>/Library/Developer/Toolchains/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-04-22-a.xctoolchain/usr/bin/swift-frontend -frontend -c -enable-upcoming-feature StrictConcurrency Crash.swift
1.	Apple Swift version 6.0-dev (LLVM 94447cf359772fc, Swift f36098a14a0d48b)
2.	Compiling with effective version 5.10
3.	While evaluating request ExecuteSILPipelineRequest(Run pipelines { Mandatory Diagnostic Passes + Enabling Optimization Passes } on SIL for Crash)
4.	While running pass #52 SILFunctionTransform "TransferNonSendable" on SILFunction "@$s5Crash4main9isolationyScA_pSgYi_tF".
 for 'main(isolation:)' (at Crash.swift:3: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           0x00000001097c8adc llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x00000001097c72a8 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x00000001097c9124 SignalHandler(int) + 304
3  libsystem_platform.dylib 0x000000019b1ef584 _sigtramp + 56
4  libsystem_pthread.dylib  0x000000019b1bec20 pthread_kill + 288
5  libsystem_c.dylib        0x000000019b0cba20 abort + 180
6  libsystem_c.dylib        0x000000019b0cad10 err + 0
7  swift-frontend           0x000000010992d38c llvm::DenseMapBase<llvm::DenseMap<swift::SILFunction*, std::__1::unique_ptr<swift::RegionAnalysisFunctionInfo, std::__1::default_delete<swift::RegionAnalysisFunctionInfo>>, llvm::DenseMapInfo<swift::SILFunction*, void>, llvm::detail::DenseMapPair<swift::SILFunction*, std::__1::unique_ptr<swift::RegionAnalysisFunctionInfo, std::__1::default_delete<swift::RegionAnalysisFunctionInfo>>>>, swift::SILFunction*, std::__1::unique_ptr<swift::RegionAnalysisFunctionInfo, std::__1::default_delete<swift::RegionAnalysisFunctionInfo>>, llvm::DenseMapInfo<swift::SILFunction*, void>, llvm::detail::DenseMapPair<swift::SILFunction*, std::__1::unique_ptr<swift::RegionAnalysisFunctionInfo, std::__1::default_delete<swift::RegionAnalysisFunctionInfo>>>>::clear() (.cold.1) + 0
8  swift-frontend           0x0000000104af76a4 swift::SILIsolationInfo::SILIsolationInfo(swift::ActorIsolation, swift::SILValue, swift::SILValue) + 180
9  swift-frontend           0x0000000104f6e4a0 swift::SILIsolationInfo::get(swift::SILInstruction*) + 1964
10 swift-frontend           0x0000000104aec994 swift::regionanalysisimpl::PartitionOpTranslator::translateSILPartialApply(swift::PartialApplyInst*) + 860
11 swift-frontend           0x0000000104ae6094 swift::regionanalysisimpl::PartitionOpTranslator::translateSILInstruction(swift::SILInstruction*)::'lambda0'()::operator()() const + 1504
12 swift-frontend           0x0000000104ae51fc swift::regionanalysisimpl::PartitionOpTranslator::translateSILInstruction(swift::SILInstruction*) + 136
13 swift-frontend           0x0000000104adf27c swift::regionanalysisimpl::PartitionOpTranslator::translateSILBasicBlock(swift::SILBasicBlock*, std::__1::vector<swift::PartitionOp, std::__1::allocator<swift::PartitionOp>>&) + 864
14 swift-frontend           0x0000000104af87e8 swift::BasicBlockData<swift::regionanalysisimpl::BlockPartitionState, 32u>::BasicBlockData(swift::SILFunction*, llvm::function_ref<swift::regionanalysisimpl::BlockPartitionState (swift::SILBasicBlock*)>) + 196
15 swift-frontend           0x0000000104ae0488 swift::RegionAnalysisFunctionInfo::RegionAnalysisFunctionInfo(swift::SILFunction*, swift::PostOrderFunctionInfo*) + 568
16 swift-frontend           0x0000000104ae29fc swift::RegionAnalysis::newFunctionAnalysis(swift::SILFunction*) + 56
17 swift-frontend           0x0000000104d2bc18 swift::FunctionAnalysisBase<swift::RegionAnalysisFunctionInfo>::get(swift::SILFunction*) + 80
18 swift-frontend           0x0000000104d2b93c (anonymous namespace)::TransferNonSendable::run() + 124
19 swift-frontend           0x0000000104d4c11c swift::SILPassManager::runPassOnFunction(unsigned int, swift::SILFunction*) + 1432
20 swift-frontend           0x0000000104d4cf88 swift::SILPassManager::runFunctionPasses(unsigned int, unsigned int) + 1060
21 swift-frontend           0x0000000104d4f8d8 swift::SILPassManager::execute() + 596
22 swift-frontend           0x0000000104d4a0fc swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 72
23 swift-frontend           0x0000000104d4a07c swift::ExecuteSILPipelineRequest::evaluate(swift::Evaluator&, swift::SILPipelineExecutionDescriptor) const + 68
24 swift-frontend           0x0000000104d857e4 swift::SimpleRequest<swift::ExecuteSILPipelineRequest, std::__1::tuple<> (swift::SILPipelineExecutionDescriptor), (swift::RequestFlags)1>::evaluateRequest(swift::ExecuteSILPipelineRequest const&, swift::Evaluator&) + 28
25 swift-frontend           0x0000000104d65f4c 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'()) + 204
26 swift-frontend           0x0000000104d4a2d8 swift::executePassPipelinePlan(swift::SILModule*, swift::SILPassPipelinePlan const&, bool, swift::irgen::IRGenModule*) + 64
27 swift-frontend           0x0000000104d68404 swift::runSILDiagnosticPasses(swift::SILModule&) + 192
28 swift-frontend           0x00000001045ace38 swift::CompilerInstance::performSILProcessing(swift::SILModule*) + 68
29 swift-frontend           0x0000000104371d24 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*) + 796
30 swift-frontend           0x000000010437165c swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1160
31 swift-frontend           0x000000010438266c withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 160
32 swift-frontend           0x0000000104373a48 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 708
33 swift-frontend           0x00000001043729b4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2368
34 swift-frontend           0x000000010418d240 swift::mainEntry(int, char const**) + 3096
35 dyld                     0x000000019ae360e0 start + 2360

Expected behavior

The compiler should not crash.

Environment

Apple Swift version 6.0-dev (LLVM 2c365f15bfc9eae, Swift 4e30159)
Target: arm64-apple-macosx14.0

Additional information

No response

@Jnosh Jnosh 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 Apr 23, 2024
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