Skip to content

Sema/Codegen/migrator: unsuffixed literal arithmetic takes its context's type (§4.2.1); one §4.2.6 rule refuses implicit numeric narrowing at every owned demand; examples widened or spelled (#1820 #1803) - #1894

Merged
ehartford merged 20 commits into
fix-miscfrom
fix-literals
Sep 29, 2026

Conversation

@ehartford

@ehartford ehartford commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Stack #1898, layer 9. Closes #1820, #1803. Eric's 2026-09-28 verdict 1: examples widen the declared type where the narrow type was incidental and write as where it was a layout or interface choice (ecs f32 fields; json byte→u8), citing the truncation matrix (5000000000 → 705032704). Also: &i32 is not &i64 (a reference views one type); a container argument widens by its operand's signedness; the C migrator spells C's usual arithmetic conversions; std.re/std.zl re-migrated. Gate green on the layer before folding; after the fold, :dev + 49 #1803/#1820/#1847/vec-push/box-dyn tests pass. Draft until the stack battery is green and posted.

@ehartford
ehartford added this pull request to stack #1898 September 29, 2026 05:03
@ehartford ehartford changed the title fix literals Sema/Codegen/migrator: unsuffixed literal arithmetic takes its context's type (§4.2.1); one §4.2.6 rule refuses implicit numeric narrowing at every owned demand; examples widened or spelled (#1820 #1803) Sep 29, 2026
Eric Hartford added 20 commits September 29, 2026 14:40
…, folded and checked at that type; c_import keeps a C literal's suffix

`let x: u8 = 1 + 2` was "implicit integer narrowing": check_binary typed
two literal operands with check_expr_value_context, so rule 1 of §4.2.1
(the target type of a typed binding) never reached them, and the i32 sum
narrowed. At the other positions the same sum was computed in i32 and
truncated silently (`take(100 + 100)` into i8 passed -56).

Rule 1 now reaches through arithmetic made of unsuffixed literals and
parentheses (`expr_is_untyped_literal_arith`): both operands are checked
with the enclosing numeric expectation, as a bare literal is. Rule 3 (the
peer operand) reaches the same way, so `y + (100 + 100)` with `y: i8` is
i8 arithmetic, a suffixed literal is a typed peer (`1 + 2u16` is u16), and
a range's literal bound takes its peer bound's type (`0..v.len()` is a
Range[i64]; the end was an i64 narrowed into the start's i32).

The value of such an expression is known, and §4.2.3 makes arithmetic
checked: an overflow at the context's type is a compile error at the
operation that overflows (`let x: u8 = 200 + 100`, `let m: u32 = 0 - 1`),
where it was a narrowing error or a run-time panic. Each operation is
checked at the declared width, as Rust's arithmetic_overflow lint and
Swift's constant propagation do (Go and Zig fold exactly and check only
the result).

D65: Sema records the type of every arithmetic node (checked, wrapping,
saturating, negation), and the LLVM constant folder reads it and nothing
else: try_eval_const_result_type's fallback to the destination's type and
the expected_tid threading are gone. 26649546 had to leave literal-only
arithmetic unrecorded because limits.h's ULONG_LONG_MAX, rendered
`9223372036854775807 * 2 + 1` into c_ulonglong, overflowed as i64; it is
now u64 arithmetic in Sema.

c_import renders a C integer literal's suffix (C11 6.4.4.1): `2ULL` is
`2u64`, `5U` is `5u32`, so `__LONG_LONG_MAX__*2ULL+1ULL` is u64 arithmetic
on its own, whatever the destination.

Also: a negation's operand is a magnitude (#943) only when it is the
literal itself; in `-(128 + 0)` the 128 is an i8 value.

Tests: behav_1820_literal_arith_takes_context (every context and shape),
behav_1820_c_import_integer_suffix, err_1820_* (overflow at the context
type, below an unsigned zero, through a peer, a suffixed peer). Each
fails on a1f82be6 (accepted, truncated, or the narrowing error).

Fixes #1820
…ed demand, not only at an annotated `let`

Only check_binding_annotation ran int_narrowing_requires_cast. Every other
position that demands a number took a narrower or differently-signed value
and truncated it at run time. Measured on a1f82be6 (one program per cell,
`let s: i64 = 5` etc.): array, Vec and tuple elements, struct fields, call
and method arguments, Vec.push, tail and `return` values, annotated
globals, assignments, compound assignments, enum payloads, if/match arms
under a demand and a `??` payload all accepted i64->i32, u32->u8, i32->u8
and i32->u32 (`take(s)` with `s: i32 = -1` into u32 passed 4294967295).
Floats were worse: `let x: i32 = f` (f: f64) type-checked and the binding
held the f64; an f64 into an i32 element or return read 0 or garbage; an
i32 into an f64 element, field, return or assignment stored its bit
pattern (3.45846e-323 for 7).

reject_implicit_numeric_narrowing is the rule (§4.2.6): a numeric demand
accepts the value's own type or a lossless widening; a narrower integer,
the other signedness at equal width, a float into an integer, an integer
into a float and f64 into f32 need `as`. A Copy view is read as the value
its demand materializes. Every owned demand reaches it:
check_expr_with_owned_demand (bindings, returns, assignments, elements,
fields, field defaults, map literals, comprehensions, yields),
note_call_arg_coercion (every call path's by-value argument), and the
demands that did not route there: the declared return type on a tail, a
sequence literal's elements, enum payloads (both constructor paths), an
annotated global (check_top_level_let_values), and each arm of an if,
match or `??` join under an owned expectation. check_binding_annotation
and the field-default check no longer carry their own copy of it.

Unsuffixed literals took the demanded type already (§4.2.1, the previous
commit), so only typed values arrive with another type. Signed into a
wider unsigned (i32 -> u64) stays accepted, exactly as the annotated
`let` accepted it; §4.2.6 lists it as needing `as` too (reported).

behav_global_init_overflow_panics spells its element conversion
(`(0 - K) as i16`): the u32 no longer narrows into i16 implicitly, and the
test still pins #1773 (the fold is at u32, the startup panics).

Tests: err_1803_* — one position per file (a passing test proves that
position refuses) plus float->int, int->float, f64->f32 and sign change.
Each is accepted on a1f82be6 (the field default gave another message).

Fixes #1803
…type

The stage1 self-check (`with check src/main.w`) under the two previous
commits, one finding at a time:

- A loop over `0..v.len()` is a Range[i64] now (§4.2.1 rule 3): where its
  index is an i32 id (places, locals, type ids, call arguments, captures),
  the bound narrows explicitly, `0..v.len() as i32`, the file's own idiom.
- `captures.len()` stored into i32 counters (MirLower): the narrowing is
  spelled.
- CodegenTraits.resolve_trait_method_type_for_impl_with_trait held an LLVM
  type handle (i64) in an i32 `var concrete_ty = 0`: it is i64.
- CodegenDispatch's FIXED_STRING_CAPACITY kept an array length (i64) in an
  i32: it is i64.
- Codegen passed `width as i64` to wl_di_create_basic_type's u64 bits: the
  i32 width widens into it unspelled.
- CImport's character-literal decoder kept `hex_value & 255` (i32) in a u8
  `var value = text[i]`: value is i32, and its `as i64` goes.
- Frontend.interface_name_token takes the i64 `find` offset;
  BuildGraphOps and main.w's escape_dump_lexeme keep byte offsets in i64.

Refs #1803
- std.alloc: Arena/FrameArena.alloc_zeroed passed `total as i64` to
  mem_set's i32 size — a widening the call then narrowed back silently.
  The i32 total goes as it is. arena_vec_grow/arena_vec_push passed
  `... as i64` sizes to mem_copy's i32 size: they narrow `sizeof` to i32
  explicitly, once (found through behav_arena_vec, which instantiates the
  generic).
- std.zlib: `const ZLIB_MAX_CHUNK = (0 as c_uint) -% 1` reads as i64 (#1836,
  an unannotated const loses a cast's type), so the if-arm
  `ZLIB_MAX_CHUNK` narrowed into the u32 avail_in/avail_out fields. It is
  annotated until #1836 is fixed.

Refs #1803
- build/emit_c.w emitc_compare_files: the first differing byte offset is
  an i64 (`var diff_at: i64`), as `min_len` is.
- tools/drop_audit.w: the cell index narrows into run_cell's i32
  explicitly (`0..cells.len() as i32`).
- tools/docs_restructure.w: section and decision positions are the i64
  offsets `find` returns; the `as i32` narrowings go with them.

Found by `with check` on build.w and each tool under the stage1 of the
#1803 commit.

Refs #1803
…e; std.re, std.zl, std.tommyds, std.c_algorithms re-migrated

The migrated corpora compiled only through the #1803 gap: C converts
implicitly at an assignment, a return, an initializer and a compound
assignment, and the migrator left those conversions to With's silent
narrowing. Under the #1803 rule std.re (the prelude's regex engine, so
every program), std.zl, std.tommyds and std.c_algorithms failed to check.
The fix is the migrator's (C library migration methodology), and every
corpus is re-migrated by it, unedited.

- Value path (lower_value_expr_ir): an implicit conversion With does not
  make — a narrower integer, the other signedness at equal width,
  integer<->float, a narrower float (ci_implicit_conversion_needs_as, read
  from clang's canonical kinds through the new with_ci_scalar_type_bits,
  never clang_Type_getSizeOf) — materializes as `as`, as #740 did for
  scalar->_Bool; the rest stay transparent. tommyds's
  `return __builtin_clz(v) ^ 31` into tommy_uint_t, pcre2's
  `return groupinfo & GI_FIXED_LENGTH_MASK` into int.
- Compound assignment (statement form): `E1 op= E2` computes in the
  promoted or common type and converts the result back to E1's type
  (C11 6.5.16.2); a promoted small left operand or a wider/float right one
  now spells that conversion (`assert_depth += 1` on a uint16_t,
  `bi_buf >>= 8` on an ush, `c -= OP_STAR - base` on a PCRE2_UCHAR).
- Global initializers (the text path): an item C converts is cast to the
  element or field type, decided by clang's own initializer cursor item by
  item (ci_init_list_item_cursor), and without one for any item that names
  a value; untyped literal arithmetic takes its context (pcre2's
  `escapes: [75]c_short = [..., (0 - ESC_A), ...]`; `(48 + 0x0a)` and
  coptable's `(1 + 2)` stay as they are, now valid under #1820).
- Macro constants (c_import and migration): a computed value states its
  C type, `let OVEC_UNIT: c_ulong = ((sizeof[usize]() / sizeof[c_int]())
  as c_ulong)` — With types `sizeof` i64 and a mixed-signedness sum by its
  left operand, neither of them C's usual conversions.
- memchr's and strncmp's size_t argument is cast to the shared preamble's
  i64 size at the call, as memcpy's already was. The declarations stay
  i64: an extern is one C symbol across modules, and every earlier
  migration declares it that way.
- The printer drops a conversion to the type its operand was just
  converted to (`((x as T) as T)`), which the materialized conversions
  would otherwise double.

Re-migration: the four corpora staged exactly as build/pcre2.w,
build/zlib.w, build/tommyds.w and build/c_algorithms.w stage them and run
through `with migrate <src> -I <src> [-D ...] --no-c-export --no-prelude
--prefer-brace --width-slice 8 --shared-defs <package>.defs` (zlib's
example.c/minigzip.c with --migrate-one and --shared-fragment), then
copied over lib/std unedited; bundle.w is unchanged. The driver targets
(`:<stem>-migrate`) could not run: the pinned seed fails
pcre2-prepare-reference in comptime evaluation, and a tree driver cannot
compile build.w until these corpora check. The same staging and flags
with the a1f82be6 migrator reproduce lib/std/re byte for byte; for zl,
tommyds and c_algorithms they also carry the migrator changes landed
since their last promotion (#1774's int enumerators, which the #1803
rule needs: zl's inflate_mode and deflate block_state ternaries, avl_tree's
AVL_TREE_NODE_*; redundant `unsafe` dropped; zl's unused
deflateInit/deflateInit2 wrappers are no longer emitted).

Verified: `with check lib/std/<corpus>/bundle.w --no-prelude
--bundle-corpus std/<corpus>` ok for all four, and pcre2test.w,
example.w, minigzip.w, check_.w and test_cpp.w check against their
bundles; the compiler self-check is ok with the new std.re. Not run: the
corpus lanes (:pcre2-test, :zlib-test, :tommyds-test,
:c-algorithms-test) — battery targets.

Refs #1803 #1820
Tests follow the spec (§4.2.6). Each of these relied on a silent
narrowing, found by `with check` over test/ under the #1803 rule and
compared with the same sweep on a1f82be6 (every other failure there is
the baseline's own):

- `len()`, `find()` and a slice-rest count are i64: the functions that
  return them say `-> i64` (duck_method_ok, behav_no_alloc_str_view,
  behav_comptime_move_arg, behav_let_else_slice_rest_binding,
  temporary_exit_cases' argument_return), the accumulators are i64
  (behav_for_full_patterns, behav_guard_local_use and spec_ss07's
  `seen` of a Mutex[i64]), and an entry point's i32 exit code and an i32
  index narrow explicitly (behav_no_std_alloc_prelude, issue66 ir_text,
  cd_str's `find`).
- `size_of[T]()` is i64 and malloc takes the C size_t: demo's
  program/stream allocations convert explicitly.
- spec_ss10_3's usize lengths convert `len()` explicitly.

Refs #1803
…t zero divisor is an error; §4.2.6's sign rule and one operand join for arithmetic

Rulings (coordinator, from the spec and the reference compilers):

- §4.2.1 through shifts and `& | ^`: an untyped left operand of a shift
  takes the context's integer type, as do both untyped operands of a
  bitwise operator; the shift amount types on its own (§4.2.1's
  `x >> 31` example). Rust and Swift type `let x: u8 = 1 << 3` and
  `1 | 2` so. behav_comptime_unsigned_arith (`fn () -> u32: 1 << 8`) and
  `let d: u64 = 1 << 40` (an i32 shift before) now hold. Untyped literal
  expressions (expr_is_literal_arith_of) include bitwise operators, shifts
  (by their left operand) and `~`, and the constant fold evaluates them
  (§4.2.4's wide-shift results).
- An integer division or remainder by a divisor known to be zero (a literal
  expression that folds to 0) always panics: a compile error at the
  expression, as in Go, Rust, Zig and Swift.
- §4.2.6 "No other implicit numeric conversion is allowed … Signed-to-
  unsigned and unsigned-to-signed conversions also require `as`, even at
  the same width": int_narrowing_requires_cast accepted a signed integer
  into any wider unsigned one (i32 -> u64 turned -1 into
  18446744073709551615). It now allows only the same signedness at an
  equal or greater width, or unsigned into a strictly wider signed type.
- An arithmetic operator's operands meet at implicit_numeric_join, the
  type one of them widens into losslessly; with none (i32 and u32, i32 and
  u64, an integer beside a float) it is an error naming both types.
  arithmetic_result_type took the left operand at equal width and let float
  win over int. An unsuffixed literal still takes its peer's type first.
  A wrapping or saturating operator computes at its left operand's type,
  so its right operand must convert to it implicitly. Compound assignment
  is `x = x op y` and follows the same rule.

Tests (each fails on a1f82be6 but the widening guard):
behav_1820_shift_bitwise_literal_context, err_1820_constant_division_by_zero,
err_1820_constant_remainder_by_zero, err_1803_signed_to_wider_unsigned,
err_1803_unsigned_to_signed_same_width, err_1803_mixed_signedness_arithmetic,
err_1803_int_float_arithmetic, err_1803_compound_mixed_signedness,
err_1803_wrapping_operand_mismatch; behav_1803_lossless_operand_widening
pins the widenings that stay implicit (u8+i32, u32+i64, f32+f64, u8->i16).

Refs #1820 #1803
…obal's initializer is checked whatever failed before it

#1836: `const B = (0 as u32) -% 1` read as i64 and `const S = (7 as u16)`
as i32. The comptime transform folds a binding's `comptime` value into a
bare literal (ct_rewrite_comptime / ct_build_value_tree) before the
program is checked, and check_top_level_let_values then typed that bare
literal from the default ladder (the [tll] trace shows the value as
NK_INT_LIT). Now the fold records the value's evaluated type on the scalar
it makes, and a binding whose whole value that literal is keeps it as the
literal's suffix (ct_keep_folded_literal_type). A literal inside a folded
aggregate stays bare, so its field's or element's type still reaches it
(`TextureId { value: 0 }` into a u32 field). std.zlib's
`const ZLIB_MAX_CHUNK = (0 as c_uint) -% 1` drops the annotation the
previous commit gave it.

The cascade: check_top_level_let_values returned at the first error, before
it and after any global initializer that failed, leaving every later
global untyped; each use of one reported a false error elsewhere ("missing
return" in src/compiler/Frontend.w, "bitwise operator requires integer
operands" in src/CImport.w during the #1803 sweep). Every initializer is
now checked and typed; a comptime value is evaluated only when its own
check found no error.

Tests: behav_1836_const_keeps_folded_type (fails on a1f82be6),
err_1836_global_error_no_cascade (a1f82be6 also reports the two false
errors, which `expect-check-fail-not` refuses).

Fixes #1836
wl_di_create_basic_type takes its size in bits as u64; the i32 type width
widened into it implicitly, a signed-to-unsigned conversion §4.2.6 requires
spelled (the sign rule of the previous commits). The only site the stage1
self-check found under it.

Refs #1803
…; std.re, std.zl, std.tommyds, std.c_algorithms re-migrated

Under the sign rule and the operand join the migrated corpora mixed
signedness and sizes With no longer joins implicitly. Fixed in the
migrator, every corpus re-migrated by it, unedited:

- ci_implicit_conversion_needs_as follows the new rule
  (ci_scalar_conversion_needs_as): signed into unsigned at any width,
  unsigned into a signed type no wider, now materialize as `as`
  (`size_t n -= int_len` in pcre2_convert, `plength -% (clength as c_ulong)`).
- C's `sizeof` is a size_t, c_import's usize, where With's is i64: the
  printer spells `(sizeof[T]() as usize)`, and a converted sizeof converts
  once (`(sizeof[T]() as c_int)`).
- A pointer difference is C's ptrdiff_t, signed: the wrapped byte
  difference and the element size convert to the expression's C type
  before dividing. It was a usize, which met the int and long operands
  beside it (pcre2_dfa_match's `(end - start) + length`).
- Compound assignment converts its left operand to the computation type
  when it does not widen into it (`int += unsigned` computes in unsigned,
  then converts back), and a promoted small right operand of an unsigned
  compound converts on to the unsigned result type (`adler += buf[0]` on
  an unsigned long, tommyds' `c += key[8]`), which the promotion's cursor
  type no longer showed.

Re-migration as in e4996268 (the same staging and `with migrate` flags);
`with check` of each bundle (--no-prelude --bundle-corpus) and of
pcre2test, example, minigzip, check_ and test_cpp against their bundles:
ok. The compiler self-check with the new std.re: ok.

Refs #1803
…2.6), and a slot, range, entry or channel store writes the element's width

`v.push(x)`, `m.insert(k, v)`, `[a, b]`, `[k: v]`, `m.get(k)`, `contains`,
`remove`, `increment`, `entry.set`, `or_insert`, `SlotMap.insert`,
`slot.set`, `range.set(i, x)`, `Atomic` operands and `tx.send(x)` took the
LLVM value of the argument and either sign-extended it
(`coerce_value_to_type` → `coerce_int_ext(..., is_unsigned=false)`: a u8 200
pushed into a Vec[i16] read -56, a u32 key 4000000000 missed its i64 entry)
or stored it at its own width (VecSlot.set / VecRange.set / Entry.set /
Sender.send stored the two-byte value into an eight-byte element: `range
-14081`). A call argument already widened by the operand's Sema signedness
(#1017); every intrinsic argument now goes through the same
`mir_operand_value_as`, and the storing intrinsics take the element type
from the receiver's `T` (`mir_recv_elem_sema_type`) rather than from the
value. Found by the widening matrix for #1803: the u8→i16 cell said 200 at
every owned demand but -56 through a Vec.

test/behavior/behav_container_arg_widening.w pins all sixteen surfaces;
before this change it printed -56, -294967296, -14081 and `get 0 false 0`.
`types_compatible` accepted `&A` for `&B` whenever `A` converted to `B`,
because `pointer_pointees_compatible` reused the value rule and every
integer is a value-compatible integer. A reference does not convert its
pointee: `show(&z)` with `z: i32` and `show(r: &i64)` read eight bytes of
a four-byte local (4294967291 for -5), `let r: &i64 = &z` reached codegen
as invalid MIR, and a `??` / `unwrap_or` / `if` / `match` join of `&i64`
and `&i32` picked the lower type id and read half the map's value
(`m.get("k") ?? &0` printed -294967296 for 4000000000). Both the mutable
and frozen compatibility paths now refuse two references whose numeric
pointees differ in width, sign or int/float, and a join whose reference
arms disagree names both types instead of failing on "one compatible
result type".

Three compile_errors pin the argument, the binding and the join.
… spelled where the type is the meaning

The one narrowing rule (#1803) is not let-only because the same silent
truncation happens at every owned demand: the matrix cell for a u32 count
into an i32 field reads `5000000000` → `705032704` at a field, a call
argument, a Vec element, a return and an assignment alike. Eric,
2026-09-28: (b) where incidental, (a) where a layout or interface choice.

(b) widened:
- nebula `SessionStats.active_count`: holds `sessions.len()`; a count is
  `i64`. The test's own `SessionStats` counts by hand and is untouched.
- ecs `DenseStorage`: the sparse map's value and `len()` are dense-array
  indices, i.e. `Vec.len()` values, so `HashMap[i32, i64]`, `idx: i64`
  and `len() -> i64`. `Entity.id` stays `i32`: it is the entity handle,
  an interface choice, and `dense_entities: Vec[i32]` holds handles.
  Nothing here is packed or GPU-facing.

(a) kept narrow, the conversion spelled:
- json-parser: `byte_at` returns `i32`; `peek() -> Option[u8]` and
  `is_digit(ch: u8)` mean a byte, so `as u8` at the three sites.
- ecs `World.dt: f32` is a component-layout choice; the literal
  `1.0 / 60.0` takes `f32` from the binding's annotation (§4.2.1 rule 1)
  instead of an `as` on the assignment.
…(§4.2.6)

rt_core.w declared `extern fn rt_mmap(size: u64)`, `rt_munmap(.., size: u64)`,
`rt_write(.., len: u64)` and `rt_read(.., len: u64)`, while every platform
backend (darwin_aarch64.w:273/280/180/190, linux_*, windows_*, wasm.w)
defines them over `i64`; rt_exit was declared `-> Unit` against the
backends' `-> Never`. Because rt_core.o and each platform object compile
separately, each unit agreed with itself, and every caller spelled
`size as u64` to fit the wrong declaration. The in-unit check lane
(behav_rt_in_unit_check_lane), which joins declaration and definition in
one unit, refused all 18 calls as implicit u64 -> i64 sign changes.

The declarations now match the definitions; the `as u64` casts at the 18
calls (rt_core.w 685..4149), in ComptimeEval.w, LlvmBridge.w and
ClangBridge.w are removed, since the operands are already i64 (widening
where incidental). with_libc_read/with_libc_write keep their C-shaped `u64`
count and spell the conversion to the i64 seam with `as`, a real interface
choice. The two runtime-domain-audit fixtures declare rt_write as the
backends define it.
…w is not a definition

The audit that exists to catch one symbol declared two ways (#761's class)
only looked at with_* names. The rt_* platform seams are exactly that
case: rt_core.w declares what darwin_aarch64.w and the other backends
define, in separate objects, so no single compilation ever sees both
spellings. That is why the runtime object build stayed silent on
rt_mmap(u64) against rt_mmap(i64): no Sema path is skipped, the narrowing
exists only between two units, and only the in-unit check lane joined them.

The scanner now takes rt_* as well as with_*, skips `fn name` rows inside
a `c facade` block (no parameter list: they describe an extern, they do
not define one; before this they parsed as empty-signature definitions and
flooded the report with false divergences), and reports each divergent declaration once
rather than once per platform definition. Against the previous commit's
parent it reports 11 divergent declarations (rt_write, rt_read, rt_mmap,
rt_munmap, rt_exit across rt_core.w, ComptimeEval.w, LlvmBridge.w,
ClangBridge.w and two audit fixtures); at this commit it reports 0.
rt-decl-audit is a `:test` lane, so every battery now runs it.
…rectly (ABI v8)

c-migrator-core-tests' run-runtime-cabi-aliases exited 1. The migrated
program's with_str_len returned 4345250758 for a two-byte string: the
migrator declared the runtime symbol as
`extern fn __with_cabi_physical_with_str_len(__param_text: &with_str)` and
bridged the C call through it (src/CiMigrate.w
ci_migrate_runtime_borrowed_str_param_mask, the pre-D5 "one place address"
compatibility descriptor). Since ABI v8 (D71 §4.8a, #1810, 8e0e58d) a
shared `&str` is a `{ptr, len}` view passed by value, so the runtime read
the bridge's pointer as the view's ptr and the next register as its len.
Declaring the same symbol with a by-value `with_str` returns 2 1 1 1 and
the program exits 0.

The migrator now emits the C declaration as written (the same shape as the
runtime's view parameter) and the borrow mask, the physical alias and the
bridge are removed. The selfhost case asserts the direct declaration and
that no `__with_cabi_physical_` bridge is emitted; its old
`&with_str` expectation described the pre-v8 ABI and was wrong under v8.
…tors, #1774)

c-algorithms-test refused test/corpora/c_algorithms avl_tree.w:467
(`__local_side = AVL_TREE_NODE_RIGHT`, u32 -> i32). The checked-in
ALLOC_TESTING test corpus predated #1774 (2489c67), which types an
enumeration constant as `int` (C11 6.7.2.2p3): its defs.w still declared
`AVL_TREE_NODE_RIGHT: c_uint`, while the migrator on this tree emits
`c_int`. #1774 re-migrated std.c_algorithms but not the test programs, and
the §4.2.6 sign rule on this layer turned the stale `c_uint` into an error.
Nothing in the migrator was wrong; the output was stale.

Regenerated with the build's own targets (driver = this tree's stage1):
`with build :c-algorithms-promote` (runs c-algorithms-migrate-tests and
c-algorithms-promote-tests). lib/std/c_algorithms/defs.w also loses the
with_va_start/with_va_end preamble externs that #1678 (173d8aa) retired.
`with build :tommyds-promote` reproduced std.tommyds byte for byte.
…er; two numeric arms join only by a lossless widening (§4.2.6)

`if ns <= 0: 0 else: ((ns + 999999) / 1000000) as u32` was i32: the
literal checked in value context as i32, and merge_contextual_owned_join_types
(SemaCheck.w) asked arithmetic_result_type (Sema.w:9271), whose "wider int
wins" returns the LEFT operand at equal width, so the u32 arm changed sign
silently and `Sleep(ms)` then refused the i32 (§4.2.6). The arms the other
way round joined at u32. 1144a96 moved operators to implicit_numeric_join
and gave an unsuffixed literal its peer's type; joins kept the old rule.
rt/windows_x86_64.w:661 and rt/windows_aarch64.w:542 (rt_nanosleep) hit it,
so the Windows stage1 runtime did not compile at 591d9c5.

Now, as at an operator: with no enclosing demand, an untyped literal arm
(a bare unsuffixed literal or arithmetic of them) does not anchor the join
while a typed owned numeric arm reaches it; the typed arms meet at
implicit_numeric_join (none for i32 beside u32, named in the error), and
each literal arm is checked again under the join's type. All-literal arms
still default; view arms keep the mixed view/owned rule.

Tests: behav_join_literal_arm_takes_peer_type (fails on 591d9c5 at
`takes_u32(ms)`), err_join_mixed_signedness_arms (591d9c5 accepts it and
prints the wrapped value). Both Windows runtime files cross-compile again
(`with-stage1 build rt/windows_x86_64.w --emit-obj --target=x86_64-pc-windows-msvc`).

Refs #1886 #1803
… beside it joins as before

The join rule (94727231) tested "numeric" through numeric_operand_type,
which maps a repr enum to its backing integer, so in `[0, K.A, K.B]` the
literal 0 became a K and the array an array of a non-Copy enum: the
compiler's own MirValidationTests (for kind in [0, TypeKind.TY_INT, ...])
failed "use of moved value" (battery internals-tests). The peer and
lossless-widening rules now apply to integer and float types only
(is_plain_numeric_type); a repr enum beside a number falls back to the
join it had (arithmetic_result_type). Test: behav_join_literal_beside_repr_enum
fails before, passes after; the join and internals tests pass.
@ehartford
ehartford marked this pull request as ready for review September 29, 2026 18:57
@ehartford
ehartford merged commit 95b7e32 into main Sep 29, 2026
@ehartford
ehartford deleted the fix-literals branch September 29, 2026 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant