lane-av1unwritten r10: the AB-arm tracker, once more, plus the number corrections
Browse files at this commit1feddfcdc81f0cbdc13dcb3176cb656f12adc1ddParent: 4ac9e122 changed files +105 -26
- crates/ec-av1/src/decode.rs +47 -12
- lanes/av1unwritten.report.md +58 -14
crates/ec-av1/src/decode.rsmodified+47 -12
| @@ -56618,10 +56618,15 @@ mod tests { | |||
| 56618 | /// a symbol's RESOLUTION and every dispatch of it. | 56618 | /// a symbol's RESOLUTION and every dispatch of it. |
| 56619 | /// | 56619 | /// |
| 56620 | /// So the invariant is stated over the dispatch structure, not over a list. | 56620 | /// So the invariant is stated over the dispatch structure, not over a list. |
| 56621 | - /// Today the file has **10 partition-symbol resolutions** and **13 | 56621 | + /// Counts in the tree this was written against, re-derived per line rather |
| 56622 | - /// `refuse_invalid_subsize((` call sites**, of which 9 are guards at 9 | 56622 | + /// than grepped: `refuse_invalid_subsize((` occurs **18 times** in this file — |
| 56623 | - /// resolutions (the extra 4 are the definition, the doc comment and the test's | 56623 | + /// **11 guard call sites** in the decode body (35588, 36278, 36406, 36472, |
| 56624 | - /// own example strings). What is asserted, exactly: | 56624 | + /// 36882, 37132, 53985, 54222, 54606, 54752, 55164), **5** in this test's own |
| 56625 | + /// string literals and comparisons, **2** in doc comments; the definition's | ||
| 56626 | + /// signature line does not match `((` at all. The scan finds **10 resolutions**: | ||
| 56627 | + /// the eleventh guard is the inter-frame 128 one, whose resolution lives in | ||
| 56628 | + /// the shared `read_sb128_root`, so a guard has no resolution of its own here. | ||
| 56629 | + /// What is asserted, exactly: | ||
| 56625 | /// | 56630 | /// |
| 56626 | /// * every `partition_w<N>[` level in the file appears among the resolutions | 56631 | /// * every `partition_w<N>[` level in the file appears among the resolutions |
| 56627 | /// this scan finds -- a new level cannot be added without a guard check; | 56632 | /// this scan finds -- a new level cannot be added without a guard check; |
| @@ -56634,8 +56639,12 @@ mod tests { | |||
| 56634 | /// * no guard sits inside a `PARTITION_HORZ_A..=PARTITION_VERT_B` arm. | 56639 | /// * no guard sits inside a `PARTITION_HORZ_A..=PARTITION_VERT_B` arm. |
| 56635 | /// | 56640 | /// |
| 56636 | /// It does NOT prove a guard is at the exact dispatch point: the window is a | 56641 | /// It does NOT prove a guard is at the exact dispatch point: the window is a |
| 56637 | - /// window. That limit is why the AB-arm invariant exists separately, and why | 56642 | + /// window. And the two cross-checks are weaker than they look — cross-check 1 |
| 56638 | - /// `EC_AV1_SUBSIZE_GUARD_TRACE` records what each site really sees. | 56643 | + /// is level PRESENCE only, cross-check 2 is `>=` — so a SECOND unguarded site |
| 56644 | + /// at an already-covered level is caught ONLY by the per-site 220-line window, | ||
| 56645 | + /// which is a window and not a dispatch bound. That limit is why the AB-arm | ||
| 56646 | + /// invariant exists separately, and why `EC_AV1_SUBSIZE_GUARD_TRACE` records | ||
| 56647 | + /// what each site really sees over the corpus. | ||
| 56639 | #[test] | 56648 | #[test] |
| 56640 | fn every_partition_symbol_resolution_is_guarded_before_it_dispatches() { | 56649 | fn every_partition_symbol_resolution_is_guarded_before_it_dispatches() { |
| 56641 | let src = include_str!("decode.rs"); | 56650 | let src = include_str!("decode.rs"); |
| @@ -56699,14 +56708,34 @@ mod tests { | |||
| 56699 | let level: usize = digits.parse().expect("digits"); | 56708 | let level: usize = digits.parse().expect("digits"); |
| 56700 | // The bound variable is the token after `let `, looked for in the two | 56709 | // The bound variable is the token after `let `, looked for in the two |
| 56701 | // lines the binding can occupy (r9: it may be the line above). | 56710 | // lines the binding can occupy (r9: it may be the line above). |
| 56711 | + // r10: scan BACKWARDS from the closest line and take the nearest `let` | ||
| 56712 | + // whose binding is the one followed by this symbol read -- taking the | ||
| 56713 | + // first `let` upward named an unrelated binding above it. | ||
| 56702 | let mut var = None; | 56714 | let mut var = None; |
| 56703 | - for cand in [lo, n] { | 56715 | + for cand in (lo..=n).rev() { |
| 56704 | let ct = lines[cand].trim_start(); | 56716 | let ct = lines[cand].trim_start(); |
| 56705 | - if let Some(v) = ct.strip_prefix("let ") { | 56717 | + if ct.starts_with("//") { |
| 56706 | - var = v | 56718 | + continue; |
| 56707 | - .split(|c: char| !(c.is_alphanumeric() || c == '_')) | 56719 | + } |
| 56708 | - .next() | 56720 | + let Some(v) = ct.strip_prefix("let ") else { |
| 56709 | - .map(str::to_string); | 56721 | + continue; |
| 56722 | + }; | ||
| 56723 | + let name = v | ||
| 56724 | + .split(|c: char| !(c.is_alphanumeric() || c == '_')) | ||
| 56725 | + .next() | ||
| 56726 | + .unwrap_or("") | ||
| 56727 | + .to_string(); | ||
| 56728 | + if name.is_empty() { | ||
| 56729 | + continue; | ||
| 56730 | + } | ||
| 56731 | + // This binding is followed by the symbol read if the SAME line | ||
| 56732 | + // completes `let <name> = dec.symbol(`, or if the next line starts | ||
| 56733 | + // the call. That is what separates `let part8 =` from an unrelated | ||
| 56734 | + // `let ec_dbg_pre =` two lines above it. | ||
| 56735 | + let next = lines.get(cand + 1).copied().unwrap_or(""); | ||
| 56736 | + let binds_here = ct.contains("= dec.symbol") || next.contains("dec.symbol("); | ||
| 56737 | + if binds_here || cand == n { | ||
| 56738 | + var = Some(name); | ||
| 56710 | break; | 56739 | break; |
| 56711 | } | 56740 | } |
| 56712 | } | 56741 | } |
| @@ -56822,6 +56851,12 @@ mod tests { | |||
| 56822 | // been inside it. | 56851 | // been inside it. |
| 56823 | if line.contains("PARTITION_HORZ_A..=PARTITION_VERT_B") { | 56852 | if line.contains("PARTITION_HORZ_A..=PARTITION_VERT_B") { |
| 56824 | ab_arm = Some((ind + 4, false)); | 56853 | ab_arm = Some((ind + 4, false)); |
| 56854 | + } else if t == "{" { | ||
| 56855 | + // r10: the arm's own brace carries the OPENER's indent, not the | ||
| 56856 | + // body's, so treating it as "backed out" cleared the arm before a | ||
| 56857 | + // single body statement was seen -- which is why the mutation that | ||
| 56858 | + // moves a guard INSIDE an arm stayed GREEN at r8 AND r9. A lone `{` | ||
| 56859 | + // never changes the state. | ||
| 56825 | } else if let Some((body, entered)) = ab_arm { | 56860 | } else if let Some((body, entered)) = ab_arm { |
| 56826 | if !entered { | 56861 | if !entered { |
| 56827 | if ind >= body { | 56862 | if ind >= body { |
lanes/av1unwritten.report.mdmodified+58 -14
| @@ -619,7 +619,11 @@ reachable at ss (1,0) today. Guarded anyway. | |||
| 619 | adds the exact guard-vs-resolution count. | 619 | adds the exact guard-vs-resolution count. |
| 620 | 3. **`sites.len() >= 9` was a floor the tree already satisfied with 10.** Replaced | 620 | 3. **`sites.len() >= 9` was a floor the tree already satisfied with 10.** Replaced |
| 621 | with a count derived from the scan: the decode body has **11 guard sites** and | 621 | with a count derived from the scan: the decode body has **11 guard sites** and |
| 622 | - the scan finds **11 resolutions**. | 622 | + the scan finds **10 resolutions** — the eleventh guard is the inter-frame 128 |
| 623 | + one at `53985`, whose resolution lives in the shared `read_sb128_root` and so | ||
| 624 | + has no resolution of its own here. That is exactly the redundancy the `>=` | ||
| 625 | + exists to allow, so the counts are reported as 11 guards against 10 | ||
| 626 | + resolutions and the reason is named. | ||
| 623 | 627 | ||
| 624 | Plus the one the refutation demonstrated green: the AB-arm tracker **self-cleared | 628 | Plus the one the refutation demonstrated green: the AB-arm tracker **self-cleared |
| 625 | on the `{` line**, because that line carries the same indent as the `if` — moving | 629 | on the `{` line**, because that line carries the same indent as the `if` — moving |
| @@ -635,19 +639,59 @@ refuse_invalid_subsize((32, 32)) within 220 lines after it | |||
| 635 | 639 | ||
| 636 | ### 11.3 The occurrence count, re-derived per line | 640 | ### 11.3 The occurrence count, re-derived per line |
| 637 | 641 | ||
| 638 | -`refuse_invalid_subsize((` appears **18 times in `decode.rs`**: **11** guard call | 642 | +`refuse_invalid_subsize((` appears **18 times in `decode.rs`**, and the breakdown |
| 639 | -sites in the decode body (one per resolution), **4** in this test's own string | 643 | +that sums is **11 + 5 + 2**: |
| 640 | -literals and comparisons, **2** in doc comments, and **1** — the definition's own | 644 | + |
| 641 | -signer line does not match `((` at all. Main's line-grep count of 13 was taken at | 645 | +* **11 guard call sites** in the decode body — 35588, 36278, 36406, 36472, 36882, |
| 642 | -r7, before the two r9 guards; the refutation's 15 was likewise pre-r9. Eleven is | 646 | + 37132, 53985, 54222, 54606, 54752, 55164; |
| 643 | -what the tree carries now, counted by call shape (`l.trim_start().starts_with(…)`) | 647 | +* **5** in this test's own string literals and comparisons — the four named in the |
| 644 | -so a multi-line assert string mentioning the function is not counted. | 648 | + assertions plus the multi-line assert string at 56835; |
| 649 | +* **2** in doc comments. | ||
| 650 | + | ||
| 651 | +The definition's own signature line does not match `((` at all. Main's line-grep | ||
| 652 | +count of 13 was taken at r7 and the refutation's 15 at r9, both before the r9 kf-w8 | ||
| 653 | +guards; 18 is what the tree carries now, counted by call shape | ||
| 654 | +(`l.trim_start().starts_with(…)`) so a multi-line assert string mentioning the | ||
| 655 | +function is not counted. The scan finds **10** resolutions against those **11** | ||
| 656 | +guards — the inter-128 guard at 53985 has no resolution of its own because | ||
| 657 | +`read_sb128_root` is shared. | ||
| 645 | 658 | ||
| 646 | ### 11.4 What is still not claimed | 659 | ### 11.4 What is still not claimed |
| 647 | 660 | ||
| 648 | -The guard-vs-resolution cross-check is `>=`, not `==`: the scan sees 11 and 11 | 661 | +The guard-vs-resolution cross-check is `>=`, not `==`: the scan sees 10 resolutions |
| 649 | -today, but a hard equality between two numbers the scan itself computes is a claim | 662 | +against 11 guards today, and a hard equality between two numbers the scan itself |
| 650 | -about the scanner, not about coverage. What reds is a resolution with no guard — | 663 | +computes is a claim about the scanner, not about coverage. What reds is a |
| 651 | -on its own line, naming the variable — and a guard sitting inside an AB arm. A | 664 | +resolution with no guard — on its own line, naming the variable — and a guard |
| 652 | -redundant guard with no resolution behind it is harmless and is not treated as a | 665 | +sitting inside an AB arm. A redundant guard with no resolution behind it is |
| 653 | -defect. | 666 | +harmless and is not treated as a defect. |
| 667 | + | ||
| 668 | +**And the two cross-checks are weaker than they look.** Cross-check 1 is level | ||
| 669 | +PRESENCE only. Cross-check 2 is `>=`. So a **second unguarded site at an | ||
| 670 | +already-covered level is caught only by the per-site 220-line window** — which is | ||
| 671 | +a window, not a dispatch bound. Stated rather than left for a reader to infer. | ||
| 672 | + | ||
| 673 | +### 11.5 r10: the AB-arm tracker, again | ||
| 674 | + | ||
| 675 | +r9's tracker was open for exactly one line: armed at the condition (indent 44, | ||
| 676 | +body 48), the wrapped `.contains(&part16)` at indent 48 set `entered = true`, and | ||
| 677 | +then the arm's own `{` — at the **opener's** indent 44, not the body's — hit | ||
| 678 | +`ind < body` and cleared it. Every statement in the arm body was invisible, and | ||
| 679 | +the mutation that moves a guard INSIDE an arm stayed GREEN at r8 *and* r9. r10 | ||
| 680 | +skips a line whose trimmed text is exactly `{` when deciding to enter or clear. | ||
| 681 | +The mutation now reds with the r5 diagnostic: | ||
| 682 | + | ||
| 683 | +``` | ||
| 684 | +$ # move the kf-16 guard inside a PARTITION_HORZ_A..=PARTITION_VERT_B arm | ||
| 685 | +decode.rs:36539 puts a refuse_invalid_subsize inside a | ||
| 686 | +PARTITION_HORZ_A..=PARTITION_VERT_B arm (values 4..=7 only); the offending | ||
| 687 | +values are PARTITION_VERT (2) and PARTITION_VERT_4 (9), which that arm can | ||
| 688 | +never observe -- r5's defect | ||
| 689 | +``` | ||
| 690 | + | ||
| 691 | +Also in r10: the bound-variable lookup scans **backwards** and takes the nearest | ||
| 692 | +`let` whose binding is the one followed by the symbol read. It used to take the | ||
| 693 | +first `let` upward, which could name an unrelated binding (`ec_dbg_pre`) instead | ||
| 694 | +of the partition symbol. | ||
| 695 | + | ||
| 696 | +**No decode-path change in r10** — the four passes found no defect in it. | ||
| 697 | + | ||