Description
Description
The code below crashes the compiler when an attempt is made to build in Release mode. This only affects 6.0-series toolchains. It does not affect 6.1-series toolchains.
Copy and paste this into a new project and attempt to build.
This was found to be a distinct issue from this one: #78444
Reproduction
import Foundation
public enum H: Hashable, RawRepresentable { // Has to be both Hashable, RawRepresentable for the build to fail
case cc(String) // Has to be present for the build to fail.
case bb // We have to use "bb" and not "cc" in lines 12, or the build will succeed.
public init?(rawValue: String) {fatalError()} // Needed for conformance to RawRepresentable
public var rawValue: String {fatalError()} // Needed for conformance to RawRepresentable
public func hash(into hasher: inout Hasher) {fatalError()} // Needed for conformance to Hashable
}
public protocol G {}
public extension G { // Has to be public for the build to fail.
func j(of m: H, to d: Date) {
guard m != .bb else { return }; // Need this line and the line below for the build to fail.
self.l(of: m, to: d) // Need this line and the line above for the build to fail.
}
func l(of key: H, to date: Date) {
if let self = self as? E {self.j(of: key, to: date)}
else {print(key)} // Has to be present for the build to fail. Printing "date" also causes the build to fail.
}
}
protocol E {func j(of: H, to: Date)}
enum F {}
extension F {final class X: G {init() {fatalError()}}} //At least one of classes X or Y have to be "final" for the build to fail.
extension F.X: E {}
extension F {final class Y: G {init() {fatalError()}}}
extension F.Y: E {} // We need this plus the line above for the build to fail. Deleting both will make it succeed.
Stack dump
1. Apple Swift version 6.0.3 (swift-6.0.3-RELEASE)
2. Compiling with effective version 5.10
3. While evaluating request ExecuteSILPipelineRequest(Run pipelines { PrepareOptimizationPasses, EarlyModulePasses, HighLevel,Function+EarlyLoopOpt, HighLevel,Module+StackPromote, MidLevel,Function, ClosureSpecialize, LowLevel,Function, LateLoopOpt, SIL Debug Info Generator } on SIL for a)
4. While running pass #9655 SILFunctionTransform "OwnershipModelEliminator" on SILFunction "@$s4a1FO1XCAA1EA2aFP1j2of2toyAA1HO_10Foundation4DateVtFTW".
for 'j(of:to:)' (at /Users/user/a/main.swift:11:5)
5. Found verification error when verifying before lowering ownership. Please re-run with -sil-verify-all to identify the actual pass that introduced the verification error.
6. While verifying SIL function "@$s4a1FO1XCAA1EA2aFP1j2of2toyAA1HO_10Foundation4DateVtFTW".
for 'j(of:to:)' (at /Users/user/a/main.swift:11: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 0x0000000109fcc0f8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1 swift-frontend 0x0000000109fca8c4 llvm::sys::RunSignalHandlers() + 112
2 swift-frontend 0x0000000109fcc740 SignalHandler(int) + 304
3 libsystem_platform.dylib 0x0000000184029a24 _sigtramp + 56
4 libsystem_pthread.dylib 0x0000000183ff9cc0 pthread_kill + 288
5 libsystem_c.dylib 0x0000000183f05a40 abort + 180
6 swift-frontend 0x0000000109f4ae90 llvm::install_out_of_memory_new_handler() + 0
7 swift-frontend 0x0000000105a576a8 swift::LinearLifetimeChecker::ErrorBuilder::tryDumpErrorCounter() const + 0
8 swift-frontend 0x0000000105a5f05c swift::SILValueOwnershipChecker::checkValueWithoutLifetimeEndingUses(llvm::ArrayRef<swift::Operand*>) + 516
9 swift-frontend 0x0000000105a5db60 swift::SILValueOwnershipChecker::checkUses() + 248
10 swift-frontend 0x0000000105a5d8a8 swift::SILValueOwnershipChecker::check() + 216
11 swift-frontend 0x0000000105a5f5ec verifySILValueHelper(swift::SILFunction const*, swift::SILValue, swift::LinearLifetimeChecker::ErrorBuilder&, swift::DeadEndBlocks*, swift::GuaranteedPhiVerifier&) + 144
12 swift-frontend 0x0000000105a5f4cc swift::SILValue::verifyOwnership(swift::DeadEndBlocks*) const + 216
13 swift-frontend 0x0000000105a8035c (anonymous namespace)::SILVerifier::checkValueBaseOwnership(swift::ValueBase*) + 164
14 swift-frontend 0x0000000105a83284 (anonymous namespace)::SILVerifier::visitSILInstruction(swift::SILInstruction*) + 6264
15 swift-frontend 0x0000000105a6c038 swift::SILVisitorBase<(anonymous namespace)::SILVerifier, void>::visitSILBasicBlock(swift::SILBasicBlock*) + 11776
16 swift-frontend 0x0000000105a69138 (anonymous namespace)::SILVerifier::visitSILBasicBlock(swift::SILBasicBlock*) + 28
17 swift-frontend 0x0000000105a678e4 (anonymous namespace)::SILVerifier::visitSILFunction(swift::SILFunction*) + 10556
18 swift-frontend 0x0000000105a60f40 swift::SILFunction::verify(swift::CalleeCache*, bool, bool, bool) const + 204
19 swift-frontend 0x00000001054e3190 (anonymous namespace)::OwnershipModelEliminator::run() + 268
20 swift-frontend 0x00000001054e99fc swift::SILPassManager::runPassOnFunction(unsigned int, swift::SILFunction*) + 1432
21 swift-frontend 0x00000001054ea868 swift::SILPassManager::runFunctionPasses(unsigned int, unsigned int) + 1060
22 swift-frontend 0x00000001054e7a38 swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 72
23 swift-frontend 0x00000001054e79b8 swift::ExecuteSILPipelineRequest::evaluate(swift::Evaluator&, swift::SILPipelineExecutionDescriptor) const + 68
24 swift-frontend 0x0000000105522130 swift::SimpleRequest<swift::ExecuteSILPipelineRequest, std::__1::tuple<> (swift::SILPipelineExecutionDescriptor), (swift::RequestFlags)1>::evaluateRequest(swift::ExecuteSILPipelineRequest const&, swift::Evaluator&) + 28
25 swift-frontend 0x0000000105502788 swift::ExecuteSILPipelineRequest::OutputType swift::Evaluator::getResultUncached<swift::ExecuteSILPipelineRequest, swift::ExecuteSILPipelineRequest::OutputType swift::evaluateOrFatal<swift::ExecuteSILPipelineRequest>(swift::Evaluator&, swift::ExecuteSILPipelineRequest)::'lambda'()>(swift::ExecuteSILPipelineRequest const&, swift::ExecuteSILPipelineRequest::OutputType swift::evaluateOrFatal<swift::ExecuteSILPipelineRequest>(swift::Evaluator&, swift::ExecuteSILPipelineRequest)::'lambda'()) + 204
26 swift-frontend 0x00000001054e7c14 swift::executePassPipelinePlan(swift::SILModule*, swift::SILPassPipelinePlan const&, bool, swift::irgen::IRGenModule*) + 64
27 swift-frontend 0x0000000105504d08 swift::runSILOptimizationPasses(swift::SILModule&) + 156
28 swift-frontend 0x0000000104d23068 swift::CompilerInstance::performSILProcessing(swift::SILModule*) + 636
29 swift-frontend 0x0000000104ae2a84 performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 796
30 swift-frontend 0x0000000104ae2380 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1216
31 swift-frontend 0x0000000104aede5c withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 160
32 swift-frontend 0x0000000104ae4028 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 708
33 swift-frontend 0x0000000104ae36fc swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2344
34 swift-frontend 0x00000001048f9edc swift::mainEntry(int, char const**) + 3096
35 dyld 0x0000000183c790e0 start + 2360
Expected behavior
The build should complete successfully.
Environment
This affects every 6.0-series toolchain I've tried:
6.0 Development Snapshot 2024-07-11a
6.0.2 Release 2024-10-24a
6.0.3 Release 2024-12-10a
This isn't impacting the 6.1 series; the build succeeds there.
Additional information
I haven't found the download URL for the 6.0 series Development Snapshots from last year on here:
https://www.swift.org/install/macos/
It looks like only 6.1 series development snapshots are available.
If provided, I can edit the date of the URL in order to try to narrow down the commits where the breaking change was introduced.