Skip to content

refactor!: generated code calls the corelib's wrapper-array helpers instead of emitting them (#587) - #592

Merged
Andste82 merged 14 commits into
mainfrom
refactor/helpers-to-corelib-587
Sep 22, 2026
Merged

Andste82 merged 14 commits into
mainfrom
refactor/helpers-to-corelib-587

Conversation

@Andste82

Copy link
Copy Markdown
Member

Summary

Closes #587. Seven backends emitted the wrapper-array placement helper into generated code, once per field: refuse an index past the bound, fill the gap omitted interior elements leave, place at the id. That code has the same shape for every schema — its only schema dependence is a bound, an element type and a default — so under ARCHITECTURE §8 it belongs in the corelib. This PR removes it from every backend and calls the corelib layer instead, with the bound passed as an argument (or a comptime / type parameter where the language keeps it a constant).

It also writes the rule down so it does not recur: a backend change that needs a static helper never emits it silently — it says the helper belongs in the corelib and puts it there first (CLAUDE.md, new section; ARCHITECTURE §8, "Never emitted silently"), with the mechanical test used here: generate two schemas that differ in bounds, element types and field count; a block identical once literals, names and types are normalised is a static helper.

What changes, per backend

backend generated code now calls corelib PR
typescript ElementSeq / FramedSeq / StringSeq / BlobSeq for every wrapper kind; longElementsEqual, fp32RawBytes instead of module-level copies sofa-buffers/corelib-ts#195
zig sofab.arrays.placeElem / reserveElem / reserveRow / allocCounted with a comptime bound sofa-buffers/corelib-zig#90
java Seq.placeElem / reserveElem / reserveRow* / checkIndex, the schema count as Bound.schema(n) sofa-buffers/corelib-java#126
kotlin Seq.placeElem / reserveElem / reserveRow* / checkIndex sofa-buffers/corelib-kotlin-mp#51
python reserve_leaf / reserve_elem / reserve_row (compiled twins on the native engine) sofa-buffers/corelib-py#159
csharp Seq.PlaceElem / ReserveElem / ReserveRow / CheckIndex sofa-buffers/corelib-cs#114
rust (rs and rs-no-std, both allow_dynamic settings) sofab::seq::place_elem / reserve_elem / reserve_row / check_index, one trait over Vec and heapless::Vec sofa-buffers/corelib-rs#110, sofa-buffers/corelib-rs-no-std#120

c, cpp (both corelibs), go and dart already called their corelib's layer and are unchanged. What stays generated is only what has a different shape per schema: the field arms, the id routing, the per-field guards, the element-index bookkeeping.

Verification

  • Nothing left to emit. Counted independently over example.yaml, vehicle_telemetry.yaml and a second probe schema, every backend and every config variant (typescript int64: bigint|long|number; rust rs, rs static, rs-no-std, rs-no-std dynamic): 0 literal index checks and 0 generated gap-fill loops.
  • go vet ./... and go test ./... green; the golden corpus regenerated where the emitted shape changed.
  • All seven conformance suites (tests/conformance/<lang>/run.sh) green locally against the corelib branches — python on both engines (including the bool_tolerant driver from perf(python)!: a boolean is bound and written by corelib-py's own boolean kinds (#590) #591), the typescript prettier gate and the python ruff gates actually run, not skipped.
  • Each corelib's own suite green on its branch, rebased on its current main (details in each corelib PR).
  • Each target was reviewed adversarially (mutation tests on the new helpers, the refused-index-leaves-the-container-unextended rule, INVALID vs LIMIT_EXCEEDED kept distinct).

Measurements

tests/bench/run.sh, both sides in one container and toolchain, A = generator main + every corelib's main, B = this branch + the corelib branches (vehicle_telemetry, Callgrind instructions/op). Encode is flat everywhere except where noted.

row decode A → B Δ
ts-bigint 787,326 → 792,703 +0.68 %
ts-long 781,455 → 786,878 +0.69 %
ts-number 776,928 → 782,221 +0.68 %
zig 22,428 → 22,292 −0.61 %
zig-unbounded 18,604 → 18,630 +0.14 %
java 31,504 → 31,752 +0.79 %
kotlin 33,030 → 32,914 −0.35 %
python (pure) 1,946,306 → 1,958,537 +0.63 %
python-native 432,913 → 431,815 −0.25 %
csharp 69,602 → 70,132 +0.76 %
rust-rs 22,514 → 22,674 +0.71 %
rust-rs-static 16,080 → 16,134 +0.34 %
rust-rs-unbounded 20,845 → 21,166 +1.54 %
rust-rs-no-std 30,045 → 30,031 −0.05 %
rust-rs-no-std-dyn 38,495 → 38,546 +0.13 %

Footprint, thumbv6m linked with --gc-sections: rust-rs-no-std .text 9,913 → 9,881 B (−32 B), rust-rs-no-std-dyn 11,641 → 11,705 B (+64 B, +0.55 %); .data/.bss unchanged. No delta is severe; the largest is rust-rs-unbounded. The per-target breakdowns and the shapes that were measured and rejected are in ARCHITECTURE §8 / §9.5. (The python encode rows moved because #590/#591 is in B and not in A: pure 1,081,702 → 1,077,940, native 130,492 → 129,123.)

tests/bench/results.txt is not regenerated here: a partial run strips the other rows' corelib provenance, and its header would point at unmerged corelib commits. It gets a full run once the corelibs have merged.

Merge order

  1. The corelib PRs. corelib-zig#90 and corelib-java#126 remove API the current generator main still emits (arrays.grow/allocN/setElem, Bound.SCHEMA_BOUNDED), so those two must land together with this PR; the other six are additive and can go first.
  2. As each corelib PR merges, delete its line from .github/corelib-refs (docs/CI.md, "Pinning a corelib branch"). Until then lang-<x> builds this branch against the corelib branches. The file has to be gone before this PR merges.
  3. Re-run the lang-* jobs against main on both sides.

Not in this PR

  • The literal length and count guards (total > maxlen, native count > N) are still emitted by most backends — only python and cpp hand them to the corelib today. §8 sanctions a call-site check where the corelib has no argument to take the bound; whether they should move is a design question of its own, to be raised as a follow-up issue.
  • The c / cpp-c-cpp footprint rows measure generated code only (bench: the c and cpp-c-cpp footprint rows exclude the corelib, measuring ~25% of the image #589).

…#587)

ARCHITECTURE S8 puts a helper in the corelib when its code has the same shape for
every schema and its schema dependence is carried entirely by arguments and type
parameters. Three things this backend emitted still failed that test, and all
three now come from corelib-ts instead of being re-emitted into every generated
package along with the rationale a reader then has to re-read per file.

**The wrapper-array index bound and the gap fill.** A framed element -- a struct,
a union, a nested row, a matrix row -- used to be placed by emitted code: `if (id
>= N) throw ...` for the schema capacity or `if (id >= MAX_DYN_ARRAY_COUNT) throw
...` for the receiver cap, then `while (_t.length <= id) _t.push(<default>)`. That
is the S6.2.1 which-verdict rule and the S9.5 shape-B growth, written out once per
array occurrence per schema with only a number and a type differing between the
copies. `StringSeq`/`BlobSeq` already took it for a leaf element; the framed kinds
take it now too, through `reserve(id)` -- which leaves an existing slot alone, so
a re-opened struct/union element merges into what its earlier fields built (S7.4)
-- and `place(id, value)`, which overwrites, a nested row being itself an array
wrapper that S7.4 makes replace. A native matrix row splits the two (`checkIndex`
... `place`) because it carries a SECOND bound, its element count at the array
header, and S7.2 item 8 wants a rejection by either bound to leave the matrix
exactly as it was. That ordering is emitted, so it is pinned as an ordered block
in three shapes -- a bounded matrix, a matrix one level down, and a matrix the
schema left unbounded, where the two bounds answer with DIFFERENT verdicts and
dropping the `checkIndex` would silently turn a LIMIT_EXCEEDED into an INVALID.

**Which collector an element takes is decided by one thing: whether its gap value
may be SHARED.** `ElementSeq<T>` writes one `def` into every gap, which is right
for `""`, for a zero-length `Uint8Array`, and for the module's shared empty typed
array a native row pads with -- that instance holds nothing, drops an indexed
store and cannot be grown. It is wrong for a struct or union element, a wrapper
row, and a `Long[]` row under `int64: long`/`number`, whose defaults are fresh
mutable objects the caller can reach: one shared instance would alias every gap of
the array onto it and, since an arriving element decodes into the slot the
reservation placed, every element onto it too. Those take `FramedSeq<T>` and a
factory. The factory stays generated -- it names a generated type, which is S8's
own line between the layers -- and is emitted once per element type as a
module-level `const`, so an array occurrence allocates a collector and not a
closure.

**The two remaining module helpers.** `_fp32Raw` becomes the corelib's
`fp32RawBytes` (the S4.6 raw-bits companion, four shifts over the 32-bit word the
hook already hands over) and `longArrEq` becomes `longElementsEqual` (a `Long` is
a corelib type and an object identity, so the default compare has to go by word
pairs). `_fp32RawInto` moves nowhere: its flavour existed for the fp32 ARRAY raw
path, which S6.7 retired, so it would have landed in the corelib's public API with
no caller in the family. With them the `helperUse` scan goes too: which corelib
names the import line carries is already read off the rendered text. A generated
module now declares no top-level `function` at all, which is what the new corpus
sweep asserts -- over every definition, both emit modes and all three `int64`
representations, because `long`/`number` are the only modes in which a 64-bit
matrix row is a `Long[]` and therefore the only ones that reach the factory path
for a native row.

What stays emitted is what has a different shape per schema or names a generated
symbol: the field arms and the id routing, the index registers and the scope
switch, the declared types, the destination a wrapper array replaces on re-open,
the row allocated at its checked wire count -- and the native-array COUNT reject,
which has no corelib call at that point to hang itself on and for which a call
invented to carry it would cost more than it saves.

One trap worth naming, because it is silent: with a collector slot on every array
scope, `emitFixlenBegin`'s `sc.seq != ""` test stopped selecting leaf elements and
had to become an explicit string/blob test -- a framed collector has no `begin`
hook, and routing a length word at it would have thrown at decode, not at build.

**Measured END TO END** (Callgrind, subtract, S15, `vehicle_telemetry`), Ir/op
encode/decode. This is a two-half change, so the A leg is the state before BOTH
halves -- this commit's parent with corelib-ts at the `origin/main` it had then.
An A that holds the corelib at the new commit measures the generator half alone
and reads ~0.4% high on decode, because the corelib half is not inert under the
old generator: `StringSeq`/`BlobSeq` take their own element index through the same
shared rule.

    ts-bigint   586113/787331 -> 585863/792697   (-0.04% / +0.68%)
    ts-long     579934/781459 -> 579935/786877   (+0.00% / +0.69%)
    ts-number   595682/776923 -> 595905/782225   (+0.04% / +0.68%)

Encode is flat within the +-0.04% these rows spread over between builds, which is
what a move with no encode path of its own has to read. Decode pays a call per
collector construction and per element event -- about 200 Ir each, because the
`ts` rows measure the V8 BASELINE tier where nothing is inlined -- and it buys the
S6.2.1 verdict rule and the S9.5 growth one implementation for the family instead
of one per array occurrence per schema. The first shape of the collectors made
three calls per element and cost +2.3% on every row, over the 2% budget; the
corelib now picks the one bound S6.2.1 leaves in force at construction, so each
entry point is a single compare and the shared rule is reached only when it
throws. results.txt is left untouched -- a partial run's header is unfit to
commit, and the corelib half is not on its `origin/main` yet.

Needs corelib-ts's `FramedSeq`, `fp32RawBytes` and `longElementsEqual`.
The zig backend already routed every container operation through
sofab.arrays; what it still emitted in front of each one was the BOUND --
`if (id >= 5) { self.inv = true; }` before a placement, an id guard plus a
count guard before a matrix row, a `return sofab.Error.InvalidMessage` in
fixlenBegin. That is the same code shaped the same way for every schema,
with its schema dependence carried entirely by one number, so by
ARCHITECTURE §8 it belongs in the corelib.

The bound now travels as a `comptime sofab.arrays.Bound` -- `.{ .schema = n }`
or `.{ .receiver = max_dyn_array_count }` -- into the call the decode path
already makes:

  * `arrays.placeElem` for a string/blob element,
  * `arrays.reserveElem` for a struct, union or nested-array element,
  * `arrays.reserveRow` for a matrix row (index bound and row-count bound as
    two separate arguments, decided in that order),
  * `arrays.allocCounted` for a count-prefixed native array,
  * `arrays.overIndex` for the one site with no container operation to ride:
    the fixlenBegin latch, where §5.2 wants the index verdict taken at the
    length word so a message truncated right after it is INVALID rather than
    INCOMPLETE.

Because the bound is `comptime`, `.{ .schema = 5 }` folds to the same
comparison against the same constant the emitted literal produced -- no
runtime tag test, no call frame -- which is why the move is free on this
maxspeed target.

What stays generated is what has a different shape per schema: the field
arms and the §7.3 wire-type tests, the id routing and the `self.ei_*`
element-index registers, the `self.an`/`self.ai` bookkeeping, the §7.4
wrapper-row reset, the element `maxlen` test (which has no corelib call at
the length word to ride, #438), the native `count > N` guard on inline
FixedArray storage (no sizing call to attach it to), and the REFUSAL itself
-- the sticky flag, the error return or the break to the dead scope, which
differ per call site. `Bound` names which flag that is, so a schema count
still answers INVALID and a receiver cap still answers LimitExceeded, never
both (CORELIB_PLAN §6.2.1).

`overIndexCond` is replaced by `arrayBound`/`boundFlag`; its third,
unreachable state goes with it, since ir.Bounds makes the cap live for any
array without a `count`. `reserveElem` takes `id`, not `id + 1`: forming the
successor before the bound decides is what §6.2.1 rules out. fixlenBeginArms
now reports whether its arms read `id`/`total` instead of being scanned for
it -- a field literally named `id` would have made the scan claim a read no
arm performs.

Requires corelib-zig with the bounded arrays API.
The java backend routed a matrix row through `Seq.reserveRow*` and emitted
everything else itself. For a string, blob, struct or union element it wrote
MESSAGE_SPEC §5.1's placement rule into each generated message class, once per
wrapper array per schema:

    if (id >= 5) throw Sofab.invalid("... above schema capacity 5");
    while (m.warnings.size() <= id) m.warnings.add("");
    m.warnings.set(id, _s);

    if (id >= MAX_DYN_ARRAY_COUNT) throw new java.io.UncheckedIOException(
        new SofabException(SofabError.LIMIT_EXCEEDED, "... above configured limit"));
    while (m.dyn_structs.size() <= id) m.dyn_structs.add(new DynStructsElem());

That is the same code shaped the same way for every schema, with its schema
dependence carried by a bound, an element type and an element default -- an
argument, a type parameter and an argument -- which is ARCHITECTURE §8's
condition for a helper belonging in the corelib. It was also a second
implementation of the §6.2.1 cap beside the one `reserveRow` already had.

The growth now happens in `Seq.placeElem` (string/blob element) and
`Seq.reserveElem` (struct, union or nested-row element), and the bound travels
into them as the same `Bound` the row calls already take. `Seq.checkIndex` takes
the one index verdict with no placement to ride: the `fixlenBegin` latch, where
§5.2 wants the index settled at the LENGTH WORD so a message truncated right
after it is refused rather than reported INCOMPLETE.

`overIndexGuard` and `rowIndexBound` collapse into one `indexBound`: with the
bound riding every call, the row rule and the element rule are literally the same
rule. Its third, unreachable state goes with it -- `ir.Bounds` makes the array cap
live for any array without a `count`, wrapper arrays included, so `cap < 0`
implies the cap is live. `needsRowCapBound` becomes `needsArrayCapBound` and now
covers every wrapper frame, since every one of them can carry the `Bound`.

What stays emitted is what has a different shape per schema or names a generated
symbol: the schema `count` verdict (`Bound.SCHEMA_BOUNDED` deliberately carries no
number, so §7.1 keeps exactly one implementation and it is this one), emitted
AHEAD of the call so the index is still decided before any growth (CORELIB_PLAN
§7.2 item 8); the element's own `maxlen`, which has no call at the length word to
ride and whose receiver half is `PayloadAcc`'s; a native array's count and its
sizing, which §5.1 assigns to the generated layer; and the routing -- the `cur`
scope switch, the `_ex_<loc>` element-index registers, the §7.3 array-kind tests,
the `.clear()` on a re-opened wrapper array. The element type reaches the corelib
only through a type parameter and a `SomeElem::new` method reference, which §8
allows.

One user-visible consequence: a receiver-cap rejection loses the field name --
"Root_dyn_strs element: array index above configured limit 65536" becomes the
corelib's "array element index 7 above configured limit 65536". `Seq.reserveRow`
has had this property since corelib-java 0.12.0; the category, the index and the
limit, which is what a receiver acts on, all survive, and nothing in
tests/conformance asserts the wording.

Measured (Callgrind, subtract, §15, `vehicle_telemetry`, which exercises all three
signatures), against one corelib build so the generator half is what moves:

    both loops emitted (before)             17006 / 31511  encode/decode Ir/op
    placeElem, framed element still emitted  17006 / 31230  (-0.89% decode)
    placeElem and reserveElem (shipped)      17005 / 31683  (+0.55% decode)

Encode is the control -- no wrapper-array growth runs there -- and its +-2 Ir is
the noise floor (two repeats of the shipped shape read 31686 and 31679). +0.55% is
inside the ~0.7% the family accepted for this move in typescript and well under
the 2% that turned a shape down there.

The split is recorded because the two signatures do not cost the same thing.
Moving the LEAF loop is negative: one call replaces a while/add/set sequence
emitted per array, and C2 inlines a sub-35-bytecode static. Moving the FRAMED loop
costs about +1.45% on its own, ~75 Ir per element created, for the reason the
design predicted -- `new SomeElem()` inlined in the caller can have its allocation
seen through, the same allocation behind `Supplier.get()` in a shared corelib
method cannot. The lever, if a future throughput push wants those points back, is
to keep `placeElem` and hand the framed case only its bound; it is not taken here,
and ARCHITECTURE §9.5.3 says so with the numbers.

results.txt is left untouched: a partial (--rows) run's header is unfit to commit,
and the corelib half is not on its origin/main yet.

Requires corelib-java with `Seq.placeElem`, `Seq.reserveElem` and a public
`Seq.checkIndex`.
…lently

A backend change that needs a helper whose shape is the same for every
schema must say that the helper belongs in the corelib, put it there first
(own file/namespace, own tests) and call it - or, where that is out of scope,
raise it as an issue and name it in the PR as a known gap. An emitted helper
reaches every user's source tree, is out of the corelib test suite's reach,
and can only be corrected by every user regenerating.

Adds the rule to CLAUDE.md and to ARCHITECTURE section 8, with the mechanical
test used for #587: two schemas that differ in bounds, element types and field
count; a block identical once literals, names and types are normalised is a
static helper.
…#587)

The kotlin backend emitted the flat wrapper-array helpers itself. It wrote a
literal `if (id >= N)` guard (or `>= MAX_DYN_ARRAY_COUNT`), then a gap-filling
`while (L.size <= id) L.add(...)` loop in front of every string/blob
placement and every struct/union element, plus the same guard at each
element's length word. That code has one shape for every schema, so it now
lives in corelib-kotlin-mp's `Seq`, next to `reserveRow*`:

* a string/blob element: `Seq.placeElem(list, id, def, value, cap, rcap)`
* a struct/union/nested-row element:
  `Seq.reserveElem(list, id, cap, rcap) { Elem() }`, then the generated
  routing (`_ex_<loc> = id; cur = K`)
* at the element's length word: `Seq.checkIndex(id, cap, rcap)`

The schema count travels as `cap` (-1 where the schema declares none), next
to MAX_DYN_ARRAY_COUNT. The corelib compares exactly one of the two, so the
INVALID_MSG verdict of a declared count moves too. The generated code has
no literal index check left (0 across the corpus and examples), which
matches typescript and zig rather than java's split. overIndexGuard and the
limArr side channel are gone. Every wrapper frame now states the cap
constant.

The refusal message loses the field name ("array index 7 above declared
count 4"). Only the category is normative.

Bench `kotlin`, decode Ir/op: 33,036 -> 32,922 (-0.35 %), encode flat. This
needs corelib-kotlin-mp's small-checkIndex change. With the older 48-byte
checkIndex, C2 would not inline it at the length-word arms, and the move
cost +1.15 %. ARCHITECTURE §8, §9.5 and §10 are updated, and §9.5.4 now has
the measurement.
…#587)

The flat visitor no longer emits the element index test or the gap-fill
loop. It calls corelib-py's reserve_leaf (string/blob, from on_field),
reserve_elem (struct/union from on_sequence_begin, native row from
on_field) and reserve_row (wrapper row, from on_sequence_begin), handing
the schema count (or UNBOUNDED) and the receiver cap as two exclusive
arguments. The value hooks become plain indexed stores. Generated code
emits zero literal index checks.

Drops the unused schemaHasCountedNativeArray,
schemaHasCountedWrapperArray, schemaHasMaxlenStringBlob and
schemaHasField. Measured on vehicle_telemetry: pure decode +0.54% Ir/op,
native -0.19% (noise; corelib-py ships compiled twins).
…#587)

The csharp backend emitted the wrapper-array helpers itself. Each site had a
literal `if (id >= N)` guard (or `>= MaxDynArrayCount`), then a gap-filling
`while (L.Count <= id) L.Add(...)` loop. The same guard also ran at the
element's length word, and every matrix row was grown and replaced inline.
These now call corelib-cs's `Seq`:

* a string/blob element: `Seq.PlaceElem(list, id, def, value, cap, rcap)`
* a native or wrapper matrix row: `Seq.ReserveRow(rows, id, cap, rcap)`.
  A re-opened row is emptied in place instead of being replaced.
* the element's length word and a struct/union element:
  `Seq.CheckIndex(id, cap, rcap)`

The schema count travels as `cap` (-1 where the schema declares none), next
to MaxDynArrayCount. The corelib compares exactly one of the two, so the
InvalidMessage verdict of a declared count moves too. No literal index check
is left in the generated code. The count is 0 across example, nested_rows,
seq_elements_dyn, vehicle_telemetry and an uncounted-rows probe, and a new
test pins it. Every message with a wrapper frame now declares
MaxDynArrayCount. overIndexGuard, placeRow/placeRowAt and csSeqElemDefault
are gone.

The struct/union gap fill stays generated, behind Seq.CheckIndex. This is the
ARCHITECTURE §8 maxspeed override, measured on the csharp bench row (decode
Ir/op, baseline 69,602):
* Seq.ReserveElem with a Func<T> factory: 70,133 (+0.77 %). The JIT inlines
  the helper but not the delegate call it makes per new element, and
  AggressiveInlining changed nothing.
* a `where T : new()` overload: 71,508 (+2.7 %).
* the shipped shape: 69,774 (+0.25 %). Encode is flat at 29,166.

The native-row verdict order is unchanged: kind first, then the row id, then
the row's element count. The refusal message loses the field name. Only the
category is normative.

ARCHITECTURE §8, §9.5 (the family list and the enforcement table), §9.5.5 and
§10 are updated.
…587)

The rust backend stops emitting its wrapper-array helpers and calls the
new sofab::seq layer in corelib-rs and corelib-rs-no-std instead:
place_elem for a string/blob element, reserve_elem for a struct/union
element, reserve_row for a matrix or wrapper row, check_index at the
length word and a native row's header. The bound travels as one
Bound::Schema(count) or Bound::Cap(MAX_DYN_ARRAY_COUNT) argument, so no
literal index check is left in any configuration, and V::refuse files
the corelib's verdict in the existing sticky flags.

The generated Cargo.toml enables the corelib feature that carries the
container impl: heapless under static storage on either corelib, alloc
for rs-no-std with allow_dynamic. ARCHITECTURE gains 9.5.6 with the
five-row bench before/after.
…587)

Java was the one target still emitting a literal wrapper-array index check
(`if (id >= N) throw Sofab.invalid(...)`, 7 sites on example.yaml) in front
of Seq.placeElem / reserveElem / reserveRow*, because Bound.SCHEMA_BOUNDED
carried no number. corelib-java now takes Bound.schema(count) and compares it
itself (INVALID_MSG), beside the receiver cap (LIMIT_EXCEEDED), exactly one per
field. The visitor emits one static final SCHEMA_COUNT_<n> per distinct count
and passes it; the length word and a native row's header name the same bound on
Seq.checkIndex, so the row id is still judged before the row's own count.

Bench (java row, decode Ir/op): 31685 before, 31745 after (+0.19%); encode
unchanged. ARCHITECTURE 8 and 9.5.3 updated, with why Bound is a record.
…lem (#587)

The struct/union gap fill was the one wrapper-array growth still emitted into
generated C#: Seq.CheckIndex bounded the index, then a generated
'while (L.Count <= id) L.Add(new Elem())' filled the gap. It now goes through
corelib-cs's Seq.ReserveElem with the element constructor as a cached static
lambda, as java, kotlin and rust already do for the same element kinds.

Measured on the csharp bench row (vehicle_telemetry, subtract): decode 70130
Ir/op against a 69603 baseline (+0.76%), encode flat at 29166. Keeping the fill
generated was half a point cheaper (69774); a static abstract Create() on every
generated element would recover it but adds public API to every generated class,
so it is not taken. ARCHITECTURE 9.5.5 records both.

TestCsNoLiteralIndexCheck now also pins that no generated gap-fill loop is left.
The 9.5 family paragraph no longer lists any backend as growing arrays in
generated code, and the 10 C# row says the element growth is the corelib's.
The generated code on this branch calls the wrapper-array helpers generator#587
moves into the corelibs, so lang-<x> has to build against those branches until
each corelib PR merges (docs/CI.md, 'Pinning a corelib branch'). Every entry is
to be deleted as its corelib PR lands; the file must be gone before this merges.
The alignment of five trailing comments had been rewritten by a local gofmt
from Go 1.24, whose alignment rule differs from the 1.27 the hermetic job
runs; this restores the 1.27 layout, which is also main's. Whitespace only.
corelib-ts#195, corelib-kotlin-mp#51, corelib-py#159, corelib-cs#114,
corelib-rs#110 and corelib-rs-no-std#120 have merged, so lang-<x> builds against
their main again. corelib-zig and corelib-java stay pinned until they merge in
lockstep with this PR.
corelib-zig#90 and corelib-java#126 have merged too, so no corelib is pinned
any more and lang-<x> builds against main on both sides (docs/CI.md, merge
order step 2).
@Andste82
Andste82 merged commit 1c88f41 into main Sep 22, 2026
15 checks passed
@Andste82
Andste82 deleted the refactor/helpers-to-corelib-587 branch September 22, 2026 06:42
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.

codegen: static helpers are still emitted in five backends, three of them into corelibs that already ship the layer (generator#345 unfinished)

1 participant