Repository navigation
Prop-mutual .below families — canonical rec order + casesOn regeneration - #571
Conversation
66b0bcd to
8de193e
Compare
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.
8de193e to
48c3a6f
Compare
| -- can regenerate it against the canonical below-rec. | ||
| match p1 with | ||
| | .str gp ps _ => | ||
| if ps == "below" || ps.startsWith "below_" then |
There was a problem hiding this comment.
Casing on Name fragments is so uncomfortable... but I don't see any better method at the moment
There was a problem hiding this comment.
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
| 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 |
There was a problem hiding this comment.
Confirmation question: adding these here is enough to exercise the fix, right?
There was a problem hiding this comment.
Only partly, it exercises the casesOn path, but not the .rec order-divergence. I will try to add a better fixture for that
There was a problem hiding this comment.
If you want something to test ixvm on in the interim you can look at some of the stuff I've added to https://github.com/argumentcomputer/ix/tree/main/Benchmarks, e.g. you can directly test on https://github.com/argumentcomputer/ix/blob/main/Benchmarks/CatalogReal/CompileHS.lean
There was a problem hiding this comment.
yeap, going through those now
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.
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.
…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.
Fixes the known-open finding from the mega-PR's real-library benchmark:
ix check-rsrejected 25 constants of HaskellSpec's env — every.belowauxiliary of its Prop-valued mutual inductive predicates(dict/pat/type/bind/exp/gde… families;
mainrejected a strictsuperset 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
.belowfamily, and itsrecursor block was compiled through the keyless
compile_aux_block—so
sort_constspicked its own structural permutation. Siblingbelow-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_blockpairsrec_block[i]withflat[i]positionally (canonicity §6.2, verified loudly). The mainrecursor block already passes a class-order key for exactly this
reason; the below-rec block now does too.
2. Lean's authored
X.below.casesOndies once the rec iscanonical. Its value applies
X.below.recwith motives in Lean'smember 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
casesOnfrom the canonical rec (Phase 1b/2b); the below pathnow does the same.
Decompile had to learn the new shape:
classify_aux_genrootedX.below.casesOnatX.below— an aux inductive, not a family — sothe member joined no processed block and silently vanished from
decompiled envs; it now roots at the family like
X.below.rec. Andsince 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'swrapPhasegains a rec-resolverparameter; the Rust side factors Phase 1b's body into
regen_one_cases_on).Commits
IX_RECURSOR_DUMP/ alignment-failure / rule-diff dumps logged viathe
logfacade with no backend installed in the CLI; everybreakdown the kernel's own error hints point at was silently
dropped. Now stderr, like the compile-side mirror dumps.
regenerate below.casesOn (mutual.rs + AuxGen/CompileAux.lean).
below-rec (Phase 3b) (decompile.rs + DecompileDriver.lean +
CallSiteSurgery.lean classifier).
BelowPredicatecorpus fixture — EvenP/OddP mutual Proppredicates + 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
CompileHS.lean)ix catalog --audit+check-rs)957e5f8cfc35…lake testvalidate-auxaux-gen-diffdecompile-diffix validate0 failurescompile-lean @16 --rust-check)cmp-identical with the on-disk artifactvalidate-lean(5-phase, @8)skippedAux+99 = the below-casesOn constants now on the aux track); phase 5 decompile in flight at PR timeX.below.casesOnstorage changes from standalone authored defs toregenerated aux-block members across every Prop-below family
(
Nat.le,Relation.TransGen,Acc,List.Perm, …). Same wireformat, different compiler output — all artifacts regenerate.
Open decision: bump
Env::VERSIONto 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.