Skip to content

d126 locals - #2342

Merged
ehartford merged 9 commits into
d127-static-viewsfrom
d126-locals
Oct 11, 2026
Merged

ehartford merged 9 commits into
d127-static-viewsfrom
d126-locals

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Stack created with GitHub Stacks CLI • Give Feedback 💬

Eric Hartford added 2 commits October 10, 2026 09:31
…ee on (§4.2.1, law 1)

The D114 battery went red on three release UAT programs (`var total = 0`
returned as i32, `var sum = 0` as an Ok payload, `var x = 40` to a C int):
law 10 reporting that "locals are not typed by their uses" had quietly
lost law 1, since the compiler can establish the type from the body it is
checking. The rule D126 deferred, per function, with the guarantee it set:

- A body's first check records each demand narrower than isize on a
  literal-typed local (bare name, or names reached through arithmetic)
  instead of refusing it. A body that recorded one is checked again, once,
  with each such `let` at its first demand; a use that cannot take that
  type reports both uses. A body that records nothing is checked once, so
  no local in a program that compiles without the rule changes type.
- A slice demand on a list-literal binding makes it a List of the element
  (D93 carries the decision, one mechanism for collections).
- Law 2's own example: a literal operand of a generic call leaves T open;
  the demand binds it, and when the demand is a carrier (`Option[i32]`)
  T is the payload (D103): `let x: Option[i32] = ident(3)` is
  `Some(ident(3))` with T := i32.

examples/c-interop drops the two annotations D126 made necessary (the
ruling said the rule removes them); behav_law2_demand_order spells
`ident(3)` again.
… type-diff gate: zero over the compiler and std)
@ehartford
ehartford added this pull request to stack #2339 October 10, 2026 16:57
@ehartford

Copy link
Copy Markdown
Contributor Author

D126's two gates, on the gate's release binary (commit 44670ce):

Type diff (WITH_PROFILE=1, int-local-rechecks on the sema line): src/main.w 0 (17,493 decls), build.w 0, lib/std/build.w 0, tools/battery.w 0, tools/ceremony_census.w 0, tools/drop_audit.w 0. A body is rechecked only when a demand narrower than isize was recorded, so zero rechecks means no local in the compiler or std changed type.

Sema time on src/main.w, interleaved, pre-rule binary vs this one: 70.9 s / 69.3 s before, 67.4 s / 67.8 s after. No cost.

Acceptance: uat/libcurl, uat/sqlite3, uat/raylib_spiral check unedited; examples/c-interop drops D126's two annotations; behav_law2_demand_order spells ident(3) again; D128 (#2341) records the ruling and the §4.2.1 words.

The drop audit's cells (`for i in 1..9: heap.push(mk(i, slot))`, `mk(id:
i32)`) were refused: the rule covered a `let` and not a `for` binding over
literal bounds, which is the same local by the same law. The body's
second check types the range at the variable's decision (`Range[i32]`),
through the same demand that types a demanded range's bounds.
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery 1 on this stack: gate green, UAT green (all 12 scenarios, the three fixtures unedited), then drop-audit red: 18 cells COMPILE-FAIL, all for i in 1..9: mk(i, slot) at mk(id: i32). A loop variable over a literal range is a literal-typed local by the same law; c60c71a covers it (the range is typed at the variable's decision on the second check). int-local-rechecks still 0 over src/main.w and build.w. Gate rerunning, then the battery again.

Eric Hartford added 6 commits October 10, 2026 10:45
Two drop-audit shapes reached a literal-typed local through the argument
mismatch site rather than the narrowing one: `index.remove(&i)` at `&i32`,
and `eat(move a)` with `a = (mk(1, slot), 7)` at `(R, i32)`. The mismatch
site now records the demand for the body's second check: the integer
local at the parameter's value type, the tuple local at the demanded
tuple when the elements differ only where its literal elements are
untyped.
…oint, never rechecks an erroring pass

Battery 2 surveyed sixteen red targets; all but two were D114 fallout in
corpora the behavior sweep never ran, now covered by the rule:

- A demand reaches a literal-typed local through a block tail, a derived
  local's initializer (`let mid = lo + (hi - lo) / 2`, an `if`, a `match`
  of literals), a slice of a list literal's binding (`a[1..3]`), a struct
  literal field, a `loop`'s untyped `break`, an explicit result, and a
  tail judged after the body's scope closed (fn_demand_lets).
- A loop variable over a list literal (`for sym in [1, 2]`), a tuple
  literal's binding, and `var xs = List.new()` filled by literal pushes
  (recognized by its constructor; D93 carries the slice case) take the
  demanded type; a literal `push` is a weak D93 demand a typed one
  overrides.
- A decision can create a demand (`sum: i32` then `sum = sum + i`
  demands of `i`), so a body is checked until no undecided local is
  demanded; a join of a decided local and an undecided one demands of
  the latter. A pass with an error of its own is never rechecked: the
  program is rejected whatever the locals' types, and once-only tables
  (D32's dedup, the facade's call state) would otherwise drift.
- Float literal locals are not the rule's; a literal arm's `if`
  condition is never checked twice; a later pass may re-record a Copy
  adjustment or a join decision.
- The free and method generic paths share one literal-binds-last helper:
  an untyped literal argument binds T from the call's demand (an async
  call's through its Task, a carrier's through its payload) and only then
  from the default. `h.apply(3, (x: i32) -> i32 => …)` is T := i32.
- D111's two-level copy is `str`'s alone; `&&i32` keeps its explicit
  deref (two pinned tests). A comptime cast to a repr enum evaluates.
- Compiler sources only the internals tests reach carry the audit's own
  spellings (a page size as an untyped const, a parameter index as i32).

WITH_PROFILE names each rechecked body; `int-local-rechecks=0` over the
compiler and the build layer.
… spelling (#2343)

behav_d128_int_local_shapes covers the tail, slice, struct field, loop
break, assignment-after-decision and literal-push shapes; the obsolete
err_d114_ok_wrap_narrowing (D128 accepts it) is retired. A few spec and
debug-alloc fixtures spell what the rule does not yet reach — a
comprehension's binding, a builtin's result from a literal init, a loop
value's local, a tuple local read by element — listed on #2343 with the
annotations that come out when it lands. generic_sizeof_mono sizes an
i32 and an i64 instance as before (`PC.make(1i32)`).
…ment, lengths compared as isize); the census bar holds
… slice demands stay weak; view arms and lazy arms defer to the local's decision

`opt.unwrap_or_else(() => 130)` with `opt: Option[&i32]` is a join arm
beside the payload (§4.2.1 rule 8): the closure is checked against
`fn() -> i32` through the view, so the literal takes i32. The dead
`method_closure_arg_expected_type` hook that never ran is gone; the
decision sits at the one caller of `method_expected_arg_type`.

The phase dump expectations follow D114: a join of untyped literals is
`Option[isize]`. pcre2_verify's argv index is an isize.

Self-check: int-local-rechecks=0; Sema time matches main's stage1 on the
same source (167.6 s vs 166.0 s).
…al range; a demand on the loop variable decides the bound's local too

`let unique = 6000; for i in 0..unique: symbol_name(i)` left `i` an
isize and refused the narrowing (battery red: intern_pool_stress_test).
A bound whose value comes from literal-typed locals makes the range
literal, the loop variable's demand lands on those locals, and a call
argument's demand reaches every literal-typed local the argument comes
from, so `i` and `unique` are decided i32 in the same round.

Self-check: int-local-rechecks=0, Sema 159 s (main's stage1: 166 s).
@ehartford
ehartford marked this pull request as ready for review October 11, 2026 14:41
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery green on dab009c (seed-driven, with run tools/battery.w): gate, UAT and the full survey (fixpoint, drop and move audits, every test target, user-programs-safe, green evidence) all green. Self-check: int-local-rechecks=0; Sema time equals main's stage1 on the same source.

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