Commit 547455e
Compiler fixes for auxiliary constant generation (#473)
* Ixon: drop recr/refl/nested flags from Inductive
Remove the `recr`/`refl` bools and the `nested` count from the Ixon
`Inductive` constant and its serialization (Rust and Lean), and from
the `Indc` reveal-proof variant, renumbering the field-presence mask
bits. These flags are derivable from constructor structure, so storing
them was redundant and trusting declared values was an adversarial
surface (e.g. is_rec = false on a recursive inductive enables improper
struct-eta).
- kernel: KConst::Indc loses is_rec/is_refl/nested. is_rec is now
computed on demand (computed_is_rec), memoized in the new env
is_rec_cache with a provisional entry to break the whnf ->
try_struct_eta_iota -> is_struct_like cycle. This replaces the
declared-vs-computed H1 verification in check_inductive.
- compile: new compute_lean_ind_flags recomputes Lean's block-wide
isRec/isReflexive/numNested wherever an InductiveVal is reconstructed
without a source Lean env (kernel egress, decompile), since Ixon no
longer stores the flags; validate_lean_ind_flags checks a whole env
against the recomputation.
- tests/benchmarks: add AuxDedup1/AuxDedup2 mutual fixtures exercising
aux-constant dedup across blocks (fix forthcoming); add a
CompileMutualFixtures benchmark lib building the mutual test
fixtures; ignore *.ixe.
* Compile: evaporated-aux canonicalization and byte-exact aux roundtrip
Evaporated auxiliaries (over-merge splits): when SCC splitting strands a
nested aux's spec-param inductives outside the owner's SCC, no SCC holds
the joint family, and dropping the irrelevant over-merged motives leaves
exactly the external inductive's generic recursor. Canonical treatment:
`rec_N` claims alias `<Ext>.rec` (e.g. `List.rec`), call sites are
rebuilt onto the external telescope via head-rewrite CallSitePlans
(owner-gated, single-motive targets), and `below_N`/`brecOn_N` compile
as surgered originals like `_sizeOf_N`. Fixes the AuxDedup kernel-check
failures (28 -> 0); AuxDedup1 now generates identical auxiliaries to
AuxDedup2 (the canonical structure). New AuxDedupMixed fixture covers a
perm mixing a canonical slot and PERM_OUT_OF_SCC for the same owner.
Documented in docs/ix_canonicity.md 6.5.
Call-site surgery guard is now durable across serialization: aux-regen
detection accepts `Named.original.is_some()` in addition to the
in-memory `aux_name_to_addr`, so deserialized-state roundtrip recompiles
no longer misapply surgery. Shift-aware `instantiate_rev` replaces
unshifted substitution in the type-walking helpers (fixes fvar leaks in
`.brecOn.go` bodies).
Byte-exact aux roundtrip: `roundtrip_block` Phase A now preseeds the
ref/univ tables (`preseed_expr_tables`) like every production compile
path. The serialized constant embeds those tables in sorted order;
compiling without the preseed filled them in traversal order instead,
permuting every `Ref`/univ index — byte-different but semantically
identical constants (decode resolves through the embedded table). This
silently failed the Phase-A address comparison against
`Named.original.0` for 1529 of 1545 aux constants (including plain
stdlib like `Nat.casesOn`); a debug probe proved
compile(original) == compile(regen) in every case, i.e. the
regeneration itself was always faithful.
With the invariant holding corpus-wide, the Phase-A recompile-hash
mismatch is now a hard error with no aux exemption, and every roundtrip
arm records failures in `aux_gen_errors` (recovery keeps the
Lean-facing env populated for diagnosis but is never silent). Pass-2
scope hygiene: the below-def roundtrip loop filters by the
original-gated `aux_members` like its sibling loops, so evaporated
`below_N` keep their faithful Pass-1 decompile. IX_ROUNDTRIP_DEBUG now
dumps hashed component scalars/hashes and runs an original-form
recompile probe for any mismatch.
Test fixes: kernel-tutorial `bad_raw_consts` inductive fixtures carry
recomputation-honest flags so compile-side `validate_ind_flags` no
longer poisons the shared tutorial env (73/335 -> 335/335, with the
kernel rejecting each bad fixture as designed); validate-aux seeds
match module-private fixture names via `privateToUserName?` and enable
the Canonicity prefix; Phase 4b gains per-module markers so a fully
absent identity group fails loudly when its fixture module is loaded
(previously vacuous at 0 pass / 0 fail, now 109 pass).
Gates: kernel-check-env 201296/201296; rust-compile all phases with 0
aux_gen errors, 0 mismatches, and 0 Phase-A address divergences on the
full 213k env (live and deserialized); validate-aux 0 failures at
4393-constant scope; rust-serialize byte-exact; kernel-ixon-roundtrip
143694/0; kernel-tutorial 335/335; cargo test and lake test green.
* chore: fix clippy warnings and fmt drift
Behavior-neutral cleanups flagged by `cargo clippy --all-targets`:
map_or over map+unwrap_or and slice::contains in surgery.rs, an
enumerate loop for the motive-peeling walk in aux_motive_sigs, and
let-chain collapses for the inductive-flags fixup loops in decompile.rs
and kernel_egress.rs. Plus `cargo fmt` line-wrapping drift left over
from the previous commit.
* IxVM Aiur kernel: fix Lean.Syntax.rec (shard 53) aux-recursor gen
Three interlocking bugs in the Aiur block-flattening / recursor-type
builder caused `ix check --interp bytecode Lean.Syntax.rec` to fail with
`assert_eq mismatch: 0 != 1` on the declared-vs-canonical type equality:
- `build_flat_block` traversed originals once; nested-aux members
(`Array Syntax`, `List Syntax`) never had their own ctors scanned, so
`flat` had 2 motives when Lean's recursor declares 3. Replaced with a
queue-based fixed point mirroring `crates/kernel/src/inductive.rs:
build_flat_block:531-599`.
- `is_rec_field` classified any ctor field as recursive when its spine
head Const-idx matched a flat member's ind idx. For `Lean.Syntax.ident`,
the field `preresolved : List Preresolved` shares the base List const
idx with the block's `List Lean.Syntax` aux and got a spurious
`motive_2 preresolved` IH binder. Match key is now (head_idx,
spine-arg prefix ≡ member.spec_params) — direct members carry
`spec_params = []` and match on idx alone, auxes require the concrete
occurrence.
- `build_all_minors` was iterating `flat` and passing the shrinking
suffix into `build_minor_doms`, so field classification for later
members was blind to earlier members. Split into a wrapper +
`build_all_minors_walk` that pins the caller's full flat while the
iteration state shrinks.
Pin `Lean.Syntax.rec` in the ixvm test suite; rebump every FFT cost
shifted by the codegen refresh (`ix codegen`).
* IxVM: port Inductive flag-drop + evaporated-aux aliasing to Aiur kernel
Port of the two Rust kernel fixes on this branch:
- Ixon.Inductive drops recr/refl/nested (9 -> 6 fields); KConstantInfo.Induct
drops is_rec/is_reflexive/nested (10 -> 7). is_rec is computed on demand
(computed_is_rec_ind), nested detection is structural (member_has_nested /
ind_has_nested over detect_nested_in_orig), is_aux_inductive is rewritten
member-scoped without the declared nested count. Serialization packs one
bool; reveal-proof Indc masks renumber to 6 fields; all 88 primitive
addresses re-pinned.
- collectDependencies (Ix/Common.lean) now closes over a declaration's full
recursor family (sibling <ind>.rec + nested-aux rec_N, which cross-reference
in rule RHSs) plus each rule ctor's owning external recursor (List.rec).
Without these the per-name compile either failed (MissingConstant
AuxDedup1.C.rec from A.rec_1's block) or silently skipped the
evaporated-aux alias (target_ok probe misses List.rec), compiling M.rec_2
in original form, which the kernel rejects.
AuxDedup1/2/Mixed fixtures from Tests/Ix/Compile/Mutual.lean join
kernelCheckEntries; the four evaporated rec_N entries pin the identical
3_073_003 FFT cost (their claims are byte-exact List.rec:
lake exe ix check --interp bytecode _private...AuxDedupMixed.M.rec_2).
All stdlib pins re-measured via lake test -- --ignored ixvm (flag drop
shrinks serialized inductives, e.g. HEq 1_713_377 -> 1_696_277).
---------
Co-authored-by: Arthur Paulino <arthurleonardo.ap@gmail.com>1 parent 77e363b commit 547455e
66 files changed
Lines changed: 10790 additions & 8462 deletions
File tree
- Benchmarks/Compile
- Ix
- IxVM
- Kernel
- Tests
- Gen
- Ix
- Compile
- Kernel
- crates
- compile/src
- compile
- aux_gen
- ffi/src
- lean_ixon
- ixon/src
- ixvm-codegen/src
- kernel/src
- tutorial
- docs
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
24 | 31 | | |
25 | 32 | | |
26 | 33 | | |
| |||
110 | 117 | | |
111 | 118 | | |
112 | 119 | | |
113 | | - | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
114 | 141 | | |
115 | 142 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
20 | 27 | | |
21 | 28 | | |
22 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
101 | 100 | | |
102 | 101 | | |
103 | 102 | | |
| |||
240 | 239 | | |
241 | 240 | | |
242 | 241 | | |
243 | | - | |
| 242 | + | |
244 | 243 | | |
245 | | - | |
246 | | - | |
247 | | - | |
| 244 | + | |
| 245 | + | |
248 | 246 | | |
249 | | - | |
250 | | - | |
251 | 247 | | |
252 | 248 | | |
253 | 249 | | |
254 | 250 | | |
255 | | - | |
256 | 251 | | |
257 | 252 | | |
258 | 253 | | |
| |||
283 | 278 | | |
284 | 279 | | |
285 | 280 | | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
296 | 288 | | |
297 | 289 | | |
298 | 290 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
211 | | - | |
212 | | - | |
| 211 | + | |
213 | 212 | | |
214 | 213 | | |
215 | 214 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
328 | 328 | | |
329 | 329 | | |
330 | 330 | | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
331 | 365 | | |
332 | 366 | | |
333 | 367 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1112 | 1112 | | |
1113 | 1113 | | |
1114 | 1114 | | |
1115 | | - | |
1116 | | - | |
1117 | 1115 | | |
1118 | 1116 | | |
1119 | 1117 | | |
1120 | 1118 | | |
1121 | | - | |
1122 | 1119 | | |
1123 | 1120 | | |
1124 | 1121 | | |
| |||
1194 | 1191 | | |
1195 | 1192 | | |
1196 | 1193 | | |
1197 | | - | |
1198 | | - | |
1199 | 1194 | | |
1200 | 1195 | | |
1201 | 1196 | | |
1202 | 1197 | | |
1203 | | - | |
1204 | 1198 | | |
1205 | 1199 | | |
1206 | 1200 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
670 | 670 | | |
671 | 671 | | |
672 | 672 | | |
673 | | - | |
674 | | - | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
675 | 676 | | |
676 | 677 | | |
677 | 678 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
314 | 314 | | |
315 | 315 | | |
316 | 316 | | |
317 | | - | |
| 317 | + | |
318 | 318 | | |
319 | 319 | | |
320 | 320 | | |
321 | | - | |
| 321 | + | |
322 | 322 | | |
323 | 323 | | |
324 | 324 | | |
| |||
0 commit comments