Never crash: AV1 encoder without expect()/unreachable!()

Replaces the encoder's 11 expect()/unreachable!() calls on internal invariants with handling
that can't panic: the rate-control state is passed in rather than re-borrowed, inter decisions
without a reference frame fall back to intra, per-plane results are bound directly, and the
writer's impossible branches become debug_asserts. Denies the panic lints in the crate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Brandon Thomas
2026-10-04 13:22:59 -04:00
co-authored by Claude Opus 5.5
parent 10644a83aa
commit ee90d87742
5 changed files with 59 additions and 22 deletions
+5 -3
View File
@@ -211,7 +211,8 @@ impl<'a> TileWriter<'a> {
debug_assert_eq!(leaf.bsize, bsize);
self.block(r, c, leaf);
}
Node::Out => unreachable!("decided block inside the frame"),
// Blocks inside the frame are always decided; nothing is coded outside it.
Node::Out => debug_assert!(false, "undecided block inside the frame"),
}
}
@@ -460,10 +461,11 @@ impl<'a> TileWriter<'a> {
if set > 0 && self.qidx > 0 {
let sqr = TX_SIZE_SQR[tx_sz] as usize;
if b.is_inter {
let s = TX_TYPE_INTER_INV_SET3.iter().position(|&v| v as usize == t).expect("inter tx type in set");
// The decision only picks types of this set (DCT_DCT otherwise).
let s = TX_TYPE_INTER_INV_SET3.iter().position(|&v| v as usize == t).unwrap_or_default();
self.sw.symbol(s, &mut self.cdf.inter_tx_type_set3[sqr]);
} else {
let s = TX_TYPE_INTRA_INV_SET2.iter().position(|&v| v as usize == t).expect("intra tx type in set");
let s = TX_TYPE_INTRA_INV_SET2.iter().position(|&v| v as usize == t).unwrap_or_default();
self.sw.symbol(s, &mut self.cdf.intra_tx_type_set2[sqr][b.y_mode]);
}
} else {