Complete the C++20 compiler migration - #4
Draft
PhysicistJohn wants to merge 1 commit into
Draft
Conversation
Use C++20 for CPU JIT compilation and preamble generation, and propagate the requirement through installed CMake targets and examples. Add a runtime regression test that compiles a C++20 concept through MLX's actual CPU JIT path.
PhysicistJohn
force-pushed
the
draft/cpu-jit-cxx20
branch
from
August 2, 2026 01:30
81a23b7 to
222a92e
Compare
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.
Summary
MLX moved its project build and documented C++ requirement to C++20 in ml-explore#3050, but several compiler entry points still selected C++17:
This change aligns those remaining paths. It also exports
cxx_std_20as a usage requirement so CMake consumers inherit the same standard as MLX itself.Why
The mismatch is latent until a header shared with the CPU JIT uses a C++20 feature. The normal MLX build then succeeds under C++20, but
mx.compilerecompiles the generated source under C++17 and fails at runtime. Concepts are one concrete way to expose that split.The added regression test sends a C++20 concept through MLX's actual CPU JIT compiler and generated preamble. The identical test, applied alone to base commit
fb5133e1, invokesg++ -std=c++17and fails withunknown type name 'concept'; on this branch it emits the shared library and passes all four assertions.The change is intentionally limited to language-standard selection. It does not alter compiler discovery or the preamble architecture discussed in ml-explore#3430.
Validation
The MLX CPU, Metal, and Python builds used Apple Clang 21 with C++ switch warnings promoted to errors.
xcrun --find metalresolved the active toolchain, andxcrun metal --versionreported Apple Metal 32023.921.-std=c++20-std=c++20; its 3,472,631-byte output compiled successfullyCMAKE_CXX_STANDARD 17, linkedmlx, and was correctly compiled as-std=gnu++20cmake_project,export, and the C++/Metal extension examples configured and built successfullypre-commit run --all-filesandgit diff --checkpassedThe MSVC and PowerShell paths were audited but cannot be executed locally on this macOS host; upstream Windows CI is the execution gate.
Size and cold-JIT impact
libmlx.a: 29,204,112 bytes before and after; 83 archive members in bothThe measured cost is confined to first compilation of a CPU kernel cache key. Both samples produced identical machine-code text, so there is no measured cached-execution or binary-size regression.
Checklist
pre-commit run --all-files