nesrve
August 17, 2025, 12:29am
1
struct Foo<T> {}
struct Bar {}
let foo = Foo<Bar>()
let foos: Set<Foo> = [foo]
trying to run this crashes the compiler.
the code snippet above is an attempt from me to get a minimal reproduction of the code that causes the crash. my original code is structured like this (still super simplified, took me a good hour to find the problem):
protocol Game {}
struct Card<Game> {}
struct Blackjack: Game {}
let card = Card<Blackjack>()
let cards: Set<Card> = [card]
where i had forgot to add a Hashable conformance to Card.
2 Likes
Danny
August 17, 2025, 1:01am
2
The compiler should not be crashing, but here is the solution:
struct Foo<T> { }
struct Bar: Hashable { }
extension Foo: Hashable & Equatable where T: Hashable { }
let foo = Foo<Bar>()
let foos: Set = [foo]
protocol Game { }
struct Card<Game: ModuleName.Game> { }
extension Card: Hashable & Equatable where Game: Hashable { }
struct Blackjack: Game & Hashable { }
let card = Card<Blackjack>()
let cards: Set = [card]
1 Like
nesrve
August 17, 2025, 1:15am
3
seems to be a recently discovered compiler bug that appears to have been sitting there since swift 5.5:
opened 01:42PM - 02 Jul 25 UTC
bug
compiler
type checker
generics
crash
### Description
~Not sure where the problem actually comes from, but I have a (… small, it’s a single swift file) repository that crashes when compiled.~
### Reproduction
~Clone and build https://gitlab.com/frizlab-demo-projects/swift-ast-check-crash.git~
I have reduced it to this single line:
```swift
let filesToIgnore: Set<Regex> = [#/(.*/|)Readme\.[^/]+/#]
```
So, to reproduce the crash you can run this beautiful one-liner:
`echo 'let filesToIgnore: Set<Regex> = [#/(.*/|)Readme\.[^/]+/#]' | swiftc -`
### Stack dump
```text
0. Program arguments: "/Volumes/Common/Applications/Xcode 26 beta 2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend" -frontend -emit-module -experimental-skip-non-inlinable-function-bodies-without-types /Users/frizlab/Downloads/swift-ast-check-crash/main.swift -target arm64-apple-macosx13.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk "/Volumes/Common/Applications/Xcode 26 beta 2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX26.0.sdk" -I /Users/frizlab/Downloads/swift-ast-check-crash/.build/arm64-apple-macosx/debug/Modules -I "/Volumes/Common/Applications/Xcode 26 beta 2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib" -F "/Volumes/Common/Applications/Xcode 26 beta 2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks" -F "/Volumes/Common/Applications/Xcode 26 beta 2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/PrivateFrameworks" -color-diagnostics -Xcc -fcolor-diagnostics -enable-testing -g -debug-info-format=dwarf -dwarf-version=4 -module-cache-path /Users/frizlab/Downloads/swift-ast-check-crash/.build/arm64-apple-macosx/debug/ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -D SWIFT_MODULE_RESOURCE_BUNDLE_UNAVAILABLE -new-driver-path "/Volumes/Common/Applications/Xcode 26 beta 2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver" -entry-point-function-name AwesomeExecutable_main -empty-abi-descriptor -plugin-path "/Volumes/Common/Applications/Xcode 26 beta 2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins/testing" -enable-anonymous-context-mangled-names -file-compilation-dir /Users/frizlab/Downloads/swift-ast-check-crash -Xcc -isysroot -Xcc "/Volumes/Common/Applications/Xcode 26 beta 2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX26.0.sdk" -Xcc -F -Xcc "/Volumes/Common/Applications/Xcode 26 beta 2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks" -Xcc -F -Xcc "/Volumes/Common/Applications/Xcode 26 beta 2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/PrivateFrameworks" -Xcc -fPIC -Xcc -g -no-auto-bridging-header-chaining -module-name AwesomeExecutable -disable-clang-spi -target-sdk-version 26.0 -target-sdk-name macosx26.0 -external-plugin-path "/Volumes/Common/Applications/Xcode 26 beta 2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Volumes/Common/Applications/Xcode 26 beta 2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server" -external-plugin-path "/Volumes/Common/Applications/Xcode 26 beta 2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Volumes/Common/Applications/Xcode 26 beta 2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server" -in-process-plugin-server-path "/Volumes/Common/Applications/Xcode 26 beta 2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/libSwiftInProcPluginServer.dylib" -plugin-path "/Volumes/Common/Applications/Xcode 26 beta 2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins" -plugin-path "/Volumes/Common/Applications/Xcode 26 beta 2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins" -emit-module-doc-path /Users/frizlab/Downloads/swift-ast-check-crash/.build/arm64-apple-macosx/debug/Modules/AwesomeExecutable.swiftdoc -emit-module-source-info-path /Users/frizlab/Downloads/swift-ast-check-crash/.build/arm64-apple-macosx/debug/Modules/AwesomeExecutable.swiftsourceinfo -serialize-diagnostics-path /Users/frizlab/Downloads/swift-ast-check-crash/.build/arm64-apple-macosx/debug/AwesomeExecutable.build/AwesomeExecutable.emit-module.dia -emit-dependencies-path /Users/frizlab/Downloads/swift-ast-check-crash/.build/arm64-apple-macosx/debug/AwesomeExecutable.build/AwesomeExecutable.emit-module.d -o /Users/frizlab/Downloads/swift-ast-check-crash/.build/arm64-apple-macosx/debug/Modules/AwesomeExecutable.swiftmodule -emit-abi-descriptor-path /Users/frizlab/Downloads/swift-ast-check-crash/.build/arm64-apple-macosx/debug/Modules/AwesomeExecutable.abi.json
1. Apple Swift version 6.2 (swiftlang-6.2.0.10.950 clang-1700.3.10.950)
2. Compiling with effective version 5.10
3. While evaluating request ASTLoweringRequest(Lowering AST to SIL for module AwesomeExecutable)
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 0x0000000108b63450 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1 swift-frontend 0x0000000108b60de0 llvm::sys::RunSignalHandlers() + 112
2 swift-frontend 0x0000000108b63a7c SignalHandler(int, __siginfo*, void*) + 344
3 libsystem_platform.dylib 0x000000018ddd4624 _sigtramp + 56
4 libsystem_pthread.dylib 0x000000018dd9a88c pthread_kill + 296
5 libsystem_c.dylib 0x000000018dca3c60 abort + 124
6 swift-frontend 0x0000000102b9b228 swift::DiagnosticHelper::~DiagnosticHelper() + 0
7 swift-frontend 0x0000000108ad1590 llvm::report_fatal_error(llvm::Twine const&, bool) + 280
8 swift-frontend 0x0000000108ad1478 llvm::report_fatal_error(llvm::Twine const&, bool) + 0
9 swift-frontend 0x0000000103376728 swift::Lowering::SILGenModule::useConformance(swift::ProtocolConformanceRef) + 236
10 swift-frontend 0x0000000103377868 void llvm::function_ref<void (swift::CanType)>::callback_fn<swift::Lowering::SILGenModule::useConformancesFromType(swift::CanType)::$_0>(long, swift::CanType) + 168
11 swift-frontend 0x0000000102ca7610 bool llvm::function_ref<bool (swift::CanType)>::callback_fn<swift::CanType::visit(llvm::function_ref<void (swift::CanType)>) const::'lambda'(swift::Type)>(long, swift::CanType) + 20
12 swift-frontend 0x00000001043ed974 swift::Type::findIf(llvm::function_ref<bool (swift::Type)>) const::Walker::walkToTypePre(swift::Type) + 16
13 swift-frontend 0x000000010440da7c (anonymous namespace)::Traversal::doIt(swift::Type) + 36
14 swift-frontend 0x0000000103377b00 LazyConformanceEmitter::visitAllocRefInst(swift::AllocRefInst*) + 324
15 swift-frontend 0x00000001032ad1ec swift::Lowering::SILGenModule::emitLazyGlobalInitializer(llvm::StringRef, swift::PatternBindingDecl*, unsigned int) + 916
16 swift-frontend 0x00000001033759c0 swift::Lowering::SILGenModule::emitGlobalInitialization(swift::PatternBindingDecl*, unsigned int) + 1172
17 swift-frontend 0x000000010340ac10 (anonymous namespace)::SILGenType::emitType() + 820
18 swift-frontend 0x00000001032a7da8 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 100
19 swift-frontend 0x00000001032aec1c swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 2364
20 swift-frontend 0x00000001033f1e80 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
21 swift-frontend 0x00000001032b36a4 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
22 swift-frontend 0x00000001027d0580 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 2616
23 swift-frontend 0x00000001027d3274 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1764
24 swift-frontend 0x00000001027d1e90 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3580
25 swift-frontend 0x0000000102753444 swift::mainEntry(int, char const**) + 5412
26 dyld 0x000000018d9fab98 start + 6076
```
### Expected behavior
The program should either compile or not, but the compiler should not crash.
### Environment
Only tested on macOS with Swift versions
```text
swift-driver version: 1.120.5 Apple Swift version 6.1.2 (swiftlang-6.1.2.1.2 clang-1700.0.13.5)
Target: arm64-apple-macosx15.0
```
and
```text
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
```
and
```text
swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: arm64-apple-macosx15.0
```
### Additional information
_No response_
1 Like