forge
Explore
Log in

Don't you dare go Hollow

gate_coverage: make the count-vacuity scan comment-aware, ceiling 1 -> 0

Browse files at this commit

cefac456b8abe3540c555cc214d2b49b7baf9279Ahmet Kaan GümüşParent: 1e73b1b
The last unpinned row in the ledger was not a count. It was a `///` doc
comment quoting the pre-r4 body of `pinned_lr_sgr_stream_call_unique_dump` --
prose about code, sitting inside the gate the prose describes, which already
spends FRAMES and asserts `pics.len() == FRAMES`. A line-based scan cannot
tell the two apart, so that row sat in the ledger for a whole round as an
unpinned count no reader could act on, and the ceiling could never reach 0.

`sites()` now skips lines whose trimmed start is `//`. Only the SITE scan
skips them: the pin-window walk still sees every line, because a `//`-led line
there is a comment BETWEEN an assert and its call, not a site.

A coverage change gets a coverage test, in the shape `pin_inventory` already
uses -- a SYNTHETIC source, not the live tree, because a fix to the very gate
that motivated this would otherwise delete the row that proves the scanner
works. Both halves are asserted, and the second is the one that matters:

  * half one: a count call inside a `///` doc comment is NOT a site. That is
    the real row this change removes.
  * half two, the control: the SAME call as real code IS still a site, still
    attributed to the right gate, and still PINNED by an assert above it. A
    scanner that skips comments by skipping the wrong thing is identical on
    half one, and a ceiling of 0 is exactly the state where an over-broad skip
    would go unnoticed.

count-vacuity sweep: 59 site(s); 58 spec-pinned, 1 not -> 58 site(s); 58
spec-pinned, 0 not. UNPINNED_CEILING 1 -> 0.

RED-BEFORE, both halves, with the skip removed and the ceiling at 0:

  test ...::a_doc_commented_count_call_is_not_a_site_but_real_code_still_is
    ... FAILED
  test ...::the_count_vacuity_sweep_finds_the_known_sites ... FAILED
  1 unpinned count site(s), ceiling is 0 -- a new one was added
  test result: FAILED. 1 passed; 2 failed

so neither half of this change can be reverted silently.
crates/ec-av1/src/gate_coverage.rsmodified+107 -14
@@ -2293,6 +2293,21 @@ mod count_vacuity {
2293 }2293 }
2294 }2294 }
2295 }2295 }
2296+ // A DOC COMMENT is prose about code, not code. One row in the ledger
2297+ // was a `///` line quoting a gate's pre-fix body (`stream.rs:30924`,
2298+ // inside `pinned_lr_sgr_stream_call_unique_dump`) and the sweep
2299+ // counted it as an unpinned count site for a whole round: the gate
2300+ // it describes already spends `FRAMES` and asserts
2301+ // `pics.len() == FRAMES`. Skipping comment lines is not cosmetic --
2302+ // without it the ledger carries a row no reader can act on, and the
2303+ // ceiling can never reach 0.
2304+ //
2305+ // Only the SITE scan skips comments. The pin-window walk further
2306+ // down still sees every line, because a `//`-led line there is a
2307+ // comment BETWEEN the assert and the call, not a site.
2308+ if t.starts_with("//") {
2309+ continue;
2310+ }
2296 for callee in CALLEES {2311 for callee in CALLEES {
2297 let Some(at) = line.find(callee) else {2312 let Some(at) = line.find(callee) else {
2298 continue;2313 continue;
@@ -2604,21 +2619,27 @@ mod count_vacuity_tests {
2604 // against the encode instead of read off our decode. Two rows survived2619 // against the encode instead of read off our decode. Two rows survived
2605 // that round; lane-av1pinspec2 closed both, so the ceiling is now 0.2620 // that round; lane-av1pinspec2 closed both, so the ceiling is now 0.
2606 //2621 //
2607- // lane-av1pinspec2: 2 -> 1, for the SVT row. That gate was handed2622+ // lane-av1pinspec2: 2 -> 0, in two steps.
2608- // forward last round because the count was underivable: the stream came2623+ // * `an_svt_screen_palette_block_with_a_split_transform_decodes_exactly`
2609- // from `EC_AV1_SVT1_STREAM`, was never committed, and the gate SKIPped2624+ // was handed forward because the count was underivable: the stream
2610- // on a stock box -- so a wire-derived assert would have been an2625+ // came from `EC_AV1_SVT1_STREAM`, was never committed, and the gate
2611- // unexercised assert wearing a pin's clothes. The crop is now COMMITTED2626+ // SKIPped on a stock box -- so a wire-derived assert would have been
2612- // (`fixtures/svt1-split-tx-pin.obu`, a byte-reproducible replay of a2627+ // an unexercised assert wearing a pin's clothes. The crop is now
2613- // `-frames:v 1` libsvtav1 encode), the gate reads it, and its count2628+ // COMMITTED (`fixtures/svt1-split-tx-pin.obu`, a byte-reproducible
2614- // comes from the stream's own OBU frame headers with2629+ // replay of a `-frames:v 1` libsvtav1 encode), the gate reads it, and
2615- // `show_existing_frame` asserted false, so a header count cannot2630+ // its count comes from the stream's own OBU frame headers with
2616- // over-count. The gate runs on a stock box, so the assert executes.2631+ // `show_existing_frame` asserted false so a header count cannot
2632+ // over-count. The gate runs on a stock box, so the assert executes.
2633+ // * the other row was a `///` DOC COMMENT quoting the pre-r4 body of
2634+ // `pinned_lr_sgr_stream_call_unique_dump`, which this line-based
2635+ // scan could not tell from code. `sites()` now skips comment lines,
2636+ // so the row is no longer a site at all.
2617 //2637 //
2618- // The remaining unpinned row is a `///` DOC COMMENT quoting the pre-r42638+ // RED-BEFORE for the comment skip, which is a coverage change and not a
2619- // body of `pinned_lr_sgr_stream_call_unique_dump`, which this2639+ // cosmetic one: with the `t.starts_with("//")` guard removed and this
2620- // line-based scan cannot tell from code.2640+ // ceiling at 0, the doc-comment row comes BACK as an unpinned site and
2621- const UNPINNED_CEILING: usize = 1;2641+ // reds with "1 unpinned count site(s), ceiling is 0".
2642+ const UNPINNED_CEILING: usize = 0;
2622 let unpinned = s.iter().filter(|x| x.pinned_by.is_none()).count();2643 let unpinned = s.iter().filter(|x| x.pinned_by.is_none()).count();
2623 assert!(2644 assert!(
2624 unpinned <= UNPINNED_CEILING,2645 unpinned <= UNPINNED_CEILING,
@@ -2681,4 +2702,76 @@ mod count_vacuity_tests {
2681 "a site has no owning gate -- the sweep's gate attribution is broken"2702 "a site has no owning gate -- the sweep's gate attribution is broken"
2682 );2703 );
2683 }2704 }
2705+
2706+ /// The comment skip is a COVERAGE change, so it is held to the same shape
2707+ /// the `pin_inventory` capability tests use: a SYNTHETIC source, not the
2708+ /// live tree, with BOTH halves. Run against the live tree instead, a fix
2709+ /// to the very gate that motivated it would delete the row that proves the
2710+ /// scanner still works -- the failure mode `pin_inventory` already records
2711+ /// as "a scanner that cannot see this shape is how 14 pins survived three
2712+ /// rounds".
2713+ ///
2714+ /// Half one: a count call that lives INSIDE a doc comment must not be a
2715+ /// site. That is the real `stream.rs:30924` row, which spent a whole round
2716+ /// in the ledger as an unpinned count no reader could act on -- the gate it
2717+ /// quotes already spends `FRAMES` and asserts `pics.len() == FRAMES`.
2718+ ///
2719+ /// Half two, the control: the SAME call as real code must still be a site,
2720+ /// and must still be pinned by an assert above it. A scanner that skips
2721+ /// comments by skipping the wrong thing looks identical on half one, and a
2722+ /// ceiling of 0 is exactly the state where an over-broad skip would go
2723+ /// unnoticed.
2724+ #[test]
2725+ fn a_doc_commented_count_call_is_not_a_site_but_real_code_still_is() {
2726+ let commented = r#"
2727+ /// The old body passed the wrong count to the oracle:
2728+ /// let reference = ffmpeg_decode_sequence(&stream, 192, 128, pics.len());
2729+ /// so a decoder that emitted zero frames asked ffmpeg for zero frames.
2730+ fn a_gate_whose_doc_comment_quotes_the_old_body() {
2731+ let pics = decode_stream(&data).unwrap();
2732+ }
2733+"#;
2734+ let commented_sites = sites(commented);
2735+ assert!(
2736+ commented_sites.is_empty(),
2737+ "a count call inside a `///` doc comment was counted as a site: {:?} -- a line-based \
2738+ scan cannot tell prose from code, and this row is why it now skips comment lines",
2739+ commented_sites
2740+ .iter()
2741+ .map(|x| (x.line, x.count_expr.clone()))
2742+ .collect::<Vec<_>>()
2743+ );
2744+
2745+ let real = r#"
2746+ fn a_gate_that_really_spends_its_own_decode_length() {
2747+ let pics = decode_stream(&data).unwrap();
2748+ assert_eq!(pics.len(), 7, "{NAME}: expected seven key frames");
2749+ let reference = ffmpeg_decode_sequence(&stream, 192, 128, pics.len());
2750+ }
2751+"#;
2752+ let found = sites(real);
2753+ assert_eq!(
2754+ found.len(),
2755+ 1,
2756+ "the control did not find its one real site: {:?} -- the comment skip is over-broad \
2757+ if the same call is skipped as code",
2758+ found
2759+ .iter()
2760+ .map(|x| (x.line, x.count_expr.clone(), x.gate.clone()))
2761+ .collect::<Vec<_>>()
2762+ );
2763+ assert_eq!(
2764+ found[0].count_expr, "pics.len()",
2765+ "control: wrong count expr"
2766+ );
2767+ assert_eq!(
2768+ found[0].gate, "a_gate_that_really_spends_its_own_decode_length",
2769+ "control: wrong gate attribution"
2770+ );
2771+ assert!(
2772+ found[0].pinned_by.is_some(),
2773+ "the control's site is UNPINNED: the comment skip changed the pin window too, \
2774+ because a `//` line between an assert and its call is still walked"
2775+ );
2776+ }
2684 }2777 }