Skip to content

Swift 6 / Xcode 16: Segmentation fault during Analyzing… (v3.3.0) and build failure in JobPool.swift from v3.4.0+ #1087

@matheuspcunha

Description

@matheuspcunha

Hi 👋

I'm experiencing two separate but related issues when using Periphery with Xcode 16 (Swift 6) in a real-world iOS workspace (CocoaPods-based project).


1️⃣ Segmentation fault during Analyzing… (v3.3.0)

Version

Periphery 3.3.0
Xcode 16.0
Swift 6 toolchain
macOS (Apple Silicon)

Symptom

make periphery fails with:

Segmentation fault: 11 (exit 139)

The crash happens during the:

* Inspecting project...
* Building Rewards...
* Indexing...
* Analyzing...

Build and indexing complete successfully. The crash occurs specifically during the analysis phase.

Observations

  • Project builds successfully via xcodebuild.
  • Index store is generated.
  • Crash occurs inside the Periphery binary during analysis (reading the index store and performing reference / unused code analysis via SwiftParser / IndexStore).
  • Not caused by incorrect paths or failed build.
  • Workspace contains CocoaPods + SPM tooling.

This appears to be an internal crash during analysis rather than a configuration issue.


2️⃣ Swift 6 compilation failure from v3.4.0+

Starting from Periphery 3.4.0, the package fails to compile under Swift 6 (Xcode 16).

Error

/Tools/.build/checkouts/periphery/Sources/Shared/JobPool.swift:33:13:
error: 'results' used after consume

Relevant code snippet (JobPool.swift)

public func flatMap<Result>(_ block: @escaping (Job) throws -> [Result]) throws -> [Result] {
    var error: Error?
    let results = Mutex<[Result]>([])

    DispatchQueue.concurrentPerform(iterations: jobs.count) { idx in
        guard error == nil else { return }

        do {
            let jobResults = try block(jobs[idx])
            results.withLock { $0.append(contentsOf: jobResults) }
        } catch {
            error = error
        }
    }

    if let error {
        throw error
    }

    return results.withLock { $0 }
}

Root cause hypothesis

Swift 6 introduces stricter ownership and concurrency rules.
The compiler now reports:

'results' used after consumption

This appears to be due to Mutex usage combined with concurrentPerform and Swift 6's stricter move/consume checking.

Versions ≤ 3.3.0 compile because they were built under Swift 5 rules (pre–Swift 6 enforcement).


Expected behavior

  • Periphery should compile under Swift 6 / Xcode 16.
  • Periphery should not crash during the Analyzing… stage for a valid indexed workspace.

What we tested

  • Running via SPM (swift run -c release periphery)
  • Running isolated via Tools/Package.swift
  • Using .xcworkspace
  • Using --skip-build
  • Using existing DerivedData index

Results:

  • v3.3.0 compiles but crashes during analysis (SIGSEGV).
  • v3.4.0+ fails to compile under Swift 6 due to JobPool.swift.

Request

Could you confirm:

  1. Is there known Swift 6 compatibility work ongoing?
  2. Is the segmentation fault during analysis a known issue with larger CocoaPods-based workspaces?
  3. Is there a recommended version for Xcode 16 compatibility?

Happy to provide:

  • Full crash logs
  • Sample project reproduction
  • Toolchain / macOS details

Thank you 🙏


Se você quiser, posso também preparar uma versão ainda mais técnica (com stack trace formatting e sugestão de patch no JobPool.swift).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions