Make Arch.hostArchitecture() fail fast on unsupported architectures.#1900
Open
anxkhn wants to merge 1 commit into
Open
Make Arch.hostArchitecture() fail fast on unsupported architectures.#1900anxkhn wants to merge 1 commit into
anxkhn wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of Change
Motivation and Context
Arch.hostArchitecture()inSources/Services/ContainerAPIService/Client/Arch.swiftresolves the host architecture with a compile-time switch:
The
#if/#elseifhas no#elsearm. Onarch(arm64)andarch(x86_64)thiscompiles and returns the right value, but on any other architecture the function
declares a non-optional
Archreturn type yet has noreturnstatement, so thecompiler emits a confusing "missing return in a function expected to return 'Arch'"
diagnostic rather than a clear reason.
This adds an
#elsearm that fails the build with an explicit message:This makes the conditional exhaustive and turns a vague missing-return error into a
precise one, mirroring how
ClientKernel.swiftalready handles the runtime analogueof this switch with
fatalError("unknown architecture"). It is behavior-preservingon the two supported architectures: the
#elsearm is inert there, so there is nochange to generated code or runtime behavior on Apple silicon or Intel.
Testing
Built
swift build --target ContainerAPIClientbefore and after the change; bothsucceed on arm64, and only
Arch.swiftrecompiles, confirming the#elsearm isinert on a supported architecture.
swift format lint --strictreports no issuesand the formatter is a no-op on the file. The existing
ArchTestssuite passes.No test was added:
hostArchitecture()is resolved entirely at compile time, so the#else/#errorarm is stripped by the compiler and has no runtime code path toexercise.
ArchTestscovers the runtimeArch(rawValue:)initializer, which isunchanged.