diff --git a/cpp/README.md b/cpp/README.md index 0d36cc3..7a1d2d1 100644 --- a/cpp/README.md +++ b/cpp/README.md @@ -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 | diff --git a/cpp/run-coverage.sh b/cpp/run-coverage.sh index de573d4..3d7ee39 100755 --- a/cpp/run-coverage.sh +++ b/cpp/run-coverage.sh @@ -1,7 +1,8 @@ #!/usr/bin/env bash -# Build with Clang source-based coverage and require 100% line coverage of the -# summarised implementation (`src/fast.cpp`). `exhaustive_test` enumerates -# small readable instances deterministically and is sufficient on its own. +# Build with Clang source-based coverage and require 100% line and branch +# coverage of the summarised implementation (`src/fast.cpp`). `exhaustive_test` +# enumerates small readable instances deterministically and is sufficient on its +# own. set -euo pipefail here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" @@ -39,8 +40,13 @@ report() { output="$(report)" printf '%s\n' "$output" line_cover="$(printf '%s\n' "$output" | awk '/fast\.cpp/ { print $10 }')" +branch_cover="$(printf '%s\n' "$output" | awk '/fast\.cpp/ { print $13 }')" if [[ "$line_cover" != "100.00%" ]]; then echo "fast.cpp line coverage is $line_cover, expected 100.00%" >&2 exit 1 fi -echo "fast.cpp: 100.00% line coverage" +if [[ "$branch_cover" != "100.00%" ]]; then + echo "fast.cpp branch coverage is $branch_cover, expected 100.00%" >&2 + exit 1 +fi +echo "fast.cpp: 100.00% line and branch coverage" diff --git a/cpp/src/fast.cpp b/cpp/src/fast.cpp index 9a114cd..ea1d697 100644 --- a/cpp/src/fast.cpp +++ b/cpp/src/fast.cpp @@ -4,14 +4,14 @@ // `literal.cpp` mirrors the Lean definition line by line and therefore rescans // `res.keys` (and re-derives small arithmetic facts) on almost every branch. // This version summarises the reported keys once (two binary searches on the -// sorted traversal order) and caches the handful of interval cardinalities the -// decision tree needs, then replays the same tree for readable inputs. Branches -// that the `Readable` invariant makes unreachable are omitted. Reversed results -// are handled through a `reversed` view instead of copying the key list. +// sorted traversal order), then replays the same tree for readable inputs. +// Branches and predicate operands that the `Readable` invariant or a dispatch +// invariant makes unreachable/constant are omitted; `literal.cpp` keeps the +// full Lean conditions for audit. Reversed results are handled through a +// `reversed` view instead of copying the key list. #include "fast.h" #include -#include #include namespace cr::fast { @@ -34,14 +34,10 @@ struct Obs { bool ascending = true; std::size_t n = 0; - const KeyView& firstK() const { - assert(!keys.empty()); - return reversed ? keys.back() : keys.front(); - } - const KeyView& lastK() const { - assert(!keys.empty()); - return reversed ? keys.front() : keys.back(); - } + // `closedForm` handles an empty result before building the tree, so `keys` is + // non-empty everywhere these are called. + const KeyView& firstK() const { return reversed ? keys.back() : keys.front(); } + const KeyView& lastK() const { return reversed ? keys.front() : keys.back(); } }; // Facts that only depend on the read and on the *multiset* of reported keys. @@ -51,27 +47,15 @@ struct Ctx { std::size_t n = 0; std::size_t below = 0; // number of reported keys < begin.key std::size_t t = 0; // number of reported keys >= end.key - // Lazily computed interval cardinalities. - mutable bool haveBE = false; - mutable bool haveEB = false; - mutable NatInf be; - mutable NatInf eb; }; NatInf cardBE(const Ctx& c) { - if (!c.haveBE) { - c.be = intervalCard(c.r->begin.key, c.r->end_.key); - c.haveBE = true; - } - return c.be; + return intervalCard(c.r->begin.key, c.r->end_.key); } +// Each path consults this at most once, so it needs no cache. NatInf cardEB(const Ctx& c) { - if (!c.haveEB) { - c.eb = intervalCard(c.r->end_.key, c.r->begin.key); - c.haveEB = true; - } - return c.eb; + return intervalCard(c.r->end_.key, c.r->begin.key); } NatInf cardKO(KeyView b, OptKeyView e) { @@ -132,10 +116,6 @@ Ctx makeCtx(const RangeRead& r, const Obs& o) { // Comparisons that avoid allocating a one-element `OptKey` // --------------------------------------------------------------------------- -// ↑k < b -bool kLtO(KeyView k, OptKeyView b) { return !b || keyLt(k, *b); } -// ↑k <= b -bool kLeO(KeyView k, OptKeyView b) { return !b || !keyLt(*b, k); } // a < ↑k bool oLtK(OptKeyView a, KeyView k) { return a.has_value() && keyLt(*a, k); } // a <= ↑k @@ -149,7 +129,6 @@ std::uint64_t rB(const Ctx& c) { return residualB(*c.r); } std::uint64_t npd(const Ctx& c) { return clampNonposD(*c.r); } bool allBelowEnd(const Ctx& c) { return c.t == 0; } -bool anyAtOrAboveEnd(const Ctx& c) { return c.t != 0; } const KeyView& leastReportedK(const Ctx& c, const Obs& o) { return c.r->reverse ? o.lastK() : o.firstK(); @@ -205,13 +184,16 @@ bool clampNonposBottom(const Ctx& c) { return niLe(lhs, NatInf::of(bSlack(c))); } +// The caller reaches this only after `begin.offset >= 1` failed, so the offset +// half of the condition is already known. bool clampedNonpos(const Ctx& c, const Obs& o) { - return c.r->begin.offset <= 0 && oLeK(c.r->begin.key, leastReportedK(c, o)); + return oLeK(c.r->begin.key, leastReportedK(c, o)); } -bool clampsToBottom(const Ctx& c, const Obs& o) { - return c.r->begin.offset <= 0 && oLeK(c.r->begin.key, o.firstK()); -} +// Called from the positive branch: if `begin.offset <= 0` then the entry +// dispatch already established `clampedNonpos`, i.e. the selector key is at or +// before the first reported key, so only the offset decides here. +bool clampsToBottom(const Ctx& c) { return c.r->begin.offset <= 0; } std::uint64_t cELo(Int oB, Int oE) { return std::max(toNat(2 - oE), toNat(oB - oE + 1)); @@ -253,43 +235,34 @@ OptKeyView crossedBegin(const Ctx& c) { struct Impl { // ----- crossed complete -------------------------------------------------- + // The complete-crossed subtree is entered only with `!reverse` and `!more` + // (`closedFormCrossed` normalises a reversed complete read first). Within it, + // `crossedCompleteBeginZero` has already claimed every `begin.offset == 0` + // case before these clamp nodes are tried, so `begin.offset < 0` holds here. bool negCrossClampEndOne(const Ctx& c, const Obs& o) const { - return !c.r->reverse && c.r->begin.offset < 0 && !o.more && - c.r->end_.offset == 1 && kLtO(o.firstK(), c.r->begin.key) && - c.below <= bSlack(c); + // `crossedCompleteEndLeOne` already failed, and for `end.offset == 1` it + // fails exactly when `bSlack >= below`. + return c.r->end_.offset == 1; } bool negCrossHeadBottom(const Ctx& c, const Obs& o) const { - return !c.r->reverse && c.r->begin.offset < 0 && !o.more && - c.r->end_.offset <= 0 && optLe(c.r->begin.key, c.r->end_.key) && + return c.r->end_.offset <= 0 && optLe(c.r->begin.key, c.r->end_.key) && o.firstK().empty(); } - bool negCrossClampNonposLastGe(const Ctx& c, const Obs& o) const { - return !c.r->reverse && c.r->begin.offset < 0 && !o.more && - c.r->end_.offset <= 0 && kLtO(o.firstK(), c.r->begin.key) && - oLeK(c.r->begin.key, o.lastK()) && c.below <= bSlack(c); - } - bool negCrossClampNonposBottom(const Ctx& c, const Obs& o) const { - return !c.r->reverse && c.r->begin.offset < 0 && !o.more && - c.r->end_.offset <= 0 && optLe(c.r->begin.key, c.r->end_.key) && - kLtO(o.firstK(), c.r->begin.key) && clampNonposBottom(c); + return c.r->end_.offset <= 0 && optLe(c.r->begin.key, c.r->end_.key); } bool negCrossClampLongNonpos(const Ctx& c, const Obs& o) const { - return !c.r->reverse && c.r->begin.offset < 0 && !o.more && - c.r->end_.offset <= 0 && kLtO(o.firstK(), c.r->begin.key) && - c.below <= bSlack(c) && clampNonposBottom(c) && - optLt(c.r->end_.key, c.r->begin.key); + return c.r->end_.offset <= 0 && optLt(c.r->end_.key, c.r->begin.key); } ConflictRange closedFormNegCrossClampUnified(const Ctx& c, const Obs& o) const { OptKey end; if (negCrossClampEndOne(c, o)) end = clampEndOneUpper(c, o); - else if (negCrossClampLongNonpos(c, o) && - !negCrossClampNonposLastGe(c, o)) + else if (negCrossClampLongNonpos(c, o)) end = clampLongUpper(c, o); else end = c.r->end_.key; @@ -316,9 +289,7 @@ struct Impl { } bool negCrossCompleteHigh(const Ctx& c, const Obs& o) const { - return !c.r->reverse && c.r->begin.offset < 0 && !o.more && - c.r->end_.offset >= 2 && kLtO(o.firstK(), c.r->begin.key) && - oLtK(c.r->end_.key, o.firstK()); + return oLtK(c.r->end_.key, o.firstK()); } ConflictRange closedFormNegCrossCompleteHigh(const Ctx& c, const Obs& o) const { @@ -379,28 +350,17 @@ struct Impl { // ----- crossed truncated ------------------------------------------------- - bool negCrossTruncNonposGap(const Ctx& c, const Obs& o) const { - return o.more && !c.r->reverse && c.r->begin.offset < 0 && - kLtO(leastReportedK(c, o), c.r->begin.key) && - c.r->end_.offset <= 0 && c.below <= bSlack(c) && - kLtO(o.lastK(), c.r->begin.key) && - kLtO(o.lastK(), c.r->end_.key) && - !isTop(c.r->end_.key) && - (optLt(c.r->end_.key, c.r->begin.key) || - niLt(cardBE(c), NatInf::of(npd(c) + 1))); - } - - bool negCrossTruncNonposGapA2aBottom(const Ctx& c, const Obs& o) const { - return negCrossTruncNonposGap(c, o) && - optLt(c.r->end_.key, c.r->begin.key) && clampNonposBottom(c); - } - + // `closedFormForwardTruncatedNonpos` calls this only inside + // `below <= bSlack`, `end.offset <= 0`, `end < begin` and + // `clampNonposBottom`; the remaining Lean conditions of + // `negCrossTruncNonposGap`/`...A2aBottom` are invariants of the readable + // forward-crossed regime. bool negCrossTruncNonposGapA2aBottomHigh(const Ctx& c, const Obs& o) const { std::uint64_t extra = o.firstK().empty() ? 1 : 0; NatInf lhs = NatInf::of(bSlack(c) + 1 + extra); NatInf rhs = niAdd(NatInf::of(static_cast(c.n)), cardKO(keyAfter(o.lastK()), c.r->begin.key)); - return negCrossTruncNonposGapA2aBottom(c, o) && niLe(lhs, rhs); + return niLe(lhs, rhs); } ConflictRange closedFormNegCrossTruncNonposGapA2aBottom(const Ctx& c, @@ -416,10 +376,10 @@ struct Impl { return niLe(lhs, NatInf::of(bSlack(c))); } + // Reached only in the reversed truncation branch (`more` set, `reverse` set, + // `begin.offset < 0`, `end.offset >= 2`). bool negCrossTruncRevResidualFiniteOver(const Ctx& c, const Obs& o) const { - return o.more && c.r->reverse && c.r->begin.offset < 0 && - c.r->end_.offset >= 2 && oLtK(c.r->end_.key, o.lastK()) && - kLtO(o.lastK(), c.r->begin.key) && c.t == rE(c); + return oLtK(c.r->end_.key, o.lastK()); } ConflictRange closedFormNegCrossTruncRevResidualFiniteUnified(const Ctx& c, @@ -440,10 +400,7 @@ struct Impl { } bool negCrossTruncRevResidualTopLarge(const Ctx& c, const Obs& o) const { - if (!(o.more && c.r->reverse && c.r->begin.offset < 0 && - c.r->end_.offset >= 2 && oLtK(c.r->end_.key, o.lastK()) && - c.t < rE(c))) - return false; + if (!(oLtK(c.r->end_.key, o.lastK()) && c.t < rE(c))) return false; NatInf lhs = NatInf::of(rE(c)); NatInf rhs = niAdd(cardOK(c.r->end_.key, o.lastK()), NatInf::of(static_cast(c.n))); @@ -561,10 +518,8 @@ struct Impl { } bool zeroCrossUnderEnd(const Ctx& c, const Obs& o) const { - return c.r->begin.offset == 0 && !o.more && !c.r->reverse && - c.r->end_.offset >= 2 && - kLtO(leastReportedK(c, o), c.r->begin.key) && - optLe(c.r->begin.key, c.r->end_.key); + // The only caller tests `crossedCompleteBeginZero`, i.e. `begin.offset == 0`. + return optLe(c.r->begin.key, c.r->end_.key); } ConflictRange closedFormZeroCrossResidual(const Ctx& c, const Obs& o) const { @@ -598,16 +553,14 @@ struct Impl { } else if (isTop(r.end_.key)) { inner = true; } else { - bool firstFour = - niLe(NatInf::of(b), underBegin) && - niLe(NatInf::of(e), underEnd) && - niLe(NatInf::of(natSub(b, e)), - intervalCard(r.end_.key, r.begin.key)) && - niLe(NatInf::of(natSub(e, b)), - intervalCard(r.begin.key, r.end_.key)); + // Readability makes the two cardinality bounds and `ePlusEnd > 0` + // automatic once the first two bounds hold, so only the endpoint + // ordering remains to decide. + bool firstTwo = niLe(NatInf::of(b), underBegin) && + niLe(NatInf::of(e), underEnd); Int ePlusEnd = static_cast(e) + r.end_.offset - 1; Int bPlusBegin = static_cast(b) + r.begin.offset - 1; - inner = firstFour && ePlusEnd > 0 && bPlusBegin < ePlusEnd; + inner = firstTwo && bPlusBegin < ePlusEnd; } return !inner; } @@ -644,7 +597,7 @@ struct Impl { // ----- complete and forward truncated results ---------------------------- OptKeyView closedFormBegin(const Ctx& c, const Obs& o) const { - return clampsToBottom(c, o) ? bottomKeyView() : c.r->begin.key; + return clampsToBottom(c) ? bottomKeyView() : c.r->begin.key; } bool closedFormFinite(const Ctx& c) const { @@ -655,7 +608,7 @@ struct Impl { OptKeyView begin = closedFormBegin(c, o); if (c.r->end_.offset <= 1) return mk(std::move(begin), c.r->end_.key); - if (clampsToBottom(c, o) || optLe(c.r->begin.key, c.r->end_.key)) { + if (clampsToBottom(c) || optLe(c.r->begin.key, c.r->end_.key)) { if (c.t == rE(c)) return mk(std::move(begin), after(o.lastK())); if (allBelowEnd(c)) return mk(std::move(begin), topKey()); if (closedFormFinite(c)) return mk(std::move(begin), after(o.lastK())); @@ -678,7 +631,7 @@ struct Impl { } NatInf closedFormForwardCapacity(const Ctx& c, const Obs& o) const { - if (clampsToBottom(c, o)) return NatInf::of(0); + if (clampsToBottom(c)) return NatInf::of(0); return cardEB(c); } @@ -746,13 +699,11 @@ struct Impl { } bool zeroCrossOvershootComplete(const Ctx& c, const Obs& o) const { - return c.r->begin.offset == 0 && !o.more && !c.r->reverse && - overshoot(c) && kLtO(leastReportedK(c, o), c.r->begin.key); + return c.r->begin.offset == 0 && overshoot(c); } bool negCrossOvershoot(const Ctx& c, const Obs& o) const { - return !c.r->reverse && c.r->begin.offset < 0 && !o.more && overshoot(c) && - kLtO(o.firstK(), c.r->begin.key); + return c.r->begin.offset < 0 && overshoot(c); } bool crossedCompleteOvershoot(const Ctx& c, const Obs& o) const { @@ -766,21 +717,10 @@ struct Impl { !(c.below <= bSlack(c) && clampNonposBottom(c)); } - bool zeroCrossLongTop(const Ctx& c, const Obs& o) const { - return c.r->begin.offset == 0 && !o.more && !c.r->reverse && - c.r->end_.offset >= 2 && isTop(c.r->begin.key); - } - - bool zeroCrossLongFinite(const Ctx& c, const Obs& o) const { - return c.r->begin.offset == 0 && !o.more && !c.r->reverse && - c.r->end_.offset >= 2 && !isTop(c.r->begin.key) && - optLt(c.r->end_.key, c.r->begin.key) && - kLtO(leastReportedK(c, o), c.r->begin.key); - } - + // The three `zeroCross*` predicates above cover every `begin.offset == 0` + // case of the complete-crossed subtree, so the mode alone decides here. bool crossedCompleteBeginZero(const Ctx& c, const Obs& o) const { - return zeroCrossUnderEnd(c, o) || zeroCrossLongTop(c, o) || - zeroCrossLongFinite(c, o); + return c.r->begin.offset == 0; } bool crossedCompleteClamp(const Ctx& c, const Obs& o) const { @@ -803,21 +743,19 @@ struct Impl { // ----- crossed truncated dispatch --------------------------------------- + // Every node below is reached only from the reversed truncation branch, where + // `more` is set, `reverse` is set, `begin.offset < 0` and `end.offset >= 2` + // (the `end.offset <= 1` case is handled by the dispatch). bool zeroCrossTruncRevCrossed(const Ctx& c, const Obs& o) const { - return c.r->begin.offset == 0 && c.r->reverse && o.more && - kLtO(leastReportedK(c, o), c.r->begin.key); + return c.r->begin.offset == 0; } bool negCrossTruncRevUnder(const Ctx& c, const Obs& o) const { - return o.more && c.r->reverse && c.r->begin.offset < 0 && - kLtO(o.lastK(), c.r->begin.key) && - optLe(c.r->begin.key, c.r->end_.key) && c.r->end_.offset <= 1; + return optLe(c.r->begin.key, c.r->end_.key) && c.r->end_.offset <= 1; } bool negCrossTruncRevCrossedLow(const Ctx& c, const Obs& o) const { - return o.more && c.r->reverse && c.r->begin.offset < 0 && - kLtO(o.lastK(), c.r->begin.key) && - optLt(c.r->end_.key, c.r->begin.key) && + return optLt(c.r->end_.key, c.r->begin.key) && c.r->end_.offset <= 1 && niLe(niAdd(niAdd(cardEB(c), NatInf::of(static_cast(c.n))), @@ -831,31 +769,24 @@ struct Impl { } bool negCrossTruncRevBelowEnd(const Ctx& c, const Obs& o) const { - return o.more && c.r->reverse && c.r->begin.offset < 0 && - kLtO(o.lastK(), c.r->begin.key) && overshoot(c); + return overshoot(c); } bool negCrossTruncRevResidualRoom(const Ctx& c, const Obs& o) const { - return o.more && c.r->reverse && c.r->begin.offset < 0 && - c.r->end_.offset >= 2 && anyAtOrAboveEnd(c) && - niLe(niAdd(cardOK(c.r->end_.key, o.firstK()), NatInf::of(2)), + return niLe(niAdd(cardOK(c.r->end_.key, o.firstK()), NatInf::of(2)), NatInf::of(rE(c))); } bool negCrossTruncRevResidualTopCrossedSmallGap(const Ctx& c, const Obs& o) const { - if (!(o.more && c.r->reverse && c.r->begin.offset < 0 && - c.r->end_.offset >= 2 && oLtK(c.r->end_.key, o.lastK()))) - return false; + if (!oLtK(c.r->end_.key, o.lastK())) return false; NatInf lhs = niAdd(cardOK(c.r->end_.key, o.lastK()), NatInf::of(static_cast(c.n))); return niLt(lhs, NatInf::of(rE(c))); } bool negCrossTruncRevResidualTopCrossed(const Ctx& c, const Obs& o) const { - return o.more && c.r->reverse && c.r->begin.offset < 0 && - c.r->end_.offset >= 2 && kLeO(o.lastK(), c.r->end_.key) && - c.t < rE(c); + return !oLtK(c.r->end_.key, o.lastK()) && c.t < rE(c); } bool revTruncGeTwoTop(const Ctx& c, const Obs& o) const { @@ -867,7 +798,7 @@ struct Impl { bool negCrossTruncRevResidualTopLargeCrossed(const Ctx& c, const Obs& o) const { return negCrossTruncRevResidualTopLarge(c, o) && - kLtO(o.lastK(), c.r->begin.key) && !isTop(c.r->begin.key); + !isTop(c.r->begin.key); } bool revTruncGeTwoLarge(const Ctx& c, const Obs& o) const { @@ -876,9 +807,7 @@ struct Impl { } bool negCrossTruncTopTop(const Ctx& c, const Obs& o) const { - return o.more && !c.r->reverse && c.r->begin.offset < 0 && - isTop(c.r->begin.key) && isTop(c.r->end_.key) && - c.r->end_.offset <= 0; + return isTop(c.r->begin.key); } bool negCrossTruncTopTopEq(const Ctx& c, const Obs& o) const { diff --git a/cpp/tests/exhaustive.cpp b/cpp/tests/exhaustive.cpp index fcc72da..0aca704 100644 --- a/cpp/tests/exhaustive.cpp +++ b/cpp/tests/exhaustive.cpp @@ -3,12 +3,12 @@ // // The fuzzers sample readable instances; this test enumerates them: every // sorted database (up to four keys) over a fixed universe of interesting keys, -// every selector key (including ⊥ and ⊤) paired with offsets in [-3, 4], and +// every selector key (including ⊥ and ⊤) paired 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. // // Together with `golden_test`, `diff_corpus`, and `extreme_test`, this covers -// every line of `src/fast.cpp`. +// every line and branch side of `src/fast.cpp`. #include #include #include @@ -24,7 +24,9 @@ namespace { using namespace cr; -const Int kOffsets[] = {-3, -2, -1, 0, 1, 2, 3, 4}; +// Offset 5 is what lets the default sweep exercise the last three +// short-circuit branch sides in `fast.cpp` (all in crossed subtrees). +const Int kOffsets[] = {-3, -2, -1, 0, 1, 2, 3, 4, 5}; void check(const RangeRead& r, const Result& res, long long& cases, long long& bad, const char* kind, Int bo, Int eo, bool reverse,