Repository navigation
d126 locals - #2342
d126 locals#2342
Conversation
…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)
|
D126's two gates, on the gate's release binary (commit 44670ce): Type diff ( Sema time on Acceptance: |
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.
|
Battery 1 on this stack: gate green, UAT green (all 12 scenarios, the three fixtures unedited), then |
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).
|
Battery green on dab009c (seed-driven, |
Stack created with GitHub Stacks CLI • Give Feedback 💬