Remove dead branches from the fast translation
Drop predicate operands and unreachable arms that dispatch and readable invariants fix, and extend the exhaustive sweep to cover every branch side. Gate coverage on branch coverage as well.
This commit is contained in:
1 parent
3bb5d062ff
commit
73e371fb40
4 files changed
+101
-172
No files matched your search
+17
-25
@@ -23,7 +23,7 @@ The Lean build is untouched.
|
||||
| `tests/fuzz_raw.cpp` | libFuzzer safety test on arbitrary instances under ASan/UBSan. |
|
||||
| `tests/bench.cpp` | nanobench literal-vs-fast benchmark. |
|
||||
| `run-fuzz.sh` | Rebuilds and runs both fuzzers for a fixed time. |
|
||||
| `run-coverage.sh` | Builds with Clang source-based coverage and requires 100% line coverage of `src/fast.cpp`. |
|
||||
| `run-coverage.sh` | Builds with Clang source-based coverage and requires 100% line and branch coverage of `src/fast.cpp`. |
|
||||
| `third_party/nanobench.h` | Vendored nanobench (commit `7252da9d96bd0d71f508e9b2813ab1f57fdfaec1`). |
|
||||
|
||||
## Data model
|
||||
@@ -92,7 +92,7 @@ cases that satisfy the readable sorting invariant:
|
||||
|
||||
`exhaustive_test` enumerates small readable instances instead of sampling them:
|
||||
every sorted database of up to four keys over a fixed universe of boundary
|
||||
keys, every selector key (including `⊥` and `⊤`) with offsets in `[-3, 4]`, and
|
||||
keys, every selector key (including `⊥` and `⊤`) with offsets in `[-3, 5]`, and
|
||||
every readable result (the complete traversal, each nonempty truncated prefix,
|
||||
or the empty result when the traversal is empty) in both directions:
|
||||
|
||||
@@ -110,34 +110,26 @@ It runs in about a second and is also the coverage driver.
|
||||
```
|
||||
|
||||
The script configures a Clang source-based-coverage build, runs
|
||||
`exhaustive_test`, and fails unless `src/fast.cpp` has 100% line coverage.
|
||||
`exhaustive_test` alone covers every line of the summarised implementation:
|
||||
`exhaustive_test`, and fails unless `src/fast.cpp` has 100% line and branch
|
||||
coverage. `exhaustive_test` alone covers every region, function, line, and
|
||||
branch side of the summarised implementation:
|
||||
|
||||
```text
|
||||
src/fast.cpp 836 regions (12 missed) 131 functions (0 missed) 773 lines (0 missed) 670 branches (125 missed)
|
||||
src/fast.cpp 570 regions (0 missed) 123 functions (0 missed) 684 lines (0 missed) 388 branches (0 missed)
|
||||
```
|
||||
|
||||
That is 100.00% line and function coverage, 98.56% region coverage, and 81.34%
|
||||
branch coverage. The missed branches are short-circuit operands: line coverage
|
||||
counts a condition as covered once any operand decides it, but branch coverage
|
||||
requires every operand to be the deciding one. Reaching 100% branch coverage
|
||||
would need inputs that force each redundant operand to disagree with the rest of
|
||||
its condition, which is not practical here.
|
||||
That is 100.00% line, function, region, and branch coverage. Offset 5 is part of
|
||||
the sweep specifically to exercise the last three short-circuit branch sides,
|
||||
which the previous `[-3, 4]` window missed.
|
||||
|
||||
Because equivalence is only promised on readable inputs, `src/fast.cpp` deletes
|
||||
*control-flow branches* that no readable input can take: the complete-closed
|
||||
family, the offset-one total/any wrappers and their `end.offset <= 1` shortcut,
|
||||
the `end.offset <= 1` shortcut in `completeForwardCrossedGeneral`, the
|
||||
`crossedCompleteEndLeOne` guard, and one `lastK < end.key` test that readability
|
||||
always satisfies.
|
||||
|
||||
The deletion criterion is deliberately limited to unreachable arms. An
|
||||
individual predicate operand that a dispatch invariant makes always true at one
|
||||
call site (for example `!c.r->reverse` inside a condition only reached after the
|
||||
forward branch was selected) is kept, because it is part of the Lean condition
|
||||
that the translation mirrors; re-proving the invariant at every site would make
|
||||
the tree harder to audit. Those operands are why every line is covered while branch coverage stays
|
||||
around 81%.
|
||||
both unreachable control-flow branches and predicate operands that an enclosing
|
||||
dispatch invariant fixes. Examples include the complete-closed family, the
|
||||
offset-one total/any wrappers, the `end.offset <= 1` shortcuts, the
|
||||
`crossedCompleteEndLeOne` guard, and the repeated
|
||||
`!c.r->reverse`/`!o.more`/offset tests inside subtrees that are only entered
|
||||
after those tests succeeded. `literal.cpp` keeps the full Lean conditions so the
|
||||
translation can still be audited line by line.
|
||||
|
||||
## Fuzzing
|
||||
|
||||
@@ -168,7 +160,7 @@ One representative validation run on this machine:
|
||||
| literal vs. Lean golden vectors | 40,000 | 0 mismatches (exact endpoints) |
|
||||
| fast vs. literal on sorted corpus | 18,971 | 0 mismatches |
|
||||
| extreme-offset regression (`extreme_test`) | 7,574 | 0 mismatches |
|
||||
| exhaustive readable sweep (`exhaustive_test`) | 10,562,068 | 0 mismatches |
|
||||
| exhaustive readable sweep (`exhaustive_test`) | 13,565,772 | 0 mismatches |
|
||||
| readable differential fuzzing (60 s) | 1,182,424 | 0 mismatches |
|
||||
| raw safety fuzzing (60 s) | 1,905,270 | no ASan/UBSan findings |
|
||||
|
||||
|
||||
Reference in new issue
Block a user