|
| 1 | +# P-022 step 6b (#259) — checkpoint 4: analysis wiring |
| 2 | + |
| 3 | +> Status: **checkpoint-4 deliverable** — the bridge feeds real `OwnIR` facts |
| 4 | +> through the ported analyses and maps their verdicts back to C# anchors, at |
| 5 | +> the checkpoint-4 comparison surface (identity, anchor, kind, tiering). |
| 6 | +> Checkpoint 5 (messages, evidence, rendered surfaces) is unblocked and |
| 7 | +> compares against the same goldens. Written from the tree at the commit that |
| 8 | +> landed it; the numbers below are the ones the suites assert. |
| 9 | +
|
| 10 | +## What landed |
| 11 | + |
| 12 | +- **`own_bridge::check_facts(&OwnIr) -> Result<Vec<Finding>, BridgeError>`** — |
| 13 | + `ownlang/ownir.py::check_facts` as spec/Bridge.md §5 writes it, in order: |
| 14 | + lower (the cp2 `lower_full`, now also returning the Python-shaped handle |
| 15 | + records with `column`, the OWN051 tuples and the solve-failure reason) → |
| 16 | + the Layer 2 document rebuilt as the core AST (`ast.rs`) → |
| 17 | + `own_analysis::check_module` (buffer policy, lifetime, resolver, ownership) |
| 18 | + → ERROR-only, the closed BR-V2 skip list, `subject` → handle or the |
| 19 | + reference's map-or-raise refusal (BR-V3) → anchors per BR-V5 (the record's |
| 20 | + line; OWN025 at the view site with `column: None`; DI004/DI005 at the |
| 21 | + finder-selected call/store site) → kind and tiering per BR-V4/V6 → DI |
| 22 | + (`services[]` through BR-P1's coercions into the five `own-analysis` |
| 23 | + finders, in the bridge's append order) → effects (`effects[]`, BR-P2 |
| 24 | + skip-not-coerce, `find_effect_storms`) → OWN050 → OWN051 → OWN052 → dedup |
| 25 | + (BR-V7) → the stable `(file, line, column or 0, code)` sort (BR-V8). |
| 26 | +- **Layer 2 → core AST** rather than a second lowering: the projection |
| 27 | + `ownlang/lowered.py` drops only the declaration lines `to_module` fixes at |
| 28 | + `0`, so the AST built from the 27/27 byte-exact document is the reference's |
| 29 | + node for node, and a lowering defect stays visible at the Layer 2 seam |
| 30 | + instead of hiding behind a verdict. |
| 31 | +- **The one core change: the verdict `subject`.** `own-analysis` emitted |
| 32 | + `(code, line)` only; the bridge maps through `subject` (`name#line`) and |
| 33 | + nothing else, so `Emit::push_at` now stamps the symbol's `origin` exactly |
| 34 | + where `analysis.py` passes `subject=sym.origin` (state problems, OWN001 via |
| 35 | + the RID's minting symbol, release, overspan, the return path, the buffer |
| 36 | + escape codes) and `lifetimes.py` stamps `source#line` on OWN014 — and |
| 37 | + nowhere else (the loan/permission codes stay subject-less, as in Python). |
| 38 | + Pinned through `check_module` in `own-analysis/tests/subject.rs`. |
| 39 | + Not stamped, deliberately: `resource_kind`, messages and evidence on the |
| 40 | + `.own` path are the core's own later contract (own-cli), not this |
| 41 | + checkpoint's, and nothing here asserts them. |
| 42 | +- **Layer 3 fixture family** (spec/Bridge.md §6): `ownlang/verdicts.py` |
| 43 | + (`VERDICTS_VERSION = 1`, every `Finding` member in declaration order, a |
| 44 | + refusal as `{"error": …}`), `tests/test_verdict_fixtures.py` (verify / |
| 45 | + `--write`, ledger == swept corpora + synthetic == goldens, orphan/stale/ |
| 46 | + missing red, determinism), `tests/fixtures/verdicts/manifest.json`, and the |
| 47 | + Rust replay `own-bridge/tests/verdicts.rs`. All cases go through the |
| 48 | + **tolerant door** (`check_facts` on the loaded document) on both sides. |
| 49 | +- DAG: `own-bridge` → `own-syntax`, `own-cfg`, `own-analysis`, |
| 50 | + `own-diagnostics` added to the allowed set; a named test now asserts no |
| 51 | + core crate depends on the bridge. |
| 52 | + |
| 53 | +## Census |
| 54 | + |
| 55 | +| | | |
| 56 | +|---|---| |
| 57 | +| goldens (Python's truth, complete) | **77** — 22 `ownir` + 27 `lowered` + 9 `summaries` swept, **19** synthetic | |
| 58 | +| replayed by Rust at the cp4 surface | **69** — 5 refusals, **127** findings | |
| 59 | +| declared exclusions (executable) | **8** — 2 protocol documents, 4 coordinate-boundary controls, 2 OD-1 door controls | |
| 60 | +| Python-only / Rust-only / Changed / Ordering-only / Unexplained, over the replayed set | **0 / 0 / 0 / 0 / 0** | |
| 61 | + |
| 62 | +The **compared members** at cp4: `file, line, column, code, component, event, |
| 63 | +handler, kind, advisory, severity, ignore_reason`. Not compared yet: |
| 64 | +`message`, `related`, `flow` — the goldens carry them, cp5 compares them |
| 65 | +without regenerating a golden. |
| 66 | + |
| 67 | +### The unmeasured set is named, not hidden |
| 68 | + |
| 69 | +Each exclusion is an entry in `rust_replay_excluded` with a reason and an |
| 70 | +expectation the replay executes (`rust_refusal: bridge` + an error substring, |
| 71 | +or `door`); the set is also pinned by name, and an exclusion that stops |
| 72 | +holding is a red build demanding promotion. |
| 73 | + |
| 74 | +1. **Obligation protocols (2).** `ownlang/obligations.py` has no |
| 75 | + `own-analysis` port. A document that declares a protocol is **refused** |
| 76 | + by `check_facts`, never given a verdict list with a family missing — |
| 77 | + `protocol_isloaded_clean` would otherwise have "matched" vacuously. |
| 78 | + #259's checkpoint list never names the protocol analysis; its final |
| 79 | + acceptance ("full test-family inventory from #258") does. Recorded as |
| 80 | + **its own checkpoint (P-022 row 4b)**, deliberately not folded into cp5: |
| 81 | + cp5 is messages, evidence and rendering, and a whole analysis family on |
| 82 | + top would make the last checkpoint a bag. 4b does not block cp5; #259's |
| 83 | + final acceptance needs it. |
| 84 | +2. **The `u32` coordinate domain (4).** The core's line is a `u32`; the |
| 85 | + strict door admits every signed 64-bit coordinate (`spec/OwnIR.md` §4.2) |
| 86 | + and the tolerant door anything `_as_int` passes. A coordinate outside |
| 87 | + `0..=u32::MAX` on a lowered node, a DI registration line or an effect line |
| 88 | + is **refused, never clamped** (`ast::core_line`); a site or binding line |
| 89 | + whose only reader guards on `>= 1` folds a negative value to `0`, which |
| 90 | + is exact on every path (`verdict_di_duplicate_sites_last_wins` pins it). |
| 91 | + The reference analyzes these documents (OWN001 at `B.cs:-1`, DI001 at |
| 92 | + `reg.cs:-5`, …). This is the cp1 pattern again: a divergence family |
| 93 | + outside the measured set, recorded so a decision can be taken — a |
| 94 | + Python-first bound in §4.2, or a wider core line type — rather than |
| 95 | + "closed by widening Rust" or reported as parity. The owner's stated |
| 96 | + direction on review: **Python-first tightening** — define the valid |
| 97 | + coordinate domain normatively (a negative source line is meaningless), |
| 98 | + teach the reference to reject it, then remove the exclusion; as its own |
| 99 | + contract change with parity evidence, never by declaring the reference |
| 100 | + wrong because the port is `u32`. |
| 101 | +3. **OD-1, measured (2).** The Rust tolerant entry is the typed `OwnIr` |
| 102 | + constructor, so BR-D2's skip-not-coerce (`deps: "a"`) and the finders' |
| 103 | + unknown-lifetime tolerance are unreachable through it: the reference |
| 104 | + reports the sibling finding, the constructor refuses the document. The |
| 105 | + bridge-side port of both rules exists and is pinned at the raw-document |
| 106 | + level (`verdict::tests`), because that is the only level the production |
| 107 | + surface can reach them from today. |
| 108 | + |
| 109 | +One **comparison** boundary on refusals: the map-or-raise text interpolates |
| 110 | +the core diagnostic's `message`, and this core's messages are still titles |
| 111 | +(`undefined name` vs the reference's `undefined name 'loc_0'`), so the three |
| 112 | +`hoist_neg_*` refusals are compared up to their `message=` member — on both |
| 113 | +sides, by the same function. The lowering-time refusals are byte-exact. |
| 114 | + |
| 115 | +### The `subject` tail |
| 116 | + |
| 117 | +The core change adds data to a diagnostic; whether it changes any |
| 118 | +**serialized** surface was checked rather than assumed. On the Rust side |
| 119 | +`render.rs` states it does not consult `subject`, `sarif.rs` never reads it, |
| 120 | +and its only carrier is `LocatedDiagnostic`/`DiagIdentity` — an in-memory |
| 121 | +comparison key, not an output. On the reference, `subject` is read by the |
| 122 | +bridge and by `report.py` (the `.ownreport.json` buffer report, struck from |
| 123 | +the port in #256). No Rust output surface serializes it, so "behavior |
| 124 | +changes: none" holds; cp5 re-checks this when the bridge's render/SARIF |
| 125 | +paths land. |
| 126 | + |
| 127 | +### The dedup key, minus `message` |
| 128 | + |
| 129 | +BR-V7's key is `(file, line, column, code, component, event, handler, |
| 130 | +message, kind, advisory, severity, ignore_reason)`; cp4 carries every member |
| 131 | +but `message`. On the reference's own outputs that is exact: every message is |
| 132 | +a function of the handle record and the code (the flow-local wordings key on |
| 133 | +`code`/`pool`/`ever_released`, the token wordings on the record, and the |
| 134 | +same-handle same-code duplicates BR-V7 exists for are byte-identical), so two |
| 135 | +findings equal on the carried members are equal on the message. The corpus |
| 136 | +measures it (the two-exit and nested-throw leaks fold to one finding on both |
| 137 | +sides); cp5 adds the member. |
| 138 | + |
| 139 | +## Mutation campaign |
| 140 | + |
| 141 | +Per the P-022 discipline (rule 2: a test is evidence only once its mutation |
| 142 | +fails through the production surface; rule 3: no fail-fast — every catching |
| 143 | +layer is recorded). Each mutation is applied to a copy of the file and |
| 144 | +restored from that copy, never by `git checkout` (the lesson from cp1's |
| 145 | +third round); `M00` is the harness-honesty control (no mutation must report |
| 146 | +zero failures); a compile error is reported as such, never as "caught". |
| 147 | + |
| 148 | +**Round 1 (24 mutations) surfaced three real gaps and one bad mutation**, |
| 149 | +all fixed before round 2: |
| 150 | + |
| 151 | +- M01 survived — nothing in the corpus produced an OWN033/034/035/041, so |
| 152 | + the *closed* BR-V2 list had no control per member. |
| 153 | + → `verdict_skip_list_artifacts` (partial return, bare return beside a |
| 154 | + value return, a borrow handed to a consume position, an arity mismatch; |
| 155 | + OWN040 is unreachable by construction). |
| 156 | +- M04/M06 survived — `column` and `event` were redundant in the dedup key on |
| 157 | + that corpus (`handler` and the distinct names kept the pairs apart). |
| 158 | + → a same-name rebind on one line differing only in column; one record |
| 159 | + pair per key member (event, handler, component, kind, severity, |
| 160 | + ignore_reason) differing in exactly that member. |
| 161 | +- M10 was not a mutation: `owned_here.is_empty() && …` kept the gate for the |
| 162 | + empty case it was meant to drop. Rewritten as `false && …`. |
| 163 | +- The harness attributed catchers to the wrong target: cargo's `Running` |
| 164 | + lines are on stderr, test results on stdout, and capturing them |
| 165 | + separately loses the interleaving. Fixed by merging the streams. |
| 166 | + |
| 167 | +**Round 2: 30 mutations, 29 caught, 1 declared survivor — closed on review |
| 168 | +(round 3): 30/30.** M19 survived because BR-V1's ERROR-only rule guards a |
| 169 | +state the corpus cannot produce (no facts producer reaches the one core |
| 170 | +pass that grades below ERROR). Leaving a normative rule permanently |
| 171 | +unprovable was the wrong resting place: the filter is now a pure predicate |
| 172 | +(`is_mapped`, BR-V1 + BR-V2 in one place) and a synthetic WARNING is driven |
| 173 | +through `map_core` itself — same diagnostic, same handle, ERROR → one |
| 174 | +finding, WARNING → none — so the mutation is caught at the unit level, with |
| 175 | +the corpus still unable to reach it (recorded as such below). |
| 176 | + |
| 177 | +| id | mutation | caught by | |
| 178 | +|---|---|---| |
| 179 | +| M01 | BR-V2 skip list: OWN033 no longer skipped | verdict replay | |
| 180 | +| M02 | BR-V5 flow-local anchored at the core's line, not the acquire record | verdict replay | |
| 181 | +| M03 | BR-V5 OWN025 anchored at the acquire, not the view site | verdict replay | |
| 182 | +| M04 | BR-V7 dedup key drops `column` | verdict replay | |
| 183 | +| M05 | BR-V8 sort key drops `column` | verdict replay | |
| 184 | +| M06 | BR-V7 dedup key drops `event` | verdict replay | |
| 185 | +| M07 | DI004/DI005 duplicate site: last-wins → first-wins (`own-analysis`) | `fact_parity::di_fact_parity` **and** verdict replay | |
| 186 | +| M08 | BR-V6 DI001 graded `warning` | verdict replay | |
| 187 | +| M09 | BR-D2 effect `deps` coerced instead of skipped | `verdict::tests::malformed_effect_entries_are_skipped_not_coerced` (raw-document level — the only reachable one, see OD-1) | |
| 188 | +| M10 | BR-L8 OWN051 owned-local gate dropped | verdict replay | |
| 189 | +| M11 | BR-M1 OWN052 never minted | verdict replay | |
| 190 | +| M12 | BR-V3 OWN001 emitted without a subject (`own-analysis`) | `subject.rs` ×3 **and** verdict replay | |
| 191 | +| M13 | BR-V3 OWN014 emitted without a subject (`own-analysis`) | `subject.rs` **and** verdict replay | |
| 192 | +| M14 | protocol documents no longer refused | verdict replay (the executable exclusion ledger) | |
| 193 | +| M15 | `core_line` clamps instead of refusing | verdict replay (the executable exclusion ledger) | |
| 194 | +| M16 | BR-V6 source tiering inverted | verdict replay | |
| 195 | +| M17 | BR-V6 an empty `ignore_reason` suppresses | verdict replay | |
| 196 | +| M18 | BR-V7 dedup removed | verdict replay | |
| 197 | +| M19 | BR-V1 ERROR-only half of the mapping predicate removed | `verdict::tests::only_error_severity_core_verdicts_are_mapped` (synthetic WARNING through `map_core`; the corpus cannot reach it — no facts producer feeds a sub-error core verdict today) | |
| 198 | +| M20 | `_as_col` accepts `0` | verdict replay | |
| 199 | +| M21 | a negative DI site line folds to `1`, not `0` | verdict replay | |
| 200 | +| M22 | OWN050 never minted | verdict replay | |
| 201 | +| M23 | BR-V3 handle read from the wrong subject separator | verdict replay | |
| 202 | +| M24 | OWN051 anchored at `0`, not the call line | verdict replay | |
| 203 | +| M25 | BR-V7 dedup key drops `handler` | verdict replay | |
| 204 | +| M26 | BR-V7 dedup key drops `component` | verdict replay | |
| 205 | +| M27 | BR-V7 dedup key drops `kind` | verdict replay | |
| 206 | +| M28 | BR-V7 dedup key drops `severity` | verdict replay | |
| 207 | +| M29 | BR-V7 dedup key drops `ignore_reason` | verdict replay | |
| 208 | +| M30 | DI findings anchored at `0`, not the finder's anchor | `verdict::tests::di_coercions_match_the_reference` **and** verdict replay | |
| 209 | + |
| 210 | +Two catching layers exist where the analysis owns the rule (M07, M12, M13, |
| 211 | +M30) and one where only the bridge does — the same shape as cp1's ledger: |
| 212 | +the bridge replay is the outer catcher, and a rule with a single catcher is a |
| 213 | +rule with a single control. Two rules (M09, M19) are catchable only at the |
| 214 | +unit level because the production entry cannot reach them; both say so in |
| 215 | +the test. |
| 216 | + |
| 217 | +## What checkpoint 5 needs |
| 218 | + |
| 219 | +The comparison matrix over the same frozen goldens — cp5 turns every |
| 220 | +"deferred" row into "prove" and keeps every "proven" row as a regression |
| 221 | +guard; **no golden is regenerated beside the cp5 implementation**, because |
| 222 | +"implementation disagreed with the golden → regenerate → agreement" is the |
| 223 | +one move this family exists to make impossible: |
| 224 | + |
| 225 | +| `Finding` surface | cp4 | cp5 | |
| 226 | +|---|---|---| |
| 227 | +| identity (`file`, `code`, `component`, `event`, `handler`) | proven | regression | |
| 228 | +| anchor (`line`, `column`) | proven | regression | |
| 229 | +| `kind` | proven | regression | |
| 230 | +| tiering (`advisory`, `severity`, `ignore_reason`) | proven | regression | |
| 231 | +| ordering and dedup | proven | regression | |
| 232 | +| `message` | deferred (carried) | prove | |
| 233 | +| `related` | deferred (carried) | prove | |
| 234 | +| `flow` (evidence slices) | deferred (carried) | prove | |
| 235 | +| rendered diagnostic (`render*`) | deferred | prove | |
| 236 | +| SARIF projection (`build_sarif`, bridge path) | deferred | prove | |
| 237 | + |
| 238 | +And the wording discipline that comes with it: what cp4 proved is |
| 239 | +"127 verdicts × the cp4 comparison projection", never "verdict parity |
| 240 | +complete" — the shortcut a roadmap status is made of. |
| 241 | + |
| 242 | +Concretely: |
| 243 | + |
| 244 | +- the message matrix (BR-V4) on the bridge findings, and the core diagnostic |
| 245 | + messages behind the map-or-raise text; |
| 246 | +- the `related`/`flow` evidence slices (DI paths via the registration map, |
| 247 | + the DI004/DI005 registration `related`, the effect re-run → mint slice, |
| 248 | + the flow-local origin → violation slice, the capture escape slice); |
| 249 | +- `render`/`render_github`/`render_msbuild`/`build_sarif` on the bridge path |
| 250 | + (BR-V9), reusing `own_diagnostics::sarif`; |
| 251 | +- tightening `verdicts.rs` to full equality on the existing goldens; |
| 252 | +- the two decisions this checkpoint owes: the protocol analysis, and the |
| 253 | + coordinate domain. |
0 commit comments