Skip to content

Consistent crash related to opaque return types + variadic generics #82260

Open
@GeorgeLyon

Description

@GeorgeLyon

Description

This code consistently crashes and I have not found a workaround.

Reproduction

  static func enumSchemaCaseDefinition<
    Value,
    AssociatedValueSchema
  >(
    name: StaticString,
    description: String? = nil,
    associatedValues associatedValue: SchemaCoding.SchemaCodingSupport
      .EnumSchemaNamedAssociatedValueDefinition<
        AssociatedValueSchema
      >,
    initializer: @escaping @Sendable (AssociatedValueSchema.Value) -> Value
  ) -> EnumSchemaCaseDefinition<
    Value,
    some Schema<AssociatedValueSchema.Value>
  > {
    let schema: some ObjectSchema<AssociatedValueSchema.Value> = objectSchema(
      representing: AssociatedValueSchema.Value.self,
      description: nil,
      properties: (ObjectPropertyDefinition(
        name: associatedValue.name,
        description: nil,
        schema: associatedValue.schema
      )),
      initializer: { (value: AssociatedValueSchema.Value) in
        value
      }
    )
    let initializer = { @Sendable (value: AssociatedValueSchema.Value) -> Value in
      initializer(value)
    }
    let def: EnumSchemaCaseDefinition<Value, some Schema<AssociatedValueSchema.Value>> = EnumSchemaCaseDefinition(
       name: name,
       description: description,
       schema: schema,
       initializer: initializer
     )
    /// Uncommenting this crashes the compiler
    // return def
  }

Stack dump

Building for debugging...
[0/6] Write sources
[1/6] Write OpaqueReturnTypeError-entitlement.plist
[2/6] Write swift-version-FA066E4FF67FA78.txt
error: compile command failed due to signal 5 (use -v to see invocation)
[4/10] Compiling OpaqueReturnTypeError Object Schema.swift
[5/10] Compiling OpaqueReturnTypeError Schema.swift
[6/10] Emitting module OpaqueReturnTypeError
[cleanup]   %2 = alloc_stack $Pack{AssociatedValueSchema.Value}, let, name "value" // user: %3
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: "/Volumes/Shared/Developer/Xcode/Xcode 26 beta 1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend" -frontend -c -primary-file "/Volumes/Shared/Developer/Projects/OpaqueReturnTypeError/Sources/OpaqueReturnTypeError/Enum Schema.swift" "/Volumes/Shared/Developer/Projects/OpaqueReturnTypeError/Sources/OpaqueReturnTypeError/Object Schema.swift" /Volumes/Shared/Developer/Projects/OpaqueReturnTypeError/Sources/OpaqueReturnTypeError/Schema.swift -emit-dependencies-path "/Volumes/Shared/Developer/Projects/OpaqueReturnTypeError/.build/arm64-apple-macosx/debug/OpaqueReturnTypeError.build/Enum Schema.d" -emit-reference-dependencies-path "/Volumes/Shared/Developer/Projects/OpaqueReturnTypeError/.build/arm64-apple-macosx/debug/OpaqueReturnTypeError.build/Enum Schema.swiftdeps" -serialize-diagnostics-path "/Volumes/Shared/Developer/Projects/OpaqueReturnTypeError/.build/arm64-apple-macosx/debug/OpaqueReturnTypeError.build/Enum Schema.dia" -target arm64-apple-macosx14.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk "/Volumes/Shared/Developer/Xcode/Xcode 26 beta 1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX26.0.sdk" -I /Volumes/Shared/Developer/Projects/OpaqueReturnTypeError/.build/arm64-apple-macosx/debug/Modules -I "/Volumes/Shared/Developer/Xcode/Xcode 26 beta 1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib" -F "/Volumes/Shared/Developer/Xcode/Xcode 26 beta 1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks" -F "/Volumes/Shared/Developer/Xcode/Xcode 26 beta 1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/PrivateFrameworks" -no-color-diagnostics -Xcc -fno-color-diagnostics -enable-testing -g -debug-info-format=dwarf -dwarf-version=4 -module-cache-path /Volumes/Shared/Developer/Projects/OpaqueReturnTypeError/.build/arm64-apple-macosx/debug/ModuleCache -swift-version 6 -Onone -D SWIFT_PACKAGE -D DEBUG -D SWIFT_MODULE_RESOURCE_BUNDLE_UNAVAILABLE -new-driver-path "/Volumes/Shared/Developer/Xcode/Xcode 26 beta 1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver" -entry-point-function-name OpaqueReturnTypeError_main -empty-abi-descriptor -plugin-path "/Volumes/Shared/Developer/Xcode/Xcode 26 beta 1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins/testing" -enable-anonymous-context-mangled-names -file-compilation-dir /Volumes/Shared/Developer/Projects/OpaqueReturnTypeError -Xcc -isysroot -Xcc "/Volumes/Shared/Developer/Xcode/Xcode 26 beta 1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX26.0.sdk" -Xcc -F -Xcc "/Volumes/Shared/Developer/Xcode/Xcode 26 beta 1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks" -Xcc -F -Xcc "/Volumes/Shared/Developer/Xcode/Xcode 26 beta 1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/PrivateFrameworks" -Xcc -fPIC -Xcc -g -no-auto-bridging-header-chaining -module-name OpaqueReturnTypeError -package-name opaquereturntypeerror -disable-clang-spi -target-sdk-version 26.0 -target-sdk-name macosx26.0 -external-plugin-path "/Volumes/Shared/Developer/Xcode/Xcode 26 beta 1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Volumes/Shared/Developer/Xcode/Xcode 26 beta 1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server" -external-plugin-path "/Volumes/Shared/Developer/Xcode/Xcode 26 beta 1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Volumes/Shared/Developer/Xcode/Xcode 26 beta 1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server" -in-process-plugin-server-path "/Volumes/Shared/Developer/Xcode/Xcode 26 beta 1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/libSwiftInProcPluginServer.dylib" -plugin-path "/Volumes/Shared/Developer/Xcode/Xcode 26 beta 1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins" -plugin-path "/Volumes/Shared/Developer/Xcode/Xcode 26 beta 1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins" -o "/Volumes/Shared/Developer/Projects/OpaqueReturnTypeError/.build/arm64-apple-macosx/debug/OpaqueReturnTypeError.build/Enum Schema.swift.o" -index-store-path /Volumes/Shared/Developer/Projects/OpaqueReturnTypeError/.build/arm64-apple-macosx/debug/index/store -index-system-modules
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 "/Volumes/Shared/Developer/Projects/OpaqueReturnTypeError/Sources/OpaqueReturnTypeError/Enum Schema.swift")
4.	While silgen emitFunction SIL function "@$s21OpaqueReturnTypeError12SchemaCodingO0eF7SupportO04enumE14CaseDefinition4name11description16associatedValues11initializerAE04EnumeiJ0Vy__xQrGs12StaticStringV_SSSgAE0pe20NamedAssociatedValueJ0Vy__q_Gx0U0Qy_YbctAE0E0R_r0_lFZ".
 for 'enumSchemaCaseDefinition(name:description:associatedValues:initializer:)' (at /Volumes/Shared/Developer/Projects/OpaqueReturnTypeError/Sources/OpaqueReturnTypeError/Enum Schema.swift:31:3)
5.	While silgen closureexpr SIL function "@$s21OpaqueReturnTypeError12SchemaCodingO0eF7SupportO04enumE14CaseDefinition4name11description16associatedValues11initializerAE04EnumeiJ0Vy__xQrGs12StaticStringV_SSSgAE0pe20NamedAssociatedValueJ0Vy__q_Gx0U0Qy_YbctAE0E0R_r0_lFZA2UYbcfU_".
 for expression at [/Volumes/Shared/Developer/Projects/OpaqueReturnTypeError/Sources/OpaqueReturnTypeError/Enum Schema.swift:54:20 - line:56:7] RangeText="{ (value: AssociatedValueSchema.Value) in
        value
      "
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           0x00000001086d3cb0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x00000001086d1640 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x00000001086d42dc SignalHandler(int, __siginfo*, void*) + 344
3  libsystem_platform.dylib 0x000000018e698704 _sigtramp + 56
4  swift-frontend           0x0000000102f3f3b0 (anonymous namespace)::Transform::transform(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::SILType, swift::Lowering::SGFContext) + 7248
5  swift-frontend           0x0000000102f3cdfc swift::Lowering::SILGenFunction::emitOrigToSubstValue(swift::SILLocation, swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::SGFContext) + 328
6  swift-frontend           0x0000000102f624a4 (anonymous namespace)::EmitBBArguments::handleScalar(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::Initialization*, bool, bool) + 1660
7  swift-frontend           0x0000000102f63c8c swift::CanTypeVisitor<(anonymous namespace)::EmitBBArguments, swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::Lowering::Initialization*>::visitBuiltinIntegerType(swift::CanTypeWrapper<swift::BuiltinIntegerType>, swift::Lowering::AbstractionPattern, swift::Lowering::Initialization*) + 100
8  swift-frontend           0x0000000102f635a0 swift::CanTypeVisitor<(anonymous namespace)::EmitBBArguments, swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::Lowering::Initialization*>::visit(swift::CanType, swift::Lowering::AbstractionPattern, swift::Lowering::Initialization*) + 424
9  swift-frontend           0x0000000102f617b0 (anonymous namespace)::ArgumentInitHelper::makeArgument(swift::SILLocation, swift::ParamDecl*) + 1328
10 swift-frontend           0x0000000102f60024 (anonymous namespace)::ArgumentInitHelper::emitParam(swift::ParamDecl*) + 396
11 swift-frontend           0x0000000102f5edc0 swift::Lowering::SILGenFunction::emitBasicProlog(swift::DeclContext*, swift::ParameterList*, swift::ParamDecl*, swift::Type, std::__1::optional<swift::Type>, swift::SourceLoc, unsigned int) + 2836
12 swift-frontend           0x0000000102f5c590 swift::Lowering::SILGenFunction::emitProlog(swift::DeclContext*, swift::CaptureInfo, swift::ParameterList*, swift::ParamDecl*, swift::Type, std::__1::optional<swift::Type>, swift::SourceLoc) + 140
13 swift-frontend           0x0000000102ee068c swift::Lowering::SILGenFunction::emitClosure(swift::AbstractClosureExpr*) + 728
14 swift-frontend           0x0000000102e1cee8 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 5160
15 swift-frontend           0x0000000102e266e8 void llvm::function_ref<void ()>::callback_fn<swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*, swift::Lowering::FunctionTypeInfo const&)::$_0>(long) + 200
16 swift-frontend           0x0000000102ed3f00 (anonymous namespace)::RValueEmitter::visitAbstractClosureExpr(swift::AbstractClosureExpr*, swift::Lowering::SGFContext) + 1836
17 swift-frontend           0x0000000102eaae00 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 40
18 swift-frontend           0x0000000102e88158 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
19 swift-frontend           0x0000000102e00fc8 swift::Lowering::ArgumentSource::getConverted(swift::Lowering::SILGenFunction&, swift::Lowering::Conversion const&, swift::Lowering::SGFContext) && + 124
20 swift-frontend           0x0000000102e43800 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, bool, std::__1::optional<swift::AnyFunctionType::Param>) + 6112
21 swift-frontend           0x0000000102e2fcd8 (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, bool, std::__1::optional<swift::AnyFunctionType::Param>) + 204
22 swift-frontend           0x0000000102e419c4 (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern, llvm::ArrayRef<swift::LifetimeDependenceInfo>) + 304
23 swift-frontend           0x0000000102e4e47c (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
24 swift-frontend           0x0000000102e4dc30 (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
25 swift-frontend           0x0000000102e34890 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 1112
26 swift-frontend           0x0000000102e33228 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 3192
27 swift-frontend           0x0000000102ecae90 (anonymous namespace)::RValueEmitter::visitUnderlyingToOpaqueExpr(swift::UnderlyingToOpaqueExpr*, swift::Lowering::SGFContext) + 636
28 swift-frontend           0x0000000102ea7aa0 swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, std::__1::optional<swift::SILLocation>) + 132
29 swift-frontend           0x0000000102e90b48 swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int, bool) + 1728
30 swift-frontend           0x0000000102e98e9c swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Decl*) + 164
31 swift-frontend           0x0000000102f67648 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 6396
32 swift-frontend           0x0000000102ee0364 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 384
33 swift-frontend           0x0000000102e1d86c swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 7596
34 swift-frontend           0x0000000102e1e888 swift::Lowering::SILGenModule::emitOrDelayFunction(swift::SILDeclRef) + 236
35 swift-frontend           0x0000000102e1baac swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 136
36 swift-frontend           0x0000000102f82fd4 SILGenExtension::visitFuncDecl(swift::FuncDecl*) + 236
37 swift-frontend           0x0000000102f7eec4 SILGenExtension::emitExtension(swift::ExtensionDecl*) + 348
38 swift-frontend           0x0000000102e1ba08 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 684
39 swift-frontend           0x0000000102e22600 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 2364
40 swift-frontend           0x0000000102f653f4 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
41 swift-frontend           0x0000000102e27088 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
42 swift-frontend           0x0000000102347d78 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 964
43 swift-frontend           0x000000010234b0e0 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1764
44 swift-frontend           0x0000000102349cfc swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3580
45 swift-frontend           0x00000001022cb390 swift::mainEntry(int, char const**) + 5412
46 dyld                     0x000000018e2d9854 start + 6256

Expected behavior

Doesn't crash.

Environment

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-macosx26.0

Swift version 6.1.2 (swift-6.1.2-RELEASE)
Target: aarch64-unknown-linux-gnu

Additional information

Github Repo:

https://github.com/GeorgeLyon/OpaqueReturnTypeCompilerCrash/blob/957f3b69bb9344d11375a5d91f6799c4a42c644b/Sources/OpaqueReturnTypeError/Enum%20Schema.swift#L67-L68

zip:

OpaqueReturnTypeError.zip

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