Open El-Fitz opened 4 days ago
I think I've also reproduced it in another case, but here I can't figure out how to avoid this one.
protocol ContextDescriptor: Sendable {
}
protocol OutcomeDescriptor: Sendable {
}
protocol ResultDescriptor: Sendable {
}
protocol ErasedReducer<Context>: Sendable {
associatedtype Context: ContextDescriptor
associatedtype TriggerOutcome: OutcomeDescriptor
associatedtype Result: ResultDescriptor
var name: String { get }
var function: @Sendable (_ context: Context?, _ trigger: TriggerOutcome) -> Result { get }
}
protocol Reducer<Context, TriggerOutcome>: ErasedReducer {
var name: String { get }
var function: @Sendable (_ context: Context?, _ trigger: TriggerOutcome) -> Result { get }
}
struct ExampleContext: ContextDescriptor {
}
struct ExampleOutcome: OutcomeDescriptor {
}
struct ExampleResult: ResultDescriptor {
}
struct ExampleReducer<Context: ContextDescriptor, TriggerOutcome: OutcomeDescriptor, Result: ResultDescriptor>: Reducer {
let name: String
let function: @Sendable (_ context: Context?, _ trigger: TriggerOutcome) -> Result
}
class ExampleService<Context: ContextDescriptor> {
let reducers: [any ErasedReducer<Context>]
public init(reducers: [any ErasedReducer<Context>]) {
self.reducers = reducers
}
func reduce<TriggerOutcome: OutcomeDescriptor>(outcome: TriggerOutcome, context: Context) -> (any ResultDescriptor)? {
// This line appears to be what's causing the crash
guard let reducer = (reducers.compactMap { reducer in reducer as? any Reducer<Context, TriggerOutcome> }).first else {
return nil
}
return reducer.function(context, outcome)
}
}
public class SimpleTest: XCTestCase {
public func testReducing() {
let erasedReducers: [any ErasedReducer<ExampleContext>] = [
ExampleReducer<ExampleContext, ExampleOutcome, ExampleResult>(name: "Example", function: { (_, _) in ExampleResult() })
]
let context = ExampleContext()
let trigger = ExampleOutcome()
let service = ExampleService<ExampleContext>(reducers: erasedReducers)
service.reduce(outcome: trigger, context: context)
}
}
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0. Program arguments: /Applications/Xcode-16.0.0-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /Users/elfitz/Projects/Personal/GenericService/Tests/IntegrationTests/GenericServiceTests/0-SimpleTests.swift -emit-dependencies-path /Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Build/Intermediates.noindex/GenericService.build/Debug-iphonesimulator/IntegrationTests.build/Objects-normal/arm64/0-SimpleTests.d -emit-const-values-path /Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Build/Intermediates.noindex/GenericService.build/Debug-iphonesimulator/IntegrationTests.build/Objects-normal/arm64/0-SimpleTests.swiftconstvalues -emit-reference-dependencies-path /Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Build/Intermediates.noindex/GenericService.build/Debug-iphonesimulator/IntegrationTests.build/Objects-normal/arm64/0-SimpleTests.swiftdeps -serialize-diagnostics-path /Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Build/Intermediates.noindex/GenericService.build/Debug-iphonesimulator/IntegrationTests.build/Objects-normal/arm64/0-SimpleTests.dia -target arm64-apple-ios17.0-simulator -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode-16.0.0-Beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.0.sdk -I /Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Build/Products/Debug-iphonesimulator -I /Applications/Xcode-16.0.0-Beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/lib -F /Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Build/Products/Debug-iphonesimulator/PackageFrameworks -F /Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Build/Products/Debug-iphonesimulator/PackageFrameworks -F /Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Build/Products/Debug-iphonesimulator/PackageFrameworks -F /Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Build/Products/Debug-iphonesimulator -F /Applications/Xcode-16.0.0-Beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Frameworks -F /Applications/Xcode-16.0.0-Beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.0.sdk/Developer/Library/Frameworks -no-color-diagnostics -enable-testing -g -debug-info-format=dwarf -dwarf-version=4 -module-cache-path /Users/elfitz/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -profile-generate -profile-coverage-mapping -swift-version 5 -enforce-exclusivity=checked -Onone -D SWIFT_PACKAGE -D DEBUG -D SWIFT_PM_SUPPORTS_SWIFT_TESTING -D Xcode -serialize-debugging-options -enable-experimental-opaque-type-erasure -const-gather-protocols-file /Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Build/Intermediates.noindex/GenericService.build/Debug-iphonesimulator/IntegrationTests.build/Objects-normal/arm64/IntegrationTests_const_extract_protocols.json -enable-experimental-feature DebugDescriptionMacro -empty-abi-descriptor -plugin-path /Applications/Xcode-16.0.0-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins/testing -validate-clang-modules-once -clang-build-session-file /Users/elfitz/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -Xcc -working-directory -Xcc /Users/elfitz/Projects/Personal/GenericService/.swiftpm/xcode -resource-dir /Applications/Xcode-16.0.0-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir /Users/elfitz/Projects/Personal/GenericService/.swiftpm/xcode -Xcc -ivfsstatcache -Xcc /Users/elfitz/Library/Developer/Xcode/DerivedData/SDKStatCaches.noindex/iphonesimulator18.0-22A5282g-f46cc61c0d4ec2f57568566c87a94c0a.sdkstatcache -Xcc -I/Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Build/Products/Debug-iphonesimulator/include -Xcc -I/Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Build/Intermediates.noindex/GenericService.build/Debug-iphonesimulator/IntegrationTests.build/DerivedSources-normal/arm64 -Xcc -I/Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Build/Intermediates.noindex/GenericService.build/Debug-iphonesimulator/IntegrationTests.build/DerivedSources/arm64 -Xcc -I/Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Build/Intermediates.noindex/GenericService.build/Debug-iphonesimulator/IntegrationTests.build/DerivedSources -Xcc -DSWIFT_PACKAGE -Xcc -DDEBUG=1 -module-name IntegrationTests -package-name GenericService -frontend-parseable-output -disable-clang-spi -target-sdk-version 18.0 -target-sdk-name iphonesimulator18.0 -external-plugin-path /Applications/Xcode-16.0.0-Beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode-16.0.0-Beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode-16.0.0-Beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode-16.0.0-Beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Applications/Xcode-16.0.0-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode-16.0.0-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -parse-as-library -o /Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Build/Intermediates.noindex/GenericService.build/Debug-iphonesimulator/IntegrationTests.build/Objects-normal/arm64/0-SimpleTests.o -index-unit-output-path /GenericService.build/Debug-iphonesimulator/IntegrationTests.build/Objects-normal/arm64/0-SimpleTests.o -index-store-path /Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Index.noindex/DataStore -index-system-modules
1. Apple Swift version 6.0 (swiftlang-6.0.0.3.300 clang-1600.0.20.10)
2. Compiling with effective version 5.10
3. While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "/Users/elfitz/Projects/Personal/GenericService/Tests/IntegrationTests/GenericServiceTests/0-SimpleTests.swift")
4. While silgen emitFunction SIL function "@$s16IntegrationTests14ExampleServiceC6reduce7outcome7contextAA16ResultDescriptor_pSgqd___xtAA07OutcomeI0Rd__lF".
for 'reduce(outcome:context:)' (at /Users/elfitz/Projects/Personal/GenericService/Tests/IntegrationTests/GenericServiceTests/0-SimpleTests.swift:56:5)
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 0x000000010893a118 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 40
1 swift-frontend 0x0000000108937f19 llvm::sys::RunSignalHandlers() + 233
2 swift-frontend 0x000000010893a6f9 SignalHandler(int) + 313
3 libsystem_platform.dylib 0x00007ff8120cafdd _sigtramp + 29
4 libsystem_platform.dylib 0x00000000d3994160 _sigtramp + 18446603373828149664
5 swift-frontend 0x00000001041025d7 swift::Mangle::ASTMangler::appendRequirement(swift::Requirement const&, swift::GenericSignature, bool) + 231
6 swift-frontend 0x0000000104100a50 swift::Mangle::ASTMangler::appendGenericSignatureParts(swift::GenericSignature, swift::Mangle::ASTMangler::GenericSignatureParts const&) + 240
7 swift-frontend 0x00000001040f1e52 swift::Mangle::ASTMangler::appendGenericSignature(swift::GenericSignature) + 194
8 swift-frontend 0x00000001040f4588 swift::Mangle::ASTMangler::mangleReabstractionThunkHelper(swift::CanTypeWrapper<swift::SILFunctionType>, swift::Type, swift::Type, swift::Type, swift::Type, swift::ModuleDecl*) + 184
9 swift-frontend 0x00000001033d4c51 swift::Lowering::SILGenModule::getOrCreateReabstractionThunk(swift::CanTypeWrapper<swift::SILFunctionType>, swift::CanTypeWrapper<swift::SILFunctionType>, swift::CanTypeWrapper<swift::SILFunctionType>, swift::CanType, swift::CanType) + 1473
10 swift-frontend 0x000000010339faa1 createThunk(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::TypeLowering const&) + 4225
11 swift-frontend 0x0000000103392cc2 (anonymous namespace)::Transform::transform(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::SILType, swift::Lowering::SGFContext) + 2690
12 swift-frontend 0x0000000103392229 swift::Lowering::SILGenFunction::emitTransformedValue(swift::SILLocation, swift::Lowering::ManagedValue, swift::CanType, swift::CanType, swift::Lowering::SGFContext) + 441
13 swift-frontend 0x0000000103326d5f (anonymous namespace)::RValueEmitter::visitFunctionConversionExpr(swift::FunctionConversionExpr*, swift::Lowering::SGFContext) + 3263
SwiftCompile normal arm64 /Users/elfitz/Projects/Personal/GenericService/Tests/IntegrationTests/GenericServiceTests/0-SimpleTests.swift (in target 'IntegrationTests' from project 'GenericService')
cd /Users/elfitz/Projects/Personal/GenericService/.swiftpm/xcode
/Applications/Xcode-16.0.0-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -c -primary-file /Users/elfitz/Projects/Personal/GenericService/Tests/IntegrationTests/GenericServiceTests/0-SimpleTests.swift -emit-dependencies-path /Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Build/Intermediates.noindex/GenericService.build/Debug-iphonesimulator/IntegrationTests.build/Objects-normal/arm64/0-SimpleTests.d -emit-const-values-path /Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Build/Intermediates.noindex/GenericService.build/Debug-iphonesimulator/IntegrationTests.build/Objects-normal/arm64/0-SimpleTests.swiftconstvalues -emit-reference-dependencies-path /Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Build/Intermediates.noindex/GenericService.build/Debug-iphonesimulator/IntegrationTests.build/Objects-normal/arm64/0-SimpleTests.swiftdeps -serialize-diagnostics-path /Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Build/Intermediates.noindex/GenericService.build/Debug-iphonesimulator/IntegrationTests.build/Objects-normal/arm64/0-SimpleTests.dia -target arm64-apple-ios17.0-simulator -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode-16.0.0-Beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.0.sdk -I /Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Build/Products/Debug-iphonesimulator -I /Applications/Xcode-16.0.0-Beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/lib -F /Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Build/Products/Debug-iphonesimulator/PackageFrameworks -F /Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Build/Products/Debug-iphonesimulator/PackageFrameworks -F /Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Build/Products/Debug-iphonesimulator/PackageFrameworks -F /Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Build/Products/Debug-iphonesimulator -F /Applications/Xcode-16.0.0-Beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Frameworks -F /Applications/Xcode-16.0.0-Beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.0.sdk/Developer/Library/Frameworks -no-color-diagnostics -enable-testing -g -debug-info-format\=dwarf -dwarf-version\=4 -module-cache-path /Users/elfitz/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -profile-generate -profile-coverage-mapping -swift-version 5 -enforce-exclusivity\=checked -Onone -D SWIFT_PACKAGE -D DEBUG -D SWIFT_PM_SUPPORTS_SWIFT_TESTING -D Xcode -serialize-debugging-options -enable-experimental-opaque-type-erasure -const-gather-protocols-file /Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Build/Intermediates.noindex/GenericService.build/Debug-iphonesimulator/IntegrationTests.build/Objects-normal/arm64/IntegrationTests_const_extract_protocols.json -enable-experimental-feature DebugDescriptionMacro -empty-abi-descriptor -plugin-path /Applications/Xcode-16.0.0-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins/testing -validate-clang-modules-once -clang-build-session-file /Users/elfitz/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -Xcc -working-directory -Xcc /Users/elfitz/Projects/Personal/GenericService/.swiftpm/xcode -resource-dir /Applications/Xcode-16.0.0-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir /Users/elfitz/Projects/Personal/GenericService/.swiftpm/xcode -Xcc -ivfsstatcache -Xcc /Users/elfitz/Library/Developer/Xcode/DerivedData/SDKStatCaches.noindex/iphonesimulator18.0-22A5282g-f46cc61c0d4ec2f57568566c87a94c0a.sdkstatcache -Xcc -I/Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Build/Products/Debug-iphonesimulator/include -Xcc -I/Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Build/Intermediates.noindex/GenericService.build/Debug-iphonesimulator/IntegrationTests.build/DerivedSources-normal/arm64 -Xcc -I/Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Build/Intermediates.noindex/GenericService.build/Debug-iphonesimulator/IntegrationTests.build/DerivedSources/arm64 -Xcc -I/Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Build/Intermediates.noindex/GenericService.build/Debug-iphonesimulator/IntegrationTests.build/DerivedSources -Xcc -DSWIFT_PACKAGE -Xcc -DDEBUG\=1 -module-name IntegrationTests -package-name GenericService -frontend-parseable-output -disable-clang-spi -target-sdk-version 18.0 -target-sdk-name iphonesimulator18.0 -external-plugin-path /Applications/Xcode-16.0.0-Beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib/swift/host/plugins\#/Applications/Xcode-16.0.0-Beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode-16.0.0-Beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/local/lib/swift/host/plugins\#/Applications/Xcode-16.0.0-Beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Applications/Xcode-16.0.0-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode-16.0.0-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -parse-as-library -o /Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Build/Intermediates.noindex/GenericService.build/Debug-iphonesimulator/IntegrationTests.build/Objects-normal/arm64/0-SimpleTests.o -index-unit-output-path /GenericService.build/Debug-iphonesimulator/IntegrationTests.build/Objects-normal/arm64/0-SimpleTests.o -index-store-path /Users/elfitz/Library/Developer/Xcode/DerivedData/GenericService-chzyvvkikbfrwuewbnavurdyadfw/Index.noindex/DataStore -index-system-modules
14 swift-frontend 0x000000010331a05a swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 890
15 swift-frontend 0x000000010332534a (anonymous namespace)::RValueEmitter::visitOpenExistentialExpr(swift::OpenExistentialExpr*, swift::Lowering::SGFContext) + 1226
16 swift-frontend 0x000000010331a007 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 807
17 swift-frontend 0x000000010330b7f8 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 40
18 swift-frontend 0x00000001032a7504 (anonymous namespace)::SILGenApply::visitExpr(swift::Expr*) + 36
19 swift-frontend 0x000000010328b8d9 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 345
20 swift-frontend 0x000000010331a02a swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 842
21 swift-frontend 0x0000000103337a9c swift::Lowering::ManagedValue llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::SGFContext)>::callback_fn<(anonymous namespace)::RValueEmitter::visitInjectIntoOptionalExpr(swift::InjectIntoOptionalExpr*, swift::Lowering::SGFContext)::$_0>(long, swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::SGFContext) + 44
22 swift-frontend 0x00000001032e3f24 swift::Lowering::SILGenFunction::emitOptionalSome(swift::SILLocation, swift::SILType, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::SGFContext)>, swift::Lowering::SGFContext) + 1284
23 swift-frontend 0x000000010332a45e (anonymous namespace)::RValueEmitter::visitInjectIntoOptionalExpr(swift::InjectIntoOptionalExpr*, swift::Lowering::SGFContext) + 1582
24 swift-frontend 0x000000010331a10e swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 1070
25 swift-frontend 0x0000000103307ec8 swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, std::__1::optional<swift::SILLocation>) + 120
26 swift-frontend 0x00000001033cb0ea swift::Lowering::SILGenFunction::emitReturnExpr(swift::SILLocation, swift::Expr*) + 1706
27 swift-frontend 0x00000001033c6a48 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 6168
28 swift-frontend 0x0000000103342414 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 500
29 swift-frontend 0x0000000103275737 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 8535
30 swift-frontend 0x0000000103275f97 swift::Lowering::SILGenModule::emitOrDelayFunction(swift::SILDeclRef) + 215
31 swift-frontend 0x00000001032735cd swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 173
32 swift-frontend 0x00000001033e2d99 (anonymous namespace)::SILGenType::visitFuncDecl(swift::FuncDecl*) + 25
33 swift-frontend 0x00000001033de8fb (anonymous namespace)::SILGenType::emitType() + 427
34 swift-frontend 0x00000001032733a2 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 82
35 swift-frontend 0x0000000103279e7d swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 2365
36 swift-frontend 0x00000001033c4ee3 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&) + 179
37 swift-frontend 0x000000010327f97d 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'()) + 589
38 swift-frontend 0x000000010274f2e4 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 852
39 swift-frontend 0x0000000102754eeb performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 4699
40 swift-frontend 0x0000000102751ded swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 5581
41 swift-frontend 0x00000001026c3acd swift::mainEntry(int, char const**) + 5421
42 dyld 0x000000020c192366 start + 1942
Command SwiftCompile failed with a nonzero exit code
And the second crash can be avoided by providing a method returning an existential instead of an associated type, and using this method instead of the generic closure property.
protocol Reducer<Context, TriggerOutcome>: ErasedReducer {
var name: String { get }
var function: @Sendable (_ context: Context?, _ trigger: TriggerOutcome) -> Result { get }
// Using this method instead of the `function` closure directly does not make the compiler crash
func reduce(_ context: Context?, _ trigger: TriggerOutcome) -> any ResultDescriptor
}
extension Reducer {
func reduce(_ context: Context?, _ trigger: TriggerOutcome) -> any ResultDescriptor {
function(context, trigger)
}
}
...
class ExampleService<Context: ContextDescriptor> {
let reducers: [any ErasedReducer<Context>]
public init(reducers: [any ErasedReducer<Context>]) {
self.reducers = reducers
}
func reduce<TriggerOutcome: OutcomeDescriptor>(outcome: TriggerOutcome, context: Context) -> (any ResultDescriptor)? {
guard let reducer = (reducers.compactMap { reducer in reducer as? any Reducer<Context, TriggerOutcome> }).first else {
return nil
}
return reducer.reduce(context, outcome)
}
}
Description
The compiler appears to crash when resolving a generic method. Perhaps due to an abuse of generics?
Reproduction
But when using a generic type for the builder factory instead of a generic function, it builds successfully.
Stack dump
Expected behavior
Successful compilation. Or a compilation error if this shouldn't build.
Environment
swift-driver version: 1.109.2 Apple Swift version 6.0 (swiftlang-6.0.0.3.300 clang-1600.0.20.10) Target: x86_64-apple-macosx14.0
But I also had it with Swift 5.10
Additional information
No response