Harden and fully cover the C++ translation

Add an exhaustive readable-instance sweep and a coverage gate requiring
100% line coverage of the summarised implementation. Delete branches that
are unreachable under `Readable`, centralise and assert the 32-bit offset
contract at the public entry points, and stop materialising `n` zero bytes
when deciding `keyAfterN n k < upper`.

Also add the extreme-offset regression test, harden the corpus parsers,
remove unused model helpers, document the literal-total / fast-readable
split, and refresh the validation and benchmark numbers.
This commit is contained in:
andrew committed 2026-11-17 18:46:24 -05:00
1 parent e32e42d933
commit 3bb5d062ff
15 files changed
+620 -196

No files matched your search

+11 -3
View File
@@ -1,5 +1,6 @@
// Validates the C++ literal translation against golden vectors produced by
// `cpp/oracle/gen.lean` (which calls the real `Statement.closedForm`).
#include <cstdint>
#include <cstdio>
#include <fstream>
#include <sstream>
@@ -34,7 +35,7 @@ bool parseKey(const std::string& tok, OptKey& out) {
int hi = hex(tok[i]);
int lo = hex(tok[i + 1]);
if (hi < 0 || lo < 0) return false;
k.push_back(static_cast<Byte>(hi * 16 + lo));
k.push_back(static_cast<char>(static_cast<Byte>(hi * 16 + lo)));
}
out = std::move(k);
return true;
@@ -46,7 +47,8 @@ std::string encKey(const OptKey& k) {
static const char* digits = "0123456789abcdef";
std::string out;
out.reserve(k->size() * 2);
for (Byte b : *k) {
for (char ch : *k) {
const Byte b = static_cast<Byte>(ch);
out.push_back(digits[b >> 4]);
out.push_back(digits[b & 0xf]);
}
@@ -79,7 +81,9 @@ int main(int argc, char** argv) {
std::size_t n = 0;
OptKey beginKey, endKey;
if (!(ss >> bk >> bo >> ek >> eo >> rev >> more >> n) ||
!parseKey(bk, beginKey) || !parseKey(ek, endKey)) {
!parseKey(bk, beginKey) || !parseKey(ek, endKey) || n > line.size() ||
!cr::offsetsFitInt32(static_cast<cr::Int>(bo),
static_cast<cr::Int>(eo))) {
std::fprintf(stderr, "line %zu: bad header: %s\n", lineNo, line.c_str());
++bad;
continue;
@@ -125,6 +129,10 @@ int main(int argc, char** argv) {
}
}
}
if (cases == 0) {
std::fprintf(stderr, "golden: no cases in %s\n", argv[1]);
return 1;
}
std::printf("golden: %zu cases, %zu mismatches\n", cases, bad);
return bad == 0 ? 0 : 1;
}