Skip to content

doc: record the Array.ofFn call-site audit, and add ofFn' compatibility lemmas - #9048

Merged
kim-em merged 2 commits into
mainfrom
offn-audit
Jul 28, 2026
Merged

doc: record the Array.ofFn call-site audit, and add ofFn' compatibility lemmas#9048
kim-em merged 2 commits into
mainfrom
offn-audit

Conversation

@kim-em

@kim-em kim-em commented Jul 28, 2026

Copy link
Copy Markdown
Owner

This PR records the outcome of auditing whether the tree should adopt the ofFn shim ahead of the upstream fix in leanprover/lean4#14270. It should not, and the reasoning is worth keeping so it is not relitigated.

The defect is real rather than hypothetical. Hex.Vector.unit in HexMatrix.Basic is @[expose], is built with core Vector.ofFn, and does not reduce in the kernel from a downstream module; hex-matrix is a released library, so that ships. Switching that single definition to ofFn' fixes it.

The scale is smaller than the raw grep suggests. Of 297 occurrences across 48 files, only about 100 sit in def / abbrev / instance bodies, which is the only position where kernel reduction is affected; the rest are theorem statements.

A blanket migration of the 62 mechanically reachable sites was attempted and produces 29 build errors in three classes, each of which is a reason not to do it: some files are not module files at all, so public import is a syntax error there; ofFn' is only propositionally equal to ofFn, so rfl proofs that went through simp only [..., Vector.getElem_ofFn, ...] break; and the shim has no lemma ecosystem, so anything reasoning about a migrated definition's contents needs ofFn'_eq_ofFn threaded in by hand. Each migrated site therefore costs proof churn proportional to how much its callers reason about the array.

The recommendation is to fix it upstream and migrate individual definitions only where something concretely needs them to reduce, repairing their lemma uses at the same time, and never to migrate *Impl definitions, which are runtime implementations behind @[csimp] where core ofFn is correct.

Documentation only; no code changes.

🤖 Prepared with Claude Code

Kim Morrison and others added 2 commits July 28, 2026 09:43
Decides whether the tree should adopt the ofFn shim ahead of the upstream
fix. It should not.

Of 297 raw occurrences, only ~100 are in definition bodies, where kernel
reduction is actually affected. The defect is real: Hex.Vector.unit in the
released hex-matrix is @[expose], built with core Vector.ofFn, and does not
reduce from a downstream module.

But a blanket migration of the 62 mechanically reachable sites produces 29
build errors in three classes: files that are not module files at all, rfl
proofs that break because ofFn is not defeq to ofFn, and proofs that break
because the core getElem_ofFn/size_ofFn lemmas do not apply to the shim.
Each migrated site costs proof churn proportional to how much its callers
reason about the array contents.

So migrate per-definition only where something concretely needs reduction,
and fix the upstream gap instead.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0188fgvPvjbcXhvTYVSATLhv
Review of the first draft was right on two counts.

The counts were wrong: a plain grep counts matching lines, including prose and
the primed shim names. Stripping comments and matching the exact core
identifiers gives 255 references, of which 66 are in definition bodies (not
~106) and 9 of those are `*Impl` definitions that must keep core `ofFn`.
HexPoly has 3, all `*Impl`, not 13.

And the blanket-migration experiment tested the wrong population. It rewrote
`*Impl` definitions the recommendation says to leave alone, non-exposed
definitions where reduction stops earlier anyway, and a file that is not a
module file at all. Its failures are therefore not evidence that a targeted
migration is costly, and the note no longer claims they are.

Most of the churn it did show was a missing shim API rather than an inherent
cost, so `HexBasic.OfFn` now provides `Array.size_ofFn'`,
`Array.getElem_ofFn'`, `Vector.getElem_ofFn'`, and `Vector.toArray_ofFn'`.

The conclusion stands but for a better reason: `import all
Init.Data.Array.Basic` in the *consuming* module fixes the reduction with no
change to any definition, which is cheaper than migrating anything. Verified
against the `Vector.unit` probe.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0188fgvPvjbcXhvTYVSATLhv
@kim-em kim-em changed the title doc: record the Array.ofFn call-site audit doc: record the Array.ofFn call-site audit, and add ofFn' compatibility lemmas Jul 28, 2026
@kim-em
kim-em merged commit 81a841f into main Jul 28, 2026
1 check passed
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