Skip to content

Crash with 6.1 macOS OSS Toolchain: SILFunctionTransform "MoveOnlyChecker" #80759

@marcprux

Description

@marcprux

Description

The repo https://github.com/pointfreeco/swift-sharing.git builds with both the Xcode 6.1 toolchain and the Ubuntu 24.04 6.1 toolchain, but crashes when building with the OSS 6.1 Toolchain:

4.	While running pass #331 SILFunctionTransform "MoveOnlyChecker" on SILFunction "@$s7Sharing5MutexVAARi_zrlE8withLockyqd__qd__xzYuqd_0_YKYTXEqd_0_YKs5ErrorRd_0_Ri_d__r0_lF".
 for 'withLock(_:)' (at /opt/src/github/swift-everywhere/swift-sharing/Sources/Sharing/Internal/MutexBackport.swift:33:23)

See the full stack trace below. The offending code MutexBackport.swift seems to be:

  extension Mutex: @unchecked Sendable where Value: ~Copyable {}


  extension Mutex where Value: ~Copyable {
    /// Calls the given closure after acquiring the lock and then releases ownership.
    borrowing package func withLock<Result: ~Copyable, E: Error>(
      _ body: (inout sending Value) throws(E) -> sending Result
    ) throws(E) -> sending Result {
      _lock.lock()
      defer { _lock.unlock() }
      return try body(&_box.value)
    }

This is another example (#79870) of a compiler crash with the OSS toolchain for a package that works with Xcode's toolchain.

Reproduction

git clone https://github.com/pointfreeco/swift-sharing.git
cd swift-sharing
~/Library/Developer/Toolchains/swift-6.1-RELEASE.xctoolchain/usr/bin/swift build

Stack dump

error: compile command failed due to signal 6 (use -v to see invocation)
Assertion failed: (isa<UnreachableInst>(block->getTerminator())), function computeRegion, file OSSALifetimeCompletion.cpp, line 319.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /Users/marc/Library/Developer/Toolchains/swift-6.1-RELEASE.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /opt/src/github/swift-everywhere/swift-sharing/Sources/Sharing/Internal/Deprecations.swift -primary-file /opt/src/github/swift-everywhere/swift-sharing/Sources/Sharing/Internal/KeyPath+Sendable.swift -primary-file /opt/src/github/swift-everywhere/swift-sharing/Sources/Sharing/Internal/MutexBackport.swift /opt/src/github/swift-everywhere/swift-sharing/Sources/Sharing/Internal/NSRecursiveLock+WithLock.swift /opt/src/github/swift-everywhere/swift-sharing/Sources/Sharing/Internal/PassthroughRelay.swift /opt/src/github/swift-everywhere/swift-sharing/Sources/Sharing/Internal/PersistentReferences.swift /opt/src/github/swift-everywhere/swift-sharing/Sources/Sharing/Internal/Reference.swift /opt/src/github/swift-everywhere/swift-sharing/Sources/Sharing/Internal/SharedChangeTracker.swift /opt/src/github/swift-everywhere/swift-sharing/Sources/Sharing/Internal/TypeName.swift /opt/src/github/swift-everywhere/swift-sharing/Sources/Sharing/Shared.swift /opt/src/github/swift-everywhere/swift-sharing/Sources/Sharing/SharedBinding.swift /opt/src/github/swift-everywhere/swift-sharing/Sources/Sharing/SharedCollection.swift /opt/src/github/swift-everywhere/swift-sharing/Sources/Sharing/SharedContinuations.swift /opt/src/github/swift-everywhere/swift-sharing/Sources/Sharing/SharedKey.swift /opt/src/github/swift-everywhere/swift-sharing/Sources/Sharing/SharedKeys/AppStorageKey.swift /opt/src/github/swift-everywhere/swift-sharing/Sources/Sharing/SharedKeys/DefaultKey.swift /opt/src/github/swift-everywhere/swift-sharing/Sources/Sharing/SharedKeys/FileStorageKey.swift /opt/src/github/swift-everywhere/swift-sharing/Sources/Sharing/SharedKeys/InMemoryKey.swift /opt/src/github/swift-everywhere/swift-sharing/Sources/Sharing/SharedPublisher.swift /opt/src/github/swift-everywhere/swift-sharing/Sources/Sharing/SharedReader.swift /opt/src/github/swift-everywhere/swift-sharing/Sources/Sharing/SharedReaderKey.swift /opt/src/github/swift-everywhere/swift-sharing/Sources/Sharing/SwiftUIStateSharing.swift /opt/src/github/swift-everywhere/swift-sharing/.build/arm64-apple-macosx/debug/Sharing.build/DerivedSources/resource_bundle_accessor.swift -supplementary-output-file-map /var/folders/zl/wkdjv4s1271fbm6w0plzknkh0000gn/T/com.apple.shortcuts.mac-helper/TemporaryDirectory.LyuR78/supplementaryOutputs-1 -target arm64-apple-macosx10.15 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.4.sdk -I /opt/src/github/swift-everywhere/swift-sharing/.build/arm64-apple-macosx/debug/Modules -I /Users/marc/Library/Developer/Toolchains/swift-6.1-RELEASE.xctoolchain/usr/lib/swift/macosx/testing -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/PrivateFrameworks -color-diagnostics -enable-testing -g -debug-info-format=dwarf -dwarf-version=4 -module-cache-path /opt/src/github/swift-everywhere/swift-sharing/.build/arm64-apple-macosx/debug/ModuleCache -swift-version 6 -Onone -D SWIFT_PACKAGE -D DEBUG -empty-abi-descriptor -plugin-path /Users/marc/Library/Developer/Toolchains/swift-6.1-RELEASE.xctoolchain/usr/lib/swift/host/plugins/testing -resource-dir /Users/marc/Library/Developer/Toolchains/swift-6.1-RELEASE.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir /opt/src/github/swift-everywhere/swift-sharing -Xcc -isysroot -Xcc /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.4.sdk -Xcc -F -Xcc /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -Xcc -F -Xcc /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/PrivateFrameworks -Xcc -fPIC -Xcc -g -module-name Sharing -package-name swift_sharing -in-process-plugin-server-path /Users/marc/Library/Developer/Toolchains/swift-6.1-RELEASE.xctoolchain/usr/lib/swift/host/libSwiftInProcPluginServer.dylib -plugin-path /Users/marc/Library/Developer/Toolchains/swift-6.1-RELEASE.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Users/marc/Library/Developer/Toolchains/swift-6.1-RELEASE.xctoolchain/usr/local/lib/swift/host/plugins -target-sdk-version 15.4 -target-sdk-name macosx15.4 -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -parse-as-library -o /opt/src/github/swift-everywhere/swift-sharing/.build/arm64-apple-macosx/debug/Sharing.build/Deprecations.swift.o -o /opt/src/github/swift-everywhere/swift-sharing/.build/arm64-apple-macosx/debug/Sharing.build/KeyPath+Sendable.swift.o -o /opt/src/github/swift-everywhere/swift-sharing/.build/arm64-apple-macosx/debug/Sharing.build/MutexBackport.swift.o -index-store-path /opt/src/github/swift-everywhere/swift-sharing/.build/arm64-apple-macosx/debug/index/store -index-system-modules
1.	Apple Swift version 6.1 (swift-6.1-RELEASE)
2.	Compiling with the current language version
3.	While evaluating request ExecuteSILPipelineRequest(Run pipelines { Mandatory Diagnostic Passes + Enabling Optimization Passes } on SIL for Sharing)
4.	While running pass #331 SILFunctionTransform "MoveOnlyChecker" on SILFunction "@$s7Sharing5MutexVAARi_zrlE8withLockyqd__qd__xzYuqd_0_YKYTXEqd_0_YKs5ErrorRd_0_Ri_d__r0_lF".
 for 'withLock(_:)' (at /opt/src/github/swift-everywhere/swift-sharing/Sources/Sharing/Internal/MutexBackport.swift:33:23)
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           0x0000000107697884 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000107695fb0 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000107697ec8 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x000000018ff1b624 _sigtramp + 56
4  libsystem_pthread.dylib  0x000000018fee188c pthread_kill + 296
5  libsystem_c.dylib        0x000000018fdeac60 abort + 124
6  libsystem_c.dylib        0x000000018fde9eec err + 0
7  swift-frontend           0x000000010777e9cc swift::OSSALifetimeCompletion::analyzeAndUpdateLifetime(swift::SILValue, swift::OSSALifetimeCompletion::Boundary) (.cold.3) + 0
8  swift-frontend           0x00000001031d9194 swift::OSSALifetimeCompletion::visitAvailabilityBoundary(swift::SILValue, swift::SSAPrunedLiveness const&, llvm::function_ref<void (swift::SILInstruction*, swift::OSSALifetimeCompletion::LifetimeEnd)>) + 4048
9  swift-frontend           0x00000001031da0fc endLifetimeAtBoundary(swift::SILValue, swift::SSAPrunedLiveness const&, swift::OSSALifetimeCompletion::Boundary, swift::DeadEndBlocks&) + 340
10 swift-frontend           0x00000001031da4d0 swift::OSSALifetimeCompletion::analyzeAndUpdateLifetime(swift::SILValue, swift::OSSALifetimeCompletion::Boundary) + 248
11 swift-frontend           0x0000000102c9b0d8 swift::OSSALifetimeCompletion::completeOSSALifetime(swift::SILValue, swift::OSSALifetimeCompletion::Boundary) + 300
12 swift-frontend           0x0000000102c9adf4 swift::siloptimizer::MoveOnlyAddressChecker::completeLifetimes() + 292
13 swift-frontend           0x0000000102cbcb48 (anonymous namespace)::MoveOnlyCheckerPass::run() + 3452
14 swift-frontend           0x0000000102d0b054 swift::SILPassManager::runPassOnFunction(unsigned int, swift::SILFunction*) + 1452
15 swift-frontend           0x0000000102d0bdd8 swift::SILPassManager::runFunctionPasses(unsigned int, unsigned int) + 1060
16 swift-frontend           0x0000000102d0e50c swift::SILPassManager::execute() + 596
17 swift-frontend           0x0000000102d08fd0 swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 72
18 swift-frontend           0x0000000102d08f50 swift::ExecuteSILPipelineRequest::evaluate(swift::Evaluator&, swift::SILPipelineExecutionDescriptor) const + 68
19 swift-frontend           0x0000000102d54d90 swift::SimpleRequest<swift::ExecuteSILPipelineRequest, std::__1::tuple<> (swift::SILPipelineExecutionDescriptor), (swift::RequestFlags)1>::evaluateRequest(swift::ExecuteSILPipelineRequest const&, swift::Evaluator&) + 28
20 swift-frontend           0x0000000102d25154 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
21 swift-frontend           0x0000000102d091c0 swift::executePassPipelinePlan(swift::SILModule*, swift::SILPassPipelinePlan const&, bool, swift::irgen::IRGenModule*) + 64
22 swift-frontend           0x0000000102d37ef8 swift::runSILDiagnosticPasses(swift::SILModule&) + 192
23 swift-frontend           0x00000001025dc758 swift::CompilerInstance::performSILProcessing(swift::SILModule*) + 80
24 swift-frontend           0x00000001023a93ac 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*) + 820
25 swift-frontend           0x00000001023a8a3c swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 468
26 swift-frontend           0x00000001023b4b50 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 164
27 swift-frontend           0x00000001023aa74c performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 716
28 swift-frontend           0x00000001023a9f68 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2228
29 swift-frontend           0x000000010218d8f0 swift::mainEntry(int, char const**) + 3064
30 dyld                     0x000000018fb42b4c start + 6000

Expected behavior

Compiler shouldn't crash.

Environment

% ~/Library/Developer/Toolchains/swift-6.1-RELEASE.xctoolchain/usr/bin/swift -version
Apple Swift version 6.1 (swift-6.1-RELEASE)
Target: arm64-apple-macosx15.0

% /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -version
swift-driver version: 1.120.5 Apple Swift version 6.1 (swiftlang-6.1.0.110.21 clang-1700.0.13.3)
Target: arm64-apple-macosx15.0

% sw_vers 
ProductName:		macOS
ProductVersion:		15.4
BuildVersion:		24E248

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