Repository navigation
A user program is a contract: the spiral as published, no unsafe in UATs; c_import lends strings (D47); the spec stops cataloguing lib/std (D48) - #1222
Merged
Conversation
added 5 commits
September 20, 2026 00:43
…safe` in UATs or examples 2026-06-17 (a88df01, #379) replaced the blanket `const char*` modeling with a curated libc overlay: a c_import function with a string parameter outside that list became the raw surface. That broke the raylib spiral release UAT, which sat broken until 2026-09-07 (bd9683f), when the fixture was rewritten to `unsafe { InitWindow(900, 600, c"...".ptr) }` so it would pass. Eric was not told; his blog and the project primer ("Functions imported via c_import are callable directly. The import is the opt-in.") still show the original. - The spiral fixture is again the program a user writes: plain string literals to InitWindow and DrawText, no `unsafe`, and `sin`/`cos` from the language (D42) instead of two `extern fn` lines. It is red until c_import models a string lent to C for a call; that red is the truth. - `with build :user-programs-safe`, a gate of `:release-uat`: no release UAT fixture and no program under examples/ says `unsafe`. It reports 28 uses today, across the zlib, bzip2, sqlite3 and libcurl fixtures: the list of C surfaces the compiler has not yet made humane. - CLAUDE.md / AGENTS.md: editing a user program so a new rule passes is deleting a failing test; an application developer never writes `unsafe`. - The release runbook no longer documents the workaround.
…D47, §16.3c); std.zip Eric, 2026-09-20: "I do not want the language spec to care what we do in lib/std." §18.6's Module Map table and the std.internal paragraph are removed, and spec-inventory-check no longer reads lib/std against the spec (its keyword, attribute, command and flag arms stay). What remains normative is the library surface the language depends on, each in its own section. §16.3c gains the sentence Eric blessed 2026-09-20, verbatim: binding evidence governs what With receives from C; a c_imported `const char *` parameter accepts a `str` lent for the call, a literal passed directly and any other `str` through call-scoped storage that stays readable if the callee retains it. The compiler is NON-COMPLIANT until the next commits: it still calls such a function the raw surface. std.zip lands as an ordinary documented module (list, read, extract over the migrated minizip reader), with the test that reads an Info-ZIP-made archive. It was held out of #1219 only because the inventory wanted a spec row.
Eric, 2026-09-20. The file was a hand-maintained snapshot of the spec with no generator in the tree (build/requirements.w was removed earlier) and line references about 870 lines stale. requirements-informative-check, its two helpers, its :test dependency and the implementation-plan entry (#386, closed) go with it.
`strlen(name(1))` called `name` twice, on main too:
bb0: call name(1) -> _2 // lower_auto_deref_call_arg, probing
bb1: _3 = move _2
call name(1) -> _4 // lower_call_arg, for real
bb2: call strlen(copy _4)
lower_auto_deref_call_arg (src/MirLower.w) lowered the argument into a place
before it knew whether any deref path leads from the argument's type to the
parameter's; for a `str` going to `*const c_char` there is none, so it
returned -1 with the call already emitted and lower_call_arg lowered the
argument again. (Found with --dump-mir, --explain-mir-origin main:_4, and an
lldb backtrace at each MirBuilder.lower_call.)
auto_deref_reaches decides the walk from the types; the argument is lowered
only when the walk can finish. The test counts calls for the failing walk
(str to a C string), a walk that needs none, and one through a field.
The compiler now conforms to the sentence blessed 2026-09-20.
- Sema: a `const char *` input never makes a c_imported function the raw
surface. ci_overlay_cstr_in_param_count, the hardcoded list of libc names
that vouched for string inputs, is deleted; evidence still governs what
With receives (pointer returns, mutable buffers).
- A string literal is passed directly: its bytes are a static NUL-terminated
global, so nothing is lent and nothing can dangle. One with an interior NUL
is a compile error.
- Any other str is lent by with_cstr_lend and returned by with_cstr_release
(rt_core.w): blocks mapped outside the allocator, reused only for lent
strings, each ending in a zero byte no lend overwrites. A callee that keeps
the pointer reads stale text, never freed memory. The memory held is the
peak of strings lent at once.
The raylib spiral, as published and with no `unsafe`, checks and runs:
"raylib spiral UAT passed: 581/7342 bright spiral samples". Generated code
for `remove("/x")` calls remove alone; for `remove(f"/x{n}")` it calls
with_cstr_lend, remove, with_cstr_release.
err_c_import_const_char_requires_overlay_evidence asserted #379's rule and is
replaced by behav_c_import_lends_str_to_const_char (non-curated functions
with a literal and a runtime str; every size class of the lending storage up
to 300000 bytes).
ehartford
added a commit
that referenced
this pull request
Sep 20, 2026
…st (D49) (#1223) * Green evidence is keyed on what was tested: git tree, pinned seed, host (D49) #1222's battery passed in a staging worktree; after the squash-merge main's tree was byte-identical (git diff empty) and :install-user still demanded a second 25-minute battery. last-green and the driver's install gate accepted only the exact tested binary, and the binary names its commit (the version ends in -g<hash>) and, through debug paths, its worktree. - :last-green is now a group: last-green-record (the action, unchanged in what it verifies) also records the source identity — git rev-parse HEAD^{tree}, the pinned seed's digest, the host — and last-green-publish installs the store ($WITH_GREEN_DIR, else ~/.local/with-green/green.tsv), one line per identity. A dirty worktree has no identity and publishes nothing. - require-last-green (build/retention.w) and the driver's :install-user gate (src/main.w cli_fast_install_blessed) accept a compiler when the local manifest names that binary, as before, or when the worktree is clean, its chain was seeded by a compiler seed.lock pins, and its identity has a published green. The accepting line names the commit the green was recorded at. After a squash-merge of a tested branch the reseed is git pull, build, :install-user. * The install gate's git code lives in compiler/GreenEvidence.w, not the CLI's flag file spec-inventory-check reads string literals in src/main.w as `with` flags and rightly reported git's "--porcelain" as an unspec'd one. The source-identity lookup moves into its own module; src/main.w calls green_by_source_identity(root). * last-green-record writes its captures under its own name The action's capture directory is out/command/<target name>; the renamed target still declared out/command/last-green as its write scope. --------- Co-authored-by: Eric Hartford <[email protected]>
ehartford
added a commit
that referenced
this pull request
Sep 20, 2026
… CStr.from_ptr, §4.9 fall-through, @[c_export] over a declared prototype, parameter shadowing (#1232) * A str is lent to a const char * in a raw call too (§16.3c, D47) The blessed sentence has no condition on the function's other parameters. SemaDiag.try_ci_coercion gated lending on ci_raw_syms, so any function with a raw-pointer parameter (sqlite3_open, sqlite3_prepare_v2, strtol) refused a str for its text input and sent the caller to c"...".ptr and CString. I added that gate in #1222; it was never part of the ruling. * CStr.from_ptr and CStr.to_str: read the C string C handed back (§16.1) The spec spells CStr.from_ptr(p).to_str(); CStr had only len() and ptr(), and the stdlib read C strings through with_str_from_cstr, which a program may not name. sqlite3_errmsg and sqlite3_column_text left every user writing an unsafe byte loop. from_ptr is unsafe (the caller vouches for the pointer); to_str is an owned copy. * A Result[Unit, E] body that falls through after an early return Err is Ok(()) (§4.9) The spec's own validate example was 'missing return': SemaCheck flagged any Unit-typed body that holds an explicit value return and can fall through, with no exemption for Result[Unit, E], where falling through is the Ok(()) §4.9 promises. The closure site waits on #1230. * @[c_export] defines the prototype a c_imported header declares A C library that calls back into With declares the callback in its header. The c_imported prototype and the With definition became two LLVM functions of one name: the body was renamed name.1 and the prototype the C code calls stayed undefined at link. The body now goes into the existing declaration, as it already does for runtime names, so every call site that holds the prototype holds the definition. * A parameter or local shadows another module's global of its name A private top-level `let ptr` broke every imported function that has a `ptr` parameter: "symbol 'ptr' is not visible from this module", for a free function, a type-level function and a method alike. check_ident (SemaCheck.w) found the parameter through scope_lookup, then ran the visibility checks through binding_decl_node / global_value_decl_kind, which look the NAME up again and found the other module's global. Found by an lldb breakpoint on emit_private_symbol_error. A binding made below the module-level scope is a local, and visibility does not apply to it. Exposed by CStr.from_ptr(ptr: ...), which put a `ptr` parameter in the prelude and collided with behav_annotated_top_level_runtime_init.w's global. --------- Co-authored-by: Eric Hartford <[email protected]>
ehartford
added a commit
that referenced
this pull request
Sep 20, 2026
… CStr.from_ptr, §4.9 fall-through, @[c_export] over a declared prototype, parameter shadowing (#1232) * A str is lent to a const char * in a raw call too (§16.3c, D47) The blessed sentence has no condition on the function's other parameters. SemaDiag.try_ci_coercion gated lending on ci_raw_syms, so any function with a raw-pointer parameter (sqlite3_open, sqlite3_prepare_v2, strtol) refused a str for its text input and sent the caller to c"...".ptr and CString. I added that gate in #1222; it was never part of the ruling. * CStr.from_ptr and CStr.to_str: read the C string C handed back (§16.1) The spec spells CStr.from_ptr(p).to_str(); CStr had only len() and ptr(), and the stdlib read C strings through with_str_from_cstr, which a program may not name. sqlite3_errmsg and sqlite3_column_text left every user writing an unsafe byte loop. from_ptr is unsafe (the caller vouches for the pointer); to_str is an owned copy. * A Result[Unit, E] body that falls through after an early return Err is Ok(()) (§4.9) The spec's own validate example was 'missing return': SemaCheck flagged any Unit-typed body that holds an explicit value return and can fall through, with no exemption for Result[Unit, E], where falling through is the Ok(()) §4.9 promises. The closure site waits on #1230. * @[c_export] defines the prototype a c_imported header declares A C library that calls back into With declares the callback in its header. The c_imported prototype and the With definition became two LLVM functions of one name: the body was renamed name.1 and the prototype the C code calls stayed undefined at link. The body now goes into the existing declaration, as it already does for runtime names, so every call site that holds the prototype holds the definition. * A parameter or local shadows another module's global of its name A private top-level `let ptr` broke every imported function that has a `ptr` parameter: "symbol 'ptr' is not visible from this module", for a free function, a type-level function and a method alike. check_ident (SemaCheck.w) found the parameter through scope_lookup, then ran the visibility checks through binding_decl_node / global_value_decl_kind, which look the NAME up again and found the other module's global. Found by an lldb breakpoint on emit_private_symbol_error. A binding made below the module-level scope is a local, and visibility does not apply to it. Exposed by CStr.from_ptr(ptr: ...), which put a `ptr` parameter in the prelude and collided with behav_annotated_top_level_runtime_init.w's global. --------- Co-authored-by: Eric Hartford <[email protected]>
ehartford
added a commit
that referenced
this pull request
Sep 20, 2026
…o_owned; the old example removed until the SQLite facade (D51 §66) (#1234) * Five defects the c-interop example exposed: str lending in raw calls, CStr.from_ptr, §4.9 fall-through, @[c_export] over a declared prototype, parameter shadowing (#1232) * A str is lent to a const char * in a raw call too (§16.3c, D47) The blessed sentence has no condition on the function's other parameters. SemaDiag.try_ci_coercion gated lending on ci_raw_syms, so any function with a raw-pointer parameter (sqlite3_open, sqlite3_prepare_v2, strtol) refused a str for its text input and sent the caller to c"...".ptr and CString. I added that gate in #1222; it was never part of the ruling. * CStr.from_ptr and CStr.to_str: read the C string C handed back (§16.1) The spec spells CStr.from_ptr(p).to_str(); CStr had only len() and ptr(), and the stdlib read C strings through with_str_from_cstr, which a program may not name. sqlite3_errmsg and sqlite3_column_text left every user writing an unsafe byte loop. from_ptr is unsafe (the caller vouches for the pointer); to_str is an owned copy. * A Result[Unit, E] body that falls through after an early return Err is Ok(()) (§4.9) The spec's own validate example was 'missing return': SemaCheck flagged any Unit-typed body that holds an explicit value return and can fall through, with no exemption for Result[Unit, E], where falling through is the Ok(()) §4.9 promises. The closure site waits on #1230. * @[c_export] defines the prototype a c_imported header declares A C library that calls back into With declares the callback in its header. The c_imported prototype and the With definition became two LLVM functions of one name: the body was renamed name.1 and the prototype the C code calls stayed undefined at link. The body now goes into the existing declaration, as it already does for runtime names, so every call site that holds the prototype holds the definition. * A parameter or local shadows another module's global of its name A private top-level `let ptr` broke every imported function that has a `ptr` parameter: "symbol 'ptr' is not visible from this module", for a free function, a type-level function and a method alike. check_ident (SemaCheck.w) found the parameter through scope_lookup, then ran the visibility checks through binding_decl_node / global_value_decl_kind, which look the NAME up again and found the other module's global. Found by an lldb breakpoint on emit_private_symbol_error. A binding made below the module-level scope is a local, and visibility does not apply to it. Exposed by CStr.from_ptr(ptr: ...), which put a `ptr` parameter in the prelude and collided with behav_annotated_top_level_runtime_init.w's global. --------- Co-authored-by: Eric Hartford <[email protected]> * CStr.to_owned, not to_str: the allocating conversion is named for what it does (D51 §41) The ruling reserves to_str() for the validating conversion and names the owned copy to_owned(). Renamed before the name lands. * examples/c-interop is removed until the SQLite facade exists (D51 §66) The old example did not compile, its test tested strlen, its README described a program that no longer existed, and a compiled binary was checked in; the three source files went with #1232. The README and with.toml that remained described nothing. The example returns rewritten against the facade surface, after the SQLite facade compiles, as the ruling orders. --------- Co-authored-by: Eric Hartford <[email protected]>
4 tasks
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.
What went wrong. 1e53f8a (2026-06-11) let every
const char *parameter of a c_imported function take a With string; the raylib spiral on the blog dates from then. a88df01 (2026-06-17, #379) replaced that with a hardcoded list of libc names, which broke the spiral release UAT. It sat broken until bd9683f (2026-09-07) rewrote the fixture tounsafe { InitWindow(900, 600, c"...".ptr) }so it would pass. Eric was not told. By 2026-09-19 all five release UAT fixtures saidunsafe(30 uses).Rulings (Eric, 2026-09-19/20), recorded as D47 and D48.
unsafe. A UAT fixture, an example, or published code is a contract: a change that breaks one stops and goes to Eric; the program is never edited to pass. (CLAUDE.md, AGENTS.md.)strlent to a c_importedconst char *parameter for a call needs none.lib/std: §18.6's Module Map and thestd.internalparagraph are removed, andspec-inventory-checkloses its stdlib arm.docs/requirements.mdand its lane are deleted.What changed.
unsafe,sin/cosfrom the language (D42).with build :user-programs-safe, a gate of:release-uat: nounsafeinbuild/release_uat_fixtures/orexamples/. It is red on purpose: 28 uses across the zlib, bzip2, sqlite3 and libcurl fixtures (buffer+length pairs, handles, out-parameters, variadics). That list is the work after this PR;:release-uatstays red until it is done.const char *input never makes a function the raw surface, and the hardcoded overlay list is deleted. A literal is passed directly (static, NUL-terminated; an interior NUL is a compile error). Any otherstrgoes throughwith_cstr_lend/with_cstr_release: blocks mapped outside the allocator, reused only for lent strings, each ending in a zero byte nothing overwrites, so a callee that keeps the pointer reads stale text and never freed memory.strlen(name(1))callednametwice.lower_auto_deref_call_arglowered the argument while probing for a deref path, found none, and the caller lowered it again. It now decides from the types first.std.zip(list, read, extract over the migrated minizip reader) lands as an ordinary module; it was held out of zlib corpus gains minizip's reader; six defects it exposed (a?compiler crash, survey running through failures, three migrator bugs, an unchecked promotion) #1219 only for want of a spec row.Evidence (pinned seed, head c8f2b17):
The spiral UAT, as published:
raylib spiral UAT passed: 581/7342 bright spiral samples. Generated code forremove("/x")callsremovealone; forremove(f"/x{n}")it callswith_cstr_lend,remove,with_cstr_release.Filed on the way: #1220 (Sema accepts float→int and float→bool; the mistake surfaces in codegen with no location), #1221 (a c_import name collides with an imported module's unused name; a selective import drags in the whole module).