Repository navigation
tests: contract.register publishes a probe and its kernel together, in every suite - #5058
Merged
Merged
Conversation
ashhart
force-pushed
the
lead/contract-register
branch
from
November 25, 2026 14:27
b87f6e4 to
36f102e
Compare
…ister The kernel-contract suites published each probe with two fallible appends, its list then the kernel list. When the second failed, the probe was already in its list: a suite whose errdefer frees the probe freed it twice (the errdefer, then Suite.deinit), and one without an errdefer leaked it on any earlier failure. contract.register (zig/src/core/contract/register.zig) reserves room in both lists, then publishes with appendAssumeCapacity on both, so a failure leaves neither holding the probe and the caller's errdefer still owning it; once it returns, the lists own the probe. It is generic over the probe and takes the kernel value, so a suite whose kernel is p.kernel(name) or a literal uses it too; either list may be passed as a pointer or as a pointer field. All 85 two-append sites on main (59 files under zig/tests/contract) now call it, and every probe has an errdefer that mirrors its suite's teardown (deinit once initialized, destroy where the teardown destroys) and runs only until it is published: 107 errdefers were added where a suite had none or only half. register_test.zig, run by test-kernel-contract, counts a probe's frees under std.testing.FailingAllocator: the old pattern frees it twice when the kernel list's growth fails and never when the probe list's does; register frees it exactly once either way, and once at teardown on success. Test code and the contract harness only: no kernel, engine or token change.
…together, in every suite
ashhart
force-pushed
the
lead/contract-register
branch
from
November 25, 2026 15:27
36f102e to
a5bbb03
Compare
This was referenced Nov 25, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Kernel-contract suites registered each probe with two fallible appends:
If the second append fails, the probe's own
errdeferfreesp, butpis already ins.probes, so the suite's teardown frees it again. Suites with noerrdeferleak on any failure instead. The pattern was in 85 places across 59 suites, and about ten open pull requests copied it and were asked in review to fix it.The fix:
contract.register(zig/src/core/contract/register.zig):appendAssumeCapacityon both, so ownership moves in one step that can't fail halfway.On
error.OutOfMemoryneither list holds the probe, and the caller'serrdeferstill frees it. Usage:What changed:
errdefers were added, each mirroring its suite's teardown and running only until registration.Test:
register_test.zig(intest-kernel-contract) counts frees understd.testing.FailingAllocator:errdeferregisterThe test fails when
register's body is swapped back to the old two appends.Checks:
test-kernel-contractpasses on Linux.tf-kernel-contracttype-checks for macOS.fmt, AST and the line caps are clean; lean is 164, as on main.
Synthena