From d8a578a1f13e84a1d7a78594925689f712eab0af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 4 Sep 2026 14:09:35 +0300 Subject: [PATCH] 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.rs | 39 ++++++++++------ crates/ec-av1/src/refusal_inventory.rs | 65 ++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 14 deletions(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index da0e2270..6c96f75d 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -4133,6 +4133,27 @@ fn dc_sign_ctx(vote: i32) -> usize { } } +/// The `tx_type` a CDF symbol names, given the width of the row it was read +/// from. +/// +/// The row's own width names its set (spec `Tx_Type_Intra_Inv_Set*` / +/// `Tx_Type_Inter_Inv_Set*`): 17 slots (16 symbols) is `EXT_TX_SET_ALL16`, 13 +/// (12) `EXT_TX_SET_DTT9_IDTX_1DDCT`, 8 (7) `TX_SET_INTRA_1`, and everything +/// narrower the reduced `TX_SET_INTRA_2`/`TX_SET_INTER_3` order, whose two +/// members are a prefix of the five. +/// +/// One function rather than a `match` at each reader, so +/// [`crate::refusal_inventory`]'s enumeration of every (width, symbol) pair +/// tests the mapping the readers actually use. +pub(crate) fn tx_type_from_symbol(cdf_len: usize, t: usize) -> Option { + match cdf_len { + 17 => TxType::from_symbol_all16(t), + 13 => TxType::from_symbol_set2_12(t), + 8 => TxType::from_symbol_set1(t), + _ => TxType::from_symbol(t), + } +} + /// The remainder of a level the base and base-range syntax could not reach /// (spec 5.11.40): its bit length in unary, then that many of its own bits, /// most significant first — the exact inverse of [`crate::tile::write_golomb`]. @@ -4327,13 +4348,8 @@ fn read_coeffs( if trace { eprintln!("TRACE tx_type value={t} len={len}"); } - tx_type = match len { - 17 => TxType::from_symbol_all16(t), - 13 => TxType::from_symbol_set2_12(t), - 8 => TxType::from_symbol_set1(t), - _ => TxType::from_symbol(t), - } - .ok_or_else(|| unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")))?; + tx_type = tx_type_from_symbol(len, t) + .ok_or_else(|| unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")))?; } let class = TxClass::of(tx_type); @@ -4512,13 +4528,8 @@ fn read_coeffs_rect( if let Some(tx_type_cdf) = coding.tx_type.as_deref_mut() { let len = tx_type_cdf.len(); let t = dec.symbol(tx_type_cdf); - tx_type = match len { - 17 => TxType::from_symbol_all16(t), - 13 => TxType::from_symbol_set2_12(t), - 8 => TxType::from_symbol_set1(t), - _ => TxType::from_symbol(t), - } - .ok_or_else(|| unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")))?; + tx_type = tx_type_from_symbol(len, t) + .ok_or_else(|| unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")))?; if rect_trace { eprintln!("EC_COEFF_STEP tag=tx_type plane=0 rng={}", dec.debug_state().0); } diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index 8172ec3e..0f89949c 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -247,6 +247,12 @@ const PROVEN: &[(&str, &str)] = &[ "an inter 16x16-level partition value outside NONE/HORZ/VERT/SPLIT/AB/1:4", "every_partition_value_of_an_if_chain_alphabet_is_named_by_a_branch", ), + // lane-t900 r24, enumeration: every (CDF width, symbol) pair a tx_type row + // can present maps to a distinct member of that width's own set. + ( + "a tx_type symbol outside its CDF's own set: {t}", + "every_tx_type_symbol_of_every_cdf_width_maps_into_its_own_set", + ), ( "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)", "a_twelve_bit_sequence_header_is_refused_by_name", @@ -668,6 +674,65 @@ mod tests { assert_eq!(found, chains.len()); } + /// Every `tx_type` symbol of every CDF width, mapped through the set that + /// width names. + /// + /// The reader decodes `t` from a row of `n` slots, so `t` is in + /// `0..n - 1`, and hands `(n, t)` to [`crate::decode::tx_type_from_symbol`] + /// -- the readers' own mapping, called here rather than transcribed + /// (class `shared-oracle-blindness`: a second copy of a table can be + /// self-consistently wrong). The widths are read from `cdf_state.rs`'s + /// `tx_type` field declarations, so a new table with a width the mapping + /// does not name fails this test rather than reaching the refusal at + /// runtime. + /// + /// Distinctness is part of the claim: a set of `n - 1` symbols must map to + /// `n - 1` DIFFERENT transform types, or the mapping has lost a member of + /// the spec's `Tx_Type_*_Inv_Set*` even while every symbol resolves. + #[test] + fn every_tx_type_symbol_of_every_cdf_width_maps_into_its_own_set() { + let mut widths: BTreeSet = BTreeSet::new(); + for line in include_str!("cdf_state.rs").lines() { + let t = line.trim(); + if !(t.starts_with("pub ") && t.contains("tx_type") && t.contains("[u16;")) { + continue; + } + let tail = t.rsplit("[u16;").next().unwrap_or(""); + let n: usize = tail + .split(']') + .next() + .unwrap_or("") + .trim() + .parse() + .unwrap_or_else(|_| panic!("cannot read a CDF width out of {t:?}")); + widths.insert(n); + } + assert!( + widths.len() >= 4, + "the cdf_state.rs scan found only {widths:?} -- it is broken, not the decoder" + ); + for &n in &widths { + let nsyms = n - 1; + let mut set: Vec = Vec::new(); + for t in 0..nsyms { + let ty = crate::decode::tx_type_from_symbol(n, t).unwrap_or_else(|| { + panic!( + "a {n}-slot tx_type CDF codes symbol {t}, which maps to no transform \ + type -- the refusal \"a tx_type symbol outside its CDF's own set\" is \ + reachable, and that is a mapping-table gap to fix" + ) + }); + assert!( + !set.contains(&ty), + "a {n}-slot tx_type CDF maps symbol {t} to {ty:?}, which another symbol of \ + the same set already names -- a member of the spec's inverse table is lost" + ); + set.push(ty); + } + assert_eq!(set.len(), nsyms); + } + } + /// Every entry of [`PROVEN`] must still name a live refusal and a test /// that exists, and the count it prints is the inventory's numerator. #[test]