Conversation
view(_:) casts dtype + makes contiguous once, then vends zero-copy Span<Scalar> (lifetime-tied via @_lifetime(borrow self)) plus single/range copy-out. Enables the Lifetimes experimental feature on the MLX target. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JMq6N8WW3h7bGdgskwoFDQ # Conflicts: # Package.swift
# Conflicts: # Source/MLX/Transforms+Compile.swift
# Conflicts: # Source/MLX/MLXArray+Bytes.swift # Tests/MLXTests/MLXArrayTests.swift
# Conflicts: # Source/MLX/Transforms+Eval.swift
| .enableExperimentalFeature("StrictConcurrency") | ||
| .swiftLanguageMode(.v6), |
There was a problem hiding this comment.
build issue here -- missing a comma on 363
| while true { | ||
| // offset relative to the span's own start -- always >= 0 by construction, | ||
| // since minSourceIndex is the true minimum reachable sourceIndex | ||
| let spanOffset = (sourceIndex - minSourceIndex) * itemSize |
There was a problem hiding this comment.
This looks like it is maybe missing a commit -- minSourceIndex is not defined.
| traceState.stateInputs = inputs.flatMap { $0.innerState() } | ||
| traceState.argumentsCount = arguments.count |
There was a problem hiding this comment.
I think this needs to be done inside evalLock, otherwise concurrent use of the compiled function is mutating shared state.
evalLock is fine, but I wonder if the instance needs its own lock. Eventually (I hope) evalLock will go away -- we didn't need it in early versions of mlx because the mutation of shared state was done on the cpu/gpu worker threads. We need it now because some of that was hoisted into the calling thread.
Anyway, it might be better to express the intent here with a lock owned by trace state.
Proposed changes
MLXArrayOf- a fixed-Scalar type wrapping an MLXArray instead of type-unsafe representationsSpanAll this should increase safety, reduce allocations and reduce memory copies.
Checklist
Put an
xin the boxes that apply.pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes