Enumerate the 128-root partition alphabet too, keyed by the refusal itself
Browse files at this commit5b764e4be2c9a56677c51dcd8635b36e83c90f5aParent: 7ee6680- test
- enumerate the 128-root partition alphabet too, keyed by the refusal itself
1 changed file +81 -56
crates/ec-av1/src/refusal_inventory.rsmodified+81 -56
| @@ -192,16 +192,21 @@ const PROVEN: &[(&str, &str)] = &[ | |||
| 192 | // than decoded wrong) and a witness gate (a real aomenc screen key frame | 192 | // than decoded wrong) and a witness gate (a real aomenc screen key frame |
| 193 | // reaches intrabc on a rect strip, so the refusal names a shape a real | 193 | // reaches intrabc on a rect strip, so the refusal names a shape a real |
| 194 | // encoder does write). | 194 | // encoder does write). |
| 195 | - // lane-t900 r21, enumeration: `partition_w32` is a ten-symbol CDF and both | 195 | + // lane-t900 r21, enumeration: `partition_w32` is a ten-symbol CDF and |
| 196 | - // `match part32` blocks carry an arm for each of its values, so neither | 196 | + // `partition_w128` an eight-symbol one, and every `match` carrying one of |
| 197 | - // fallback arm can be reached by any stream. | 197 | + // these three fallbacks has an arm for each value of its own alphabet, so |
| 198 | + // no stream can reach them. | ||
| 198 | ( | 199 | ( |
| 199 | "a 32x32 partition type this decoder does not code (value={part32})", | 200 | "a 32x32 partition type this decoder does not code (value={part32})", |
| 200 | - "every_32x32_partition_value_has_an_arm_on_both_paths", | 201 | + "every_partition_value_of_an_enumerated_alphabet_has_an_arm", |
| 201 | ), | 202 | ), |
| 202 | ( | 203 | ( |
| 203 | "an INTER 32x32 partition type this decoder does not code (value={part32})", | 204 | "an INTER 32x32 partition type this decoder does not code (value={part32})", |
| 204 | - "every_32x32_partition_value_has_an_arm_on_both_paths", | 205 | + "every_partition_value_of_an_enumerated_alphabet_has_an_arm", |
| 206 | + ), | ||
| 207 | + ( | ||
| 208 | + "a 128x128 superblock partition value outside the 8-symbol alphabet", | ||
| 209 | + "every_partition_value_of_an_enumerated_alphabet_has_an_arm", | ||
| 205 | ), | 210 | ), |
| 206 | ( | 211 | ( |
| 207 | "a bit depth of 12 (this decoder is gated at 8 and 10 only: warp/MC/wiener rounding shifts change at 12-bit and no 12-bit gate exists)", | 212 | "a bit depth of 12 (this decoder is gated at 8 and 10 only: warp/MC/wiener rounding shifts change at 12-bit and no 12-bit gate exists)", |
| @@ -390,22 +395,27 @@ mod tests { | |||
| 390 | ); | 395 | ); |
| 391 | } | 396 | } |
| 392 | 397 | ||
| 393 | - /// The 32x32 partition alphabet, enumerated against the arms that code it. | 398 | + /// The partition alphabets, enumerated against the arms that code them. |
| 394 | /// | 399 | /// |
| 395 | - /// `partition_w32` is a ten-symbol CDF -- `PARTITION_NONE ..= | 400 | + /// A partition value is a CDF symbol, and `SymbolDecoder::symbol_fixed` |
| 396 | - /// PARTITION_VERT_4` -- and `SymbolDecoder::symbol_fixed` cannot return a | 401 | + /// cannot return one outside `0..nsyms` -- so a `match` whose arms cover |
| 397 | - /// value outside `0..nsyms`, so those ten values are the whole domain of | 402 | + /// its whole alphabet has an unreachable fallback, and the refusal that |
| 398 | - /// `part32` (the frame-edge path narrows it further still, to | 403 | + /// fallback carries names a value no stream can present. This test finds |
| 399 | - /// HORZ/VERT/SPLIT). If both `match part32` blocks -- the intra one and | 404 | + /// each such `match` by the refusal in its OWN fallback arm (rather than |
| 400 | - /// the inter one -- carry an arm for every value, then the `_ =>` refusal | 405 | + /// by line number, which drifts) and enumerates the alphabet against the |
| 401 | - /// each ends with names a value no stream can present. | 406 | + /// arm patterns, ranges included. |
| 402 | /// | 407 | /// |
| 403 | - /// The refusals stay in the code: `part32` is a `usize`, so the match | 408 | + /// The refusals stay in the code: a partition value is a `usize`, so the |
| 404 | - /// needs a fallback arm, and a named refusal is a better one than a panic | 409 | + /// match needs a fallback arm, and a named refusal is a better one than a |
| 405 | - /// (class `branch-dropped-as-unreachable`). What this test removes is the | 410 | + /// panic (class `branch-dropped-as-unreachable`). What this removes is the |
| 406 | /// UNMEASURED part of the claim. | 411 | /// UNMEASURED part of the claim. |
| 412 | + /// | ||
| 413 | + /// Not every partition fallback belongs here: the ones that name a shape | ||
| 414 | + /// this decoder genuinely does not code yet (the 128-root consumers) are | ||
| 415 | + /// live refusals, and the 16x16-level inter chain is an `if`/`else if` | ||
| 416 | + /// ladder rather than a match, so it needs its own enumerator. | ||
| 407 | #[test] | 417 | #[test] |
| 408 | - fn every_32x32_partition_value_has_an_arm_on_both_paths() { | 418 | + fn every_partition_value_of_an_enumerated_alphabet_has_an_arm() { |
| 409 | const NAMES: [&str; 10] = [ | 419 | const NAMES: [&str; 10] = [ |
| 410 | "PARTITION_NONE", | 420 | "PARTITION_NONE", |
| 411 | "PARTITION_HORZ", | 421 | "PARTITION_HORZ", |
| @@ -418,67 +428,82 @@ mod tests { | |||
| 418 | "PARTITION_HORZ_4", | 428 | "PARTITION_HORZ_4", |
| 419 | "PARTITION_VERT_4", | 429 | "PARTITION_VERT_4", |
| 420 | ]; | 430 | ]; |
| 421 | - let alphabet = crate::cdf::PARTITION_W32[0].len() - 1; | 431 | + // (the refusal in the fallback arm, the alphabet its CDF codes) |
| 422 | - assert_eq!( | 432 | + let blocks: [(&str, usize); 3] = [ |
| 423 | - alphabet, | 433 | + ("a 32x32 partition type this decoder does not code", crate::cdf::PARTITION_W32[0].len() - 1), |
| 424 | - NAMES.len(), | 434 | + ("an INTER 32x32 partition type this decoder does not code", crate::cdf::PARTITION_W32[0].len() - 1), |
| 425 | - "the partition_w32 CDF codes {alphabet} symbols, not the {} this test enumerates", | 435 | + ("a 128x128 superblock partition value outside the 8-symbol alphabet", crate::cdf::PARTITION_W128[0].len() - 1), |
| 426 | - NAMES.len() | 436 | + ]; |
| 427 | - ); | 437 | + // A pattern's own tokens, plus every value of an inclusive range |
| 438 | + // (`p if (PARTITION_HORZ_A..=PARTITION_VERT_B).contains(&p)` is four | ||
| 439 | + // arms in one). | ||
| 440 | + let covered = |head: &str| -> BTreeSet<usize> { | ||
| 441 | + let mut out = BTreeSet::new(); | ||
| 442 | + let idx: Vec<usize> = head | ||
| 443 | + .split(|c: char| !(c.is_ascii_alphanumeric() || c == '_')) | ||
| 444 | + .filter_map(|tok| NAMES.iter().position(|n| *n == tok)) | ||
| 445 | + .collect(); | ||
| 446 | + if head.contains("..=") && idx.len() == 2 { | ||
| 447 | + for v in idx[0]..=idx[1] { | ||
| 448 | + out.insert(v); | ||
| 449 | + } | ||
| 450 | + } | ||
| 451 | + out.extend(idx); | ||
| 452 | + out | ||
| 453 | + }; | ||
| 428 | 454 | ||
| 429 | let src = include_str!("decode.rs"); | 455 | let src = include_str!("decode.rs"); |
| 430 | let lines: Vec<&str> = src.lines().collect(); | 456 | let lines: Vec<&str> = src.lines().collect(); |
| 431 | let indent = |l: &str| l.len() - l.trim_start().len(); | 457 | let indent = |l: &str| l.len() - l.trim_start().len(); |
| 432 | - let mut blocks = 0usize; | 458 | + let mut found = 0usize; |
| 433 | for (i, line) in lines.iter().enumerate() { | 459 | for (i, line) in lines.iter().enumerate() { |
| 434 | - if line.trim() != "match part32 {" { | 460 | + let t = line.trim(); |
| 461 | + if !(t.starts_with("match part") && t.ends_with('{')) { | ||
| 435 | continue; | 462 | continue; |
| 436 | } | 463 | } |
| 437 | - blocks += 1; | ||
| 438 | let outer = indent(line); | 464 | let outer = indent(line); |
| 439 | let close = " ".repeat(outer) + "}"; | 465 | let close = " ".repeat(outer) + "}"; |
| 440 | - let mut arms: BTreeSet<&str> = BTreeSet::new(); | 466 | + let (mut arms, mut fallback) = (BTreeSet::new(), String::new()); |
| 441 | - let mut has_fallback = false; | 467 | + let mut in_fallback = false; |
| 442 | for l in &lines[i + 1..] { | 468 | for l in &lines[i + 1..] { |
| 443 | if *l == close { | 469 | if *l == close { |
| 444 | break; | 470 | break; |
| 445 | } | 471 | } |
| 446 | // Arm patterns sit exactly one level in; anything deeper is an | 472 | // Arm patterns sit exactly one level in; anything deeper is an |
| 447 | - // arm's body, including the nested `match` blocks and the | 473 | + // arm's body, nested matches and `part == PARTITION_*` reads |
| 448 | - // `part32 == PARTITION_HORZ_4` reads inside them. | 474 | + // included. |
| 449 | - if indent(l) != outer + 4 || !l.contains("=>") { | 475 | + if indent(l) != outer + 4 && !l.trim().is_empty() { |
| 450 | - continue; | 476 | + if in_fallback { |
| 451 | - } | 477 | + fallback.push_str(l.trim()); |
| 452 | - let pat = l.trim(); | ||
| 453 | - if pat.starts_with("_ =>") { | ||
| 454 | - has_fallback = true; | ||
| 455 | } | 478 | } |
| 456 | - // Token-exact, not substring: `PARTITION_VERT_B` is a prefix of | 479 | + continue; |
| 457 | - // other identifiers, and a misspelled constant in a pattern | ||
| 458 | - // position is an irrefutable BINDING that swallows the whole | ||
| 459 | - // alphabet while still compiling. | ||
| 460 | - let head = pat.split("=>").next().unwrap_or(""); | ||
| 461 | - for tok in head.split(|c: char| !(c.is_ascii_alphanumeric() || c == '_')) { | ||
| 462 | - if let Some(name) = NAMES.iter().find(|n| **n == tok) { | ||
| 463 | - arms.insert(name); | ||
| 464 | } | 480 | } |
| 481 | + if !l.contains("=>") { | ||
| 482 | + continue; | ||
| 465 | } | 483 | } |
| 484 | + in_fallback = l.trim_start().starts_with("_ =>"); | ||
| 485 | + arms.extend(covered(l.split("=>").next().unwrap_or(""))); | ||
| 466 | } | 486 | } |
| 467 | - let missing: Vec<&&str> = NAMES.iter().filter(|n| !arms.contains(**n)).collect(); | 487 | + let Some((reason, alphabet)) = |
| 488 | + blocks.iter().find(|(reason, _)| fallback.contains(reason)) | ||
| 489 | + else { | ||
| 490 | + continue; | ||
| 491 | + }; | ||
| 492 | + found += 1; | ||
| 493 | + let missing: Vec<usize> = (0..*alphabet).filter(|v| !arms.contains(v)).collect(); | ||
| 468 | assert!( | 494 | assert!( |
| 469 | missing.is_empty(), | 495 | missing.is_empty(), |
| 470 | - "the `match part32` at decode.rs:{} has no arm for {missing:?} -- that is a real \ | 496 | + "the `match` at decode.rs:{} refuses {reason:?} but has no arm for {:?} -- that \ |
| 471 | - gap in the 32x32 partition alphabet, not a dead refusal", | 497 | + is a real gap in its {alphabet}-value alphabet, not a dead refusal", |
| 472 | - i + 1 | 498 | + i + 1, |
| 473 | - ); | 499 | + missing.iter().map(|v| NAMES[*v]).collect::<Vec<_>>() |
| 474 | - assert!( | ||
| 475 | - has_fallback, | ||
| 476 | - "the `match part32` at decode.rs:{} lost its fallback arm; if it is exhaustive \ | ||
| 477 | - now, drop its refusal from the inventory instead", | ||
| 478 | - i + 1 | ||
| 479 | ); | 500 | ); |
| 480 | } | 501 | } |
| 481 | - assert_eq!(blocks, 2, "expected the intra and inter 32x32 partition matches"); | 502 | + assert_eq!( |
| 503 | + found, | ||
| 504 | + blocks.len(), | ||
| 505 | + "not every enumerated partition refusal was located in decode.rs" | ||
| 506 | + ); | ||
| 482 | } | 507 | } |
| 483 | 508 | ||
| 484 | /// Every entry of [`PROVEN`] must still name a live refusal and a test | 509 | /// Every entry of [`PROVEN`] must still name a live refusal and a test |