Skip to content

Clear the compiler warnings from the library and both test targets - #594

Merged
davidkoski merged 4 commits into
ml-explore:mainfrom
thechriswebb:webb/remove-unwanted-warnings
Aug 31, 2026
Merged

davidkoski merged 4 commits into
ml-explore:mainfrom
thechriswebb:webb/remove-unwanted-warnings

Conversation

@thechriswebb

Copy link
Copy Markdown
Collaborator

The problem

The compiler printed many warnings. Most came from style diagnostics, and from calls to MLX functions that MLX has renamed. It printed them on every build and every test run, so a warning that mattered was hard to find.

Two warnings came from real defects. Gemma read each video frame through a deprecated property. That property traps when the frame's image is not a CoreImage image. The process then stops. A quantization test passes a model layer into a concurrent closure. Swift cannot prove that this is safe. The test does it on purpose, but the code never said so.

What this PR does

  • Gemma reads each video frame through the supported accessor. If a frame's image is not a CoreImage image, the caller now gets an error instead of a crash. Gemma was the last model still calling the deprecated frame API. Every other vision model already used the current one.
  • The integration tests call MLX's Memory type for memory figures and for cache clearing, not the older GPU names. Behavior does not change, because the deprecated calls forward to the new ones.
  • The quantization concurrency test now shares its layer through a small wrapper marked unchecked-Sendable, so the compiler no longer warns about the sharing. The test still uses that layer from several threads without synchronization, which is the behavior it checks.
  • Removes the style diagnostics from the library and both test targets: an unused local, bindings that never change, and try and await markers on calls that neither throw nor suspend. One conditional cast tested a conformance that the compiler checks statically. If someone removes that conformance, the build still fails.

The compiler still warns about MLX's own Metal kernels. Those kernels come from a vendored dependency, so this repository cannot fix them.

Tests

No file in this repository now produces a warning.

The unit suite passes: 549 XCTest cases, one skipped, and 938 swift-testing cases in four targets. The two integration suites whose files changed ran against real models. All 15 of their tests passed.

MLX moved its memory inspection and cache control onto a Memory type and deprecated the older GPU spellings. The integration tests still used the old names, so every build of the IntegrationTesting scheme printed a dozen deprecation warnings that buried the warnings actually worth reading.

Switch the call sites over to Memory.snapshot() and Memory.clearCache(), and fix a doc comment that pointed at the old name. The deprecated calls just forward to the new ones, so behavior is unchanged.
Gemma was the last video model still building frames through the old VideoFrame spellings, which take and hand back a CoreImage image directly. Every other vision model already goes through the newer form that wraps the image in the general-purpose image case, so this was the only source of these deprecation warnings left in the library.

Reading the incoming frame through the supported accessor also removes a force-try: the deprecated property traps when the frame is not backed by a CoreImage image, whereas the surrounding frame-processing closure is already allowed to throw, so the failure now surfaces to the caller instead of killing the process.
An earlier fix to Gemma's cross-layer key/value sharing stopped consulting whether the caller supplied a cache when deciding which layers reuse an earlier layer's keys and values. That fix removed both readers of the local variable holding that answer but left the variable itself behind, so the compiler has been reporting it as an unused value ever since.

Drop the declaration. Its initializer only tested an optional for nil, so nothing observable changes.
With the deprecation warnings fixed, the build still reported a handful of style diagnostics. Most were `var` bindings that are only mutated through subscript assignment or a copying update, which `let` already permits, and `try`/`await` markers on expressions whose callees turned out to be synchronous. Breakpoints of note: the optional-key-path mock in the chat-session tests calls a synchronous prepare overload, and the reranker test used a conditional cast to an existential to check a protocol conformance that is statically guaranteed; the coercion form still fails the build if that conformance is ever removed, but no longer warns.

The one warning needing care was ParoQuant's concurrency test, which captures a non-Sendable layer in the @sendable closure of DispatchQueue.concurrentPerform. Unsynchronized access is the whole point of that test, so the layer now crosses the boundary in a small unchecked-Sendable wrapper, alongside the existing thread-safe accumulator in the same file.

@davidkoski davidkoski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good, thanks!

@davidkoski
davidkoski merged commit fc0566a into ml-explore:main Aug 31, 2026
3 checks passed
djandrewgibbons pushed a commit to djandrewgibbons/mlx-swift-lm that referenced this pull request Sep 1, 2026
…l-explore#594)

* Stop calling deprecated MLX memory APIs from the integration tests

MLX moved its memory inspection and cache control onto a Memory type and deprecated the older GPU spellings. The integration tests still used the old names, so every build of the IntegrationTesting scheme printed a dozen deprecation warnings that buried the warnings actually worth reading.

Switch the call sites over to Memory.snapshot() and Memory.clearCache(), and fix a doc comment that pointed at the old name. The deprecated calls just forward to the new ones, so behavior is unchanged.

* Move Gemma's video frame handling off the deprecated VideoFrame API

Gemma was the last video model still building frames through the old VideoFrame spellings, which take and hand back a CoreImage image directly. Every other vision model already goes through the newer form that wraps the image in the general-purpose image case, so this was the only source of these deprecation warnings left in the library.

Reading the incoming frame through the supported accessor also removes a force-try: the deprecated property traps when the frame is not backed by a CoreImage image, whereas the surrounding frame-processing closure is already allowed to throw, so the failure now surfaces to the caller instead of killing the process.

* Remove a leftover unused local from Gemma's text backbone

An earlier fix to Gemma's cross-layer key/value sharing stopped consulting whether the caller supplied a cache when deciding which layers reuse an earlier layer's keys and values. That fix removed both readers of the local variable holding that answer but left the variable itself behind, so the compiler has been reporting it as an unused value ever since.

Drop the declaration. Its initializer only tested an optional for nil, so nothing observable changes.

* Clear the remaining compiler warnings from the package

With the deprecation warnings fixed, the build still reported a handful of style diagnostics. Most were `var` bindings that are only mutated through subscript assignment or a copying update, which `let` already permits, and `try`/`await` markers on expressions whose callees turned out to be synchronous. Breakpoints of note: the optional-key-path mock in the chat-session tests calls a synchronous prepare overload, and the reranker test used a conditional cast to an existential to check a protocol conformance that is statically guaranteed; the coercion form still fails the build if that conformance is ever removed, but no longer warns.

The one warning needing care was ParoQuant's concurrency test, which captures a non-Sendable layer in the @sendable closure of DispatchQueue.concurrentPerform. Unsynchronized access is the whole point of that test, so the layer now crosses the boundary in a small unchecked-Sendable wrapper, alongside the existing thread-safe accumulator in the same file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants