Files
BFM-decomp/phase-ends/current/tasks/T2.md
T

41 lines
6.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# T2 — cast and lying gate instruments, reinterpret-macro set
Status: done | expert: expert-fable | ctx-at-completion: n/a | commit: see COMMIT | coder runs: c1 opus55 done (247422bb83), c2 opus55 done (313ee50403), c3 opus55 done (7845da8f03)
Done: `type_census --check-casts` gate (raw by form, macro sites vs restruct ledger, lying vs TSV), kept-cast macro set in include/common.h with five make-check proofs + one R22, `lever_census --strict --residue`, both selftests extended, caches invalidated, check-structs still 0.
Files:
- include/common.h:62-78 — CAST_ALIAS / CAST_SIGN / CAST_WIDTH / CAST_MISALIGNED / CAST_NONSTRUCT, each `(T, p, k)` → `(*(T *)((p) + (k)))`, one cause class each; LOBU..LOWU (:55-61, already present since P37 T3) kept as class REINTERP; M2C_FIELD unchanged (raw form M) (c1)
- tools/type_census.py — KEPT_MACROS registry + FORM_K :141-147; form-K sites (tu, fn, line, pos, name, cls, base/bclass/off) :374-394; registered `#define` lines in include/common.h dropped from counts :612-620; `check_casts_inputs()` (restruct.ledger_latest, config/lying_exceptions.tsv), `check_casts_verdict()`, `--check-casts`; selftest 32 → 50 checks (c3)
- tools/lever_census.py — `load_residue`, `strict_failures(sites, pt, gte_header, residue)` :1109-1148, `--residue PATH` :1219, main --strict prints `residue <n>, residue-unused <n>` + first 10 unused rows; selftest controls i-iv :1194-1209 (c2)
- config/lying_exceptions.tsv — header only: `callee def_file kind cause task` (ledgered = row matches callee + defined_in + kind)
- config/lever_residue.tsv — header only: `file func kind pass instrument cause` (match on file + func + kind; pass/instrument carried, R113)
- docs/gen3-standards.md — §2 rule 5 (every raw cast goes or names its cause; the set, the gate, the ledger reading) + definition-of-done clause (expert)
- decomp-architect/corpus/**, docs/struct-map.md, .run/P36/census/lever_census.*, .run/P37/census/* — regenerated by kit-corpus and the census runs
Interfaces (the exact shapes later tasks read):
- `type_census --check-casts` → `check-casts: raw P=<n> I=<n> X=<n> M=<n>; macros <name>=<n> …|none (unbacked <n>); lying=<n> (ledgered <n>)`; exit 1 on raw > 0, unbacked > 0, lying − ledgered > 0.
- Backed macro site: `restruct.ledger_latest[("S", tu, fn)]` row with verdict in {KEPT, S2, KEPT-ALL} and a `sites[]` entry `verdict == "KEPT(<class>)"` for the macro's class matching `off` and `base == "<bclass>:<base>"`; REINTERP macros match on `line`. restruct does not yet write macro respells or `KEPT(SIGN|MISALIGNED|NON-STRUCT|REINTERP)` hints (pass_hint :563-591 has SCHED-ALIAS, ALIGNMENT, WIDTH only).
- Classes: SCHED-ALIAS, SIGN, WIDTH (overlap loser), MISALIGNED, NON-STRUCT, REINTERP.
Decisions:
- Legacy LOBU/LOH/HIH/LOHU/HIHU/LOW/LOWU reinstated as the sixth class REINTERP (lvalue read at another width/sign), not retired; their byte proof is restruct's macro_probe (`--selftest --real` 82/82 at b5e18e5f83, T1).
- Registered macros' `#define` lines in include/common.h are definitions, not sites: M = 19,542 (T1's 19,543 included common.h:43 itself); P unchanged at 408,974.
- binding: a kept cast is spelled only by a registered macro of include/common.h and is honest only with its ledger row; `--check-casts` is the campaign's gate, `--check` stays the broader (non-gating on block frames) reading.
- binding: reading A for levers: `lever_census --check --strict --residue config/lever_residue.tsv` is the gate; residue rows are excluded from failures and counted in every total.
Deviations:
- Byte-proof respells were restored after BYTE-IDENTICAL (tree has 0 macro sites, unbacked 0) so the next task inherits no unledgered macro sites; proof lines in logs/T2.c1.md.
- `--strict` only runs inside `--check` (unchanged tool shape), so the gate spelling is `--check --strict --residue …`.
- Residue cannot name a per-TU asm macro definition (mdefs_all is local to run_census): while pt > 0 strict fails with one synthetic `asm-macro` entry; a later task exposes mdefs if residue must cover them.
- No restruct/delever apply was run, so no recalibration was needed; `restruct --selftest --real` is still red after these commits (T1 gotcha) — the next apply task recalibrates first.
- commit_task auto-staged the pre-modified phase-ends/current/discussions/INDEX.md into 247422bb83 (one router line).
Findings:
- Byte proofs (all BYTE-IDENTICAL, .run/logs/t2_proof_sc01.log, t2_proof_sc05.log): CAST_ALIAS src/ov_SC05_010/ov_SC05_010_jr_80180F84.c:3006 (func_801814AC `+0x34` store, cookbook §458); CAST_SIGN src/ov_SC01_000/ov_SC01_000_after.c:2682 (func_801523F4); CAST_WIDTH src/ov_SC01_000/ov_SC01_000_jr_801734BC.c:2582 (func_801749C8); CAST_MISALIGNED src/ov_SC01_000/ov_SC01_000_jr_8012ACE0.c:2624 (func_801345F8 `*(int *)(param_1 + 6)`); CAST_NONSTRUCT same file :795 (func_8012E364). R22 after the common.h edit: 218 passed 0 failed (.run/logs/t2_r22.log).
- Ledger .run/P37/restruct/ledger.jsonl: 173,459 rows, rung S = 0, `KEPT(` = 0 — the gate's macro half starts empty.
- Live gate on this tree: `check-casts: raw P=408974 I=60666 X=13800 M=19542; macros none (unbacked 0); lying=229 (ledgered 0)` rc 1; `lever_census --check --strict --residue`: pins 1868, asm 1411 (non-GTE), gte-levers 450, direct GTE 6717, per-TU asm macro defs 314, residue 0, residue-unused 0 — FAIL rc 1.
Gotchas:
- harness: a PreToolUse hook denies `sed`/`cat` on tools/*.py for the expert even when the tool is the task's deliverable; source facts go through retriever-code.
- harness: `tools/run.sh --wait --max 280` inside one Bash call plus the --bg launch exceeds the 285 s call budget when the census runs cold; launch and wait in separate calls.
- generalizable: a macro definition line that textually matches a site regex is counted as a site by a text census; a gate must exclude the registry's own `#define` lines by name, not by file.
- workflow: a tools/ edit → `make kit-corpus` → `make tools-health` before the task commit (corpus copies are tracked).
Research: none new (three retriever-code answers inline, no report files).
Next task needs: restruct must learn to (a) respell a KEPT site with its class macro and (b) write `KEPT(<class>)` with the four new hints (SIGN, MISALIGNED, NON-STRUCT, REINTERP) before any macro site can be backed; recalibrate (`delever_oracle --snapshot-baseline` + `--calibrate …`) before the first apply; denominators: P 408,974 I 60,666 X 13,800 M 19,542, lying 229/24 callees, levers 3,729.
Verified: `PY tools/type_census.py --selftest && PY tools/lever_census.py --selftest && PY tools/type_census.py --check-structs --quiet` → 50/50 checks OK; selftest OK — 24 sites; check-structs OK, conflicting_types=0, rc 0 (.run/logs/t2_verify_a.log); `PY tools/type_census.py --check-casts` → the live line above, rc 1 as the verify requires (.run/logs/t2_verify_b.log)
Full log: phase-ends/current/logs/T2.md