Repository navigation
Modeled C stage 13: runtime audit — domain rows for the libc seams and the audit lane (ruling §52) - #1615
Merged
Conversation
ehartford
force-pushed
the
modeled-c-stage13
branch
from
September 24, 2026 05:25
6c13066 to
7866bba
Compare
added 5 commits
September 24, 2026 06:14
…§52, spec §16.2b.14) Each rt/*.w file that reaches a foreign symbol ends with an internal `c facade` block declaring the three libc domains — `domain errno thread`, `domain environ process`, `domain locale process` (ruling §33-§36) — and one `fn` row per foreign extern: every `extern fn` under `@[link_name]` or `@[import_module]`, and every one whose name is not an rt_*/with_* runtime symbol. A row's silence invalidates (§38: unknown effect means invalidate); `preserves domain D` appears only where the C standard says so, cited in each block's header: C11 7.5p3 (errno — any library function may set it; the accessor is the macro's lvalue, 7.5p2), C11 7.22.4.6 with POSIX setenv/unsetenv/putenv/getenv (environ), C11 7.11.1.1 (locale: setlocale, never called by the runtime). Win32, Winsock and WASI rows say nothing: the C standard does not describe them. The LLVM memory.size/grow intrinsics are not foreign calls. 385 rows over 12 files; each file still checks under --no-prelude, and the emitted object's text is byte-identical to the row-less one (the facade renders nothing: no resources, no methods).
… it must accept The lane proves it sees before it is trusted: `undeclared_extern.w` (a libc seam with no row), `no_facade.w` (foreign symbols, no facade), `missing_domain.w` (a facade that leaves one libc domain undeclared) each start with `//! expect-violation: <text>` the lane must report; `clean.w` (`//! expect-clean`) covers the runtime-internal externs the lane must ignore, the LLVM intrinsic, and comments inside the block.
… domain row is a red build (ruling §52) In the shape of libc-surface-check (build/compiler.w): for every rt/*.w, each foreign extern (@[link_name]/@[import_module], or a name outside rt_*/with_*) must have an `fn` row in the file's one `c facade` block, and the block must declare `domain errno thread`, `domain environ process`, `domain locale process`. The verdict names the extern, its C symbol and the facade the row belongs in. The compiler verifies what a row says when the file compiles; the lane verifies nothing is left unsaid. It then runs itself over test/runtime_domain_audit: each negative fixture must trip it and the clean one must pass, so a silent lane is itself red. A `:test` dependency beside libc-surface-check.
…word-for-word restated fn item is one contract (ruling §35) With the runtime rows in, the dark rt-in-unit lane (WITH_RT_IN_UNIT, D30 R2b) parses every rt/*.w into one Sema and refused `domain errno thread` as "declared twice" — rt_core.w's block against darwin_aarch64.w's, and either against a program's libc facade — and then `fn rt_libc_exit` as "described twice" (four runtime files declare and describe that extern). Both refusals keyed identity by name across every facade in the unit. Ruling §35: a facade "may also merge domains from distinct imports when they refer to the same actual state". collect_facade_domain now merges a second declaration with the same name and scope into the first — every declaring block's functions touch the one domain (facade_domain_note_file consults the merged facade set) — refuses one block declaring it twice (identity is the block node, not the name: each runtime file's block is `libc`), and refuses a different scope: one state has one scope (§36). collect_facade_fn accepts a second block's word-for-word restatement of an fn item (the same facts, compared as words) and refuses different clauses: one function has one contract. Tests: behav_c_facade_domain_merged / err_c_facade_domain_merged_invalidated prove the merge is real (a bare fn in block B invalidates the text block A borrowed from errno); err_c_facade_domain_scope_conflict, err_c_facade_domain_twice, behav_c_facade_fn_restated, err_c_facade_fn_restated_differently pin the rest. `WITH_RT_IN_UNIT=1 with-stage1 check test/hello.w` is green again (green at the base, red with the rows before this).
The toolchain libc facade stated `preserves domain environ` on `getenv`, so a program could hold one getenv view across a second getenv. C11 7.22.4.6p4: the returned string "may be overwritten by a subsequent call to the getenv function" — the second call invalidates the first view, and a `preserves` grants a capability the standard does not back (the ruling's test: never state what can create unsafety). The clause is deleted from `fn getenv` only; the runtime's own getenv rows (rt/*.w, ruling §52) already say the same. Every other row is unchanged. err_c_facade_getenv_view_invalidated pins the refusal; behav_c_facade_getenv_twice is the accepted spelling — copy the first out (`to_owned()`) before the second call. No existing fixture holds a getenv view across a second getenv (rg getenv test/ examples/ build/release_uat_fixtures/: two behavior tests, neither does).
ehartford
force-pushed
the
modeled-c-stage13
branch
from
September 24, 2026 10:15
7866bba to
0fda396
Compare
added 2 commits
September 24, 2026 06:56
…trace_v2 present as methods (callback items render on the resource); the snapshot was recorded before #1606 landed
…a failed compilation is never ok — it prints the view and exits 1; the retained-no-owner contract fixture is a stage 9 compile error, so it becomes the refused-clause fixture
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.
Stacked on stage 10 (#1614): this branch is rebased onto
modeled-c-stage10(git rebase --onto origin/modeled-c-stage10 origin/main, no conflicts) and linked withgh stack link --base main 1614 1615;:devis green on the combined tree andruntime-domain-audit,libc-surface-checkandcontract-view-testsall pass on it.Stage 13 of
docs/modeled-c-implementation-plan.md: the runtime audit of ruling §52 (spec §16.2b.14) — "Runtime foreign calls must themselves be described by an internal facade or equivalent audited contract data … There is no hidden 'runtime calls don't count' exception."What lands
Rows (
rt/*.w, 385 rows in 12 files). Each runtime file that reaches a foreign symbol ends with an internalc facadeblock — the declaration form the facade parser already accepts (§16.2b.7), verified by Sema when the file compiles — declaring the three libc domains and onefnrow per foreign extern:rt/darwin_aarch64.wlibsystem@[link_name]rt/linux_x86_64.wlibc@[link_name]rt/linux_aarch64.wlibc@[link_name]rt/rt_core.wlibcmalloc,free,gethostnamert/fiber_core_darwin.wlibcrt/fiber_runtime.w,rt/fiber_stubs.w,rt/panic_runtime.wlibc_exitand friendsrt/fiber_core_windows.wucrtabortrt/windows_x86_64.wwin32_errno/_fileno/_fseeki64/_ftelli64/_isatty/__acrt_iob_funcrt/windows_aarch64.wwin32rt/wasm.wwasillvm.wasm.memory.*are intrinsics, not rowsEvery block declares
domain errno thread,domain environ process,domain locale process(ruling §33–§36 defaults, as the plan directs). A row that says nothing invalidates all three (§38: unknown effect means invalidate).preserves domain Dappears only where the C standard says so, cited in each block's header comment:errno, so no call preserves it. The one exception is the errno accessor itself (__error,__errno_location,_errno): it is the macro's lvalue (C11 7.5p2), and evaluating an lvalue is not a library call; it preserves all three.setenv/unsetenv/putenv; POSIXgetenvmay overwrite the text it returned. Those rows (rt_libc_setenv,rt_libc_unsetenv,rt_libc_getenv) do not preserveenviron; every other libc row does.setlocaleis the function that changes the locale; the runtime never calls it, so every libc row preserveslocale.preserves.Evidence the rows change nothing but the facts: each file still checks under
--no-preludewith stage1, andrt/darwin_aarch64.w's emitted object has a byte-identical__TEXT(25978 bytes) with and without the block — the facade renders nothing (no resources, no methods). Rows were generated from the extern lists by a With script, not typed.Lane (
runtime-domain-audit,build/compiler.w+build.w). In the shape oflibc-surface-check, its sibling: for everyrt/*.w, each foreign extern —@[link_name]/@[import_module], or a name outsidert_*/with_*— must have anfnrow in the file's onec facadeblock, and the block must declare the three domains. The verdict names the extern, its C symbol, and the facade the row belongs in:Wired as a
:testdependency besidelibc-surface-check.audit:alliswith analyzeandlibc-surface-checkis not part of it, so neither is this lane. The compiler verifies what a row says (a row names a declaration in scope,preserves domain Da declared domain); the lane verifies nothing is left unsaid, which the compiler cannot know — a user's facade may describe a subset of its imports, the runtime's may not.Fixtures (
test/runtime_domain_audit/). The lane runs itself over four checked-in fixtures before it reports green, so a silent lane is itself red:undeclared_extern.w(a seam with no row),no_facade.w(foreign symbols, no facade),missing_domain.w(one libc domain undeclared) each carry//! expect-violation: <text>;clean.w(//! expect-clean) covers runtime-internal externs, the LLVM intrinsic and comments inside the block. Test targets glob per directory (test/behavior/*.w), so the fixtures never run as programs.Derived decisions (the ruling is silent; the option that at worst removes capability)
Which externs are "runtime foreign calls". Every
extern fninrt/that carries@[link_name]or@[import_module], plus every one whose name is not anrt_*/with_*runtime symbol (abort,GetLastError,socket,fd_write,__acrt_iob_func). Nothing is inferred from a name toward safety: the classification only decides who must have a row, and a row's default is invalidate. §52 names no libc-only carve-out, so Win32, Winsock and WASI calls are rows too.Rows for the runtime's stdio-stream variables (
extern var __stdinp/stdin/…) — none: §52 speaks of foreign calls, and a facadefnitem names a function. Listed in Modeled C: runtime process-global state outside the errno/environ/locale domains (signals, cwd, fd table, rlimits, process group, stdio streams) #1608.The implicit
lendof an fn row is inert inrt/. SemaFacade records a described fn as lending its parameters (§16.2b.5) and lifts raw classification for covered parameters; runtime code is already exempt from the raw-call rule by path (SemaCheck.w:139), and no resource is declared, so nothing renders and nothing changes in the object (byte-identical text). The rows assert view effects, not ownership.getenvinvalidatesenviron— C11 7.22.4.6p4: the returned string "may be overwritten by a subsequent call to the getenv function". The toolchain libc facade (src/compiler/LibcFacade.w) statedpreserves domain environongetenv, granting a capability the standard does not back; ruled (coordinator, on the ruling's test: never state what can create unsafety) and fixed in the last commit — that one clause deleted fromfn getenv, every other row untouched.err_c_facade_getenv_view_invalidatedpins the refusal (a secondgetenvwhile the first view is live),behav_c_facade_getenv_twiceis the accepted spelling (copy the first out withto_owned()before the second call).rg getenv test/ examples/ build/release_uat_fixtures/finds two behavior tests, neither holding a view across a second call; both still pass, and no example or UAT fixture names it.Same-named domains of distinct facades are one domain (ruling §35). With the rows in, the dark rt-in-unit lane (
WITH_RT_IN_UNIT=1, D30 R2b — off by default, green ontest/hello.wat the base) parsed every runtime file into one Sema and refuseddomain errno threadas "declared twice" (rt_core.w'slibcblock againstdarwin_aarch64.w'slibsystemblock, and either against a program'slibcfacade).facade_domainswas keyed by name across all facades, which made two facades naming the same state a contradiction. §35 says the opposite — a facade "may also merge domains from distinct imports when they refer to the same actual state" — soSemaFacade.collect_facade_domainnow merges a second declaration with the same name and scope into the first (every declaring facade's functions touch the one domain), still refuses one facade declaring it twice, and refuses a different scope ("one state has one scope").behav_c_facade_domain_mergedanderr_c_facade_domain_merged_invalidatedprove the merge is real (a bare fn in facade B invalidates the text facade A borrowed from errno);err_c_facade_domain_scope_conflictanderr_c_facade_domain_twicepin the two refusals. The same lane then refusedfn rt_libc_exitas "described twice" — four runtime files declare and describe that extern — so a second block's word-for-word restatement of an fn item is accepted as the same facts (compared as words,facade_item_words), and different clauses are refused: one function has one contract (behav_c_facade_fn_restated,err_c_facade_fn_restated_differently). Identity for both rules is the block node, not the facade name: each runtime file's block is calledlibc.WITH_RT_IN_UNIT=1 with-stage1 check test/hello.wis green again. This is the one Sema change in the PR; it touches facade collection only (no ownership, drop or ABI), so the PR still batches freely per the plan.Two things the dark lane still shows, neither introduced here and both for the D30 flip owner: (a)
WITH_RT_IN_UNIT=1 … run test/hello.wexits 139 — it does so on main's own stage1 at ae609cd too (R2b is "off by default until R2c retargets codegen"); (b)behav_c_facade_domain_errno.wspellsdomain errno process, so under rt-in-unit it now meets the runtime'sdomain errno threadand is refused by the scope rule. Ruling §37's spelling isthread; when the lane is flipped that fixture conforms to the ruling, not the other way round — I did not edit it, since no running lane is red.Outside the three domains
Process-global C state the runtime touches that the ruling does not name — signal disposition/mask (
sigaction,sigaltstack,sigprocmask,raise,kill), cwd (chdir,getcwd), the fd table (dup2,fcntl), rlimits, process group/children (setpgid,wait4), and the stdio stream objects — got rows under the three named domains (invalidate by default) and no domain of their own. Filed as #1608 with the full list; a laterdomain cwd processis a refinement of existing rows, not a new obligation on the lane.Verification (iterate tier;
:fixpoint/:test/audits deliberately not run)./out/bootstrap/bin/with-stage1 check src/main.w— okwith build :dev— green (before and after the rows; stage1 rebuilt with the rows embedded)with build :runtime-domain-audit—16 runtime files, 385 domain rows, every foreign extern described; 4 fixtures agreert_libc_setlocaleseam (verdict above), then restoredwith build :libc-surface-check— still greentest/hello.wlinks and runs;behav_c_facade_domain_errno,behav_c_facade_facts_verify,behav_c_facade_parses,err_c_facade_view_invalidated_by_domain,err_c_facade_bad_domain_kindpasserr_c_facade_fn_twicestill passes;WITH_RT_IN_UNIT=1 with-stage1 check test/hello.w— ok (red with the rows before the merge, green at the base)behav_c_facade_*tests fail in this tree —libc_system_headers(amemchrarity error insidelib/std/re/pcre2_match.wwhen<string.h>is imported),pending_producer_warnsandpresentation_ambiguous_warns(theirpre_d_build_runnergets rc=127) — and fail identically on a separate worktree of the base commit d783366 with its own:devstage1, so they are the tree's, not this change's (the worktree was removed afterwards)