Skip to content

Deprecate the public matrix index helpers - #70

Merged
ctreffs merged 1 commit into
perf/allocation-free-constructionfrom
api/deprecate-index-helpers
Oct 17, 2026
Merged

ctreffs merged 1 commit into
perf/allocation-free-constructionfrom
api/deprecate-index-helpers

Conversation

@ctreffs

@ctreffs ctreffs commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Stack 5/5 — base: master (#65, #66, #68, #69 merged)

Problem

The two public free functions disagree:

  • index(column:row:width:) returns row * width + column, which is row-major.
  • columnRow(index:width:) and every matrix storage use column-major order.

So columnRow(index: index(column: 1, row: 2, width: 4), width: 4) returns (column: 2, row: 1). Nothing in the package calls index(column:…). Consumers already have subscript(column:row:) and subscript(index:) on every matrix, and both helpers put very generic names (index, columnRow) into every consumer's namespace.

Change

  • Deprecated both helpers, with messages pointing at the matrix subscripts. Behavior is unchanged, so existing callers get a warning rather than different results.
  • The matrix storages now use a new internal @inlinable helper, columnMajorPosition(of:rows:).

Tests

MatrixIndexingTests:

  • checks that the flat subscript (getter and setter) is column-major for all six matrix types;
  • pins the deprecated helpers' behavior, including the documented row-major mismatch.

Both check-inlinable configurations pass, and DocC --analyze --warnings-as-errors is clean.

Left out on purpose

In the analysis I suggested also making the public SIMD.makeIterator()/elements extension internal. That was wrong. SIMD2/3/4 get a deliberate retroactive Sequence conformance in SIMD{2,3,4}+Extensions.swift, and makeIterator() implements it (Array(v) and for x in v depend on it). It stays as is.

https://claude.ai/code/session_011WSUtoLptjea3s3iC5wTNC

@ctreffs
ctreffs force-pushed the perf/allocation-free-construction branch from 8f4cf0e to fad8f8c Compare October 17, 2026 11:31
@ctreffs
ctreffs force-pushed the api/deprecate-index-helpers branch from 7780fc2 to d7264c4 Compare October 17, 2026 11:31
@ctreffs
ctreffs force-pushed the perf/allocation-free-construction branch from fad8f8c to 5538593 Compare October 17, 2026 12:18
@ctreffs
ctreffs force-pushed the api/deprecate-index-helpers branch from d7264c4 to b61ef39 Compare October 17, 2026 12:18
@ctreffs
ctreffs force-pushed the perf/allocation-free-construction branch from 5538593 to 1d23f99 Compare October 17, 2026 12:48
@ctreffs
ctreffs force-pushed the api/deprecate-index-helpers branch from b61ef39 to 165a108 Compare October 17, 2026 12:48
@ctreffs
ctreffs force-pushed the perf/allocation-free-construction branch from 1d23f99 to 29586ba Compare October 17, 2026 13:11
@ctreffs
ctreffs force-pushed the api/deprecate-index-helpers branch from 165a108 to e8162aa Compare October 17, 2026 13:11
@ctreffs
ctreffs force-pushed the perf/allocation-free-construction branch from 29586ba to 6010506 Compare October 17, 2026 13:23
@ctreffs
ctreffs force-pushed the api/deprecate-index-helpers branch from e8162aa to bdbfa67 Compare October 17, 2026 13:23
@ctreffs
ctreffs force-pushed the perf/allocation-free-construction branch from 6010506 to d5eefff Compare October 17, 2026 13:54
@ctreffs
ctreffs force-pushed the api/deprecate-index-helpers branch from bdbfa67 to d4e325f Compare October 17, 2026 13:54
index(column:row:width:) computes a row-major index ((row * width) +
column), while columnRow(index:width:) and every matrix storage use
column-major order, so the two did not round-trip. Neither is needed by
consumers (matrices have subscript(column:row:) and subscript(index:)),
and both put very generic names into every consumer's namespace.

- Deprecate both, with messages pointing at the matrix subscripts.
  Behavior is unchanged to avoid silent breakage.
- Matrix storages use a new internal @inlinable
  columnMajorPosition(of:rows:) instead.

Tests: MatrixIndexingTests checks that the flat subscript (get and set)
is column-major for all matrix types, and pins the behavior of the
deprecated helpers, including the documented row-major mismatch.

Claude-Session: https://claude.ai/code/session_011WSUtoLptjea3s3iC5wTNC
@ctreffs
ctreffs force-pushed the perf/allocation-free-construction branch from d5eefff to 2ce7789 Compare October 17, 2026 14:05
@ctreffs
ctreffs force-pushed the api/deprecate-index-helpers branch from d4e325f to 090da5a Compare October 17, 2026 14:05
@ctreffs
ctreffs merged commit 25e68e4 into perf/allocation-free-construction Oct 17, 2026
@ctreffs
ctreffs deleted the api/deprecate-index-helpers branch October 17, 2026 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant