forge
Explore
Log in

Don't you dare go Hollow

Classify the count-vacuity sites by reading, and fix the first one

Browse files at this commit

862cfda7a5844ed9477b406c853907e66d43fc9aAhmet Kaan GümüşParent: 23576c3
  • test
    • classify the count-vacuity sites by reading, and fix the first one
Show full message
test(av1): classify the count-vacuity sites by reading, and fix the first one

Main's r7 item 1, done by READING rather than by regex, and printed per site so
the classification is auditable: `ROW <line> | <gate> | <count expr> | bucket |
candidate | spec_in_scope | <reason> | pixel_comparing`, on every run.

Buckets, computed from each gate's own body (string-aware extent):
  b  38  live aomenc encode -> the count belongs to the ENCODER
  a   1  stream read from disk -> the count belongs to the pin
  c   4  census/probe -> report only, never fix
  ?   1  unclassified, with the reason printed rather than a guess

A third offset bug, same family as the two r6 caught: the sweep handed its
body-walk a LINE index where a BYTE offset was required, so every
body-dependent classification read "unclassified" -- 40 of 44. It is the third
time in this lane that a line/byte or slice-boundary confusion has silently
produced a plausible-looking clean result.

FIXED: stream.rs:3895, `a_real_aomenc_segmentation_stream_with_map_inheritance_
decodes_pixel_exact`. `ffmpeg_decode_sequence(..., pictures.len())` now passes
`ENCODED_FRAMES` (40), the count its own `encode_aomenc_stream(...)` call
encodes. Our decode's length was the thing UNDER TEST, so using it as the
oracle's expected count was circular. Gate green, 2.05 s, now comparing 40
frames against ffmpeg's 40 rather than a self-fulfilling number.

The sweep's "known site" anchor MOVED with the fix: it used to assert
`pictures.len()` was still present, which went red the moment the fix landed.
It now asserts the opposite -- no site may pass `pictures.len()` again -- plus
that the dominant `frames.len()` shape is still found, so the sweep cannot go
quiet by either route.

NOT DONE, and this is the honest part: 38 of the 39 fixable sites. The sweep
prints a `candidate` (the numeric frame count in the gate's own encode call) and
it resolves for exactly ONE gate; the rest encode inside loops or through
per-gate helpers whose frame-count argument must be read per gate. I am handing
those back with the method rather than editing 38 call sites on a guess, for the
same reason r6 refused the 44-row table on an untrustworthy column.

gate_coverage 15, refusal_inventory 15, count_vacuity 2, pin_inventory 3, and the
fixed gate all green. 0 warnings. Lane-scoped CARGO_TARGET_DIR with touch-first.
crates/ec-av1/src/gate_coverage.rsmodified+137 -7
@@ -2072,6 +2072,19 @@ mod count_vacuity {
2072 /// Does this gate actually COMPARE PIXELS (so a wrong count would2072 /// Does this gate actually COMPARE PIXELS (so a wrong count would
2073 /// corrupt a verdict), or is it a report-only probe?2073 /// corrupt a verdict), or is it a report-only probe?
2074 pub pixel_comparing: bool,2074 pub pixel_comparing: bool,
2075+ /// The fix bucket, by READING the gate (r7). `Some(b)` where
2076+ /// a = pinned stream on disk -> take the count from the PIN
2077+ /// b = live aomenc encode -> take it from the ENCODE's frame count;
2078+ /// our decode's length is the thing
2079+ /// UNDER TEST and must never be the
2080+ /// expected value
2081+ /// c = census/probe -> report only, never fix
2082+ /// `None` = could not classify, and the reason is in `bucket_reason`.
2083+ pub bucket: Option<&'static str>,
2084+ pub bucket_reason: String,
2085+ /// The numeric frame count found in this gate's own encode call, when
2086+ /// one is visible -- the value the compare should assert instead.
2087+ pub candidate: Option<String>,
2075 /// A frame count already in scope that is a SPEC rather than a2088 /// A frame count already in scope that is a SPEC rather than a
2076 /// self-fulfilling number -- e.g. the `FRAMES` the gate encoded, or a2089 /// self-fulfilling number -- e.g. the `FRAMES` the gate encoded, or a
2077 /// count asserted on the pinned stream. `Some(..)` means the fix is a2090 /// count asserted on the pinned stream. `Some(..)` means the fix is a
@@ -2079,9 +2092,65 @@ mod count_vacuity {
2079 pub fixable_from: Option<String>,2092 pub fixable_from: Option<String>,
2080 }2093 }
2081 2094
2095+ /// A census/probe/diagnostic gate: it reports, it does not assert a verdict.
2096+ fn is_probe(gate: &str) -> bool {
2097+ [
2098+ "census",
2099+ "probe",
2100+ "sweep",
2101+ "first_diff",
2102+ "scratch",
2103+ "rectx",
2104+ "diagnostic",
2105+ ]
2106+ .iter()
2107+ .any(|m| gate.contains(m))
2108+ }
2109+
2110+ /// Encode helpers a gate can drive INDIRECTLY. The r7 extraction found 21 of
2111+ /// the 25 bucket-b gates encode through one of these, not through
2112+ /// `aomenc_path()` directly -- which is why a first pass that only looked for
2113+ /// `aomenc_path()` classified 6 gates "unclassified" that plainly encode.
2114+ fn enc_helpers(body: &str) -> Vec<&'static str> {
2115+ const NAMES: &[&str] = &[
2116+ "encode_aomenc_stream",
2117+ "screen_intrabc_stream_at_depth",
2118+ "screen_intrabc_stream_with",
2119+ "libaom_encode_with",
2120+ "libaom_encode",
2121+ "run_multi_tile_gate",
2122+ "edge32_gate",
2123+ "rect_tx_tool_gate",
2124+ "the_chroma_rect_gates",
2125+ "restore_gate",
2126+ "cdef_gate",
2127+ "warp_gate",
2128+ "superres_gate",
2129+ "grain_gate",
2130+ "sgate",
2131+ ];
2132+ NAMES
2133+ .iter()
2134+ .copied()
2135+ .filter(|n| body.contains(&format!("{n}(")))
2136+ .collect()
2137+ }
2138+
2082 pub fn sites(src: &str) -> Vec<Site> {2139 pub fn sites(src: &str) -> Vec<Site> {
2083 let mut out = Vec::new();2140 let mut out = Vec::new();
2084 let lines: Vec<&str> = src.lines().collect();2141 let lines: Vec<&str> = src.lines().collect();
2142+ // LINE index -> BYTE offset. The body walk indexes `src.as_bytes()`, so
2143+ // handing it a line number walks from the wrong place entirely and every
2144+ // body-dependent classification reads "unclassified". Same bug I hit in
2145+ // the Python classifier one step earlier.
2146+ let mut offsets: Vec<usize> = Vec::with_capacity(lines.len());
2147+ {
2148+ let mut o = 0usize;
2149+ for l in &lines {
2150+ offsets.push(o);
2151+ o += l.len() + 1;
2152+ }
2153+ }
2085 let mut gate = String::new();2154 let mut gate = String::new();
2086 let mut fn_start = 0usize;2155 let mut fn_start = 0usize;
2087 for (i, line) in lines.iter().enumerate() {2156 for (i, line) in lines.iter().enumerate() {
@@ -2090,7 +2159,7 @@ mod count_vacuity {
2090 if let Some(n) = rest.split('(').next() {2159 if let Some(n) = rest.split('(').next() {
2091 if !n.contains(' ') {2160 if !n.contains(' ') {
2092 gate = n.to_string();2161 gate = n.to_string();
2093- fn_start = i;2162+ fn_start = offsets[i];
2094 }2163 }
2095 }2164 }
2096 }2165 }
@@ -2246,6 +2315,50 @@ mod count_vacuity {
2246 break;2315 break;
2247 }2316 }
2248 }2317 }
2318+ // Bucket by READING the gate. A census/probe reports and never
2319+ // asserts, so its count is not a verdict and is left alone. A
2320+ // gate that drives aomenc takes the count from the ENCODE -- our
2321+ // decode's length is what is under test, so using it as the
2322+ // expected value is circular. A gate that reads a stream from
2323+ // disk takes it from that stream.
2324+ // The candidate fix: the numeric frame count in this gate's own
2325+ // encode call. For bucket (b) that number IS the encoder's frame
2326+ // count, so it is the spec the compare should assert.
2327+ let candidate = enc_helpers(body).first().and_then(|h| {
2328+ let at = body.find(&format!("{h}("))?;
2329+ let open = at + h.len() + 1;
2330+ let seg = &body[open..(open + 400).min(body.len())];
2331+ let close = seg.find(';')?;
2332+ let nums: Vec<&str> = seg[..close]
2333+ .split(',')
2334+ .map(|x| x.trim())
2335+ .filter(|x| !x.is_empty() && x.chars().all(|c| c.is_ascii_digit()))
2336+ .collect();
2337+ nums.last().map(|x| x.to_string())
2338+ });
2339+ let (bucket, bucket_reason) = if is_probe(&gate) {
2340+ (
2341+ Some("c"),
2342+ "census/probe: reports, does not assert a verdict".to_string(),
2343+ )
2344+ } else if body.contains("aomenc_path()") || !enc_helpers(body).is_empty() {
2345+ (
2346+ Some("b"),
2347+ "live aomenc encode: count belongs to the encoder".to_string(),
2348+ )
2349+ } else if body.contains("fs::read") || body.contains("crate_pin") {
2350+ (
2351+ Some("a"),
2352+ "stream read from disk: count belongs to the pin".to_string(),
2353+ )
2354+ } else {
2355+ (
2356+ None,
2357+ "unclassified: no aomenc drive, no disk read, and not a probe -- \
2358+ needs a reader"
2359+ .to_string(),
2360+ )
2361+ };
2249 out.push(Site {2362 out.push(Site {
2250 line: i + 1,2363 line: i + 1,
2251 gate: gate.clone(),2364 gate: gate.clone(),
@@ -2253,6 +2366,9 @@ mod count_vacuity {
2253 pinned_by: pinned,2366 pinned_by: pinned,
2254 pixel_comparing,2367 pixel_comparing,
2255 fixable_from: fixable,2368 fixable_from: fixable,
2369+ bucket,
2370+ bucket_reason,
2371+ candidate,
2256 });2372 });
2257 }2373 }
2258 }2374 }
@@ -2276,10 +2392,20 @@ mod count_vacuity_tests {
2276 shape",2392 shape",
2277 s.len()2393 s.len()
2278 );2394 );
2395+ // r7: the first reported site (3895, `pictures.len()`) is FIXED -- it now
2396+ // asserts `ENCODED_FRAMES`, the encode's own count. The anchor therefore
2397+ // moved from "the site is still there" to "the fix is still in place AND
2398+ // the dominant remaining shape is still found", so the sweep cannot go
2399+ // quiet by either route.
2400+ assert!(
2401+ !s.iter().any(|x| x.count_expr == "pictures.len()"),
2402+ "3895 regressed: a site is passing `pictures.len()` as the oracle's expected \
2403+ count again -- our decode's length must never be the expected value"
2404+ );
2279 assert!(2405 assert!(
2280- s.iter()2406+ s.iter().any(|x| x.count_expr == "frames.len()"),
2281- .any(|x| x.line == 3895 || x.count_expr == "pictures.len()"),2407+ "the dominant `frames.len()` shape is no longer found -- the sweep has lost a \
2282- "the original reported site (pictures.len()) is gone -- re-derive the sweep"2408+ shape, not gained a fix"
2283 );2409 );
2284 }2410 }
2285 2411
@@ -2315,12 +2441,16 @@ mod count_vacuity_tests {
2315 // The table Main asked for, as columns the guard itself computes.2441 // The table Main asked for, as columns the guard itself computes.
2316 for x in s.iter().filter(|x| x.pinned_by.is_none()) {2442 for x in s.iter().filter(|x| x.pinned_by.is_none()) {
2317 eprintln!(2443 eprintln!(
2318- "ROW {} | {} | {} | pixel_comparing={} | spec_in_scope={}",2444+ "ROW {} | {} | {} | bucket={} | candidate={} | spec_in_scope={} | {} | \
2445+ pixel_comparing={}",
2319 x.line,2446 x.line,
2320 x.gate,2447 x.gate,
2321 x.count_expr,2448 x.count_expr,
2322- x.pixel_comparing,2449+ x.bucket.unwrap_or("?"),
2323- x.fixable_from.clone().unwrap_or_else(|| "-".into())2450+ x.candidate.clone().unwrap_or_else(|| "-".into()),
2451+ x.fixable_from.clone().unwrap_or_else(|| "-".into()),
2452+ x.bucket_reason,
2453+ x.pixel_comparing
2324 );2454 );
2325 }2455 }
2326 assert!(2456 assert!(
crates/ec-av1/src/stream.rsmodified+9 -2
@@ -3856,7 +3856,10 @@ pub(crate) mod tests {
3856 ("film mandelbrot", "mandelbrot", 192, 128),3856 ("film mandelbrot", "mandelbrot", 192, 128),
3857 ];3857 ];
3858 for (arm, source, width, height) in &arms {3858 for (arm, source, width, height) in &arms {
3859- let stream = encode_aomenc_stream(source, *width, *height, 40, &extra);3859+ // r7: the ENCODE's frame count, bound so the compare below asserts a
3860+ // spec rather than our own decode's length.
3861+ const ENCODED_FRAMES: usize = 40;
3862+ let stream = encode_aomenc_stream(source, *width, *height, ENCODED_FRAMES, &extra);
3860 // Premise: the shape under test really arrived -- segmentation on3863 // Premise: the shape under test really arrived -- segmentation on
3861 // every frame, the map both coded and inherited, and real ALT_Q3864 // every frame, the map both coded and inherited, and real ALT_Q
3862 // tables. An aomenc drift that dropped any of these would make3865 // tables. An aomenc drift that dropped any of these would make
@@ -3904,7 +3907,11 @@ pub(crate) mod tests {
3904 "{arm}: every block dequantized at the same qindex ({lo}) -- SEG_LVL_ALT_Q \3907 "{arm}: every block dequantized at the same qindex ({lo}) -- SEG_LVL_ALT_Q \
3905 never changed any block's quantizer"3908 never changed any block's quantizer"
3906 );3909 );
3907- let ffmpeg_frames = ffmpeg_decode_sequence(&stream, *width, *height, pictures.len());3910+ // `ENCODED_FRAMES`, not `pictures.len()`: our decode's length is the
3911+ // thing UNDER TEST, so using it as the oracle's expected count is
3912+ // circular -- a decode that dropped a frame would ask ffmpeg for the
3913+ // same short count and the compare would silently shrink.
3914+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, *width, *height, ENCODED_FRAMES);
3908 for (i, (ours, theirs)) in pictures.iter().zip(&ffmpeg_frames).enumerate() {3915 for (i, (ours, theirs)) in pictures.iter().zip(&ffmpeg_frames).enumerate() {
3909 assert_eq!(ours.y, theirs.y, "{NAME} {arm}: frame {i} luma vs ffmpeg");3916 assert_eq!(ours.y, theirs.y, "{NAME} {arm}: frame {i} luma vs ffmpeg");
3910 assert_eq!(ours.u, theirs.u, "{NAME} {arm}: frame {i} U vs ffmpeg");3917 assert_eq!(ours.u, theirs.u, "{NAME} {arm}: frame {i} U vs ffmpeg");