forge
Explore
Log in

Don't you dare go Hollow

Merge lane/av1422rect4dead: close the unreachable 4:2:2 else arm

Browse files at this commit

dfe201ca4cfb649e157b746cab1f8e38132dfe98Ahmet Kaan GümüşParent: df788dec9f9b40
decode_rect4_16_intrabc's else arm still halved chroma as 4:2:0. The only
shape that reaches it at ss (1,0) is a VERT_4 4x16 strip, and both 16-level
dispatches refuse that shape before the call. Closed with an assertion, not
a comment. Reviewer PASS: one caller, both callers under the guard, the
assertion is not on the 4:2:0 or 4:4:4 path, the gate reds if the assertion
string is absent.
crates/ec-av1/src/decode.rsmodified+192 -0
@@ -18500,6 +18500,26 @@ fn decode_rect4_16_intrabc(
18500 let (cw, ch) = if own_chroma {18500 let (cw, ch) = if own_chroma {
18501 (bw >> ss_x(fctx), bh >> ss_y(fctx))18501 (bw >> ss_x(fctx), bh >> ss_y(fctx))
18502 } else {18502 } else {
18503+ // lane/av1422rect4dead: this arm is the 4:2:0 PAIR geometry, and at ss
18504+ // (1, 0) it cannot run. The sole caller is `decode_rect4_16_strip`,
18505+ // reached only through the two 16x16-level 1:4 arms; both sit under
18506+ // `refuse_invalid_subsize((16, 16), part16)`, and at ss (1, 0) that
18507+ // guard refuses exactly the shape that would land here:
18508+ // `partition_subsize_dims((16, 16), PARTITION_VERT_4) == (4, 16)`,
18509+ // which is in `PLANE_BLOCK_INVALID_422`. The surviving 16x4 HORZ_4
18510+ // strip takes `own422` above, not this arm. At ss (1, 1) the arm is
18511+ // live and correct (the pair IS the geometry), and at ss (0, 0)
18512+ // `own444` already won, so this assert never fires there. The
18513+ // assertion is the closure the repo rule asks for; the census test
18514+ // `decode_rect4_16_intrabc_else_arm_stays_closed_at_422` below reds if
18515+ // either this assert or its guard chain is removed.
18516+ assert!(
18517+ !(ss_x(fctx) == 1 && ss_y(fctx) == 0),
18518+ "decode_rect4_16_intrabc else arm entered at ss (1, 0) with a 4x16 \
18519+ VERT_4 strip: (4, 16) is BLOCK_INVALID at 4:2:2 and the 16x16-level \
18520+ refuse_invalid_subsize above both callers must have refused this \
18521+ before the dispatch -- the closure is gone"
18522+ );
18503 (pw / 2, ph / 2)18523 (pw / 2, ph / 2)
18504 };18524 };
18505 let pair_mi = if has_chroma {18525 let pair_mi = if has_chroma {
@@ -58728,6 +58748,178 @@ mod tests {
58728 }58748 }
58729 }58749 }
58730 58750
58751+ /// lane/av1422rect4dead: the `(pw / 2, ph / 2)` / `MI / 2` origin `else`
58752+ /// arm of [`decode_rect4_16_intrabc`] is the 4:2:0 PAIR geometry. It is
58753+ /// still LIVE at ss (1, 1) -- a 1:4 strip's chroma lies inside its
58754+ /// 4:2:0 pair there -- so the arm is not deleted; it is CLOSED at ss
58755+ /// (1, 0), where it would run on a 4x16 VERT_4 strip whose chroma plane
58756+ /// block is BLOCK_INVALID, and where libaom's own
58757+ /// `is_chroma_reference` (av1_common_int.h:1454, `|| !subsampling_y`)
58758+ /// makes every strip its own chroma reference anyway (the `own422` arm
58759+ /// handles that). The proof: the sole caller `decode_rect4_16_strip` is
58760+ /// reached only via the two 16x16-level 1:4 arms, each under
58761+ /// `refuse_invalid_subsize((16, 16), part16)` -- at ss (1, 0) that guard
58762+ /// refuses `partition_subsize_dims((16, 16), PARTITION_VERT_4) == (4, 16)`
58763+ /// (in `PLANE_BLOCK_INVALID_422`), and the surviving HORZ_4 16x4 strip
58764+ /// takes `own422`. This test re-derives that chain from the file so it
58765+ /// REDS when any half stops holding: deleting the in-arm assertion, a
58766+ /// caller moving under a level whose guard does not refuse (4, 16) at
58767+ /// ss (1, 0), or the `(pw / 2, ph / 2)` form drifting. 4:2:0 and 4:4:4
58768+ /// behaviour are unchanged: the gate runs only the file scan and the
58769+ /// closed cell's arithmetic, no decode.
58770+ #[test]
58771+ fn decode_rect4_16_intrabc_else_arm_stays_closed_at_422() {
58772+ let src = include_str!("decode.rs");
58773+ let decode_body = match src.find("\n#[cfg(test)]\nmod tests {") {
58774+ Some(i) => &src[..i],
58775+ None => src,
58776+ };
58777+
58778+ // (a) The closure assertion must exist INSIDE the function, in the
58779+ // `else` arm of the `(cw, ch)` select, naming the shape and the
58780+ // subsampling. Deleting it -- or re-adding the bare halving without
58781+ // it -- reds here.
58782+ let fstart = decode_body
58783+ .find("\nfn decode_rect4_16_intrabc(")
58784+ .expect("decode_rect4_16_intrabc is gone -- this gate guards its else arm");
58785+ let fend = ["\nfn ", "\npub fn ", "\npub(crate) fn "]
58786+ .iter()
58787+ .filter_map(|pat| decode_body[fstart + 1..].find(pat).map(|i| fstart + 1 + i))
58788+ .min()
58789+ .unwrap_or(decode_body.len());
58790+ let body = &decode_body[fstart..fend];
58791+ let else_arm = body
58792+ .find(" let (cw, ch) = if own_chroma {")
58793+ .expect("the (cw, ch) select moved out of decode_rect4_16_intrabc");
58794+ let closure = &body[else_arm..];
58795+ assert!(
58796+ closure.contains("assert!(") && closure.contains("ss_x(fctx) == 1 && ss_y(fctx) == 0"),
58797+ "the decode_rect4_16_intrabc else arm's ss (1, 0) closure assertion is \
58798+ GONE -- the 4:2:0 pair geometry is unreachable at ss (1, 0) only while \
58799+ that assert (and the guards below) stand; re-add it"
58800+ );
58801+
58802+ // (b) The sole-caller chain, re-derived from the file: exactly one
58803+ // call to `decode_rect4_16_intrabc(` outside its own definition, in
58804+ // `decode_rect4_16_strip`; exactly two calls to
58805+ // `decode_rect4_16_strip(` from the two 1:4 routes.
58806+ let code_lines: String = decode_body
58807+ .lines()
58808+ .filter(|l| !l.trim_start().starts_with("//"))
58809+ .collect::<Vec<_>>()
58810+ .join("\n");
58811+ let count_calls = |name: &str| -> usize {
58812+ code_lines.matches(&format!("{name}(")).count()
58813+ - usize::from(code_lines.contains(&format!("fn {name}(")))
58814+ };
58815+ assert_eq!(
58816+ count_calls("decode_rect4_16_intrabc"),
58817+ 1,
58818+ "decode_rect4_16_intrabc gained a caller -- re-derive whether the new route \
58819+ sits under a guard that refuses (4, 16) at ss (1, 0) before this gate \
58820+ stays green"
58821+ );
58822+ assert_eq!(
58823+ count_calls("decode_rect4_16_strip"),
58824+ 2,
58825+ "decode_rect4_16_strip's caller set moved -- both routes must be \
58826+ 16x16-level 1:4 arms under a (16, 16) guard that refuses (4, 16) at \
58827+ ss (1, 0)"
58828+ );
58829+
58830+ // (c) Both routes sit under a `refuse_invalid_subsize((16, 16), ...)`:
58831+ // the key-frame arm's guard ordered above the arm test, the inter
58832+ // arm's guard in the inter decoder above its own 1:4 test. Scoped to
58833+ // the enclosing function so the other decoder's guard cannot stand in
58834+ // (the r2 class this file already fixed once).
58835+ let fn_scope = |at: usize| -> std::ops::Range<usize> {
58836+ let head = ["\nfn ", "\npub fn ", "\npub(crate) fn "]
58837+ .iter()
58838+ .filter_map(|pat| decode_body[..at].rfind(pat))
58839+ .max()
58840+ .unwrap_or(0);
58841+ let tail = ["\nfn ", "\npub fn ", "\npub(crate) fn "]
58842+ .iter()
58843+ .filter_map(|pat| decode_body[at..].find(pat).map(|i| at + i))
58844+ .min()
58845+ .unwrap_or(decode_body.len());
58846+ head..tail
58847+ };
58848+ let kf_test = decode_body
58849+ .find("if part16 == PARTITION_HORZ_4")
58850+ .expect("the key-frame 16-level 1:4 arm test is gone");
58851+ let kf_scope = fn_scope(kf_test);
58852+ let kf_guard = decode_body[kf_scope.clone()]
58853+ .find("refuse_invalid_subsize((16, 16)")
58854+ .map(|i| kf_scope.start + i)
58855+ .unwrap_or_else(|| {
58856+ panic!(
58857+ "the key-frame 16-level 1:4 arm has NO \
58858+ refuse_invalid_subsize((16, 16)) above it in its own \
58859+ function -- the VERT_4 (4, 16) refusal that closed \
58860+ decode_rect4_16_intrabc's else arm at ss (1, 0) is gone"
58861+ )
58862+ });
58863+ assert!(
58864+ kf_guard < kf_test,
58865+ "the key-frame (16, 16) guard sits below the 1:4 arm test -- it can never \
58866+ observe the VERT_4 symbol that must be refused before \
58867+ decode_rect4_16_intrabc's else arm can run at ss (1, 0)"
58868+ );
58869+ let inter_writer = decode_body
58870+ .find("let horz = part16 == PARTITION_HORZ_4;")
58871+ .expect("the inter 16-level 1:4 arm is gone");
58872+ let inter_scope = fn_scope(inter_writer);
58873+ let inter_guard = decode_body[inter_scope.clone()]
58874+ .find("refuse_invalid_subsize((16, 16)")
58875+ .map(|i| inter_scope.start + i)
58876+ .unwrap_or_else(|| {
58877+ panic!(
58878+ "the inter-frame 16-level 1:4 arm has NO \
58879+ refuse_invalid_subsize((16, 16)) in its function -- the VERT_4 \
58880+ (4, 16) refusal that closed decode_rect4_16_intrabc's else arm \
58881+ at ss (1, 0) is gone"
58882+ )
58883+ });
58884+ assert!(
58885+ inter_guard < inter_writer,
58886+ "the inter (16, 16) guard sits below the 1:4 arm test -- it can never \
58887+ observe the VERT_4 symbol that must be refused before \
58888+ decode_rect4_16_intrabc's else arm can run at ss (1, 0)"
58889+ );
58890+
58891+ // (d) The shape/subsampling cells the closure is written against,
58892+ // re-executed: (4, 16) must still be BLOCK_INVALID at ss (1, 0) while
58893+ // (16, 4) stays codable there, and at ss (1, 1) BOTH are codable --
58894+ // which is what keeps the arm live at 4:2:0 and the assertion inert
58895+ // there. At ss (0, 0) everything is codable, so `own444` (and the
58896+ // assertion) never see the else arm.
58897+ assert!(
58898+ !chroma_plane_block_codable(4, 16, 1, 0),
58899+ "(4, 16) left PLANE_BLOCK_INVALID_422 -- the else arm is now REACHABLE at \
58900+ ss (1, 0) with the halved pair geometry, which is a real defect, not a \
58901+ closure: re-derive the whole chain, then fix the halving instead of the \
58902+ assert"
58903+ );
58904+ assert!(
58905+ chroma_plane_block_codable(16, 4, 1, 0),
58906+ "(16, 4) became BLOCK_INVALID at ss (1, 0) -- the surviving HORZ_4 strip \
58907+ takes own422, and the closure assert would fire on a legal shape; \
58908+ re-derive"
58909+ );
58910+ assert!(
58911+ chroma_plane_block_codable(4, 16, 1, 1) && chroma_plane_block_codable(16, 4, 1, 1),
58912+ "a 1:4 strip's plane block moved at ss (1, 1) -- the else arm is LIVE there \
58913+ and the pair geometry is what decodes it; the assertion must stay inert at \
58914+ 4:2:0"
58915+ );
58916+ assert!(
58917+ chroma_plane_block_codable(4, 16, 0, 0) && chroma_plane_block_codable(16, 4, 0, 0),
58918+ "a 1:4 strip's plane block became invalid at ss (0, 0) -- the assertion sits \
58919+ after the own444 arm and must never fire at 4:4:4; re-derive"
58920+ );
58921+ }
58922+
58731 /// lane-av1chrtx: [`covering_leaf_tx_type`] resolves a chroma unit's58923 /// lane-av1chrtx: [`covering_leaf_tx_type`] resolves a chroma unit's
58732 /// `tx_type` from the luma leaf covering the unit's OWN quadrant, and58924 /// `tx_type` from the luma leaf covering the unit's OWN quadrant, and
58733 /// reports "no leaf there" as `None` so the caller can fall back to the58925 /// reports "no leaf there" as `None` so the caller can fall back to the
lanes/av1422rect4dead.report.mdadded+91 -0
@@ -0,0 +1,91 @@
1+# lane/av1422rect4dead — `decode_rect4_16_intrabc` `else` arm at ss (1,0)
2+
3+Branch of main `c38dd788ec4fc12e0b5d616f6c9773d7f849bb89`. Lane commit
4+`3a7f31c9`. Primary stayed on `main` throughout; nothing pushed, nothing merged.
5+
6+## Verdict
7+
8+UNREACHABLE at ss (1,0) — closed with an assertion, per the repo rule. The
9+arm is LIVE at ss (1,1) and inert at ss (0,0); behaviour at both is unchanged
10+(no decode-path edit, no halving rewrite).
11+
12+## The arm (re-read on main, unchanged in the worktree)
13+
14+`decode.rs` `decode_rect4_16_intrabc`, the `else` of the `(cw, ch)` select
15+(was 18500–18504) and the origin select (was 18516–18524):
16+
17+- `!own_chroma` ⇒ `(pw / 2, ph / 2)` with `(pw, ph)` = (16,8)/(8,16) → (8,4)/(4,8)
18+- `!own_chroma` ⇒ origin `(pair_mi.1 * MI / 2, pair_mi.0 * MI / 2)`
19+- `own_chroma = own444 || own422`, `own422 = ss_x==1 && ss_y==0 && horz`
20+
21+So at ss (1,0) the arm runs only with `!horz`, i.e. the (4,16) VERT_4 strip.
22+
23+## Reachability, re-derived from the guard's own predicate (not inherited)
24+
25+1. Sole caller: `decode_rect4_16_intrabc(` appears exactly once as a call in
26+ the decode body (`decode_rect4_16_strip`, 19100 on main). Crate-wide grep
27+ over `crates/**.rs`: only that site plus a doc mention in stream.rs.
28+2. `decode_rect4_16_strip(` has exactly two callers: `decode_rect4_16`
29+ (17746) and `decode_intra_rect_in_inter` (13951).
30+3. `decode_rect4_16` is dispatched only from the key-frame 16-level 1:4 arm
31+ (37569), inside `if part16 == PARTITION_HORZ_4 || part16 == PARTITION_VERT_4`
32+ (37555), BELOW `refuse_invalid_subsize((16, 16), part16)` (37248).
33+4. `decode_intra_rect_in_inter` reaches `decode_rect4_16_strip` only through
34+ `strip16` (46277), built from `fctx.inter_strip_chroma` (42346) whose ONLY
35+ writer is the inter 16-level 1:4 arm (56021), inside
36+ `part16 == PARTITION_HORZ_4 || part16 == PARTITION_VERT_4` (55939), BELOW
37+ `refuse_invalid_subsize((16, 16), part16)` (55705).
38+5. The guard's own predicate: `partition_subsize_dims((16,16), PARTITION_VERT_4)
39+ == (4,16)` and `(4,16) ∈ PLANE_BLOCK_INVALID_422` ⇒
40+ `chroma_plane_block_codable(4, 16, 1, 0) == false` ⇒ the guard errs before
41+ either dispatch. HORZ_4 gives (16,4), legal at (1,0) — and that strip takes
42+ `own422`, never the else arm.
43+
44+Per-format disposition:
45+
46+- ss (1,0): the only shape that could enter the arm is refused one level up;
47+ the arm is dead. The dispatch itself can never be reached with VERT_4.
48+- ss (1,1): both 1:4 subsizes are codable; the arm is live and correct (4:2:0
49+ pair geometry).
50+- ss (0,0): `own444` wins the select; the arm is unreachable by construction.
51+
52+## Change
53+
54+- `decode_rect4_16_intrabc` `else` arm: added
55+ `assert!(!(ss_x(fctx) == 1 && ss_y(fctx) == 0), ...)` naming the (4,16)
56+ VERT_4 shape and the ss (1,0) subsampling, above the unchanged
57+ `(pw / 2, ph / 2)` halving. Fires only if the closure breaks; cannot fire
58+ at ss (1,1) (condition false) or ss (0,0) (`own444` selected first).
59+- New gate `decode::tests::decode_rect4_16_intrabc_else_arm_stays_closed_at_422`:
60+ (a) the assertion must exist inside the function's `(cw, ch)` else arm and
61+ name `ss_x(fctx) == 1 && ss_y(fctx) == 0`; (b) caller counts re-derived
62+ (1 and 2); (c) both routes' `refuse_invalid_subsize((16, 16)` ordered above
63+ their 1:4 arm tests, scoped per enclosing function; (d) the closed cell's
64+ arithmetic re-executed — (4,16) invalid at (1,0), (16,4) codable at (1,0),
65+ both codable at (1,1) and (0,0).
66+
67+`decode_intrabc_owned_rect` untouched (other lane's function).
68+
69+## Non-vacuity (mutation-proof, red-before)
70+
71+| Mutation | Gate |
72+|---|---|
73+| M1: delete the in-arm assertion | FAILED (expected) |
74+| M2: delete key-frame 16-level guard (37248) | FAILED (expected) |
75+| M3: delete inter 16-level guard (55705) | FAILED (expected) |
76+
77+Worktree restored clean after each; committed tree is the unmuted one.
78+
79+## Checks
80+
81+- `cargo check -p ec-av1`: clean (one pre-existing `pin_reporting` dead-code
82+ warning, present on main).
83+- Scoped test: gate PASSES (1 passed). Pre-existing census test
84+ `every_chroma_walking_leaf_dispatch_is_guarded_or_closed_with_a_reason`
85+ still PASSES. No full suite per charter.
86+
87+## Item 5 disposition
88+
89+`lanes/av1floorshift.report.md` item 5: CLOSED by construction (assertion),
90+not merely by the guard one level up — the guard chain is now checked by the
91+gate, and the arm self-reports if it is ever entered at ss (1,0).