Enumerate the 32x32 partition alphabet against the arms that code it
Browse files at this commit34574f5993d6e105f102641b5255c4935f040b36Parent: 0c4727a- test
- enumerate the 32x32 partition alphabet against the arms that code it
1 changed file +107 -1
crates/ec-av1/src/refusal_inventory.rsmodified+107 -1
| @@ -171,6 +171,17 @@ const PROVEN: &[(&str, &str)] = &[ | |||
| 171 | // than decoded wrong) and a witness gate (a real aomenc screen key frame | 171 | // than decoded wrong) and a witness gate (a real aomenc screen key frame |
| 172 | // reaches intrabc on a rect strip, so the refusal names a shape a real | 172 | // reaches intrabc on a rect strip, so the refusal names a shape a real |
| 173 | // encoder does write). | 173 | // encoder does write). |
| 174 | + // lane-t900 r21, enumeration: `partition_w32` is a ten-symbol CDF and both | ||
| 175 | + // `match part32` blocks carry an arm for each of its values, so neither | ||
| 176 | + // fallback arm can be reached by any stream. | ||
| 177 | + ( | ||
| 178 | + "a 32x32 partition type this decoder does not code (value={part32})", | ||
| 179 | + "every_32x32_partition_value_has_an_arm_on_both_paths", | ||
| 180 | + ), | ||
| 181 | + ( | ||
| 182 | + "an INTER 32x32 partition type this decoder does not code (value={part32})", | ||
| 183 | + "every_32x32_partition_value_has_an_arm_on_both_paths", | ||
| 184 | + ), | ||
| 174 | ( | 185 | ( |
| 175 | "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)", | 186 | "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)", |
| 176 | "a_twelve_bit_sequence_header_is_refused_by_name", | 187 | "a_twelve_bit_sequence_header_is_refused_by_name", |
| @@ -358,12 +369,107 @@ mod tests { | |||
| 358 | ); | 369 | ); |
| 359 | } | 370 | } |
| 360 | 371 | ||
| 372 | + /// The 32x32 partition alphabet, enumerated against the arms that code it. | ||
| 373 | + /// | ||
| 374 | + /// `partition_w32` is a ten-symbol CDF -- `PARTITION_NONE ..= | ||
| 375 | + /// PARTITION_VERT_4` -- and `SymbolDecoder::symbol_fixed` cannot return a | ||
| 376 | + /// value outside `0..nsyms`, so those ten values are the whole domain of | ||
| 377 | + /// `part32` (the frame-edge path narrows it further still, to | ||
| 378 | + /// HORZ/VERT/SPLIT). If both `match part32` blocks -- the intra one and | ||
| 379 | + /// the inter one -- carry an arm for every value, then the `_ =>` refusal | ||
| 380 | + /// each ends with names a value no stream can present. | ||
| 381 | + /// | ||
| 382 | + /// The refusals stay in the code: `part32` is a `usize`, so the match | ||
| 383 | + /// needs a fallback arm, and a named refusal is a better one than a panic | ||
| 384 | + /// (class `branch-dropped-as-unreachable`). What this test removes is the | ||
| 385 | + /// UNMEASURED part of the claim. | ||
| 386 | + #[test] | ||
| 387 | + fn every_32x32_partition_value_has_an_arm_on_both_paths() { | ||
| 388 | + const NAMES: [&str; 10] = [ | ||
| 389 | + "PARTITION_NONE", | ||
| 390 | + "PARTITION_HORZ", | ||
| 391 | + "PARTITION_VERT", | ||
| 392 | + "PARTITION_SPLIT", | ||
| 393 | + "PARTITION_HORZ_A", | ||
| 394 | + "PARTITION_HORZ_B", | ||
| 395 | + "PARTITION_VERT_A", | ||
| 396 | + "PARTITION_VERT_B", | ||
| 397 | + "PARTITION_HORZ_4", | ||
| 398 | + "PARTITION_VERT_4", | ||
| 399 | + ]; | ||
| 400 | + let alphabet = crate::cdf::PARTITION_W32[0].len() - 1; | ||
| 401 | + assert_eq!( | ||
| 402 | + alphabet, | ||
| 403 | + NAMES.len(), | ||
| 404 | + "the partition_w32 CDF codes {alphabet} symbols, not the {} this test enumerates", | ||
| 405 | + NAMES.len() | ||
| 406 | + ); | ||
| 407 | + | ||
| 408 | + let src = include_str!("decode.rs"); | ||
| 409 | + let lines: Vec<&str> = src.lines().collect(); | ||
| 410 | + let indent = |l: &str| l.len() - l.trim_start().len(); | ||
| 411 | + let mut blocks = 0usize; | ||
| 412 | + for (i, line) in lines.iter().enumerate() { | ||
| 413 | + if line.trim() != "match part32 {" { | ||
| 414 | + continue; | ||
| 415 | + } | ||
| 416 | + blocks += 1; | ||
| 417 | + let outer = indent(line); | ||
| 418 | + let close = " ".repeat(outer) + "}"; | ||
| 419 | + let mut arms: BTreeSet<&str> = BTreeSet::new(); | ||
| 420 | + let mut has_fallback = false; | ||
| 421 | + for l in &lines[i + 1..] { | ||
| 422 | + if *l == close { | ||
| 423 | + break; | ||
| 424 | + } | ||
| 425 | + // Arm patterns sit exactly one level in; anything deeper is an | ||
| 426 | + // arm's body, including the nested `match` blocks and the | ||
| 427 | + // `part32 == PARTITION_HORZ_4` reads inside them. | ||
| 428 | + if indent(l) != outer + 4 || !l.contains("=>") { | ||
| 429 | + continue; | ||
| 430 | + } | ||
| 431 | + let pat = l.trim(); | ||
| 432 | + if pat.starts_with("_ =>") { | ||
| 433 | + has_fallback = true; | ||
| 434 | + } | ||
| 435 | + // Token-exact, not substring: `PARTITION_VERT_B` is a prefix of | ||
| 436 | + // other identifiers, and a misspelled constant in a pattern | ||
| 437 | + // position is an irrefutable BINDING that swallows the whole | ||
| 438 | + // alphabet while still compiling. | ||
| 439 | + let head = pat.split("=>").next().unwrap_or(""); | ||
| 440 | + for tok in head.split(|c: char| !(c.is_ascii_alphanumeric() || c == '_')) { | ||
| 441 | + if let Some(name) = NAMES.iter().find(|n| **n == tok) { | ||
| 442 | + arms.insert(name); | ||
| 443 | + } | ||
| 444 | + } | ||
| 445 | + } | ||
| 446 | + let missing: Vec<&&str> = NAMES.iter().filter(|n| !arms.contains(**n)).collect(); | ||
| 447 | + assert!( | ||
| 448 | + missing.is_empty(), | ||
| 449 | + "the `match part32` at decode.rs:{} has no arm for {missing:?} -- that is a real \ | ||
| 450 | + gap in the 32x32 partition alphabet, not a dead refusal", | ||
| 451 | + i + 1 | ||
| 452 | + ); | ||
| 453 | + assert!( | ||
| 454 | + has_fallback, | ||
| 455 | + "the `match part32` at decode.rs:{} lost its fallback arm; if it is exhaustive \ | ||
| 456 | + now, drop its refusal from the inventory instead", | ||
| 457 | + i + 1 | ||
| 458 | + ); | ||
| 459 | + } | ||
| 460 | + assert_eq!(blocks, 2, "expected the intra and inter 32x32 partition matches"); | ||
| 461 | + } | ||
| 462 | + | ||
| 361 | /// Every entry of [`PROVEN`] must still name a live refusal and a test | 463 | /// Every entry of [`PROVEN`] must still name a live refusal and a test |
| 362 | /// that exists, and the count it prints is the inventory's numerator. | 464 | /// that exists, and the count it prints is the inventory's numerator. |
| 363 | #[test] | 465 | #[test] |
| 364 | fn every_proven_refusal_names_a_test_that_exists() { | 466 | fn every_proven_refusal_names_a_test_that_exists() { |
| 365 | let found = decode_path_refusals(); | 467 | let found = decode_path_refusals(); |
| 366 | - let sources = [include_str!("stream.rs"), include_str!("decode.rs")]; | 468 | + let sources = [ |
| 469 | + include_str!("stream.rs"), | ||
| 470 | + include_str!("decode.rs"), | ||
| 471 | + include_str!("refusal_inventory.rs"), | ||
| 472 | + ]; | ||
| 367 | for (reason, gate) in PROVEN { | 473 | for (reason, gate) in PROVEN { |
| 368 | assert!( | 474 | assert!( |
| 369 | found.contains(*reason), | 475 | found.contains(*reason), |