Skip to content

SILGen crash sending typed throws closure through Mutex #82554

Open
@KeithBauerANZ

Description

@KeithBauerANZ

Description

Somehow, sending a closure with a typed throws through a mutex, causes a SILGen crash.

Reproduction

import Synchronization

func f<E: Error>(
    closure: sending @escaping () throws(E) -> Void
) throws(E) {
    let m = Mutex(Optional(closure))
    let c = m.withLock {
        let result = $0
        $0 = nil
        return result!
    }
    try c()
}
swiftc -swift-version 6 SILGenTypedThrows.swift

Stack dump

error: compile command failed due to signal 11 (use -v to see invocation)
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /Applications/Xcode-26.0.0-Beta.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file SILGenTypedThrows.swift -target arm64-apple-macosx15.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode-26.0.0-Beta.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX26.0.sdk -color-diagnostics -Xcc -fcolor-diagnostics -swift-version 6 -new-driver-path /Applications/Xcode-26.0.0-Beta.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -empty-abi-descriptor -no-auto-bridging-header-chaining -module-name SILGenTypedThrows -disable-clang-spi -target-sdk-version 26.0 -target-sdk-name macosx26.0 -external-plugin-path /Applications/Xcode-26.0.0-Beta.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode-26.0.0-Beta.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode-26.0.0-Beta.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode-26.0.0-Beta.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -in-process-plugin-server-path /Applications/Xcode-26.0.0-Beta.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/libSwiftInProcPluginServer.dylib -plugin-path /Applications/Xcode-26.0.0-Beta.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode-26.0.0-Beta.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -o /var/folders/jg/3hxr5hxx7hd3kcfjs1c7ylqr0000gp/T/TemporaryDirectory.ujpHFo/SILGenTypedThrows-1.o
1.	Apple Swift version 6.2 (swiftlang-6.2.0.10.950 clang-1700.3.10.950)
2.	Compiling with the current language version
3.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "SILGenTypedThrows.swift")
4.	While silgen emitFunction SIL function "@$s17SILGenTypedThrows1f7closureyyyxYKcn_txYKs5ErrorRzlF".
 for 'f(closure:)' (at SILGenTypedThrows.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           0x0000000109553450 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000109550de0 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000109553a7c SignalHandler(int, __siginfo*, void*) + 344
3  libsystem_platform.dylib 0x0000000195c3c624 _sigtramp + 56
4  swift-frontend           0x0000000103a7b1b4 (anonymous namespace)::SubstFunctionTypePatternVisitor::visit(swift::CanType, swift::Lowering::AbstractionPattern) + 768
5  swift-frontend           0x0000000103a7b1b4 (anonymous namespace)::SubstFunctionTypePatternVisitor::visit(swift::CanType, swift::Lowering::AbstractionPattern) + 768
6  swift-frontend           0x0000000103a7ac48 (anonymous namespace)::SubstFunctionTypePatternVisitor::handleUnabstractedFunctionType(swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern) + 232
7  swift-frontend           0x0000000103a7a7b8 swift::Lowering::AbstractionPattern::getSubstFunctionTypePattern(swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::TypeConverter&, swift::Lowering::AbstractionPattern, swift::CanType, bool&) const + 240
8  swift-frontend           0x0000000103ac1a5c getSILFunctionType(swift::Lowering::TypeConverter&, swift::TypeExpansionContext, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::SILExtInfoBuilder, (anonymous namespace)::Conventions const&, swift::ForeignInfo const&, std::__1::optional<swift::SILDeclRef>, std::__1::optional<swift::SILDeclRef>, std::__1::optional<swift::SubstitutionMap>, swift::ProtocolConformanceRef) + 1428
9  swift-frontend           0x0000000103ab9468 getNativeSILFunctionType(swift::Lowering::TypeConverter&, swift::TypeExpansionContext, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::SILExtInfoBuilder, std::__1::optional<swift::SILDeclRef>, std::__1::optional<swift::SILDeclRef>, std::__1::optional<swift::SubstitutionMap>, swift::ProtocolConformanceRef) + 684
10 swift-frontend           0x0000000103b7ec24 swift::Lowering::TypeConverter::computeLoweredRValueType(swift::TypeExpansionContext, swift::Lowering::AbstractionPattern, swift::CanType)::LoweredRValueTypeVisitor::visitAnyFunctionType(swift::CanTypeWrapper<swift::AnyFunctionType>) + 1272
11 swift-frontend           0x0000000103b6ba08 swift::Lowering::TypeConverter::getTypeLowering(swift::Lowering::AbstractionPattern, swift::Type, swift::TypeExpansionContext) + 540
12 swift-frontend           0x0000000103b7e4c0 swift::Lowering::TypeConverter::computeLoweredRValueType(swift::TypeExpansionContext, swift::Lowering::AbstractionPattern, swift::CanType)::LoweredRValueTypeVisitor::visitType(swift::CanType) + 592
13 swift-frontend           0x0000000103b6ba08 swift::Lowering::TypeConverter::getTypeLowering(swift::Lowering::AbstractionPattern, swift::Type, swift::TypeExpansionContext) + 540
14 swift-frontend           0x0000000103ac5728 (anonymous namespace)::DestructureInputs::visit(swift::ValueOwnership, int, bool, bool, swift::Lowering::AbstractionPattern, swift::CanType, swift::ParameterTypeFlags) + 424
15 swift-frontend           0x0000000103ac519c (anonymous namespace)::DestructureInputs::visit(swift::Lowering::AbstractionPattern, swift::AnyFunctionType::Param, unsigned int, bool, bool) + 312
16 swift-frontend           0x0000000103ac6750 void llvm::function_ref<void (swift::Lowering::FunctionParamGenerator&)>::callback_fn<(anonymous namespace)::DestructureInputs::visitTopLevelParams(swift::Lowering::AbstractionPattern, swift::ArrayRefView<swift::AnyFunctionType::Param, swift::AnyFunctionType::CanParam, swift::AnyFunctionType::CanParam::getFromParam(swift::AnyFunctionType::Param const&), true>, swift::SILExtInfoBuilder, bool&)::'lambda'(swift::Lowering::FunctionParamGenerator&)>(long, swift::Lowering::FunctionParamGenerator&) + 756
17 swift-frontend           0x0000000103a78854 swift::Lowering::AbstractionPattern::forEachFunctionParam(swift::ArrayRefView<swift::AnyFunctionType::Param, swift::AnyFunctionType::CanParam, swift::AnyFunctionType::CanParam::getFromParam(swift::AnyFunctionType::Param const&), true>, bool, llvm::function_ref<void (swift::Lowering::FunctionParamGenerator&)>) const + 184
18 swift-frontend           0x0000000103ac3f78 (anonymous namespace)::DestructureInputs::destructure(swift::Lowering::AbstractionPattern, swift::ArrayRefView<swift::AnyFunctionType::Param, swift::AnyFunctionType::CanParam, swift::AnyFunctionType::CanParam::getFromParam(swift::AnyFunctionType::Param const&), true>, swift::SILExtInfoBuilder, bool&) + 1208
19 swift-frontend           0x0000000103ac1e7c getSILFunctionType(swift::Lowering::TypeConverter&, swift::TypeExpansionContext, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::SILExtInfoBuilder, (anonymous namespace)::Conventions const&, swift::ForeignInfo const&, std::__1::optional<swift::SILDeclRef>, std::__1::optional<swift::SILDeclRef>, std::__1::optional<swift::SubstitutionMap>, swift::ProtocolConformanceRef) + 2484
20 swift-frontend           0x0000000103ab9468 getNativeSILFunctionType(swift::Lowering::TypeConverter&, swift::TypeExpansionContext, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::SILExtInfoBuilder, std::__1::optional<swift::SILDeclRef>, std::__1::optional<swift::SILDeclRef>, std::__1::optional<swift::SubstitutionMap>, swift::ProtocolConformanceRef) + 684
21 swift-frontend           0x0000000103abc2a8 getUncachedSILFunctionTypeForConstant(swift::Lowering::TypeConverter&, swift::TypeExpansionContext, swift::SILDeclRef, swift::Lowering::TypeConverter::LoweredFormalTypes) + 1392
22 swift-frontend           0x0000000103abcec4 swift::Lowering::TypeConverter::getConstantInfo(swift::TypeExpansionContext, swift::SILDeclRef) + 200
23 swift-frontend           0x0000000103ab2d1c swift::SILFunctionBuilder::getOrCreateFunction(swift::SILLocation, swift::SILDeclRef, swift::ForDefinition_t, llvm::function_ref<swift::SILFunction* (swift::SILLocation, swift::SILDeclRef)>, swift::ProfileCounter) + 124
24 swift-frontend           0x0000000103c97128 swift::Lowering::SILGenModule::getFunction(swift::SILDeclRef, swift::ForDefinition_t) + 728
25 swift-frontend           0x0000000103ca2c98 void llvm::function_ref<void ()>::callback_fn<swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*, swift::Lowering::FunctionTypeInfo const&)::$_0>(long) + 92
26 swift-frontend           0x0000000103d5043c (anonymous namespace)::RValueEmitter::visitAbstractClosureExpr(swift::AbstractClosureExpr*, swift::Lowering::SGFContext) + 1836
27 swift-frontend           0x0000000103d2733c swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 40
28 swift-frontend           0x0000000103d047a8 swift::Lowering::SILGenFunction::emitConvertedRValue(swift::SILLocation, swift::Lowering::Conversion const&, swift::Lowering::SGFContext, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::SGFContext)>) + 300
29 swift-frontend           0x0000000103c7d468 swift::Lowering::ArgumentSource::getConverted(swift::Lowering::SILGenFunction&, swift::Lowering::Conversion const&, swift::Lowering::SGFContext) && + 124
30 swift-frontend           0x0000000103cbfdb8 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, bool, std::__1::optional<swift::AnyFunctionType::Param>) + 5964
31 swift-frontend           0x0000000103cac324 (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, bool, std::__1::optional<swift::AnyFunctionType::Param>) + 204
32 swift-frontend           0x0000000103cbe010 (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern, llvm::ArrayRef<swift::LifetimeDependenceInfo>) + 304
33 swift-frontend           0x0000000103ccaac8 (anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, llvm::ArrayRef<swift::LifetimeDependenceInfo>, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::SmallVectorImpl<(anonymous namespace)::DelayedArgument>&, swift::ForeignInfo const&) && + 676
34 swift-frontend           0x0000000103cca27c (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, llvm::ArrayRef<swift::LifetimeDependenceInfo>, swift::ForeignInfo const&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, std::__1::optional<swift::SILLocation>&) + 1112
35 swift-frontend           0x0000000103cb0edc (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 1112
36 swift-frontend           0x0000000103caf874 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 3192
37 swift-frontend           0x0000000103d23fdc swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, std::__1::optional<swift::SILLocation>) + 132
38 swift-frontend           0x0000000103d0d198 swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int, bool) + 1728
39 swift-frontend           0x0000000103d154ec swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Decl*) + 164
40 swift-frontend           0x0000000103de40d4 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 6396
41 swift-frontend           0x0000000103d5c8a0 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 384
42 swift-frontend           0x0000000103c99e54 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 7596
43 swift-frontend           0x0000000103c9aea4 swift::Lowering::SILGenModule::emitOrDelayFunction(swift::SILDeclRef) + 236
44 swift-frontend           0x0000000103c98094 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 136
45 swift-frontend           0x0000000103c9ec1c swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 2364
46 swift-frontend           0x0000000103de1e80 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&) + 208
47 swift-frontend           0x0000000103ca36a4 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'()) + 572
48 swift-frontend           0x00000001031bff0c swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 964
49 swift-frontend           0x00000001031c3274 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1764
50 swift-frontend           0x00000001031c1e90 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3580
51 swift-frontend           0x0000000103143444 swift::mainEntry(int, char const**) + 5412
52 dyld                     0x0000000195862b98 start + 6076

Expected behavior

Not… crash?

Environment

swift-driver version: 1.127.5.3 Apple Swift version 6.2 (swiftlang-6.2.0.10.950 clang-1700.3.10.950)
Target: arm64-apple-macosx15.0

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.crashBug: A crash, i.e., an abnormal termination of softwaretriage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions