Skip to content

Commit b5063c1

Browse files
serde_2026: remove debug_assert_roundtrip
The fuzzer covers roundtrips more thoroughly (thousands of execs, mutations discovering edge cases). debug_assert_roundtrip only runs in debug builds (which nobody uses in practice), adds maintenance burden, and provides negative incentive to use debug builds. The dedicated panic-finder catches robustness bugs; the roundtrip-checker catches correctness bugs; the debug assertion duplicates the latter and doesn't pull its weight. Addresses Arvid's review thread on ser.rs:269. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent abef37a commit b5063c1

1 file changed

Lines changed: 0 additions & 36 deletions

File tree

src/serde_2026/ser.rs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -255,40 +255,6 @@ pub(super) fn serialize_with_strategy<W: Write, S: VisitStrategy>(
255255
Ok(())
256256
}
257257

258-
/// Debug-only: deserialize `bytes` and verify it equals `node`. Panics on mismatch.
259-
#[cfg(debug_assertions)]
260-
pub(super) fn debug_assert_roundtrip(allocator: &Allocator, node: NodePtr, bytes: &[u8]) {
261-
use super::de::deserialize_2026_body;
262-
let mut probe = Allocator::new();
263-
// Self-check uses 1 MiB max atom (matches the legacy non-consensus default).
264-
let decoded = deserialize_2026_body(&mut probe, bytes, 1 << 20, false)
265-
.expect("serde_2026 self-check: produced bytes that fail to deserialize");
266-
assert!(
267-
cross_allocator_eq(allocator, node, &probe, decoded),
268-
"serde_2026 self-check: round-trip tree mismatch",
269-
);
270-
}
271-
272-
#[cfg(debug_assertions)]
273-
fn cross_allocator_eq(a: &Allocator, na: NodePtr, b: &Allocator, nb: NodePtr) -> bool {
274-
let mut stack = vec![(na, nb)];
275-
while let Some((x, y)) = stack.pop() {
276-
match (a.sexp(x), b.sexp(y)) {
277-
(SExp::Atom, SExp::Atom) => {
278-
if a.atom(x).as_ref() != b.atom(y).as_ref() {
279-
return false;
280-
}
281-
}
282-
(SExp::Pair(xl, xr), SExp::Pair(yl, yr)) => {
283-
stack.push((xr, yr));
284-
stack.push((xl, yl));
285-
}
286-
_ => return false,
287-
}
288-
}
289-
true
290-
}
291-
292258
// --- Public entry points ---
293259

294260
use super::Compression;
@@ -351,8 +317,6 @@ pub fn serialize_2026(allocator: &Allocator, node: NodePtr) -> Result<Vec<u8>> {
351317
pub fn serialize_2026_level(allocator: &Allocator, node: NodePtr, level: u32) -> Result<Vec<u8>> {
352318
let mut output = Vec::new();
353319
serialize_2026_to_stream_level(allocator, node, level, &mut output)?;
354-
#[cfg(debug_assertions)]
355-
debug_assert_roundtrip(allocator, node, &output);
356320
Ok(output)
357321
}
358322

0 commit comments

Comments
 (0)