Open
Description
Description
Filed in FB17932177
In a module, we create below struct that receives
@MainActor` closure for initalizer
@MainActor
public struct BugStruct {
let closure: @Sendable @MainActor () -> Void // Without @Sendable is also okay
public init(
closure: @escaping @Sendable @MainActor () -> Void, // Without @Sendable is also okay
) {
self.closure = closure
}
}
And using it from other module makes compier crash like below
@MainActor
struct Proxy {
private let bugStruct: BugStruct
init() {
bugStruct = BugStruct { } // Crash!!!!
}
}
Reproduction
@MainActor
public struct BugStruct {
let closure: @Sendable @MainActor () -> Void // Without @Sendable is also okay
public init(
closure: @escaping @Sendable @MainActor () -> Void, // Without @Sendable is also okay
) {
self.closure = closure
}
}
And using it from other module makes compier crash like below
@MainActor
struct Proxy {
private let bugStruct: BugStruct
init() {
bugStruct = BugStruct { } // Crash!!!!
}
}
Stack dump
1. Apple Swift version 6.2 (swiftlang-6.2.0.9.909 clang-1700.3.9.907)
2. Compiling with the current language version
3. While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "/Users/freddi/workspace/BugTest6-2/BugTest6-2/ViewController.swift")
4. While silgen constructor initializer SIL function "@$s10BugTest6_25ProxyCACycfc".
for 'init()' (at /Users/freddi/workspace/BugTest6-2/BugTest6-2/ViewController.swift:15:5)
5. While silgen closureexpr SIL function "@$s10BugTest6_25ProxyCACycfcyyYbYCcfU_".
for expression at [/Users/freddi/workspace/BugTest6-2/BugTest6-2/ViewController.swift:16:31 - line:16:33] RangeText="{ "
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 0x0000000108d2fcb0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1 swift-frontend 0x0000000108d2d640 llvm::sys::RunSignalHandlers() + 112
2 swift-frontend 0x0000000108d302dc SignalHandler(int, __siginfo*, void*) + 344
3 libsystem_platform.dylib 0x000000018ddb4624 _sigtramp + 56
4 swift-frontend 0x00000001034cfd34 swift::Lowering::SILGenFunction::emitExpectedExecutorProlog() + 652
5 swift-frontend 0x00000001034cfd34 swift::Lowering::SILGenFunction::emitExpectedExecutorProlog() + 652
6 swift-frontend 0x00000001035ba10c swift::Lowering::SILGenFunction::emitProlog(swift::DeclContext*, swift::CaptureInfo, swift::ParameterList*, swift::ParamDecl*, swift::Type, std::__1::optional<swift::Type>, swift::SourceLoc) + 7176
7 swift-frontend 0x000000010353c68c swift::Lowering::SILGenFunction::emitClosure(swift::AbstractClosureExpr*) + 728
8 swift-frontend 0x0000000103478ee8 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 5160
9 swift-frontend 0x00000001034826e8 void llvm::function_ref<void ()>::callback_fn<swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*, swift::Lowering::FunctionTypeInfo const&)::$_0>(long) + 200
10 swift-frontend 0x000000010353041c (anonymous namespace)::RValueEmitter::visitAbstractClosureExpr(swift::AbstractClosureExpr*, swift::Lowering::SGFContext) + 3144
11 swift-frontend 0x0000000103506e00 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 40
12 swift-frontend 0x000000010349f4a8 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, bool, std::__1::optional<swift::AnyFunctionType::Param>) + 5256
13 swift-frontend 0x000000010348bcd8 (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, bool, std::__1::optional<swift::AnyFunctionType::Param>) + 204
14 swift-frontend 0x000000010349d9c4 (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern, llvm::ArrayRef<swift::LifetimeDependenceInfo>) + 304
15 swift-frontend 0x00000001034aa47c (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
16 swift-frontend 0x00000001034a9c30 (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
17 swift-frontend 0x0000000103490890 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 1112
18 swift-frontend 0x000000010348f228 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 3192
19 swift-frontend 0x000000010356cd44 swift::Lowering::SILGenFunction::emitAssignToLValue(swift::SILLocation, swift::Lowering::ArgumentSource&&, swift::Lowering::LValue&&) + 356
20 swift-frontend 0x000000010352b0a8 (anonymous namespace)::RValueEmitter::visitAssignExpr(swift::AssignExpr*, swift::Lowering::SGFContext) + 980
21 swift-frontend 0x000000010350755c swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 988
22 swift-frontend 0x00000001035c36b4 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 6504
23 swift-frontend 0x00000001034db018 swift::Lowering::SILGenFunction::emitClassConstructorInitializer(swift::ConstructorDecl*) + 4888
24 swift-frontend 0x00000001034795c8 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 6920
25 swift-frontend 0x000000010347a888 swift::Lowering::SILGenModule::emitOrDelayFunction(swift::SILDeclRef) + 236
26 swift-frontend 0x000000010347bd00 swift::Lowering::SILGenModule::emitConstructor(swift::ConstructorDecl*) + 312
27 swift-frontend 0x00000001035da108 (anonymous namespace)::SILGenType::emitType() + 584
28 swift-frontend 0x00000001034777c0 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 100
29 swift-frontend 0x000000010347e600 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 2364
30 swift-frontend 0x00000001035c13f4 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
31 swift-frontend 0x0000000103483088 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
32 swift-frontend 0x00000001029a3d78 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 964
33 swift-frontend 0x00000001029a70e0 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1764
34 swift-frontend 0x00000001029a5cfc swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3580
35 swift-frontend 0x0000000102927390 swift::mainEntry(int, char const**) + 5412
36 dyld 0x000000018d9dab98 start + 6076
Expected behavior
Not crash
Environment
- Xcode 26 Beta 1 (17A5241e)
- swift-driver version: 1.127.4.2 Apple Swift version 6.2 (swiftlang-6.2.0.9.909 clang-1700.3.9.907)
Target: arm64-apple-macosx15.0
Additional information
If we made BugStruct class
, compiler will not crash