Fix implicit thread address space qualifier becoming explicit in metal 4.1 - #3963
Open
louen wants to merge 9 commits into
Open
Fix implicit thread address space qualifier becoming explicit in metal 4.1 #3963louen wants to merge 9 commits into
thread address space qualifier becoming explicit in metal 4.1 #3963louen wants to merge 9 commits into
Conversation
thread memory addressing becoming explicit in metal 4.1
thread memory addressing becoming explicit in metal 4.1 thread address space qualifier becoming explicit in metal 4.1
louen
marked this pull request as ready for review
August 2, 2026 00:48
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.
Proposed changes
Metal 4.1 introduced the concept of "generic address space" and defaults pointers and references to this address space (where it used to implicitly be
threadbefore)In particular this means that
thiswhich previously wasthreadis nowgenericwhich causes code with functions that return a thread reference type to fail to compile, for example:starting from Xcode 27.0 Beta 4 this will fail with
on previous versions of the toolchain, this would emit a warning (if enabled)
To fix the code under the new compiler rules the
threadqualifier has to be added to such functions returning a reference to, but also to all member functions of classes that call them, propagating virally similarly toconstmember functions in C++.This propagation stops at the creation of the object since as an automatic variable
Foo f; foo.at(42);Foois still implicitly delclared asthread.The fix has been applied automatically in most instances by adding
-Xclang -fixit -Wmetal-addr-spacesto themetalcompiler flags in CMake (the warning flag remains in this PR, as discussed below).Extra fixes were necessary especially in the instancing macros which clang could not fix automatically.
To verify the fixes, I have taken the following steps
Apple metal version 32023.918 (metalfe-32023.918.1)) and Beta 4 toolchains (Apple metal version 32023.921 (metalfe-32023.921)).threadkeyword only makes explicit what was previously implicit behavior. I checked producedairfiles are binary-identical under both toolchains.As said above in addition to the addition of the keyword I have left the
-Wmetal-addr-spacesso that older toolchains still warn about the construct.Note that mlx-swift will have to upgrade its submodule to compile under the new Xcode toolchain
Checklist
Put an
xin the boxes that apply.pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes