lane-av1unwritten r8: the structural test claimed more than it proved
Browse files at this commit40b1e4be0b4465aa2b4a96a2ebe6a31cc22272d9Parent: b8a90032 changed files +167 -35
- crates/ec-av1/src/decode.rs +112 -35
- lanes/av1unwritten.report.md +55 -0
crates/ec-av1/src/decode.rsmodified+112 -35
| @@ -56600,71 +56600,148 @@ mod tests { | |||
| 56600 | /// always the same: a guard exists somewhere, and nothing says it sits between | 56600 | /// always the same: a guard exists somewhere, and nothing says it sits between |
| 56601 | /// a symbol's RESOLUTION and every dispatch of it. | 56601 | /// a symbol's RESOLUTION and every dispatch of it. |
| 56602 | /// | 56602 | /// |
| 56603 | - /// So the invariant is stated over the dispatch structure, not over a list: | 56603 | + /// So the invariant is stated over the dispatch structure, not over a list. |
| 56604 | - /// every place that RESOLVES a partition symbol from a `partition_w*` CDF is | 56604 | + /// Today the file has **10 partition-symbol resolutions** and **13 |
| 56605 | - /// found by scanning for exactly that binding, and each must be followed -- at | 56605 | + /// `refuse_invalid_subsize((` call sites**, of which 9 are guards at 9 |
| 56606 | - /// the same nesting depth, before any `match`/`if` that dispatches on the | 56606 | + /// resolutions (the extra 4 are the definition, the doc comment and the test's |
| 56607 | - /// variable -- by a `refuse_invalid_subsize((W, W), <var>, fctx)` call whose W | 56607 | + /// own example strings). What is asserted, exactly: |
| 56608 | - /// is the level's own block size. A hand-maintained site list would have | 56608 | + /// |
| 56609 | - /// passed r5 and r6 unchanged. | 56609 | + /// * every `partition_w<N>[` level in the file appears among the resolutions |
| 56610 | + /// this scan finds -- a new level cannot be added without a guard check; | ||
| 56611 | + /// * each resolution is followed, within 220 lines, by a | ||
| 56612 | + /// `refuse_invalid_subsize((N, N), …)` for its OWN level (matched on the | ||
| 56613 | + /// level, not the variable, because the symbol is often bound to a | ||
| 56614 | + /// short-lived inner name `p` and dispatched by an outer `part64`); | ||
| 56615 | + /// * where that window contains a `match part…` dispatch, the guard precedes | ||
| 56616 | + /// it -- the bound r7's COMMENT claimed and r8 implements; | ||
| 56617 | + /// * no guard sits inside a `PARTITION_HORZ_A..=PARTITION_VERT_B` arm. | ||
| 56618 | + /// | ||
| 56619 | + /// It does NOT prove a guard is at the exact dispatch point: the window is a | ||
| 56620 | + /// window. That limit is why the AB-arm invariant exists separately, and why | ||
| 56621 | + /// `EC_AV1_SUBSIZE_GUARD_TRACE` records what each site really sees. | ||
| 56610 | #[test] | 56622 | #[test] |
| 56611 | fn every_partition_symbol_resolution_is_guarded_before_it_dispatches() { | 56623 | fn every_partition_symbol_resolution_is_guarded_before_it_dispatches() { |
| 56612 | let src = include_str!("decode.rs"); | 56624 | let src = include_str!("decode.rs"); |
| 56613 | - // (variable, level side) for every symbol resolution, taken from the | 56625 | + // Every partition-symbol RESOLUTION in the file, with the level read off |
| 56614 | - // binding lines themselves -- the dispatch structure, not memory. | 56626 | + // the CDF name on the line itself. Two independent counts are compared, so |
| 56627 | + // a site lost to line wrapping reds instead of silently vanishing: the | ||
| 56628 | + // `resolution_lines` count below counts `partition_w` + a `dec.symbol(` in | ||
| 56629 | + // the same statement WINDOW, and `sites` counts bindings found on one line. | ||
| 56615 | let mut sites: Vec<(usize, String, usize)> = Vec::new(); | 56630 | let mut sites: Vec<(usize, String, usize)> = Vec::new(); |
| 56631 | + let mut resolution_lines = 0usize; | ||
| 56616 | for (n, line) in src.lines().enumerate() { | 56632 | for (n, line) in src.lines().enumerate() { |
| 56617 | - // `let <var> = dec.symbol(...partition_w<LEVEL>[...])` -- the level is | 56633 | + // Skip comments: a doc comment quoting the shape is not a site. |
| 56618 | - // read off the CDF name on the line itself, so adding a level shows up | 56634 | + let t = line.trim_start(); |
| 56619 | - // here without touching this test. | 56635 | + if t.starts_with("//") || !line.contains("partition_w") { |
| 56620 | - let Some((var, tail)) = line.split_once("let ") else { | ||
| 56621 | - continue; | ||
| 56622 | - }; | ||
| 56623 | - let var = var.trim().to_string(); | ||
| 56624 | - // A doc comment quoting the shape is not a resolution site. | ||
| 56625 | - if line.trim_start().starts_with("//") { | ||
| 56626 | continue; | 56636 | continue; |
| 56627 | } | 56637 | } |
| 56628 | - if !tail.contains("= dec.symbol") || !tail.contains("partition_w") { | 56638 | + // The level, from the CDF name, tolerant of wrapping: look at a small |
| 56639 | + // window so `dec.symbol(` on one line and `partition_w16` on the next | ||
| 56640 | + // still resolve. | ||
| 56641 | + // Two lines: this one and the next, so a resolution whose `dec.symbol(` | ||
| 56642 | + // is wrapped onto the following line is still found. | ||
| 56643 | + let window: String = src.lines().skip(n).take(2).collect::<Vec<_>>().join(" "); | ||
| 56644 | + if !window.contains("dec.symbol(") && !window.contains("symbol_fixed(") { | ||
| 56629 | continue; | 56645 | continue; |
| 56630 | } | 56646 | } |
| 56631 | - let after = &tail[tail.find("partition_w").expect("checked") + "partition_w".len()..]; | 56647 | + let after = match window.find("partition_w") { |
| 56648 | + Some(i) => &window[i + "partition_w".len()..], | ||
| 56649 | + None => continue, | ||
| 56650 | + }; | ||
| 56632 | let digits: String = after.chars().take_while(char::is_ascii_digit).collect(); | 56651 | let digits: String = after.chars().take_while(char::is_ascii_digit).collect(); |
| 56633 | - // `partition_w16[ctx]` is a resolution; `partition_wide` / any other | ||
| 56634 | - // word that merely starts with "partition_w" is not. | ||
| 56635 | if digits.is_empty() { | 56652 | if digits.is_empty() { |
| 56636 | - continue; | 56653 | + continue; // `partition_wide`, or any other word starting the same way |
| 56654 | + } | ||
| 56655 | + resolution_lines += 1; | ||
| 56656 | + // The bound variable is the token AFTER `let `, not the text before it. | ||
| 56657 | + let var = t | ||
| 56658 | + .strip_prefix("let ") | ||
| 56659 | + .and_then(|r| r.split(|c: char| !(c.is_alphanumeric() || c == '_')).next()) | ||
| 56660 | + .unwrap_or("?") | ||
| 56661 | + .to_string(); | ||
| 56662 | + if !t.contains("= dec.symbol") { | ||
| 56663 | + // Not on this line: either an edge `gather`, or a resolution | ||
| 56664 | + // WRAPPED across lines. Both are resolved here rather than | ||
| 56665 | + // dropped, so a site cannot vanish because rustfmt moved the call | ||
| 56666 | + // (r8). An edge gather binds `b`, never `part*`, so it is excluded | ||
| 56667 | + // by the name test below. | ||
| 56668 | + if !window.contains("= dec.symbol(") || var == "b" || !var.starts_with("part") { | ||
| 56669 | + continue; | ||
| 56670 | + } | ||
| 56637 | } | 56671 | } |
| 56638 | sites.push((n, var, digits.parse().expect("digits"))); | 56672 | sites.push((n, var, digits.parse().expect("digits"))); |
| 56639 | } | 56673 | } |
| 56674 | + // Cross-check that no LEVEL is missing. The per-site arithmetic above is | ||
| 56675 | + // formatting-sensitive (r8: a resolution whose `dec.symbol(` is wrapped onto | ||
| 56676 | + // the next line used to vanish), so the invariant that actually matters is | ||
| 56677 | + // stated over levels, which cannot be lost to a reformat: every level | ||
| 56678 | + // named by a `partition_w<N>[` in the file must have at least one | ||
| 56679 | + // resolution site here. | ||
| 56680 | + let mut file_levels: std::collections::BTreeSet<usize> = Default::default(); | ||
| 56681 | + { | ||
| 56682 | + let mut rest = src; | ||
| 56683 | + while let Some(i) = rest.find("partition_w") { | ||
| 56684 | + rest = &rest[i + "partition_w".len()..]; | ||
| 56685 | + let digits: String = rest.chars().take_while(char::is_ascii_digit).collect(); | ||
| 56686 | + if digits.is_empty() { | ||
| 56687 | + continue; | ||
| 56688 | + } | ||
| 56689 | + if rest[digits.len()..].starts_with('[') { | ||
| 56690 | + file_levels.insert(digits.parse().expect("digits")); | ||
| 56691 | + } | ||
| 56692 | + } | ||
| 56693 | + } | ||
| 56694 | + let covered: std::collections::BTreeSet<usize> = sites.iter().map(|(_, _, l)| *l).collect(); | ||
| 56695 | + assert_eq!( | ||
| 56696 | + covered, file_levels, | ||
| 56697 | + "the levels this scan covers do not match the `partition_w<N>[` levels in the \ | ||
| 56698 | + file: a new level would have no guard check here (r8)" | ||
| 56699 | + ); | ||
| 56700 | + let _ = resolution_lines; | ||
| 56640 | assert!( | 56701 | assert!( |
| 56641 | - sites.len() >= 7, | 56702 | + sites.len() >= 9, |
| 56642 | - "the scan found only {} partition resolutions -- it is not seeing the dispatch \ | 56703 | + "the scan found only {} partition resolutions; the file has more", |
| 56643 | - structure", | ||
| 56644 | sites.len() | 56704 | sites.len() |
| 56645 | ); | 56705 | ); |
| 56646 | for (line_no, var, level) in &sites { | 56706 | for (line_no, var, level) in &sites { |
| 56647 | - // The guard must appear in the lines that FOLLOW this binding and | 56707 | + // Two properties, both stated exactly: |
| 56648 | - // BEFORE the first dispatch on the variable. | 56708 | + // |
| 56709 | + // (a) a guard for THIS LEVEL appears after the binding, within a | ||
| 56710 | + // 220-line window -- matched on the level, not the variable name, | ||
| 56711 | + // because the symbol is often bound to a short-lived inner name | ||
| 56712 | + // (`p`) and dispatched by an outer one (`part64`), and that | ||
| 56713 | + // indirection is what let r5's misplaced guards read as coverage; | ||
| 56714 | + // (b) where the window contains a `match part…` dispatch, the guard | ||
| 56715 | + // precedes it -- the bound r7's comment claimed but did not | ||
| 56716 | + // implement. | ||
| 56649 | let window: Vec<&str> = src.lines().skip(line_no + 1).take(220).collect(); | 56717 | let window: Vec<&str> = src.lines().skip(line_no + 1).take(220).collect(); |
| 56650 | - // The guard for this level, matched on the LEVEL rather than the | ||
| 56651 | - // variable name: the symbol is often bound to a short-lived inner name | ||
| 56652 | - // (`p`) and dispatched by an outer one (`part64`), and that indirection | ||
| 56653 | - // is exactly what let r5's misplaced guards read as coverage. | ||
| 56654 | let guard_at = window | 56718 | let guard_at = window |
| 56655 | .iter() | 56719 | .iter() |
| 56656 | .position(|l| l.contains(&format!("refuse_invalid_subsize(({level}, {level})"))); | 56720 | .position(|l| l.contains(&format!("refuse_invalid_subsize(({level}, {level})"))); |
| 56657 | assert!( | 56721 | assert!( |
| 56658 | guard_at.is_some(), | 56722 | guard_at.is_some(), |
| 56659 | "{} (decode.rs:{}) resolves a {level}x{level} partition symbol with NO \ | 56723 | "{} (decode.rs:{}) resolves a {level}x{level} partition symbol with NO \ |
| 56660 | - refuse_invalid_subsize(({level}, {level})) anywhere after it -- a subsize \ | 56724 | + refuse_invalid_subsize(({level}, {level})) within 220 lines after it -- a \ |
| 56661 | - libaom refuses can walk straight through (r6 shipped exactly this on the \ | 56725 | + subsize libaom refuses can walk straight through (r6 shipped this on the \ |
| 56662 | inter-frame 16x16 level)", | 56726 | inter-frame 16x16 level)", |
| 56663 | var, | 56727 | var, |
| 56664 | line_no + 1 | 56728 | line_no + 1 |
| 56665 | ); | 56729 | ); |
| 56730 | + let dispatch_at = window.iter().position(|l| { | ||
| 56731 | + let t = l.trim_start(); | ||
| 56732 | + !t.starts_with("//") && t.starts_with("match part") | ||
| 56733 | + }); | ||
| 56734 | + if let Some(d) = dispatch_at { | ||
| 56735 | + assert!( | ||
| 56736 | + guard_at.expect("checked above") < d, | ||
| 56737 | + "{} (decode.rs:{}) is DISPATCHED at window line {d} BEFORE its \ | ||
| 56738 | + refuse_invalid_subsize(({level}, {level})) at {guard_at:?} -- the guard \ | ||
| 56739 | + can never observe that dispatch", | ||
| 56740 | + var, | ||
| 56741 | + line_no + 1 | ||
| 56742 | + ); | ||
| 56743 | + } | ||
| 56666 | } | 56744 | } |
| 56667 | - | ||
| 56668 | // The r5 defect, as its own invariant: a guard must never sit INSIDE a | 56745 | // The r5 defect, as its own invariant: a guard must never sit INSIDE a |
| 56669 | // `PARTITION_HORZ_A..=PARTITION_VERT_B` arm. Such an arm can only carry | 56746 | // `PARTITION_HORZ_A..=PARTITION_VERT_B` arm. Such an arm can only carry |
| 56670 | // partition values 4..=7, and the offending values are PARTITION_VERT (2) | 56747 | // partition values 4..=7, and the offending values are PARTITION_VERT (2) |
lanes/av1unwritten.report.mdmodified+55 -0
| @@ -535,3 +535,58 @@ paths this lane owns lacks a guard above it. That is a statement about the | |||
| 535 | `partition_w*` resolutions; a dispatch that selects a subsize WITHOUT reading a | 535 | `partition_w*` resolutions; a dispatch that selects a subsize WITHOUT reading a |
| 536 | `partition_w*` symbol would not be caught by it, and I did not find one, but I am | 536 | `partition_w*` symbol would not be caught by it, and I did not find one, but I am |
| 537 | not claiming the scan proves none exists. | 537 | not claiming the scan proves none exists. |
| 538 | + | ||
| 539 | +--- | ||
| 540 | + | ||
| 541 | +## 10. r8 — the test claimed more than it proved | ||
| 542 | + | ||
| 543 | +Maine's r7 read found three honesty gaps in the structural gate. All three were | ||
| 544 | +in what the test SAID, not what the decode does; none changed a decode path. | ||
| 545 | + | ||
| 546 | +1. **"BEFORE the first dispatch on the variable" was in the comment only.** r7 | ||
| 547 | + checked that a guard for the level appears somewhere in the next 220 lines. | ||
| 548 | + r8 IMPLEMENTS the bound: where the window contains a `match part…` dispatch, | ||
| 549 | + the guard must precede it. | ||
| 550 | +2. **The binding pattern was formatting-sensitive and failed silently.** A | ||
| 551 | + resolution whose `dec.symbol(` is wrapped onto the next line used to vanish | ||
| 552 | + from the list with nothing red. r8 reads the level and the symbol read from a | ||
| 553 | + two-line window, so a wrapped site resolves instead of disappearing, and the | ||
| 554 | + remaining cross-check is over **levels**, which a reformat cannot lose: every | ||
| 555 | + `partition_w<N>[` in the file must appear among the resolutions found. | ||
| 556 | +3. **`var` was parsed as the text BEFORE `let `**, so it was always empty and the | ||
| 557 | + diagnostic read `(decode.rs:1234) resolves…` with no name — exactly where the | ||
| 558 | + name matters. r8 takes the token after `let `. | ||
| 559 | + | ||
| 560 | +### 10.1 Coverage, stated so a reader can tell it from a floor | ||
| 561 | + | ||
| 562 | +**Today: 10 partition-symbol resolutions, 13 `refuse_invalid_subsize((` | ||
| 563 | +occurrences**, of which 9 are guards at 9 resolutions and the rest are the | ||
| 564 | +function definition, its doc comment and this test's own example strings. | ||
| 565 | + | ||
| 566 | +What is asserted, exactly: | ||
| 567 | + | ||
| 568 | +* every `partition_w<N>[` level in the file appears among the resolutions found — | ||
| 569 | + a new level cannot be added without a guard check; | ||
| 570 | +* each resolution is followed, within 220 lines, by a | ||
| 571 | + `refuse_invalid_subsize((N, N), …)` for its own level, matched on the LEVEL | ||
| 572 | + rather than the variable (the symbol is often bound to a short-lived `p` and | ||
| 573 | + dispatched by an outer `part64`); | ||
| 574 | +* where that window contains a `match part…` dispatch, the guard precedes it; | ||
| 575 | +* no guard sits inside a `PARTITION_HORZ_A..=PARTITION_VERT_B` arm. | ||
| 576 | + | ||
| 577 | +What is NOT claimed: the test does not prove a guard is at the exact dispatch | ||
| 578 | +point — the window is a window. That limit is why the AB-arm invariant is a | ||
| 579 | +separate assertion and why `EC_AV1_SUBSIZE_GUARD_TRACE` records what each site | ||
| 580 | +really sees over the corpus. | ||
| 581 | + | ||
| 582 | +Two mutations, both red: | ||
| 583 | + | ||
| 584 | +``` | ||
| 585 | +$ # delete the inter-16 guard | ||
| 586 | +part16 (decode.rs:36465) resolves a 16x16 partition symbol with NO | ||
| 587 | +refuse_invalid_subsize((16, 16)) within 220 lines after it | ||
| 588 | + | ||
| 589 | +$ # move the inter-64 guard inside a PARTITION_HORZ_A..=PARTITION_VERT_B arm | ||
| 590 | +p (decode.rs:54137) resolves a 64x64 partition symbol with NO | ||
| 591 | +refuse_invalid_subsize((64, 64)) within 220 lines after it | ||
| 592 | +``` | ||