Skip to content

Sema: corpus-private std modules (#2248); str.trim() is a view, the evaluator runs std str bodies and slices strings (#2225) - #2249

Merged
ehartford merged 7 commits into
mainfrom
next-fixes
Oct 7, 2026
Merged

ehartford merged 7 commits into
mainfrom
next-fixes

Conversation

@ehartford

@ehartford ehartford commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Three layers, one battery:

Gate pending, then the battery.

Eric Hartford added 2 commits October 7, 2026 06:29
…2248, D39 §3.4)

stage1 has no bundle slot, so it compiles std.re from source and loads
the corpus's own std.libc and, through it, std.os; the release compiler
serves the corpus as an interface and loads neither. Every lookup that
consulted the loaded std set then differed between the two generations
(a bare `Target` named std.os.Target on stage1 only). record_engine_corpora
now marks as corpus-private every std module whose importers are all
engine or corpus-private modules (a fixpoint; a module the user or the
prelude closure imports is never private), decl_visible_from_current
refuses them to user code, and both visibility walks stay within a corpus
and never enter one from outside. Gated lookups now resolve the same on
both generations; the comptime-match subject and a type candidate without
a module path still bypass the gate (noted on #2248).
…rings (#2225, D71, D105, D104)

`trim` was the STR_TRIM intrinsic over an owned runtime copy, written
before D71 made `s[a..b]` a view; D105's `trim_start`/`trim_end` are
views. `trim` is now the same: one `impl str` method in std.string
returning `&str`, O(1), spelled with its two siblings; the intrinsic
leaves Sema's method map and return table, both codegens and the
evaluator's builtin table. The runtime copy stays only because the
PINNED SEED still lowers the compiler's own `.trim()` calls to it; it
retires with the next seed bump (marked). The callers that keep the
result past its source spell `.to_owned()` (seed.w, release_publish.w,
main.w, Lsp.w, FacadeRender.w, ConanClient.w, two tools).

At compile time the evaluator refused every `str` method it had no
builtin for ("not comptime-evaluable yet"), so `trim_start()` never
evaluated either; an unknown str method now takes the user-method path
and runs the std body (D104), the comptime string value carrying `str`
as its type, and `s[a..b]` on a comptime str evaluates as a
bounds-checked substring (NK_SLICE), which the three bodies are built on.
@ehartford ehartford changed the title Sema: a std module loaded only for a corpus's sake is private to it (#2248) Sema: corpus-private std modules (#2248); str.trim() is a view, the evaluator runs std str bodies and slices strings (#2225) Oct 7, 2026
Eric Hartford added 5 commits October 7, 2026 07:24
…it (§21.1, #962 for a callee)

The trim view found it in the compiler itself: `line.slice(4,
line.len()).trim()` bound a view into the owned str the slice returns,
the str died at the statement's end, and stage2 read freed memory for a
module name (an interior-NUL panic in link-compiler and selfcheck). The
checker rejected only `temp()[i]` (#962): a callee whose result views an
argument that is a statement temporary owning storage, or carries a view
into one, now records the same mark, so a binding or a return of the
result is refused with the same words. Eight more sites in the compiler
that read freed memory under the new view (Lsp, Uat, Resolve,
ConanRecipe, main) are fixed; a compile_errors fixture pins the rule.
…longer probes an engine twin's ambience (#2249, #2248)

A visibility verdict is three walks, a gate of rules and the §18.2
fallback bridge, and a 0 out of them said nothing: #2249's red (`is_alnum`
needing an import after the corpus boundary) was being hunted by
toggling a rule and rebuilding. `with analyze file.w
'explain:visible:<name>'` lists every declaration the name could mean
from the root — values, types, displaced identities (#1350) — with its
module, package, engine id, prelude-closure and corpus-private marks,
then the verdict and every rule and walk edge it passed through, and the
bridge's own reasoning; `explain:modules` says why each module is loaded
and who imports it. Both run from Compilation, where the Zcu owns the
finalized Sema as a mutable place.

The first run named the defect: a bare std name two std modules declare
is displaced, and the bridge resolved it to the one non-engine module
only if the engine twin was "ambient" through the std-tier walk — a proxy
that D39 §3.4's corpus boundary (#2248) turned false for every program.
The bridge now asks only that an engine twin exists and exactly one
non-engine, non-corpus-private std module declares the name.
… backtraces, timeout sampling, a generation differential (#2249)

Eric, 2026-10-07: "we are experimenting instead of measuring". Each of
these prints what the compiler or the build already knew:

- The thing that compiled was not the thing under test: every compiler a
  build action spawns is named in the action log — `[compile] <target>
  ran <digest> <binary> <argv>` from the process runner (hashed once per
  binary), the same line for a corpus test's runner from the build graph,
  and `[driver-compile] … compiler=<WITH_BUILD_COMPILER>` for a Workspace
  compile, which now REFUSES a std corpus module or its harness (the
  driver is the pinned seed; those are built by the compiler under test
  with --bundle-corpus).
- A nameless panic: rt_backtrace_print on Darwin walks the stack through
  libSystem's backtrace/backtrace_symbols_fd, innermost first; codegen
  keeps the frame-pointer chain in every function ("frame-pointer"="all")
  so the walk reaches past the panic frame, and with_panic_ref prints it
  too (the index-panic path).
- A pass past its timeout: the runtime samples the child
  (`/usr/bin/sample <pid> 2` to /tmp/with-timeout-<pid>.sample) before
  killing it and prints the path.
- Two generations disagree: tools/gen_diff.w runs `analyze <file>
  <query>` under two binaries, normalizes shifting ids and the std path
  spelling, and prints the lines only one side produced.
@ehartford
ehartford added this pull request to stack #2251 October 7, 2026 16:20
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery GREEN on stack #2251 top 06a4a6e (tools/battery.w: gate 61s, uat 27s, battery-checks 785s; status.txt has no RED). Gate on this layer: f384a21 rc=0.

@ehartford
ehartford marked this pull request as ready for review October 7, 2026 16:45
@ehartford
ehartford merged commit 46876b6 into main Oct 7, 2026
@ehartford
ehartford deleted the next-fixes branch October 7, 2026 16:45
ehartford added a commit that referenced this pull request Oct 29, 2026
…#985), unit elision (#723), typed extern var (#2335) (#2803)

* std: drop the len() casts nothing needs

Range bounds now join at the lossless widening (§4.2.6), and isize and
i32 widen into i64 at any demand, so these casts said nothing:
- build.w: str.slice bounds (as i64) and the https_fetch source's
  0..len() as i32 loops, which a literal start always allowed.
- cfg/stackify.w: stackify_bool_list took its count as i32, which forced
  three len() as i32; a count is an isize (D108). Its counting while loop
  is a for.

The rest stay: C ABI widths (c_int, c_uint, u64), stores into i32 fields
and parameters, and if-arms joining isize with i64 (D125).

* rt: a timed-out child is stopped without running the host's sample

The darwin runtime ran /usr/bin/sample on every child past its timeout
(#2249) before killing it: a host command in the toolchain (Eric,
2026-10-28: the compiler and its build are bootstrapped), seconds of
delay, a 'timeout: child N sampled' note on the waiting program's stderr,
and a /tmp file per child (135 had piled up since 2026-10-24). A build
that stops its lanes on an early return took the same path, so a
deliberate stop read as a hang.

The hang route in deep-debugging-tools.md is now the debugger: rerun the
timed-out command and `lldb --batch -p <pid> -o "bt all"` (run as
written: it named the spinning function and line).

Test: behav_process_timeout_stops_child, a probe that times out a
sleeping child; the installed compiler prints the sample note, stage1
nothing.

* std.crypto: ChaCha20-Poly1305 has a safe public seal and open, and its tag is RFC 8439's (#1054)

The AEAD's one entry point was a private raw-pointer unsafe fn, so no
program could call it. Worse, it never produced RFC 8439 tags: it fed the
AAD and its zero padding to poly1305_update in two calls, and
poly1305_update closes a short final block (0x01 marker) at the end of
every call, so a partial last block went in marked and short instead of
zero-padded to 16. Poly1305 alone matches RFC 8439 §2.5.2; the AEAD's
ciphertext matched §2.8.2 and its tag did not (36ae32c8… for 1ae10b59…).

- chacha20_poly1305_seal(key, nonce, aad, plaintext) -> Result[List[u8],
  AeadError]: ciphertext then tag. chacha20_poly1305_open checks the tag
  in constant time before decrypting. Both take the buffer they turn into
  their result and work in place (D110: the callee stores it); key, nonce
  and aad are observed.
- AeadError: KeyLength, NonceLength, Forged.
- chacha20_crypt and poly1305_update take their length as an isize (D108),
  which retires their callers' len() as i32.

Test: behav_1054_chacha20_poly1305_rfc8439, RFC 8439 §2.8.2 both ways, a
flipped ciphertext bit, other aad, a short input, and bad key and nonce
lengths; clean under the debug allocator.

* std.random and std.sys: shared state is synchronized, not a plain global (#985)

std.random's xorshift state was a plain var that every draw read and wrote.
Threads drawing at once read one state and drew the same value: eight OS
threads drawing 20000 each got 10219 duplicates under the installed
compiler. xorshift64 repeats nothing within its period, so each duplicate
is a lost step. std.sys filled five globals behind a plain bool on first
call, so first calls from two threads both measured and raced the writes.

§9.1c: shared mutable globals are Sync types.
- rng_state is a global Atomic[i64]; a draw is one compare-exchange from
  the state it read to its successor, and the first draw seeds it.
  seed and seed_now store.
- std.sys keeps its facts in a global Mutex[Option[SysFacts]]; the first
  caller measures under the lock. The _bw_sink global was dead (the read
  pass's barrier is inline asm on a local) and is gone.

The issue's 0 - v overflow went with #2279's rewrite (wrapping draws).

Test: behav_985_random_draws_race_free (installed: 10219 duplicate draws;
stage1: 160000 distinct, five runs out of five).

* sema: unwrap_or() on a Unit payload elides its argument (§4.8, #723)

§4.8 unit elision: a single expected Unit argument may be omitted, and its
first example is unwrap_or(). Ok(), Some(), a user fn's Unit parameter and
an Ok() pattern already elided; unwrap_or() on Option[Unit] or
Result[Unit, E] was refused ('expects exactly one argument') because
method_expected_arg_type leaves unwrap_or's default untyped on purpose (a
given default is a join input). With no argument there is no join, so the
method path's elision step reads the payload type for unwrap_or itself.
Option[i32].unwrap_or() is still refused.

spec_ss04_8_unit_elision passes (5 tests); its known-issue marker is gone.

* frontend: an extern var naming a typed owner global is kept (#2335)

An `extern var` naming another module's global resolved when the owner
was untyped and was refused when it stated its type ('symbol ... is not
visible from this module'). The frontend dropped an `extern var` from the
user and root tiers when its name, mutability and type text matched a
declaration in the tier (8a434e0, for migrated modules that each
declared the same global). An untyped owner has no type text, so its
`extern var` survived; a typed one's was dropped, and with it the
declaring module's grant (has_extern_var_decl), so the owner's global,
private to its own package (D100), was not visible.

Sema merges an `extern var` with its owner (the #113 test), so the user
and root tiers keep the declaration. The prelude tier's filter is
unchanged. The regex tests, which compile the migrated pcre2 from source
on stage1, pass.

Test: issue2335_extern_var_typed_redeclaration (installed: not visible;
stage1: ok).

---------

Co-authored-by: Eric Hartford <[email protected]>
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