forge
Explore
Log in

Don't you dare go Hollow

gate_coverage: bind a hoisted `for (...,) in <name>` arm table

Browse files at this commit

db9b45e6e0dba0351584f1d4977d3f476181de99Ahmet Kaan GümüşParent: 6f07b44
Wave 3a integration. lane-av1txsearch landed
`print_tx_size_search_census`'s `unresolvable == 0` assertion, whose
stated purpose is to go red the moment a gate body builds the flag in a
shape the resolver cannot bind. lane-av1lossy128x96 then landed a gate
written exactly that way -- `for (label, search, want_mode, want_len,
want_fnv) in arms` with the arm table hoisted into `let arms` -- and the
assertion fired, as designed.

`bound_values` strategy (3) only understood an array spelled INLINE after
`in`. With a named collection it read past the `for` line to the next `[`
in the body, which is the gate's unrelated `&[..]` flag list, found no
digits, and returned an empty set. The gate's two arms were sitting
verbatim in the source the whole time.

New strategy (3b) follows the `for` line's collection name back to its
`let` binding and takes that column. Two details are load-bearing: the
word-boundary guard (`let arms_foo` must not answer for `let arms`), and
the `=` hop, because the binding's TYPE annotation is itself bracketed
(`[(&str, &str, TxMode, usize, u64); 2]`) -- scanning for the first `[`
after the name returns the type, not the table.

Red-before: with `merge(set)` replaced by `let _ = set;` the new case in
`the_resolver_binds_a_format_built_flag_in_both_directions` fails with
"the unmutated body should resolve to both values, got {}". Restored,
and the census reports the gate as `=0 and =1 (one arm each)` with
`unresolvable 0`.
crates/ec-av1/src/gate_coverage.rsmodified+93 -0
@@ -779,6 +779,87 @@ mod tests {
779 }779 }
780 }780 }
781 }781 }
782+ // (3b) `for (<var>, ...) in <ident>` where `<ident>` is a `let`
783+ // binding in this same body -- the arm table hoisted OUT of the
784+ // loop header, so the `for` line NAMES the array instead of
785+ // spelling it. Strategy (3) alone silently reads past the `for`
786+ // line to the next `[` in the body (an unrelated `&[..]` flag
787+ // list), finds no digits, and returns an empty set: the gate is
788+ // then filed as UNRESOLVED even though both of its arms sit
789+ // verbatim in the source. Measured: the 128x96 4:4:4 lossy
790+ // tx-size-search gate, whose `for (label, search, ...) in arms`
791+ // drove `print_tx_size_search_census`'s `unresolvable == 0`
792+ // assertion red on merge. The `=` hop matters: the binding's
793+ // TYPE annotation is itself bracketed
794+ // (`[(&str, &str, TxMode, usize, u64); 2]`), so scanning for the
795+ // first `[` after the name would return the type.
796+ // `<var>`'s column, read off the arm table a hoisted `for` line
797+ // NAMES rather than spells. Returns `None` unless the body really
798+ // has that shape, so an unrecognised loop is left to the other
799+ // strategies instead of being read as "no values".
800+ let named_column = |pos: usize| -> Option<BTreeSet<char>> {
801+ let at = body.find("for (")?;
802+ let head = &body[at..];
803+ let close = head.find(')')?;
804+ let after = head[close + 1..].trim_start().strip_prefix("in ")?;
805+ let name: &str = after
806+ .split(|c: char| !is_ident_byte(c as u8))
807+ .next()
808+ .filter(|n| !n.is_empty() && !n.starts_with(|c: char| c.is_ascii_digit()))?;
809+ let decl = body.find(&format!("let {name}"))?;
810+ let after_name = decl + "let ".len() + name.len();
811+ // `let arms_foo` must not answer for `let arms`.
812+ if body[after_name..]
813+ .chars()
814+ .next()
815+ .is_some_and(|c| is_ident_byte(c as u8))
816+ {
817+ return None;
818+ }
819+ // Hop the `=`: the binding's TYPE annotation is itself
820+ // bracketed, so the first `[` after the name is the type.
821+ let eq = after_name + body[after_name..].find('=')?;
822+ let open = eq + 1 + body[eq + 1..].find('[')?;
823+ let mut depth = 0i32;
824+ for (i, c) in body[open..].char_indices() {
825+ match c {
826+ '[' => depth += 1,
827+ ']' => {
828+ depth -= 1;
829+ if depth == 0 {
830+ let mut set: BTreeSet<char> = Default::default();
831+ for tuple in split_top(&body[open + 1..open + i]) {
832+ let Some(inner) =
833+ tuple.strip_prefix('(').and_then(|t| t.strip_suffix(')'))
834+ else {
835+ continue;
836+ };
837+ let fields = split_top(inner);
838+ let Some(field) = fields.get(pos) else {
839+ continue;
840+ };
841+ set.extend(bare_digits(field));
842+ set.extend(quoted_digits(field));
843+ }
844+ return Some(set);
845+ }
846+ }
847+ _ => {}
848+ }
849+ }
850+ None
851+ };
852+ if let Some(at) = body.find("for (") {
853+ let head = &body[at..];
854+ if let Some(close) = head.find(')') {
855+ let pattern = &head["for (".len()..close];
856+ if let Some(pos) = pattern.split(',').position(|p| p.trim() == var) {
857+ if let Some(set) = named_column(pos) {
858+ merge(set);
859+ }
860+ }
861+ }
862+ }
782 // (4) `u8::from(<a>.<field>)` over a struct-literal arm table.863 // (4) `u8::from(<a>.<field>)` over a struct-literal arm table.
783 for (i, _) in body.match_indices("u8::from(") {864 for (i, _) in body.match_indices("u8::from(") {
784 let arg = &body[i + "u8::from(".len()..];865 let arg = &body[i + "u8::from(".len()..];
@@ -1384,6 +1465,18 @@ mod tests {
1384 "for (tx_search, bit_depth) in [(\"0\", 8u8), (\"0\", 8u8), (\"0\", 10u8)]",1465 "for (tx_search, bit_depth) in [(\"0\", 8u8), (\"0\", 8u8), (\"0\", 10u8)]",
1385 "a_real_aomenc_stream_with_filter_intra_on_a_sub8_rect_leaf_decodes_pixel_exact",1466 "a_real_aomenc_stream_with_filter_intra_on_a_sub8_rect_leaf_decodes_pixel_exact",
1386 ),1467 ),
1468+ // The arm table hoisted OUT of the `for` line into a named
1469+ // `let` -- the shape lane-av1lossy128x96 writes, and the one
1470+ // that reads as UNRESOLVED unless the `for` line's collection
1471+ // name is followed back to its binding. Without this case a
1472+ // resolver that only understood inline arrays passes the
1473+ // three above and still cannot bind this gate.
1474+ (
1475+ "format!(\"--enable-tx-size-search={search}\")",
1476+ "\"tx size search on\",\n \"1\",",
1477+ "\"tx size search on\",\n \"0\",",
1478+ "a_real_aomenc_444_whole_64_root_tx_size_search_stream_decodes_pixel_exact_at_128x96",
1479+ ),
1387 ];1480 ];
1388 for (template, from, to, name) in cases {1481 for (template, from, to, name) in cases {
1389 let body = find(name);1482 let body = find(name);