Skip to content

test(kernel): regression test for circular-print mark restoration#23

Merged
jschairb merged 1 commit into
mainfrom
worktree-fe-circular-print-test
Jun 15, 2026
Merged

test(kernel): regression test for circular-print mark restoration#23
jschairb merged 1 commit into
mainfrom
worktree-fe-circular-print-test

Conversation

@jschairb

Copy link
Copy Markdown
Contributor

Summary

PR #20 added the fe_write() circular-structure fix (borrow GCMARKBIT during traversal, clear it afterward in unmarkpairs) but shipped no test for it. This adds the missing kernel/circular-print regression test.

Why this is a strong test

The mark bit lives in the low byte of a pair's car field. So a leaked mark bit doesn't just leave stale state — it corrupts the car pointer. That makes walking the structure after repr a direct, deterministic check of mark restoration, with no need to force a GC (which would be flaky across arena/pool sizes):

  • (is (repr x) "(1 2 3 ...)") — tail-cycle prints finite, ends in ...
  • (is (repr y) "(... 2 3)") — head-cycle (setcar self-reference)
  • (is (cdr (cdr (cdr x))) x) — the cycle still closes on x (pointer identity intact)
  • (is (car (cdr (cdr (cdr x)))) 1) — walking through the back-edge returns x[0]
  • (is (repr x) (repr x)) — reprʼing twice yields the same string (marks don't accumulate)

repr also runs fe_write twice internally (measure pass + fill pass), so a stale mark would skew the two passes and corrupt the output — another angle the same test covers.

Verified the test has teeth

Neutering unmarkpairs to a no-op (cycle-detection still works, so it doesn't merely hang) makes the post-print walkability checks segfault (exit 139) — ctest scores that as a failure. With the real fix restored, 20/20 ctest, 23 checks in the kernel file. Kernel source is untouched — test + CHANGELOG only.

🤖 Generated with Claude Code

PR #20 added the fe_write() cycle-detection fix (borrow GCMARKBIT, clear
it in unmarkpairs) but shipped no test for it. This closes that gap.

The mark bit lives in the low byte of a pair's car field, so a leaked
mark corrupts the car pointer — which makes walking the structure after
repr a direct, deterministic check of mark restoration (no GC needed).
repr also runs fe_write twice internally (measure + fill), so a stale
mark would skew the two passes.

Verified the test has teeth: neutering unmarkpairs to a no-op makes the
walkability checks segfault (exit 139), which ctest scores as a failure.

20/20 ctest, 23 checks in the kernel file.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jschairb
jschairb merged commit 14a9cda into main Jun 15, 2026
2 checks passed
@jschairb
jschairb deleted the worktree-fe-circular-print-test branch June 15, 2026 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant