Skip to content

Prop-mutual .below families — canonical rec order + casesOn regeneration - #571

Merged
johnchandlerburnham merged 4 commits into
mainfrom
jcb/prop-mutual-below
Aug 19, 2026
Merged

johnchandlerburnham merged 4 commits into
mainfrom
jcb/prop-mutual-below

Conversation

@johnchandlerburnham

Copy link
Copy Markdown
Member

Fixes the known-open finding from the mega-PR's real-library benchmark:
ix check-rs rejected 25 constants of HaskellSpec's env — every
.below auxiliary of its Prop-valued mutual inductive predicates
(dict/pat/type/bind/exp/gde… families; main rejected a strict
superset of 37 before the aux-alias fix). After this branch the
HaskellSpec env and the whole CatalogReal catalog kernel-check clean.

Two root causes, both compile-side

1. The below-rec block ignored §6.2. Prop-mutual predicates get an
IndPredBelow-generated mutual-inductive .below family, and its
recursor block was compiled through the keyless compile_aux_block —
so sort_consts picked its own structural permutation. Sibling
below-recursors first differ at index/motive shape while sibling
below-inductives first differ at ctor content, so the two blocks'
canonical orders can diverge — and the kernel's
populate_recursor_rules_from_block pairs rec_block[i] with
flat[i] positionally (canonicity §6.2, verified loudly). The main
recursor block already passes a class-order key for exactly this
reason; the below-rec block now does too.

2. Lean's authored X.below.casesOn dies once the rec is
canonical.
Its value applies X.below.rec with motives in Lean's
member order; ix regenerates that rec with the canonical motive
layout, so the authored wrapper becomes genuinely ill-typed in the
compiled env (the AppTypeMismatch and both universe-param-count
rejections). Ordinary families never hit this because ix regenerates
their casesOn from the canonical rec (Phase 1b/2b); the below path
now does the same.

Decompile had to learn the new shape: classify_aux_gen rooted
X.below.casesOn at X.below — an aux inductive, not a family — so
the member joined no processed block and silently vanished from
decompiled envs; it now roots at the family like X.below.rec. And
since the wrapper's rec only exists after the below-rec phase, its
regeneration is deferred to a new Phase 3b fed by the generated
RecursorVals (the Lean driver's wrapPhase gains a rec-resolver
parameter; the Rust side factors Phase 1b's body into
regen_one_cases_on).

Commits

  1. kernel: emit gated canonicity/recursor dumps on stderr — the
    IX_RECURSOR_DUMP / alignment-failure / rule-diff dumps logged via
    the log facade with no backend installed in the CLI; every
    breakdown the kernel's own error hints point at was silently
    dropped. Now stderr, like the compile-side mirror dumps.
  2. compile: align the below-rec block with its inductive block;
    regenerate below.casesOn
    (mutual.rs + AuxGen/CompileAux.lean).
  3. decompile: regenerate below.casesOn against the canonical
    below-rec (Phase 3b)
    (decompile.rs + DecompileDriver.lean +
    CallSiteSurgery.lean classifier).
  4. tests: BelowPredicate corpus fixture — EvenP/OddP mutual Prop
    predicates + mutual theorems by structural pattern-matching (the
    IndPredBelow trigger), permanently swept by validate-aux /
    aux-gen-diff / decompile-diff and the C5 qualified corpus.

Verification

gate result
HaskellSpec standalone (CompileHS.lean) 25 rejections → 64,051/64,051 kernel-clean
CatalogReal (ix catalog --audit + check-rs) 208,583/208,583, audit still green (19,584 address-preserving), root 957e5f8cfc35…
full lake test 2,670 pass (fixture included)
validate-aux 0 failures
aux-gen-diff Rust and Lean drivers byte-identical (6,247,773 B), serial + parallel
decompile-diff all gates PASS (300 plans; aux-family recovers the 19 dropped below-casesOn)
mathlib Rust compile 736,624 consts → 3,155,811,864 B, ix validate 0 failures
mathlib ALIGNED (compile-lean @16 --rust-check) byte-identical with Rust, and cmp-identical with the on-disk artifact
mathlib validate-lean (5-phase, @8) phases 1–4 PASS (phase 1 reproduces the canonical bytes; phase 4 zero findings, skippedAux +99 = the below-casesOn constants now on the aux track); phase 5 decompile in flight at PR time

⚠️ Canonical bytes move (+249,024 at mathlib scale)

X.below.casesOn storage changes from standalone authored defs to
regenerated aux-block members across every Prop-below family
(Nat.le, Relation.TransGen, Acc, List.Perm, …). Same wire
format, different compiler output — all artifacts regenerate.
Open decision: bump Env::VERSION to 2 per the policy sentence
("any change to serialized bytes bumps VERSION"), or fold into the
still-unreleased v1 from the base PR. One-integer change either way
(serialize.rs + Ix/Ixon.lean + docs/Ixon.md).

Downstream

TruthMinesLib should re-pin past this branch's merge (not just the
base PR): HaskellSpec is one of their 81 libraries, and their
kernel-check gates over any catalog containing it hit exactly the 25
pre-fix rejections.

The canonical_aux_order / recursor-alignment / rule-diff dumps in
inductive.rs logged through the log facade, but no log backend is
installed in the CLI (texray only bridges tracing spans) — every dump,
including the IX_RECURSOR_DUMP breakdowns the kernel's own error
messages point at, was silently dropped. Emit on stderr like the
compile-side mirror dumps.
…te below.casesOn

Two halves of one §6.2 violation on Prop-valued mutual inductive
predicates (HaskellSpec dict/pat/type shape — mutual Props whose
IndPredBelow .below auxiliaries form a generated mutual-inductive
family):

1. The below-rec block was compiled through the keyless
   compile_aux_block, so sort_consts picked its own structural
   permutation of the recursors. Sibling below-recursors first differ
   at index/motive shape while sibling below-inductives first differ
   at ctor content, so the two blocks' canonical orders can diverge —
   and the kernel's populate_recursor_rules_from_block pairs
   rec_block[i] with flat[i] positionally (canonicity §6.2). Pass the
   same class-order key the main recursor block already uses.

2. Lean's authored X.below.casesOn applies X.below.rec with motives in
   LEAN's member order; once the canonical below-rec replaces that rec,
   the authored wrapper is ill-typed in the compiled env (kernel:
   AppTypeMismatch on the motive arguments, plus two
   universe-param-count rejections from the same misalignment).
   Regenerate each below.casesOn from its canonical rec, exactly like
   the main family's Phase 2b.

Mirrored Rust (mutual.rs) + pure-Lean (AuxGen/CompileAux.lean);
aux-gen-diff byte-identical. Fixes 18 of the 25 known-open HaskellSpec
kernel rejections (the other 7 below.rec ones fall to the same
class-order key).
…Phase 3b)

The compile-side below.casesOn regeneration moves those constants onto
the aux regen track, and the decompiler dropped them: classify_aux_gen
rooted X.below.casesOn at X.below (an aux inductive, not a family), so
the member never joined any processed block's aux_members — and even
rooted correctly, Phase 1b runs before X.below.rec exists and skipped
it silently.

- Root X.below.casesOn at the FAMILY, like X.below.rec (Rust
  classify_aux_gen + Lean classifyAuxGen).
- Factor Phase 1b's per-member body into regen_one_cases_on and add
  Phase 3b: after the below-rec block regenerates, regenerate the
  deferred below.casesOn members from the GENERATED RecursorVals (the
  Lean driver's wrapPhase gains a rec-resolver parameter for this).

validate-aux 0 failures; decompile-diff all gates PASS (aux-family
gate recovers the 19 previously-missing below.casesOn members).
…Below

EvenP/OddP mutual Prop predicates plus mutual theorems by structural
pattern-matching, forcing Lean to generate the .below mutual-inductive
family and .below.casesOn (defined via .below.rec) — the HaskellSpec
dict/pat/type shape, permanently in the aux corpus so validate-aux /
aux-gen-diff / decompile-diff and the C5 qualified corpus all sweep
the below-rec class-order key and the below.casesOn regeneration.
Comment thread Ix/CallSiteSurgery.lean
-- can regenerate it against the canonical below-rec.
match p1 with
| .str gp ps _ =>
if ps == "below" || ps.startsWith "below_" then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Casing on Name fragments is so uncomfortable... but I don't see any better method at the moment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah agreed, I think it's okay for now because this is elaboration-level, but I'm going to try to figure out a better alternative

Comment on lines +639 to +653
mutual
public inductive EvenP : Nat → Prop where
| zero : EvenP 0
| succ : {n : Nat} → OddP n → EvenP (n + 1)
public inductive OddP : Nat → Prop where
| succ : {n : Nat} → EvenP n → OddP (n + 1)
end

mutual
public theorem evenp_nonneg : {n : Nat} → EvenP n → 0 ≤ n
| _, .zero => Nat.le_refl 0
| _, .succ h => Nat.le_trans (oddp_nonneg h) (Nat.le_succ _)
public theorem oddp_nonneg : {n : Nat} → OddP n → 0 ≤ n
| _, .succ h => Nat.le_trans (evenp_nonneg h) (Nat.le_succ _)
end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmation question: adding these here is enough to exercise the fix, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only partly, it exercises the casesOn path, but not the .rec order-divergence. I will try to add a better fixture for that

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeap, going through those now

@johnchandlerburnham
johnchandlerburnham merged commit 05e552f into main Aug 19, 2026
11 checks passed
@johnchandlerburnham
johnchandlerburnham deleted the jcb/prop-mutual-below branch August 19, 2026 11:55
johnchandlerburnham added a commit that referenced this pull request Aug 20, 2026
The IX_APP_DIFF AppTypeMismatch trace logged through the log facade,
but no log backend is installed in the CLI or test binaries, so every
dump was silently dropped — the same failure mode #571 fixed for the
inductive.rs canonicity dumps. Emit on stderr like those, and include
the failing constant's debug label in the header line since the dump
is only legible next to the constant it fired in.
johnchandlerburnham added a commit that referenced this pull request Aug 20, 2026
rebuild_named copied a Named entry's meta and original fields but
dropped hints. Decompile reconstructs DefinitionVal.hints from the
per-name channel (absent → Opaque), and roundtrip_block Phase B
validates each decompiled aux constant's Lean-level hash — which
includes hints — against the source env. On the kernel egress leg
every regenerated .casesOn/.recOn/.below/.brecOn therefore failed that
validation (Opaque vs Abbrev, 4846 spurious Pass-2 errors on a full
env), recovery's own hash check failed the same way, and the raw
generated form shipped in place of the metadata-restored one.

That substitution was invisible while raw regeneration was
name-faithful; it surfaced as kernel-ixon-roundtrip mismatches once
two things landed on top of it: #571's Phase-3b below.casesOn
regeneration (whose below-rec input is regenerated in the decompile
work env, where the original below ctors are not yet present, so the
IH binder falls back to a bare `ih`) and v4.33's _hygCtx hygienic
binder names in IndPredBelow output (ih._@.<module>.<hash>._hygCtx
._hyg.N), which made the fallback visibly diverge for every inductive
predicate's below.casesOn (Nat.le, List.Forall₂, DHashMap.Raw.WF, …).

With hints preserved, Phase B's restoration lands and the full-env
kernel roundtrip is clean again: 169194 constants verified, 0 errors,
0 aux_gen diffs.
johnchandlerburnham added a commit that referenced this pull request Aug 20, 2026
…e surgery + egress hints channel (#578)

* fix(kernel): emit the [app diff] dump on stderr

The IX_APP_DIFF AppTypeMismatch trace logged through the log facade,
but no log backend is installed in the CLI or test binaries, so every
dump was silently dropped — the same failure mode #571 fixed for the
inductive.rs canonicity dumps. Emit on stderr like those, and include
the failing constant's debug label in the header line since the dump
is only legible next to the constant it fired in.

* fix(egress): carry the per-name hints channel through ixon_egress

rebuild_named copied a Named entry's meta and original fields but
dropped hints. Decompile reconstructs DefinitionVal.hints from the
per-name channel (absent → Opaque), and roundtrip_block Phase B
validates each decompiled aux constant's Lean-level hash — which
includes hints — against the source env. On the kernel egress leg
every regenerated .casesOn/.recOn/.below/.brecOn therefore failed that
validation (Opaque vs Abbrev, 4846 spurious Pass-2 errors on a full
env), recovery's own hash check failed the same way, and the raw
generated form shipped in place of the metadata-restored one.

That substitution was invisible while raw regeneration was
name-faithful; it surfaced as kernel-ixon-roundtrip mismatches once
two things landed on top of it: #571's Phase-3b below.casesOn
regeneration (whose below-rec input is regenerated in the decompile
work env, where the original below ctors are not yet present, so the
IH binder falls back to a bare `ih`) and v4.33's _hygCtx hygienic
binder names in IndPredBelow output (ih._@.<module>.<hash>._hygCtx
._hyg.N), which made the fallback visibly diverge for every inductive
predicate's below.casesOn (Nat.le, List.Forall₂, DHashMap.Raw.WF, …).

With hints preserved, Phase B's restoration lands and the full-env
kernel roundtrip is clean again: 169194 constants verified, 0 errors,
0 aux_gen diffs.

* fix(compile): call-site surgery for Prop-below ctors and below.casesOn

On a Prop-valued MUTUAL inductive-predicate family, IndPredBelow's
.below is itself a mutual inductive whose parameters are the parent
params followed by the parent motives — in Lean's source member order.
The canonical below family is generated from the canonical parent rec,
so when sort_consts orders the members differently from source (the
BelowPredicate EvenP/OddP fixture flipped to (OddP, EvenP) under the
v4.33 content hashes), the canonical below's motive-parameter order
diverges from Lean's authored one.

.below HEAD applications in user constants were already reconciled by
below_call_site_plans, and .brecOn by its derived plans — but a
Prop-below family exposes two more user-referencable surfaces with the
same leading params+motives telescope: the .below CONSTRUCTORS and the
regenerated .below.casesOn wrapper. Matchers compiled by structural
recursion over the predicates reference both (the BelowPredicate
match_2 matchers apply OddP.below.succ / EvenP.below.zero and
OddP.below.casesOn with source-order motives), so the kernel rejected
them with AppTypeMismatch — 2 failures in kernel-check-env.

Register the same derived plan under each below ctor name and the
.below.casesOn name (Prop families only — Type-level .below is a
definition with neither). The apply site discriminates the two
telescope shapes by the key's last component (below/below_N = head,
which keeps its indices+major application floor; anything else =
family member, with NO floor, since a field-less below ctor like
EvenP.below.zero is fully applied at exactly params+motives). In both
shapes everything after the motive segment is kept in place, so the
below branch now emits one identity tail — byte-identical entries to
the old fixed/extra split for heads. X.below.rec is deliberately not
registered: only regenerated wrappers reference it, and those skip
surgery via the aux-regen guard.

Mirrored in lockstep across the Rust and pure-Lean compilers (apply,
compile-side registration, decompile-side plan install — the latter
derives the ctor names from the parent inductive via the same suffix
transplant buildBelowIndcCtor uses, since the below inductive is not
yet regenerated at install time). CallSite metadata makes the rewrite
self-describing, so decompile restores the source-order spelling with
no changes; aux-gen-diff and decompile-diff gates stay byte-identical
and validate-aux is clean.

* test: pin BelowPredicate matchers; add kernel-roundtrip-ns diagnostic

focusConsts gains the two _private BelowPredicate match_2 matchers —
the constants that pinned the Prop-below ctor/casesOn call-site gap —
so kernel-check-const reproduces that class of regression in ~10s
without a full-env pass.

Tests/Main.lean gains a kernel-roundtrip-ns=<prefixes> special arg
mirroring rust-compile: the same compile → ingress → egress →
decompile → hash-compare pipeline as kernel-ixon-roundtrip, but over
the transitive closure of the name-prefix-matched constants only.
kernel-roundtrip-ns=Nat.le reproduced the below.casesOn binder-name
regression on a 98-constant closure in 40ms.

* style: rustfmt

One over-split method chain in install_decompile_call_site_plans from
the below-family plan registration; whitespace-only.

* ci: portable codegen for the GitHub-hosted rust-test job

Since #575 stopped exporting RUSTFLAGS, .cargo/config.toml's
-Ctarget-cpu=native is authoritative in CI. That is the point for the
warp jobs (bench artifact reuse, with CPU provenance logged), but
rust-test runs on ubuntu-latest — a heterogeneous fleet sharing one
cargo cache. A proc-macro dylib or test binary compiled native on an
AVX-512 runner SIGILLs when a later run lands on a non-AVX-512 one;
clippy-driver died with SIGILL checking aiur off a cached
tracing-attributes exactly this way, and nextest --run-ignored all
executes release test binaries with the same exposure.

Pin the job to -Ctarget-cpu=x86-64-v3 (AVX2 — the baseline every
GitHub-hosted x64 runner provides). RUSTFLAGS participates in the
rust-cache key, so this also re-keys away from the poisoned
native-built cache entries.
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.

2 participants