diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 9d88207b..5cb864f5 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -18500,6 +18500,26 @@ fn decode_rect4_16_intrabc( let (cw, ch) = if own_chroma { (bw >> ss_x(fctx), bh >> ss_y(fctx)) } else { + // lane/av1422rect4dead: this arm is the 4:2:0 PAIR geometry, and at ss + // (1, 0) it cannot run. The sole caller is `decode_rect4_16_strip`, + // reached only through the two 16x16-level 1:4 arms; both sit under + // `refuse_invalid_subsize((16, 16), part16)`, and at ss (1, 0) that + // guard refuses exactly the shape that would land here: + // `partition_subsize_dims((16, 16), PARTITION_VERT_4) == (4, 16)`, + // which is in `PLANE_BLOCK_INVALID_422`. The surviving 16x4 HORZ_4 + // strip takes `own422` above, not this arm. At ss (1, 1) the arm is + // live and correct (the pair IS the geometry), and at ss (0, 0) + // `own444` already won, so this assert never fires there. The + // assertion is the closure the repo rule asks for; the census test + // `decode_rect4_16_intrabc_else_arm_stays_closed_at_422` below reds if + // either this assert or its guard chain is removed. + assert!( + !(ss_x(fctx) == 1 && ss_y(fctx) == 0), + "decode_rect4_16_intrabc else arm entered at ss (1, 0) with a 4x16 \ + VERT_4 strip: (4, 16) is BLOCK_INVALID at 4:2:2 and the 16x16-level \ + refuse_invalid_subsize above both callers must have refused this \ + before the dispatch -- the closure is gone" + ); (pw / 2, ph / 2) }; let pair_mi = if has_chroma { @@ -58728,6 +58748,178 @@ mod tests { } } + /// lane/av1422rect4dead: the `(pw / 2, ph / 2)` / `MI / 2` origin `else` + /// arm of [`decode_rect4_16_intrabc`] is the 4:2:0 PAIR geometry. It is + /// still LIVE at ss (1, 1) -- a 1:4 strip's chroma lies inside its + /// 4:2:0 pair there -- so the arm is not deleted; it is CLOSED at ss + /// (1, 0), where it would run on a 4x16 VERT_4 strip whose chroma plane + /// block is BLOCK_INVALID, and where libaom's own + /// `is_chroma_reference` (av1_common_int.h:1454, `|| !subsampling_y`) + /// makes every strip its own chroma reference anyway (the `own422` arm + /// handles that). The proof: the sole caller `decode_rect4_16_strip` is + /// reached only via the two 16x16-level 1:4 arms, each under + /// `refuse_invalid_subsize((16, 16), part16)` -- at ss (1, 0) that guard + /// refuses `partition_subsize_dims((16, 16), PARTITION_VERT_4) == (4, 16)` + /// (in `PLANE_BLOCK_INVALID_422`), and the surviving HORZ_4 16x4 strip + /// takes `own422`. This test re-derives that chain from the file so it + /// REDS when any half stops holding: deleting the in-arm assertion, a + /// caller moving under a level whose guard does not refuse (4, 16) at + /// ss (1, 0), or the `(pw / 2, ph / 2)` form drifting. 4:2:0 and 4:4:4 + /// behaviour are unchanged: the gate runs only the file scan and the + /// closed cell's arithmetic, no decode. + #[test] + fn decode_rect4_16_intrabc_else_arm_stays_closed_at_422() { + let src = include_str!("decode.rs"); + let decode_body = match src.find("\n#[cfg(test)]\nmod tests {") { + Some(i) => &src[..i], + None => src, + }; + + // (a) The closure assertion must exist INSIDE the function, in the + // `else` arm of the `(cw, ch)` select, naming the shape and the + // subsampling. Deleting it -- or re-adding the bare halving without + // it -- reds here. + let fstart = decode_body + .find("\nfn decode_rect4_16_intrabc(") + .expect("decode_rect4_16_intrabc is gone -- this gate guards its else arm"); + let fend = ["\nfn ", "\npub fn ", "\npub(crate) fn "] + .iter() + .filter_map(|pat| decode_body[fstart + 1..].find(pat).map(|i| fstart + 1 + i)) + .min() + .unwrap_or(decode_body.len()); + let body = &decode_body[fstart..fend]; + let else_arm = body + .find(" let (cw, ch) = if own_chroma {") + .expect("the (cw, ch) select moved out of decode_rect4_16_intrabc"); + let closure = &body[else_arm..]; + assert!( + closure.contains("assert!(") && closure.contains("ss_x(fctx) == 1 && ss_y(fctx) == 0"), + "the decode_rect4_16_intrabc else arm's ss (1, 0) closure assertion is \ + GONE -- the 4:2:0 pair geometry is unreachable at ss (1, 0) only while \ + that assert (and the guards below) stand; re-add it" + ); + + // (b) The sole-caller chain, re-derived from the file: exactly one + // call to `decode_rect4_16_intrabc(` outside its own definition, in + // `decode_rect4_16_strip`; exactly two calls to + // `decode_rect4_16_strip(` from the two 1:4 routes. + let code_lines: String = decode_body + .lines() + .filter(|l| !l.trim_start().starts_with("//")) + .collect::>() + .join("\n"); + let count_calls = |name: &str| -> usize { + code_lines.matches(&format!("{name}(")).count() + - usize::from(code_lines.contains(&format!("fn {name}("))) + }; + assert_eq!( + count_calls("decode_rect4_16_intrabc"), + 1, + "decode_rect4_16_intrabc gained a caller -- re-derive whether the new route \ + sits under a guard that refuses (4, 16) at ss (1, 0) before this gate \ + stays green" + ); + assert_eq!( + count_calls("decode_rect4_16_strip"), + 2, + "decode_rect4_16_strip's caller set moved -- both routes must be \ + 16x16-level 1:4 arms under a (16, 16) guard that refuses (4, 16) at \ + ss (1, 0)" + ); + + // (c) Both routes sit under a `refuse_invalid_subsize((16, 16), ...)`: + // the key-frame arm's guard ordered above the arm test, the inter + // arm's guard in the inter decoder above its own 1:4 test. Scoped to + // the enclosing function so the other decoder's guard cannot stand in + // (the r2 class this file already fixed once). + let fn_scope = |at: usize| -> std::ops::Range { + let head = ["\nfn ", "\npub fn ", "\npub(crate) fn "] + .iter() + .filter_map(|pat| decode_body[..at].rfind(pat)) + .max() + .unwrap_or(0); + let tail = ["\nfn ", "\npub fn ", "\npub(crate) fn "] + .iter() + .filter_map(|pat| decode_body[at..].find(pat).map(|i| at + i)) + .min() + .unwrap_or(decode_body.len()); + head..tail + }; + let kf_test = decode_body + .find("if part16 == PARTITION_HORZ_4") + .expect("the key-frame 16-level 1:4 arm test is gone"); + let kf_scope = fn_scope(kf_test); + let kf_guard = decode_body[kf_scope.clone()] + .find("refuse_invalid_subsize((16, 16)") + .map(|i| kf_scope.start + i) + .unwrap_or_else(|| { + panic!( + "the key-frame 16-level 1:4 arm has NO \ + refuse_invalid_subsize((16, 16)) above it in its own \ + function -- the VERT_4 (4, 16) refusal that closed \ + decode_rect4_16_intrabc's else arm at ss (1, 0) is gone" + ) + }); + assert!( + kf_guard < kf_test, + "the key-frame (16, 16) guard sits below the 1:4 arm test -- it can never \ + observe the VERT_4 symbol that must be refused before \ + decode_rect4_16_intrabc's else arm can run at ss (1, 0)" + ); + let inter_writer = decode_body + .find("let horz = part16 == PARTITION_HORZ_4;") + .expect("the inter 16-level 1:4 arm is gone"); + let inter_scope = fn_scope(inter_writer); + let inter_guard = decode_body[inter_scope.clone()] + .find("refuse_invalid_subsize((16, 16)") + .map(|i| inter_scope.start + i) + .unwrap_or_else(|| { + panic!( + "the inter-frame 16-level 1:4 arm has NO \ + refuse_invalid_subsize((16, 16)) in its function -- the VERT_4 \ + (4, 16) refusal that closed decode_rect4_16_intrabc's else arm \ + at ss (1, 0) is gone" + ) + }); + assert!( + inter_guard < inter_writer, + "the inter (16, 16) guard sits below the 1:4 arm test -- it can never \ + observe the VERT_4 symbol that must be refused before \ + decode_rect4_16_intrabc's else arm can run at ss (1, 0)" + ); + + // (d) The shape/subsampling cells the closure is written against, + // re-executed: (4, 16) must still be BLOCK_INVALID at ss (1, 0) while + // (16, 4) stays codable there, and at ss (1, 1) BOTH are codable -- + // which is what keeps the arm live at 4:2:0 and the assertion inert + // there. At ss (0, 0) everything is codable, so `own444` (and the + // assertion) never see the else arm. + assert!( + !chroma_plane_block_codable(4, 16, 1, 0), + "(4, 16) left PLANE_BLOCK_INVALID_422 -- the else arm is now REACHABLE at \ + ss (1, 0) with the halved pair geometry, which is a real defect, not a \ + closure: re-derive the whole chain, then fix the halving instead of the \ + assert" + ); + assert!( + chroma_plane_block_codable(16, 4, 1, 0), + "(16, 4) became BLOCK_INVALID at ss (1, 0) -- the surviving HORZ_4 strip \ + takes own422, and the closure assert would fire on a legal shape; \ + re-derive" + ); + assert!( + chroma_plane_block_codable(4, 16, 1, 1) && chroma_plane_block_codable(16, 4, 1, 1), + "a 1:4 strip's plane block moved at ss (1, 1) -- the else arm is LIVE there \ + and the pair geometry is what decodes it; the assertion must stay inert at \ + 4:2:0" + ); + assert!( + chroma_plane_block_codable(4, 16, 0, 0) && chroma_plane_block_codable(16, 4, 0, 0), + "a 1:4 strip's plane block became invalid at ss (0, 0) -- the assertion sits \ + after the own444 arm and must never fire at 4:4:4; re-derive" + ); + } + /// lane-av1chrtx: [`covering_leaf_tx_type`] resolves a chroma unit's /// `tx_type` from the luma leaf covering the unit's OWN quadrant, and /// reports "no leaf there" as `None` so the caller can fall back to the diff --git a/lanes/av1422rect4dead.report.md b/lanes/av1422rect4dead.report.md new file mode 100644 index 00000000..d792e332 --- /dev/null +++ b/lanes/av1422rect4dead.report.md @@ -0,0 +1,91 @@ +# lane/av1422rect4dead — `decode_rect4_16_intrabc` `else` arm at ss (1,0) + +Branch of main `c38dd788ec4fc12e0b5d616f6c9773d7f849bb89`. Lane commit +`3a7f31c9`. Primary stayed on `main` throughout; nothing pushed, nothing merged. + +## Verdict + +UNREACHABLE at ss (1,0) — closed with an assertion, per the repo rule. The +arm is LIVE at ss (1,1) and inert at ss (0,0); behaviour at both is unchanged +(no decode-path edit, no halving rewrite). + +## The arm (re-read on main, unchanged in the worktree) + +`decode.rs` `decode_rect4_16_intrabc`, the `else` of the `(cw, ch)` select +(was 18500–18504) and the origin select (was 18516–18524): + +- `!own_chroma` ⇒ `(pw / 2, ph / 2)` with `(pw, ph)` = (16,8)/(8,16) → (8,4)/(4,8) +- `!own_chroma` ⇒ origin `(pair_mi.1 * MI / 2, pair_mi.0 * MI / 2)` +- `own_chroma = own444 || own422`, `own422 = ss_x==1 && ss_y==0 && horz` + +So at ss (1,0) the arm runs only with `!horz`, i.e. the (4,16) VERT_4 strip. + +## Reachability, re-derived from the guard's own predicate (not inherited) + +1. Sole caller: `decode_rect4_16_intrabc(` appears exactly once as a call in + the decode body (`decode_rect4_16_strip`, 19100 on main). Crate-wide grep + over `crates/**.rs`: only that site plus a doc mention in stream.rs. +2. `decode_rect4_16_strip(` has exactly two callers: `decode_rect4_16` + (17746) and `decode_intra_rect_in_inter` (13951). +3. `decode_rect4_16` is dispatched only from the key-frame 16-level 1:4 arm + (37569), inside `if part16 == PARTITION_HORZ_4 || part16 == PARTITION_VERT_4` + (37555), BELOW `refuse_invalid_subsize((16, 16), part16)` (37248). +4. `decode_intra_rect_in_inter` reaches `decode_rect4_16_strip` only through + `strip16` (46277), built from `fctx.inter_strip_chroma` (42346) whose ONLY + writer is the inter 16-level 1:4 arm (56021), inside + `part16 == PARTITION_HORZ_4 || part16 == PARTITION_VERT_4` (55939), BELOW + `refuse_invalid_subsize((16, 16), part16)` (55705). +5. The guard's own predicate: `partition_subsize_dims((16,16), PARTITION_VERT_4) + == (4,16)` and `(4,16) ∈ PLANE_BLOCK_INVALID_422` ⇒ + `chroma_plane_block_codable(4, 16, 1, 0) == false` ⇒ the guard errs before + either dispatch. HORZ_4 gives (16,4), legal at (1,0) — and that strip takes + `own422`, never the else arm. + +Per-format disposition: + +- ss (1,0): the only shape that could enter the arm is refused one level up; + the arm is dead. The dispatch itself can never be reached with VERT_4. +- ss (1,1): both 1:4 subsizes are codable; the arm is live and correct (4:2:0 + pair geometry). +- ss (0,0): `own444` wins the select; the arm is unreachable by construction. + +## Change + +- `decode_rect4_16_intrabc` `else` arm: added + `assert!(!(ss_x(fctx) == 1 && ss_y(fctx) == 0), ...)` naming the (4,16) + VERT_4 shape and the ss (1,0) subsampling, above the unchanged + `(pw / 2, ph / 2)` halving. Fires only if the closure breaks; cannot fire + at ss (1,1) (condition false) or ss (0,0) (`own444` selected first). +- New gate `decode::tests::decode_rect4_16_intrabc_else_arm_stays_closed_at_422`: + (a) the assertion must exist inside the function's `(cw, ch)` else arm and + name `ss_x(fctx) == 1 && ss_y(fctx) == 0`; (b) caller counts re-derived + (1 and 2); (c) both routes' `refuse_invalid_subsize((16, 16)` ordered above + their 1:4 arm tests, scoped per enclosing function; (d) the closed cell's + arithmetic re-executed — (4,16) invalid at (1,0), (16,4) codable at (1,0), + both codable at (1,1) and (0,0). + +`decode_intrabc_owned_rect` untouched (other lane's function). + +## Non-vacuity (mutation-proof, red-before) + +| Mutation | Gate | +|---|---| +| M1: delete the in-arm assertion | FAILED (expected) | +| M2: delete key-frame 16-level guard (37248) | FAILED (expected) | +| M3: delete inter 16-level guard (55705) | FAILED (expected) | + +Worktree restored clean after each; committed tree is the unmuted one. + +## Checks + +- `cargo check -p ec-av1`: clean (one pre-existing `pin_reporting` dead-code + warning, present on main). +- Scoped test: gate PASSES (1 passed). Pre-existing census test + `every_chroma_walking_leaf_dispatch_is_guarded_or_closed_with_a_reason` + still PASSES. No full suite per charter. + +## Item 5 disposition + +`lanes/av1floorshift.report.md` item 5: CLOSED by construction (assertion), +not merely by the guard one level up — the guard chain is now checked by the +gate, and the arm self-reports if it is ever entered at ss (1,0).