forge
Explore
Log in

Don't you dare go Hollow

Enumerate every tx_type CDF width against its own inverse set

Browse files at this commit

d8a578a1f13e84a1d7a78594925689f712eab0afAhmet Kaan GümüşParent: 5f52cbd
  • test
    • enumerate every tx_type CDF width against its own inverse set
Show full message
test(av1): enumerate every tx_type CDF width against its own inverse set

"a tx_type symbol outside its CDF's own set" guards two readers that each
picked the set by the CDF row's width in their own copy of the same match.
Both now call one `tx_type_from_symbol(cdf_len, t)`, and the new enumeration
walks every width declared for a tx_type table in cdf_state.rs (the scan
fails if a new table brings a width the mapping does not name) times every
symbol that width can code -- `0..len - 1`, all a symbol read can return --
asserting each maps to a transform type and that the members of one set are
distinct, so no width has silently lost a member of the spec's
Tx_Type_*_Inv_Set*. Mutation-checked (pointing width 8 at the five-type
order fails on symbol 5).
crates/ec-av1/src/decode.rsmodified+25 -14
@@ -4133,6 +4133,27 @@ fn dc_sign_ctx(vote: i32) -> usize {
4133 }4133 }
4134 }4134 }
4135 4135
4136+/// The `tx_type` a CDF symbol names, given the width of the row it was read
4137+/// from.
4138+///
4139+/// The row's own width names its set (spec `Tx_Type_Intra_Inv_Set*` /
4140+/// `Tx_Type_Inter_Inv_Set*`): 17 slots (16 symbols) is `EXT_TX_SET_ALL16`, 13
4141+/// (12) `EXT_TX_SET_DTT9_IDTX_1DDCT`, 8 (7) `TX_SET_INTRA_1`, and everything
4142+/// narrower the reduced `TX_SET_INTRA_2`/`TX_SET_INTER_3` order, whose two
4143+/// members are a prefix of the five.
4144+///
4145+/// One function rather than a `match` at each reader, so
4146+/// [`crate::refusal_inventory`]'s enumeration of every (width, symbol) pair
4147+/// tests the mapping the readers actually use.
4148+pub(crate) fn tx_type_from_symbol(cdf_len: usize, t: usize) -> Option<TxType> {
4149+ match cdf_len {
4150+ 17 => TxType::from_symbol_all16(t),
4151+ 13 => TxType::from_symbol_set2_12(t),
4152+ 8 => TxType::from_symbol_set1(t),
4153+ _ => TxType::from_symbol(t),
4154+ }
4155+}
4156+
4136 /// The remainder of a level the base and base-range syntax could not reach4157 /// The remainder of a level the base and base-range syntax could not reach
4137 /// (spec 5.11.40): its bit length in unary, then that many of its own bits,4158 /// (spec 5.11.40): its bit length in unary, then that many of its own bits,
4138 /// most significant first — the exact inverse of [`crate::tile::write_golomb`].4159 /// most significant first — the exact inverse of [`crate::tile::write_golomb`].
@@ -4327,13 +4348,8 @@ fn read_coeffs(
4327 if trace {4348 if trace {
4328 eprintln!("TRACE tx_type value={t} len={len}");4349 eprintln!("TRACE tx_type value={t} len={len}");
4329 }4350 }
4330- tx_type = match len {4351+ tx_type = tx_type_from_symbol(len, t)
4331- 17 => TxType::from_symbol_all16(t),4352+ .ok_or_else(|| unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")))?;
4332- 13 => TxType::from_symbol_set2_12(t),
4333- 8 => TxType::from_symbol_set1(t),
4334- _ => TxType::from_symbol(t),
4335- }
4336- .ok_or_else(|| unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")))?;
4337 }4353 }
4338 4354
4339 let class = TxClass::of(tx_type);4355 let class = TxClass::of(tx_type);
@@ -4512,13 +4528,8 @@ fn read_coeffs_rect(
4512 if let Some(tx_type_cdf) = coding.tx_type.as_deref_mut() {4528 if let Some(tx_type_cdf) = coding.tx_type.as_deref_mut() {
4513 let len = tx_type_cdf.len();4529 let len = tx_type_cdf.len();
4514 let t = dec.symbol(tx_type_cdf);4530 let t = dec.symbol(tx_type_cdf);
4515- tx_type = match len {4531+ tx_type = tx_type_from_symbol(len, t)
4516- 17 => TxType::from_symbol_all16(t),4532+ .ok_or_else(|| unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")))?;
4517- 13 => TxType::from_symbol_set2_12(t),
4518- 8 => TxType::from_symbol_set1(t),
4519- _ => TxType::from_symbol(t),
4520- }
4521- .ok_or_else(|| unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")))?;
4522 if rect_trace {4533 if rect_trace {
4523 eprintln!("EC_COEFF_STEP tag=tx_type plane=0 rng={}", dec.debug_state().0);4534 eprintln!("EC_COEFF_STEP tag=tx_type plane=0 rng={}", dec.debug_state().0);
4524 }4535 }
crates/ec-av1/src/refusal_inventory.rsmodified+65 -0
@@ -247,6 +247,12 @@ const PROVEN: &[(&str, &str)] = &[
247 "an inter 16x16-level partition value outside NONE/HORZ/VERT/SPLIT/AB/1:4",247 "an inter 16x16-level partition value outside NONE/HORZ/VERT/SPLIT/AB/1:4",
248 "every_partition_value_of_an_if_chain_alphabet_is_named_by_a_branch",248 "every_partition_value_of_an_if_chain_alphabet_is_named_by_a_branch",
249 ),249 ),
250+ // lane-t900 r24, enumeration: every (CDF width, symbol) pair a tx_type row
251+ // can present maps to a distinct member of that width's own set.
252+ (
253+ "a tx_type symbol outside its CDF's own set: {t}",
254+ "every_tx_type_symbol_of_every_cdf_width_maps_into_its_own_set",
255+ ),
250 (256 (
251 "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)",257 "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)",
252 "a_twelve_bit_sequence_header_is_refused_by_name",258 "a_twelve_bit_sequence_header_is_refused_by_name",
@@ -668,6 +674,65 @@ mod tests {
668 assert_eq!(found, chains.len());674 assert_eq!(found, chains.len());
669 }675 }
670 676
677+ /// Every `tx_type` symbol of every CDF width, mapped through the set that
678+ /// width names.
679+ ///
680+ /// The reader decodes `t` from a row of `n` slots, so `t` is in
681+ /// `0..n - 1`, and hands `(n, t)` to [`crate::decode::tx_type_from_symbol`]
682+ /// -- the readers' own mapping, called here rather than transcribed
683+ /// (class `shared-oracle-blindness`: a second copy of a table can be
684+ /// self-consistently wrong). The widths are read from `cdf_state.rs`'s
685+ /// `tx_type` field declarations, so a new table with a width the mapping
686+ /// does not name fails this test rather than reaching the refusal at
687+ /// runtime.
688+ ///
689+ /// Distinctness is part of the claim: a set of `n - 1` symbols must map to
690+ /// `n - 1` DIFFERENT transform types, or the mapping has lost a member of
691+ /// the spec's `Tx_Type_*_Inv_Set*` even while every symbol resolves.
692+ #[test]
693+ fn every_tx_type_symbol_of_every_cdf_width_maps_into_its_own_set() {
694+ let mut widths: BTreeSet<usize> = BTreeSet::new();
695+ for line in include_str!("cdf_state.rs").lines() {
696+ let t = line.trim();
697+ if !(t.starts_with("pub ") && t.contains("tx_type") && t.contains("[u16;")) {
698+ continue;
699+ }
700+ let tail = t.rsplit("[u16;").next().unwrap_or("");
701+ let n: usize = tail
702+ .split(']')
703+ .next()
704+ .unwrap_or("")
705+ .trim()
706+ .parse()
707+ .unwrap_or_else(|_| panic!("cannot read a CDF width out of {t:?}"));
708+ widths.insert(n);
709+ }
710+ assert!(
711+ widths.len() >= 4,
712+ "the cdf_state.rs scan found only {widths:?} -- it is broken, not the decoder"
713+ );
714+ for &n in &widths {
715+ let nsyms = n - 1;
716+ let mut set: Vec<crate::transform::TxType> = Vec::new();
717+ for t in 0..nsyms {
718+ let ty = crate::decode::tx_type_from_symbol(n, t).unwrap_or_else(|| {
719+ panic!(
720+ "a {n}-slot tx_type CDF codes symbol {t}, which maps to no transform \
721+ type -- the refusal \"a tx_type symbol outside its CDF's own set\" is \
722+ reachable, and that is a mapping-table gap to fix"
723+ )
724+ });
725+ assert!(
726+ !set.contains(&ty),
727+ "a {n}-slot tx_type CDF maps symbol {t} to {ty:?}, which another symbol of \
728+ the same set already names -- a member of the spec's inverse table is lost"
729+ );
730+ set.push(ty);
731+ }
732+ assert_eq!(set.len(), nsyms);
733+ }
734+ }
735+
671 /// Every entry of [`PROVEN`] must still name a live refusal and a test736 /// Every entry of [`PROVEN`] must still name a live refusal and a test
672 /// that exists, and the count it prints is the inventory's numerator.737 /// that exists, and the count it prints is the inventory's numerator.
673 #[test]738 #[test]