Skip to content

Make Arch.hostArchitecture() fail fast on unsupported architectures.#1900

Open
anxkhn wants to merge 1 commit into
apple:mainfrom
anxkhn:patch-18
Open

Make Arch.hostArchitecture() fail fast on unsupported architectures.#1900
anxkhn wants to merge 1 commit into
apple:mainfrom
anxkhn:patch-18

Conversation

@anxkhn

@anxkhn anxkhn commented Jul 5, 2026

Copy link
Copy Markdown

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Motivation and Context

Arch.hostArchitecture() in Sources/Services/ContainerAPIService/Client/Arch.swift
resolves the host architecture with a compile-time switch:

public static func hostArchitecture() -> Arch {
    #if arch(arm64)
    return .arm64
    #elseif arch(x86_64)
    return .amd64
    #endif
}

The #if/#elseif has no #else arm. On arch(arm64) and arch(x86_64) this
compiles and returns the right value, but on any other architecture the function
declares a non-optional Arch return type yet has no return statement, so the
compiler emits a confusing "missing return in a function expected to return 'Arch'"
diagnostic rather than a clear reason.

This adds an #else arm that fails the build with an explicit message:

#else
#error("unsupported host architecture")
#endif

This makes the conditional exhaustive and turns a vague missing-return error into a
precise one, mirroring how ClientKernel.swift already handles the runtime analogue
of this switch with fatalError("unknown architecture"). It is behavior-preserving
on the two supported architectures: the #else arm is inert there, so there is no
change to generated code or runtime behavior on Apple silicon or Intel.

Testing

  • Tested locally
  • Added/updated tests
  • Added/updated docs

Built swift build --target ContainerAPIClient before and after the change; both
succeed on arm64, and only Arch.swift recompiles, confirming the #else arm is
inert on a supported architecture. swift format lint --strict reports no issues
and the formatter is a no-op on the file. The existing ArchTests suite passes.

No test was added: hostArchitecture() is resolved entirely at compile time, so the
#else/#error arm is stripped by the compiler and has no runtime code path to
exercise. ArchTests covers the runtime Arch(rawValue:) initializer, which is
unchanged.

The compile-time #if/#elseif switch in hostArchitecture() covered only
arch(arm64) and arch(x86_64) with no #else, so on any other architecture
the function had no return statement and produced a confusing missing-return
error. Add an #else that emits a clear #error diagnostic, mirroring the
explicit unknown-architecture handling in ClientKernel.swift. This is
behavior-preserving on the two supported architectures.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant