Skip to content

Compiler crash with isolated default values #77448

Open
@magnusrk-ch

Description

@magnusrk-ch

Description

The crash is related to isolated default values, but I don't know what actually triggers it. The smallest repro case I found is given below. Most further simplifications stop triggering the crash.

  • Explicitly specifying the first argument to crashing avoids the crash
  • Passing no arguments to crashing avoids the crash
  • Removing the third argument of crashing avoids the crash
  • Making make() and Base nonisolated avoids the crash
  • Converting the callingVar var to a function appears to avoid the crash

IsolatedDefaultValues or Swift 6 mode is necessary to for the isolated default value of make(). The compiler crashes in either case.

Reproduction

@MainActor
public class Base {
  required init() {}
}

public class Subclass: Base {}

public protocol Populatable {}

extension Base: Populatable {}

@MainActor
extension Populatable where Self: Base {
  public static func make(_ populator: (Self) -> Void = { _ in }) -> Self {
    let view = Self()
    populator(view)
    return view
  }
}

extension Base {
  public func crashing(
    _ first: Base = .make(),
    second: String = "",
    third: String = ""
  ) {}

}

@MainActor
public class Foo {
  var callingVar: Subclass = .make { (stack: Subclass) in
    Subclass().crashing(second: "blah")
  }
}

Stack dump

0.	Program arguments: /Applications/Xcode_16.0.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file example.swift -target arm64-apple-macosx14.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode_16.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk -color-diagnostics -swift-version 6 -new-driver-path /Applications/Xcode_16.0.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -empty-abi-descriptor -resource-dir /Applications/Xcode_16.0.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -module-name example -disable-clang-spi -target-sdk-version 15.0 -target-sdk-name macosx15.0 -external-plugin-path /Applications/Xcode_16.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode_16.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode_16.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode_16.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Applications/Xcode_16.0.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode_16.0.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -o /var/folders/2b/ry9_r_b919d98h9t8k4577gr002jy0/T/TemporaryDirectory.IPqpEQ/example-1.o
1.	Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
2.	Compiling with the current language version
3.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "example.swift")
4.	While silgen emitStoredPropertyInitialization SIL function "@$s7example3FooC10callingVarAA8SubclassCvpfi".
 for expression at [example.swift:32:30 - line:34:3] RangeText=".make { (stack: Subclass) in
    Subclass().crashing(second: "blah")
  "
5.	While silgen closureexpr SIL function "@$s7example3FooC10callingVarAA8SubclassCvpfiyAFXEfU_".
 for expression at [example.swift:32:36 - line:34:3] RangeText="{ (stack: Subclass) in
    Subclass().crashing(second: "blah")
  "
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           0x0000000109eaf0fc llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000109ead350 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000109eaf6c8 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x000000018469a584 _sigtramp + 56
4  swift-frontend           0x0000000105283a34 emitRawApply(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::SubstitutionMap, llvm::ArrayRef<swift::Lowering::ManagedValue>, swift::CanTypeWrapper<swift::SILFunctionType>, swift::optionset::OptionSet<swift::ApplyFlags, unsigned char>, llvm::ArrayRef<swift::SILValue>, swift::SILValue, llvm::SmallVectorImpl<swift::SILValue>&, swift::Lowering::ExecutorBreadcrumb) + 664
5  swift-frontend           0x0000000105284bf4 swift::Lowering::SILGenFunction::emitApply(std::__1::unique_ptr<swift::Lowering::ResultPlan, std::__1::default_delete<swift::Lowering::ResultPlan>>&&, swift::Lowering::ArgumentScope&&, swift::SILLocation, swift::Lowering::ManagedValue, swift::SubstitutionMap, llvm::ArrayRef<swift::Lowering::ManagedValue>, swift::Lowering::CalleeTypeInfo const&, swift::optionset::OptionSet<swift::ApplyFlags, unsigned char>, swift::Lowering::SGFContext, std::__1::optional<swift::ActorIsolation>) + 2276
6  swift-frontend           0x000000010528bcd4 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 2240
7  swift-frontend           0x000000010528a18c swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 3116
8  swift-frontend           0x00000001053b53a0 swift::Lowering::SILGenFunction::emitReturnExpr(swift::SILLocation, swift::Expr*) + 792
9  swift-frontend           0x00000001053b2d00 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 8848
10 swift-frontend           0x00000001053b2078 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 5640
11 swift-frontend           0x000000010532a0e4 swift::Lowering::SILGenFunction::emitClosure(swift::AbstractClosureExpr*) + 832
12 swift-frontend           0x0000000105274894 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 4312
13 swift-frontend           0x000000010527e490 void llvm::function_ref<void ()>::callback_fn<swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*, swift::Lowering::FunctionTypeInfo const&)::$_0>(long) + 200
14 swift-frontend           0x0000000105277594 swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*, swift::Lowering::FunctionTypeInfo const&) + 280
15 swift-frontend           0x000000010531e4f0 (anonymous namespace)::RValueEmitter::visitAbstractClosureExpr(swift::AbstractClosureExpr*, swift::Lowering::SGFContext) + 1984
16 swift-frontend           0x00000001052fa310 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 40
17 swift-frontend           0x00000001052d9fb8 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)>) + 316
18 swift-frontend           0x0000000105259bf8 swift::Lowering::ArgumentSource::getConverted(swift::Lowering::SILGenFunction&, swift::Lowering::Conversion const&, swift::Lowering::SGFContext) && + 136
19 swift-frontend           0x0000000105298fe0 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, std::__1::optional<swift::AnyFunctionType::Param>) + 5528
20 swift-frontend           0x0000000105286e74 (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, std::__1::optional<swift::AnyFunctionType::Param>) + 216
21 swift-frontend           0x0000000105297730 (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern) + 256
22 swift-frontend           0x00000001052a35fc (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&) && + 664
23 swift-frontend           0x00000001052a301c (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, swift::ForeignInfo const&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, std::__1::optional<swift::SILLocation>&) + 1000
24 swift-frontend           0x000000010528bc00 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 2028
25 swift-frontend           0x000000010528a18c swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 3116
26 swift-frontend           0x00000001053b53a0 swift::Lowering::SILGenFunction::emitReturnExpr(swift::SILLocation, swift::Expr*) + 792
27 swift-frontend           0x000000010532da4c swift::Lowering::SILGenFunction::emitGeneratorFunction(swift::SILDeclRef, swift::Expr*, bool) + 2228
28 swift-frontend           0x00000001052754a0 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 7396
29 swift-frontend           0x0000000105276140 swift::Lowering::SILGenModule::emitOrDelayFunction(swift::SILDeclRef) + 216
30 swift-frontend           0x00000001052781a4 swift::Lowering::SILGenModule::emitStoredPropertyInitialization(swift::PatternBindingDecl*, unsigned int) + 336
31 swift-frontend           0x00000001053c6174 (anonymous namespace)::SILGenType::emitType() + 868
32 swift-frontend           0x00000001052733a8 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 104
33 swift-frontend           0x0000000105279dbc swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 1804
34 swift-frontend           0x00000001053b06b0 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
35 swift-frontend           0x000000010527ec98 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
36 swift-frontend           0x0000000104858f34 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 920
37 swift-frontend           0x000000010485c228 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1680
38 swift-frontend           0x000000010485af58 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3572
39 swift-frontend           0x00000001047e201c swift::mainEntry(int, char const**) + 3680
40 dyld                     0x00000001842df154 start + 2476

Expected behavior

The code should compile.

Environment

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx14.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