Harden Foundations memory and concurrency contracts - #116
Draft
tdecroyere wants to merge 48 commits into
Draft
Conversation
tdecroyere
force-pushed
the
refactor/memory-pop-cleanup
branch
from
September 4, 2026 20:13
abe5a63 to
7eca504
Compare
tdecroyere
force-pushed
the
refactor/memory-pop-cleanup
branch
from
September 4, 2026 20:48
d027210 to
3bb224b
Compare
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.
Goal
Harden the low-level Foundations runtime around explicit memory, lifetime, and concurrency contracts. This keeps the existing arena/stack design intact while fixing correctness bugs that could otherwise lead to out-of-bounds allocations, races, stale handles, corrupted free lists, or unsafe access to uncommitted memory.
MemoryArena
SystemPopMemoryand keep rollback internal toStackMemoryArena;SystemClearMemoryArena/SystemFreeMemoryArenaas explicit exclusive lifetime operations;StackExtraStoragecapacity checks to use the actual working arena;PageInfo, committed-state bits, or page counts;SystemCommitMemoryreport success/failure and prevent committed pushes from returning a pointer when the platform commit fails;StackMemoryArenalifetime model and its regression coverage.DataPool
Dictionary
ReadOnlySpan<T>hashing soLengthis converted to bytes withsizeof(T);SystemGetDictionaryValuereturnnullptras documented while preserving the zero-valueoperator[]convenience;Span and string buffers
Span/ReadOnlySpanlightweight, non-owning pointer-and-length views;Lengthas logical characters excluding the null terminator;SystemDuplicateBuffer<char>to preserve that logical length;Regression coverage
Adds focused tests for:
StackExtraStorageancestor allocations;The remaining follow-up audit items are intentionally separate from this PR's current Foundations scope: platform-specific descriptor/query free lists in the graphics backends, deeper
PageInfosparse-decommit semantics, and POSIX physical-page release policy.