forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB00c1b3fTahinli2 months ago1999 commits

refusal_inventory.rs578 lines, 30.5 KiBHistoryRawDownload
1//! An inventory of what this decoder refuses, and a check on the claims those
2//! refusals make.
3//!
4//! Two rules this repository keeps learning the hard way:
5//!
6//! 1. A refusal string is a **claim**. "This encoder never writes one" asserts
7//! that a real encoder cannot emit the case -- and one such string was
8//! disproved by the very gate that carried it (the wedge-interintra hang,
9//! 2026-08-30): the refusal was written from a mismatching frame's header
10//! state, so it named a correlate rather than the defect. Any refusal
11//! phrased as a capability claim about the ENCODER, rather than about this
12//! decoder, needs evidence, and this module makes the set of such strings
13//! explicit instead of letting it grow quietly.
14//! 2. Refusals accumulate silently. A lane that adds one to unblock itself is
15//! doing the right thing (refuse by name rather than desync), but the total
16//! is the distance to a decoder that handles a default-settings stream, and
17//! nobody sees a total that nothing prints.
18//!
19//! So the test below re-derives every `unsupported(...)` reason reachable on
20//! the decode path -- `decode.rs` and `stream.rs` -- and pins it. Adding or
21//! removing a refusal fails until the list is updated, which is the point: the
22//! diff of this file is the decoder's capability delta, in one place, in
23//! English.
24
25#[cfg(test)]
26const CAPABILITY_CLAIMS: &[&str] = &[
27 "filter intra on a superblock-level HORZ/VERT strip (never expected -- av1_filter_intra_allowed_bsize caps at 32x32)",
28];
29
30#[cfg(test)]
31const REFUSALS: &[&str] = &[
32 "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here",
33 "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)",
34 "an OBMC neighbour whose switchable interp filter was never recorded",
35 "a sub-8x8 inter block under a scaled reference (superres, unimplemented)",
36 "a rectangular inter luma transform unit whose shape has no coefficient table set here",
37 "a rectangular inter chroma transform unit whose shape has no coefficient table set here",
38 "a rectangular transform unit whose shape has no coefficient scan table here",
39 "a 32x32 partition type this decoder does not code (value={part32})",
40 "a Golomb tail longer than this decoder reads",
41 "a tx_type symbol outside its CDF's own set: {t}",
42 "an INTER 32x32 partition type this decoder does not code (value={part32})",
43 "a superblock-level partition value outside PARTITION_NONE..PARTITION_VERT_4",
44 "a 128x128 superblock partition value outside the 8-symbol alphabet",
45 "an inter var-tx tree with a leaf transform larger than 64x64",
46 "CfL, filter intra or a palette on a 128-root HORZ/VERT intra block (every one of their size gates caps at 64x64 or below, so none of these symbols exists there)",
47 "intrabc under a 128x128 superblock (libaom's av1_is_dv_valid derives the block-vector delay from sb_size, which this decoder hardcodes to 64)",
48 "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)",
49 // lane-t900 r23: palette RECONSTRUCTION now covers the key-frame paths
50 // (earlier lanes), the intra-in-inter square/rect paths (r22) and the
51 // 8x8 LEAF inside an inter frame (this round, gate
52 // `a_screen_stream_with_palette_8x8_leaves_in_inter_frames_decodes_pixel_exact`),
53 // which is why the (UV) string is gone from the decoder entirely -- the
54 // leaf was its only site. The (Y) one survives ONLY as the defensive
55 // `palette.is_none()` guard in `read_intra_mode`/`read_intra_mode_rect`;
56 // every caller now passes a real ctx/cache pair, so no stream reaches it.
57 "a block that actually uses a palette (Y) -- reconstruction is out of scope",
58 "intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)",
59 "a sub-8x8 leaf that uses intrabc (this reader has no block-vector path; the 8x8-and-up reader reconstructs one)",
60 "an intrabc block under TxMode::Select (its transform size is coded by the inter var-tx partition tree, which this decoder never reads)",
61 "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)",
62 "a frame OBU with no tile group",
63 "a frame naming primary_ref_frame at a reference slot with no saved CDF state",
64 "a frame with no mode-info grid",
65 "a frame whose segmentation enables SEG_LVL_REF_FRAME/SKIP/GLOBALMV (this decoder reads segment_id but never lets a segment override a block's reference, skip or mode)",
66 // Still live, but NARROWED: lane-rectres r1 added the 32x32-level 1:4
67 // strips (32x8 / 8x32) to `rect_inter_residual_supported` -- THE shape both
68 // 10-bit 3840x1608 film cuts and every measured 1080p offset stopped on
69 // (gate `a_real_aomenc_inter_sequence_with_32x32_level_1to4_strips_codes_\
70 // their_rect_residual`). The string stays because the shapes below 8x8 and
71 // the AB-partition footprints still have no rectangular residual path.
72 "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding",
73 "a reference frame selected with no picture at this frame's own ref_frame_idx slot for it",
74 "a reference picture whose height does not match this frame's own true size",
75 "a show_existing_frame header naming an empty reference slot",
76 "an inter var-tx tree with a leaf transform larger than 32x32",
77 // lane-intrainter r1 lifted the >=16x16 square case (per-TU intra
78 // prediction + coefficients, gate
79 // `a_real_aomenc_inter_sequence_with_a_split_transform_intra_block_decodes_pixel_exact`);
80 // lane-leaf8tx r4 lifted the 8x8 leaf's TX_4X4 2x2 grid (gate
81 // `a_real_aomenc_inter_sequence_with_an_angle_delta_8x8_intra_leaf_decodes_pixel_exact`).
82 "an inter frame with no key frame before it",
83 // lane-inter16ab r1 lifted the AB half and r2 the 1:4 half (four 16x4 /
84 // 4x16 inter strips, their 8x4/4x8 chroma pair built from BOTH strips'
85 // motion vectors -- gate
86 // `a_real_aomenc_inter_sequence_with_16x16_level_1to4_partitions_decodes_pixel_exact`).
87 // Two narrower refusals are what is left of that shape:
88 "an inter 16x16-level partition value outside NONE/HORZ/VERT/SPLIT/AB/1:4",
89 // r2 residue: `vartx_leaves` is a list of SQUARE units, and
90 // `sub_tx_size_map[TX_16X4]` is the rectangular TX_8X4 -- the split tree
91 // and its per-unit residual reader both need rect leaves.
92 // r2 residue: `decode_intra_rect_in_inter` codes chroma at the strip's own
93 // halved footprint, which for a 16x4 strip is an 8x2 transform libaom
94 // never wrote (its chroma is the PAIR's 8x4, coded by the odd strip).
95 // lane-sub8x4 r3 narrowed this to "a strip with no chroma-pair record";
96 // lane-wit16x4 r1 put it back at FULL width (r3's witness counters were
97 // phantoms of a desync, class `refusal-lifted-without-a-gate`) behind
98 // an opt-in. lane-t900 r6 NARROWED it again -- the opt-in is
99 // gone -- on a real 10-bit 1920x792 128-superblock film witness that
100 // decodes 14/14 decode-order frames exact vs aomdec and 12/12 shown frames
101 // exact vs ffmpeg while the arm fires 78 16x4 + 149 4x16 (108 chroma-
102 // paired): gate
103 // `a_10bit_128sb_film_frames_with_warp_cdef_and_interintra_decode_pixel_exact`.
104 // What still refuses is a 16x4/4x16 strip with NO chroma-pair record and
105 // every other sub-8 shape.
106 "an intra 16x4/4x16 strip inside an inter 16x16-level 1:4 partition (its 4:2:0 chroma pair is coded once for two strips; only the inter path implements that pairing)",
107 "an intra mode this decoder does not code (round 2)",
108 // lane-intrarect r1 lifted the whole-shape refusal that stood here (the
109 // inter path's intra arm now routes 2:1 strips through `decode_rect_split`);
110 // what is left is the 1:4 shape, whose `bsize_to_tx_size_cat` breaks the
111 // size-group/category diagonal the 2:1 shapes share.
112 "an intra-coded {bw}x{bh} block on the inter block path (no size-group/tx-category row for that shape here)",
113 // lane-t900 r21 NARROWED this: the string used to guard EVERY rect intra
114 // strip of a screen-content inter frame, and a real
115 // `--tune-content=screen` stream reached it on an 8x16 (8-bit) / 16x8
116 // (10-bit) strip. The 2:1 reader now codes the palette syntax itself and
117 // the 1:4 arm goes through `read_intra_mode_rect`, which already did --
118 // both arms of gate
119 // `a_real_aomenc_screen_inter_sequence_codes_palette_syntax_on_rect_intra_strips`
120 // decode ten frames pixel-exact with the strips counted. What still
121 // lane-t900 r22 NARROWED it again: the 16x4/4x16 arm is LIFTED (that arm
122 // routes through `decode_rect4_16_strip`, which reads the palette syntax
123 // itself -- the premise was stale), gated by
124 // `a_screen_stream_with_16x4_intra_strips_in_inter_frames_decodes_pixel_exact`.
125 // What still refuses is the 128-root half of a screen-content frame, whose
126 // body (`decode_block_128rect`) reads no palette syntax and for which no
127 // `--sb-size=128` screen witness exists yet.
128 // lane-t900 r23 CENSUS for this string's remaining 128-root arm (the
129 // 16x4/4x16 arm was lifted in r22): its premise is already known to be
130 // false by the spec -- `read_palette_mode_info` (5.11.46) codes palette
131 // only for `Block_Width <= 64 && Block_Height <= 64`, so a 128x64/64x128
132 // half consumes NO palette syntax and the screen flag changes nothing
133 // about it. It stays because nothing witnesses it: 6 aomenc encodes at
134 // `--sb-size=128 --tune-content=screen` (704x320 = 5*128+64 by 2*128+64,
135 // the edge-forced size r18 proved for the non-screen twin; screen cell
136 // content at cq 10/20/40, and r18's own panning-texture-plus-fresh-ramp
137 // shape with `--max-partition-size=128 --enable-ab-partitions=0
138 // --enable-1to4-partitions=0`) code ZERO 128-root halves of any kind
139 // (`intra128_in_inter` and `sb128_rect` both 0 in every stream), so
140 // lifting it would be a capability claim no gate exercises (class
141 // `refusal-lifted-without-a-gate`). What is still untried: a 10-bit
142 // source, and screen content in the forced bands with a NON-screen
143 // interior.
144 "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)",
145 "warp prediction with a scaled reference (superres, unimplemented)",
146 "an 8x8 partition leaf under a scaled reference (superres, unimplemented)",
147 "a motion_mode symbol for a block shape with no CDF row here",
148];
149
150/// The refusals that have a PROVING test, and its name.
151///
152/// A refusal with no such test is an unmeasured claim: nothing in the suite
153/// distinguishes "this case never happens" from "no stream we decode has
154/// reached it yet". A proving test is one of two shapes:
155///
156/// * a WITNESS gate -- a real stream reaches the shape, decodes exact, and the
157/// refusal is gone (the good case), or
158/// * a CENSUS gate -- N real streams decode with the refusal firing 0 times
159/// while the counters for the sibling shapes it names fire, so the claim is
160/// measured against the domain the decoder is actually handed.
161///
162/// The count printed by [`tests::every_proven_refusal_names_a_test_that_exists`]
163/// is the honest numerator over the inventory below.
164#[cfg(test)]
165const PROVEN: &[(&str, &str)] = &[
166 // lane-t900 r20, census: three real streams present exactly the 18
167 // `(side, write_w, write_h)` triples `INTER_BLOCK_SHAPES` lists, and
168 // `rect_inter_residual_supported` covers every rectangular one -- the only
169 // footprints `reject_residual` is set for.
170 (
171 "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding",
172 "a_block_shape_census_over_three_real_streams_leaves_the_rect_residual_refusal_unreachable",
173 ),
174 // lane-t900 r20, census: the shapes that can reach `decode_intra_rect_in_inter`'s
175 // size-group/tx-category lookup are the ten rectangular census shapes with
176 // `8 <= min` and `max <= 64` (a sub-8 footprint and a 128-px one take
177 // earlier branches), and every one of them has a row.
178 (
179 "an intra-coded {bw}x{bh} block on the inter block path (no size-group/tx-category row for that shape here)",
180 "every_intra_in_inter_shape_the_census_lists_has_a_size_group_row",
181 ),
182 // lane-t900 r20, census: the only sub-8 footprints three real streams
183 // present are the 16x4/4x16 strips of a 16x16-level 1:4 partition, whose
184 // caller records the chroma pair for every strip, while the supported path
185 // fires on both orientations inside streams that decode with no refusal.
186 (
187 "an intra 16x4/4x16 strip inside an inter 16x16-level 1:4 partition (its 4:2:0 chroma pair is coded once for two strips; only the inter path implements that pairing)",
188 "a_sub8_footprint_census_over_real_streams_leaves_the_intra_16x4_pairing_refusal_unreachable",
189 ),
190 // lane-t900 r20, census: the rect transform tables and scans, enumerated
191 // over the shapes the measured block-shape domain hands each helper (block
192 // footprint, 4:2:0 chroma unit, rect var-tx leaf, clamped coded corner).
193 (
194 "a rectangular inter luma transform unit whose shape has no coefficient table set here",
195 "every_rect_transform_shape_the_census_lists_has_a_coefficient_table_and_scan",
196 ),
197 (
198 "a rectangular inter chroma transform unit whose shape has no coefficient table set here",
199 "every_rect_transform_shape_the_census_lists_has_a_coefficient_table_and_scan",
200 ),
201 (
202 "a rectangular transform unit whose shape has no coefficient scan table here",
203 "every_rect_transform_shape_the_census_lists_has_a_coefficient_table_and_scan",
204 ),
205 // lane-t900 r21, enumeration: a var-tx leaf is never larger than the unit
206 // the tree was entered with, and both callers enter at or below their own
207 // ceiling (the one case that does not, a 64px block at TX_64X64, is the
208 // `single` whole-block case the refusal is guarded by).
209 (
210 "an inter var-tx tree with a leaf transform larger than 32x32",
211 "a_var_tx_tree_never_presents_a_leaf_larger_than_the_unit_it_entered",
212 ),
213 (
214 "an inter var-tx tree with a leaf transform larger than 64x64",
215 "a_var_tx_tree_never_presents_a_leaf_larger_than_the_unit_it_entered",
216 ),
217 // Pre-existing proofs, registered by lane-t900 r21: a negative gate (a
218 // hand-built 12-bit sequence header is refused BY THIS EXACT STRING rather
219 // than decoded wrong) and a witness gate (a real aomenc screen key frame
220 // reaches intrabc on a rect strip, so the refusal names a shape a real
221 // encoder does write).
222 // lane-t900 r21, enumeration: `partition_w32` is a ten-symbol CDF and
223 // `partition_w128` an eight-symbol one, and every `match` carrying one of
224 // these three fallbacks has an arm for each value of its own alphabet, so
225 // no stream can reach them.
226 (
227 "a 32x32 partition type this decoder does not code (value={part32})",
228 "every_partition_value_of_an_enumerated_alphabet_has_an_arm",
229 ),
230 (
231 "an INTER 32x32 partition type this decoder does not code (value={part32})",
232 "every_partition_value_of_an_enumerated_alphabet_has_an_arm",
233 ),
234 (
235 "a 128x128 superblock partition value outside the 8-symbol alphabet",
236 "every_partition_value_of_an_enumerated_alphabet_has_an_arm",
237 ),
238 // lane-t900 r24, enumeration: the key-frame superblock root's own `match`
239 // has an arm for all ten `partition_w64` values.
240 (
241 "a superblock-level partition value outside PARTITION_NONE..PARTITION_VERT_4",
242 "every_partition_value_of_an_enumerated_alphabet_has_an_arm",
243 ),
244 (
245 "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)",
246 "a_twelve_bit_sequence_header_is_refused_by_name",
247 ),
248 (
249 "intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)",
250 "a_real_aomenc_screen_key_frame_reads_use_intrabc_on_rect_strips",
251 ),
252];
253
254/// Gates whose `Err` arm turns a decode failure into a printed SKIP rather than
255/// a test failure.
256///
257/// A gate named `..._decodes_pixel_exact` that cannot decode has failed, and
258/// swallowing the error keeps the suite green while the gate proves nothing --
259/// the same vacuum as a gate whose feature never fires, arrived at from the
260/// other side. These four predate the attempt-loop pattern the newer gates use
261/// (encode several fixtures, require at least one to decode, hard-assert the
262/// firing count). They are pinned here so the set cannot grow while they are
263/// converted one at a time.
264#[cfg(test)]
265const GATES_THAT_SKIP_ON_A_DECODE_ERROR: &[&str] = &[
266 "a_real_aomenc_filter_intra_stream_decodes_pixel_exact",
267 "a_real_aomenc_inter_sequence_with_deblocking_decodes_pixel_exact",
268 "a_real_aomenc_intra_stream_with_deblocking_decodes_pixel_exact",
269 "a_real_libaom_gradients_stream_with_cdef_decodes_pixel_exact",
270];
271
272#[cfg(test)]
273mod tests {
274 use super::{CAPABILITY_CLAIMS, GATES_THAT_SKIP_ON_A_DECODE_ERROR, PROVEN, REFUSALS};
275 use std::collections::BTreeSet;
276
277 /// Every distinct `unsupported(...)` reason on the decode path.
278 ///
279 /// Both sources use the same shape -- `stream.rs` calls
280 /// `Error::unsupported(context, reason)` and `decode.rs` a local
281 /// `unsupported(reason)` helper -- so the reason is always the LAST string
282 /// literal of the call, and Rust's `\` line continuations inside it are
283 /// joined the way rustc joins them.
284 fn decode_path_refusals() -> BTreeSet<String> {
285 let mut found = BTreeSet::new();
286 for src in [include_str!("decode.rs"), include_str!("stream.rs")] {
287 let bytes = src.as_bytes();
288 for (start, _) in src.match_indices("unsupported(") {
289 // `Error::unsupported(` and the bare helper both end here.
290 let mut i = start + "unsupported(".len();
291 // `unsupported(format!("..."))` is the same refusal, one layer in.
292 if src[i..].starts_with("format!(") {
293 i += "format!(".len();
294 }
295 let mut last: Option<String> = None;
296 loop {
297 while i < bytes.len() && (bytes[i] as char).is_whitespace() {
298 i += 1;
299 }
300 if i >= bytes.len() || bytes[i] != b'"' {
301 break;
302 }
303 i += 1;
304 let mut lit = String::new();
305 while i < bytes.len() && bytes[i] != b'"' {
306 if bytes[i] == b'\\' {
307 // A backslash-newline continuation drops the newline
308 // and the indentation that follows it.
309 if bytes.get(i + 1) == Some(&b'\n') {
310 i += 2;
311 while i < bytes.len() && matches!(bytes[i], b' ' | b'\t') {
312 i += 1;
313 }
314 continue;
315 }
316 lit.push(bytes[i] as char);
317 lit.push(bytes[i + 1] as char);
318 i += 2;
319 continue;
320 }
321 lit.push(bytes[i] as char);
322 i += 1;
323 }
324 i += 1;
325 last = Some(lit);
326 while i < bytes.len() && (bytes[i] as char).is_whitespace() {
327 i += 1;
328 }
329 if i < bytes.len() && bytes[i] == b',' {
330 i += 1;
331 continue;
332 }
333 break;
334 }
335 if let Some(reason) = last {
336 // `Error::unsupported`'s first argument is the context
337 // ("AV1 tile"), which is not a reason.
338 if reason != "AV1 tile" {
339 found.insert(reason);
340 }
341 }
342 }
343 }
344 found
345 }
346
347 #[test]
348 fn the_decode_path_refuses_exactly_the_listed_cases() {
349 let found = decode_path_refusals();
350 let listed: BTreeSet<String> = CAPABILITY_CLAIMS
351 .iter()
352 .chain(REFUSALS)
353 .map(|&s| s.to_owned())
354 .collect();
355 assert!(found.len() >= 30, "the refusal scan found only {} reasons -- it is broken, not the decoder", found.len());
356
357 let added: Vec<&String> = found.difference(&listed).collect();
358 assert!(
359 added.is_empty(),
360 "new decode-path refusals are not in the inventory: {added:#?}\n\
361 Add each to REFUSALS -- or, if it claims something about what an ENCODER can \
362 emit, to CAPABILITY_CLAIMS, which requires evidence that the case is genuinely \
363 unreachable rather than merely unseen."
364 );
365 let removed: Vec<&String> = listed.difference(&found).collect();
366 assert!(
367 removed.is_empty(),
368 "these refusals are listed but no longer in the decode path: {removed:#?}\n\
369 Delete them from the inventory -- the capability landed, which is the good case."
370 );
371 }
372
373 /// A refusal may say what THIS DECODER does not do. Saying what an encoder
374 /// never emits is a claim about the world, and this repository has already
375 /// shipped one that was false.
376 #[test]
377 fn capability_claims_are_declared_not_scattered() {
378 let claimy: Vec<String> = decode_path_refusals()
379 .into_iter()
380 .filter(|r| r.contains("never writes") || r.contains("never expected"))
381 .collect();
382 let declared: BTreeSet<&str> = CAPABILITY_CLAIMS.iter().copied().collect();
383 for reason in &claimy {
384 assert!(
385 declared.contains(reason.as_str()),
386 "{reason:?} claims an encoder never emits this case but is not in \
387 CAPABILITY_CLAIMS. Such a claim needs a gate that proves the case is \
388 unreachable; until it has one, phrase the refusal as what this decoder \
389 does not decode."
390 );
391 }
392 }
393
394 /// No NEW gate may quietly turn a decode error into a skip.
395 #[test]
396 fn gates_that_swallow_a_decode_error_are_declared() {
397 let src = include_str!("stream.rs");
398 let mut found: BTreeSet<String> = BTreeSet::new();
399 for (i, _) in src.match_indices("\"SKIP ") {
400 let rest = &src[i + "\"SKIP ".len()..];
401 let Some(colon) = rest.find(':') else { continue };
402 let name = &rest[..colon];
403 if !name.chars().all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '_') {
404 continue;
405 }
406 // The tail of the message says what was skipped. Only "{e}" -- the
407 // decode error itself -- is the shape this test is about; "no
408 // ffmpeg"/"no aomenc" are tool absence, governed by
409 // EC_AV1_REQUIRE_AOMENC instead.
410 let Some(end) = rest.find("\"") else { continue };
411 if rest[colon..end].contains("{e}") {
412 found.insert(name.to_owned());
413 }
414 }
415 let listed: BTreeSet<&str> = GATES_THAT_SKIP_ON_A_DECODE_ERROR.iter().copied().collect();
416 let added: Vec<&String> = found.iter().filter(|n| !listed.contains(n.as_str())).collect();
417 assert!(
418 added.is_empty(),
419 "these gates turn a decode error into a printed SKIP and are not declared: \
420 {added:#?}\nA gate that cannot decode has failed -- assert on the error, or use \
421 the attempt-loop pattern (several fixtures, at least one must decode, firing count \
422 hard-asserted)."
423 );
424 let stale: Vec<&&str> = listed.iter().filter(|n| !found.contains(**n)).collect();
425 assert!(
426 stale.is_empty(),
427 "{stale:#?} no longer swallow a decode error -- delete them from the list."
428 );
429 }
430
431 /// The partition alphabets, enumerated against the arms that code them.
432 ///
433 /// A partition value is a CDF symbol, and `SymbolDecoder::symbol_fixed`
434 /// cannot return one outside `0..nsyms` -- so a `match` whose arms cover
435 /// its whole alphabet has an unreachable fallback, and the refusal that
436 /// fallback carries names a value no stream can present. This test finds
437 /// each such `match` by the refusal in its OWN fallback arm (rather than
438 /// by line number, which drifts) and enumerates the alphabet against the
439 /// arm patterns, ranges included.
440 ///
441 /// The refusals stay in the code: a partition value is a `usize`, so the
442 /// match needs a fallback arm, and a named refusal is a better one than a
443 /// panic (class `branch-dropped-as-unreachable`). What this removes is the
444 /// UNMEASURED part of the claim.
445 ///
446 /// Not every partition fallback belongs here: the ones that name a shape
447 /// this decoder genuinely does not code yet (the 128-root consumers) are
448 /// live refusals, and the 16x16-level inter chain is an `if`/`else if`
449 /// ladder rather than a match, so it needs its own enumerator.
450 #[test]
451 fn every_partition_value_of_an_enumerated_alphabet_has_an_arm() {
452 const NAMES: [&str; 10] = [
453 "PARTITION_NONE",
454 "PARTITION_HORZ",
455 "PARTITION_VERT",
456 "PARTITION_SPLIT",
457 "PARTITION_HORZ_A",
458 "PARTITION_HORZ_B",
459 "PARTITION_VERT_A",
460 "PARTITION_VERT_B",
461 "PARTITION_HORZ_4",
462 "PARTITION_VERT_4",
463 ];
464 // (the refusal in the fallback arm, the alphabet its CDF codes)
465 let blocks: [(&str, usize); 4] = [
466 ("a 32x32 partition type this decoder does not code", crate::cdf::PARTITION_W32[0].len() - 1),
467 ("an INTER 32x32 partition type this decoder does not code", crate::cdf::PARTITION_W32[0].len() - 1),
468 ("a 128x128 superblock partition value outside the 8-symbol alphabet", crate::cdf::PARTITION_W128[0].len() - 1),
469 // lane-t900 r24: the key-frame superblock root. Its `part` is
470 // either a `partition_w64` symbol or, at a frame edge, one of the
471 // three gathered outcomes (PARTITION_HORZ, PARTITION_VERT,
472 // PARTITION_SPLIT) -- all inside the same ten-value alphabet.
473 (
474 "a superblock-level partition value outside PARTITION_NONE..PARTITION_VERT_4",
475 crate::cdf::PARTITION_W64[0].len() - 1,
476 ),
477 ];
478 // A pattern's own tokens, plus every value of an inclusive range
479 // (`p if (PARTITION_HORZ_A..=PARTITION_VERT_B).contains(&p)` is four
480 // arms in one).
481 let covered = |head: &str| -> BTreeSet<usize> {
482 let mut out = BTreeSet::new();
483 let idx: Vec<usize> = head
484 .split(|c: char| !(c.is_ascii_alphanumeric() || c == '_'))
485 .filter_map(|tok| NAMES.iter().position(|n| *n == tok))
486 .collect();
487 if head.contains("..=") && idx.len() == 2 {
488 for v in idx[0]..=idx[1] {
489 out.insert(v);
490 }
491 }
492 out.extend(idx);
493 out
494 };
495
496 let src = include_str!("decode.rs");
497 let lines: Vec<&str> = src.lines().collect();
498 let indent = |l: &str| l.len() - l.trim_start().len();
499 let mut found = 0usize;
500 for (i, line) in lines.iter().enumerate() {
501 let t = line.trim();
502 if !(t.starts_with("match part") && t.ends_with('{')) {
503 continue;
504 }
505 let outer = indent(line);
506 let close = " ".repeat(outer) + "}";
507 let (mut arms, mut fallback) = (BTreeSet::new(), String::new());
508 let mut in_fallback = false;
509 for l in &lines[i + 1..] {
510 if *l == close {
511 break;
512 }
513 // Arm patterns sit exactly one level in; anything deeper is an
514 // arm's body, nested matches and `part == PARTITION_*` reads
515 // included.
516 if indent(l) != outer + 4 && !l.trim().is_empty() {
517 if in_fallback {
518 fallback.push_str(l.trim());
519 }
520 continue;
521 }
522 if !l.contains("=>") {
523 continue;
524 }
525 in_fallback = l.trim_start().starts_with("_ =>");
526 arms.extend(covered(l.split("=>").next().unwrap_or("")));
527 }
528 let Some((reason, alphabet)) =
529 blocks.iter().find(|(reason, _)| fallback.contains(reason))
530 else {
531 continue;
532 };
533 found += 1;
534 let missing: Vec<usize> = (0..*alphabet).filter(|v| !arms.contains(v)).collect();
535 assert!(
536 missing.is_empty(),
537 "the `match` at decode.rs:{} refuses {reason:?} but has no arm for {:?} -- that \
538 is a real gap in its {alphabet}-value alphabet, not a dead refusal",
539 i + 1,
540 missing.iter().map(|v| NAMES[*v]).collect::<Vec<_>>()
541 );
542 }
543 assert_eq!(
544 found,
545 blocks.len(),
546 "not every enumerated partition refusal was located in decode.rs"
547 );
548 }
549
550 /// Every entry of [`PROVEN`] must still name a live refusal and a test
551 /// that exists, and the count it prints is the inventory's numerator.
552 #[test]
553 fn every_proven_refusal_names_a_test_that_exists() {
554 let found = decode_path_refusals();
555 let sources = [
556 include_str!("stream.rs"),
557 include_str!("decode.rs"),
558 include_str!("refusal_inventory.rs"),
559 ];
560 for (reason, gate) in PROVEN {
561 assert!(
562 found.contains(*reason),
563 "{reason:?} is listed as proven but is no longer a decode-path refusal -- drop it from PROVEN (the capability landed) or fix the string"
564 );
565 assert!(
566 sources.iter().any(|src| src.contains(&format!("fn {gate}("))),
567 "{reason:?} names the proving test {gate}, which exists in neither stream.rs \
568 nor decode.rs"
569 );
570 }
571 eprintln!(
572 "refusal inventory: {} refusals + {} capability claims, {} proven",
573 REFUSALS.len(),
574 CAPABILITY_CLAIMS.len(),
575 PROVEN.len()
576 );
577 }
578}