Skip to content

chore: align mlxcel-core and mlxcel-surgery to the root crate (edition 2024, version 0.3.3)#445

Merged
inureyes merged 2 commits into
mainfrom
chore/issue-272-member-crates-edition-2024-version-sync
Jun 25, 2026
Merged

chore: align mlxcel-core and mlxcel-surgery to the root crate (edition 2024, version 0.3.3)#445
inureyes merged 2 commits into
mainfrom
chore/issue-272-member-crates-edition-2024-version-sync

Conversation

@inureyes

Copy link
Copy Markdown
Member

Summary

Bring the two workspace member crates into line with the root mlxcel crate, which is already on Rust edition 2024 and version 0.3.3. mlxcel-core and mlxcel-surgery move from edition 2021 to 2024, and their [package] version fields move from 0.2.0 and 0.1.0 respectively to 0.3.3.

Version sync to 0.3.3

Per the CLAUDE.md "Release versioning" rule, from v0.3.3 onward the member crates carry the same version as the root. This PR sets both src/lib/mlxcel-core/Cargo.toml and src/lib/mlxcel-surgery/Cargo.toml to version = "0.3.3". The root depends on both members by path with no version requirement, so no dependency spec lines change; cargo update -p mlxcel -p mlxcel-core -p mlxcel-surgery refreshes Cargo.lock (only the two member version strings change there).

Edition 2024 migration

The migration was driven by cargo fix --edition on each crate, then reviewed and hand-finished. The mechanical and manual touch points:

  • std::env::set_var / remove_var become unsafe in edition 2024. The two runtime call sites are now wrapped in unsafe { ... } with an accurate SAFETY comment rather than the generic placeholder cargo fix inserts: ensure_persistent_ptx_cache (src/lib/mlxcel-core/src/lib.rs) and apply_metal_ops_per_buffer_default (src/lib/mlxcel-core/src/hardware.rs). Both functions are documented to run once at the very top of main, and all three in-tree callers (src/main.rs, src/bin/mlx_server.rs, src/bin/bench_decode.rs) invoke them right after Cli::parse(), before any model load, MLX op, or worker thread touches the process environment, so no other thread is concurrently reading or writing it. The stale "edition 2021 (set_var is not unsafe here)" comment in hardware.rs is replaced. The test-only sites in lang_analyzer/cache.rs and lang_analyzer/mod.rs already serialize env mutation through the existing env_lock() guard; they get the unsafe wrap plus a one-line test-only SAFETY note. The pre-wrapped sparse_v_tests.rs site is left as-is.
  • extern "C" in hardware.rs becomes unsafe extern "C".
  • gen is a reserved keyword in 2024. It is escaped to r#gen at its sites: the metal_ops_per_buffer_default and estimate_bandwidth function parameters in hardware.rs, and local test variables in the dflash round_loop.rs / round_loop_batched.rs. r#gen keeps the churn minimal and the public parameter name unchanged for callers.
  • Nested if let blocks collapse into 2024 let-chains where clippy's collapsible_if flagged them (29 sites across the cache, drafter, sampling, utils, weights, layers, generate, and lang_analyzer modules). cargo fix also applied the 2024 match-ergonomics binding fix (|(&id, _)| to |&(&id, _)|) and rewrote two if let ... else { break } loops into equivalent match forms for the changed temporary-scope rules.
  • Both crates are reformatted under the 2024 style edition (rustfmt's style_edition defaults to the crate edition), which re-sorts imports (uppercase before lowercase) and wraps some macro arguments, so cargo fmt --check stays clean on CI.

Test plan

  • cargo check -p mlxcel-surgery --lib --tests
  • cargo check -p mlxcel-core --lib --tests --examples --features metal,accelerate
  • cargo clippy -p mlxcel-core --lib --tests --features metal,accelerate -- -D warnings
  • cargo clippy -p mlxcel-surgery --lib --tests -- -D warnings
  • cargo fmt -p mlxcel-core --check and cargo fmt -p mlxcel-surgery --check

The CUDA path (#[cfg(feature = "cuda")] code, including the ensure_persistent_ptx_cache body) cannot be compiled on this macOS host, so the cuda-feature build and any release/whole-workspace verification are left for the reviewer/CI.

Closes #272

@inureyes inureyes added status:review Under review type:chore Maintenance tasks (build, CI, etc.) priority:low Low priority labels Jun 25, 2026
@inureyes

Copy link
Copy Markdown
Member Author

Implementation Review Summary

Intent

Bump the two workspace member crates (mlxcel-core, mlxcel-surgery) from Rust edition 2021 to 2024 and align their versions to the root crate (0.3.3), closing #272 plus the maintainer version-sync add-on.

Findings Addressed

None. No CRITICAL/HIGH/MEDIUM/LOW correctness or safety findings.

Remaining Items

None.

Verification

  • Version/edition bump complete and correct: both src/lib/mlxcel-core/Cargo.toml and src/lib/mlxcel-surgery/Cargo.toml now carry edition = "2024" and version = "0.3.3". Root Cargo.toml is unchanged (already 2024/0.3.3), and no version requirement was added to the path-dependency lines. Cargo.lock reflects only the two version-string updates.
  • Every std::env::set_var/remove_var call site is wrapped in unsafe { } (2 runtime sites in lib.rs/hardware.rs, plus all test sites in lang_analyzer/, cache/sparse_v_tests.rs). No unwrapped site remains, including the previously missed test site at lang_analyzer/mod.rs:1652/1667, now wrapped with a SAFETY note.
  • Runtime SAFETY claims accurate: ensure_persistent_ptx_cache (lib.rs) and apply_metal_ops_per_buffer_default (hardware.rs) are both invoked at the top of main() right after CLI parsing, before command dispatch, model load, MLX ops, or worker activity. The named caller sets in each comment (main.rs, mlx_server.rs, and bench_decode.rs for the latter) match the actual call sites.
  • Behavior-preserving rewrites verified semantically equivalent: the two if let (Some, Some) = ... else { break } to match rewrites in generate.rs; the let-chain collapses in generate.rs, utils.rs, weights.rs, and the 5-condition chain in lang_analyzer/mod.rs. The || disjunct in the 5-condition chain is correctly parenthesized as && (token_str.is_empty() || ...), short-circuit order is preserved, no else is dropped, and the nested return Some(...) statements in weights.rs are kept inside the body rather than folded into the chain.
  • Mechanical 2024 changes correct: gen to r#gen (hardware.rs, dflash tests) and extern "C" to unsafe extern "C" (hardware.rs FFI block).
  • Scope is constrained: all 50 changed files live under the two member crates plus Cargo.lock. No structural changes, renames, or moves outside the migration.
  • Build/fmt/clippy already verified green by the orchestrator (release build, workspace cargo fmt --check, scoped clippy -D warnings on both crates). cargo test was not re-run here by design.

@inureyes inureyes added status:done Completed and removed status:review Under review labels Jun 25, 2026
inureyes added 2 commits June 26, 2026 07:42
Align the two workspace member crates with the root mlxcel crate, which is already on edition 2024 and version 0.3.3 (issue #272). mlxcel-core and mlxcel-surgery move from edition 2021 to 2024, and their versions move from 0.2.0 and 0.1.0 respectively to 0.3.3, per the CLAUDE.md release-versioning rule that the members carry the same version as the root from v0.3.3 onward. The root depends on both members by path with no version requirement, so no dependency spec changes; cargo update refreshes Cargo.lock.

Edition 2024 migration, applied via cargo fix --edition plus manual review:

std::env::set_var and remove_var become unsafe in 2024. The two runtime call sites (ensure_persistent_ptx_cache in lib.rs and apply_metal_ops_per_buffer_default in hardware.rs) are now wrapped in unsafe with an accurate SAFETY comment: both run once at the top of main right after CLI parsing (src/main.rs, src/bin/mlx_server.rs, src/bin/bench_decode.rs), before any model load, MLX op, or worker thread touches the environment, so no other thread is concurrently reading or writing it. The test-only sites in lang_analyzer already serialize env mutation through the env_lock() guard and carry a one-line test-only SAFETY note.

extern "C" in hardware.rs becomes unsafe extern "C". The gen identifier (reserved in 2024) is escaped to r#gen at its function-parameter and local test-variable sites. Nested if let blocks collapse into 2024 let-chains where clippy flagged collapsible_if, and both crates are reformatted under the 2024 style edition so cargo fmt --check stays clean.

Verified with cargo check, cargo clippy -D warnings, and cargo fmt --check on both crates (mlxcel-core built with metal,accelerate).
@inureyes inureyes force-pushed the chore/issue-272-member-crates-edition-2024-version-sync branch from b002f5a to 057ceba Compare June 25, 2026 22:43
@inureyes inureyes merged commit 89a5de4 into main Jun 25, 2026
2 checks passed
@inureyes inureyes deleted the chore/issue-272-member-crates-edition-2024-version-sync branch June 25, 2026 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority:low Low priority status:done Completed type:chore Maintenance tasks (build, CI, etc.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore: Bump mlxcel-core to Rust edition 2024 to match the root crate

1 participant