diff --git a/.claude/skills/benchmark/SKILL.md b/.claude/skills/benchmark/SKILL.md index 1073deef7..2bc89b855 100644 --- a/.claude/skills/benchmark/SKILL.md +++ b/.claude/skills/benchmark/SKILL.md @@ -79,6 +79,9 @@ runs in both, so its two results show how much the machine moved. Heavy runs go - **Reach the commits** with `git merge -s ours --no-edit ` (history only: the test branch keeps main's code, so its CI runs main's code; merging an experiment's code ran CI on it, and a Go test that overflowed `int` on 386 and a Windows stack test mailed the owner a failure per push). + Check `git merge-base --is-ancestor HEAD` for both refs after the history merges. The #353 benchmark + baseline and candidate were built on independent branches, so merging only the candidate left the baseline + missing from every runner checkout (44333395182). - **Time the Nino.Core build you mean.** BenchmarkDotNet's runner project (`Nino.Benchmark-`) gets Nino.Core only through Nino.Benchmark's references, so a referenced package built for fewer frameworks than Nino.Core brings an older build into it: until f01a8d3c Nino.Immutable (net8.0 only) made every runner process load Nino.Core's diff --git a/.claude/skills/optimize-runtimes/references/blocks.md b/.claude/skills/optimize-runtimes/references/blocks.md index e37415fe0..58fe2a7b3 100644 --- a/.claude/skills/optimize-runtimes/references/blocks.md +++ b/.claude/skills/optimize-runtimes/references/blocks.md @@ -47,6 +47,17 @@ value check in a runtime or a template. ## Checking blocks in Go +- Reserve one checked block for fixed-width Go containers. Use constant wire offsets for padded primitive pairs + and copy compatible primitive grids as blocks. In runtime A/B + [44339615693](https://github.com/JasonXuDeveloper/Nino/actions/runs/44339615693), padded-pair read times fell + 66–75 % on the measured x64 CPUs and 72 % on Neoverse-N2. Byte-grid writes fell 92–96 % on both architectures. + Fixed DateTimeOffset sequence writes fell 52–59 % on x64 and 47 % on Neoverse-N2. +- Encode fixed map entries through their addresses. In the original fixed-stride loop the x64 GUID entry value + crossed two stack temporaries. The address loop reduced ten `MOVUPS` per entry to two, with the stride guard + intact. In [44347813411](https://github.com/JasonXuDeveloper/Nino/actions/runs/44347813411) the revised GUID map + write took 82–85 % less time on x64 and 81 % less on Neoverse-N2. The revised map read took 52–54 % less on + x64 and 45 % less on Neoverse-N2. + - Check a block of range-limited 8- or 16-byte values four a step with one compare each (`w[0].Valid() && ... && w[3].Valid()`, then the failing step value by value), each `Valid` a single compare (a signed range from 0 as unsigned; a Decimal's flags without the sign, rotated by 16 bits, `<= 28`). Writing 1000 values (runtime A/B runs diff --git a/.claude/skills/optimize-runtimes/references/dispatch.md b/.claude/skills/optimize-runtimes/references/dispatch.md index 79efd1351..8a434579c 100644 --- a/.claude/skills/optimize-runtimes/references/dispatch.md +++ b/.claude/skills/optimize-runtimes/references/dispatch.md @@ -35,6 +35,16 @@ call, a helper that takes a function, or a `read_into` / `deserializeInto` path. the template's had none): in the release build of `tests/generated` the standalone raw `read`/`write` symbols are gone and their callers inline them (no runner number yet: the benches' `Point` uses the macros since). +- Generate a direct fixed-stride fallback when `TryReadRaw` or `TryWriteRaw` declines a Go layout. Apple Arm64 + disassembly of the padded Gappy and Marked fixtures had direct decode and encode calls on the fallback. + Keep the exported callback helpers available for callers that supply their own codecs. +- Keep structural composite-key discovery outside Go's scalar and string duplicate loops. When the initial #353 + implementation sent all keys through the shared cache and added a byte-size test to the string loop, + [44339615693](https://github.com/JasonXuDeveloper/Nino/actions/runs/44339615693) measured the eight-int control + 15 % higher on Neoverse-N2. Caching only the composite field walk and restoring the string probe brought both + controls within 2 % by median on that CPU ([44347813411](https://github.com/JasonXuDeveloper/Nino/actions/runs/44347813411)). + The bytewise path still uses the reader's shared seeded table and bounded probing. + ## Reuse branches - Keep reuse branches off the read path of a new value: share the body, not the dispatch. Reading into an existing diff --git a/.claude/skills/platforms/references/emulation.md b/.claude/skills/platforms/references/emulation.md index a7c4943c7..087af48cb 100644 --- a/.claude/skills/platforms/references/emulation.md +++ b/.claude/skills/platforms/references/emulation.md @@ -51,6 +51,11 @@ crashing. Read it before running anything under qemu or taking a listing for Arm 8 runs with qemu 8.2 and the runners' qemu, and main's code before the run that showed it (f618b973) crashed too (1 of 10, more allocation only made it likelier); Go 1.24 crashed in 0 of 8, `GOMAXPROCS=1` in 0 of 18, `GOARM=6` did not help (4 of 8). runtimes.yml sets it on that step (r101). + Use QEMU user-mode 10.0.13 or later for local Go 386 tests on Arm64 Linux. Go 1.26.11's same static + test binary reported `bad g in signal handler` or `morestack on gsignal` on QEMU 7.2.22. On Debian + trixie's QEMU 10.0.13 it passed three runs and `GOARCH=386 go test -exec qemu-i386 ./...` passed with + asynchronous preemption enabled (#353). Where QEMU 7.2 is required, `GODEBUG=asyncpreemptoff=1` and + `GOMAXPROCS=1` allowed the 386, Arm32 and s390x suites to pass. - To run tests under qemu-aarch64, pass `-cpu neoverse-n1` (listings can keep the default): qemu 8.2's default CPU (`max`) has LRCPC2, whose `ldapur`/`stlur` (what the optimizing JIT emits for `Volatile.Read`/`Write` of a field) it emulates wrong. With or without Nino's code, runs crashed (`ToImmutableDictionary`), or a static field written by diff --git a/runtimes/csharp/src/Nino.Codegen/Targets/Go/GoShape.cs b/runtimes/csharp/src/Nino.Codegen/Targets/Go/GoShape.cs index fd12da2ae..6c9a8ba9a 100644 --- a/runtimes/csharp/src/Nino.Codegen/Targets/Go/GoShape.cs +++ b/runtimes/csharp/src/Nino.Codegen/Targets/Go/GoShape.cs @@ -47,6 +47,18 @@ public sealed class GoShape /// Whether arrays of it are one block (nino.ReadPrimitives). public bool Block { get; internal set; } + /// Whether sequences of this value use nino.ReadBlock and nino.WriteBlock. + public bool BlockValue { get; internal set; } + + /// Whether this value needs range validation when written outside raw memory. + public bool CheckedWrite { get; internal set; } + + /// Whether the fixed encoder omits padding, unused slots or false booleans. + public bool NeedsZero => Kind is "rawstruct" or "emptystruct" or "rawnullable" or "rawtuple" || Primitive == "Bool"; + + /// Whether the key of each pair is checked for repeats. + public bool UniqueKeys { get; internal set; } + /// A raw struct that can be copied as memory, its arrays as one block; else null. public GoRawBlock? RawBlock { get; internal set; } @@ -92,7 +104,7 @@ public sealed class GoShape /// fixed (raw values at their stride), /// unique (a set of comparable values), stringset, slice; a map's: block /// (primitive keys and values, pairs copied as one block where their memory is their bytes; repeated keys - /// fail), unique (repeated keys fail) or entries. + /// fail), fixed (both shapes have a stride), unique (repeated keys fail) or entries. /// public string? Mode { get; internal set; } @@ -141,7 +153,7 @@ private IEnumerable Parts() yield return Struct?.FullName ?? ""; yield return Type?.FullName ?? ""; yield return Named?.FullName ?? ""; - yield return (Mode ?? "") + (UniqueSlots ? "/unique" : ""); + yield return (Mode ?? "") + (UniqueSlots || UniqueKeys ? "/unique" : ""); yield return Pair ? "pair" : ""; yield return FlagOffset + "/" + ValueOffset + "/" + Rank + (Clean ? "/clean" : "") + (SlotElement ? "/slot" : ""); yield return string.Join("/", Offsets); diff --git a/runtimes/csharp/src/Nino.Codegen/Targets/Go/GoTarget.Shapes.cs b/runtimes/csharp/src/Nino.Codegen/Targets/Go/GoTarget.Shapes.cs index 072025c6f..ff6c696d8 100644 --- a/runtimes/csharp/src/Nino.Codegen/Targets/Go/GoTarget.Shapes.cs +++ b/runtimes/csharp/src/Nino.Codegen/Targets/Go/GoTarget.Shapes.cs @@ -88,15 +88,15 @@ internal GoShape Shape(ValueModel value, bool key) bool set = value.Collection is CollectionKind.HashSet or CollectionKind.SortedSet || CodegenModel.Implements(value.Clr, "System.Collections.Generic.ISet`1") != null; string mode = - element.Kind == "prim" && element.Primitive == "U8" ? "bytes" - : set && Comparable(element) ? "unique" + set && Comparable(element) ? "unique" + : element.Kind == "prim" && element.Primitive == "U8" ? "bytes" : set && element.Kind is "string" or "utf8" ? "stringset" : element.Kind == "prim" && element.Primitive == "Bool" ? "bools" : element.Block ? "block" - : element.Kind == "prim" && BlockValues.Contains(element.Primitive!) ? "values" + : element.BlockValue ? "values" : element is { Kind: "rawnullable", Clean: true, Inner.Block: true } ? "ninonullables" : element is { Kind: "rawnullable", SlotElement: true, Inner.Block: true } ? "nullableslots" - : element.Kind is "rawstruct" or "rawnullable" or "rawtuple" ? "fixed" + : element.Size > 0 && element.Kind != "emptystruct" ? "fixed" : "slice"; return Open(value, new GoShape("seq") { @@ -106,11 +106,13 @@ internal GoShape Shape(ValueModel value, bool key) case ValueKind.Map: { var (k, v) = (Shape(value.Key!, true), Shape(value.Value!, false)); + bool unique = Comparable(k) || k.Kind is "keystring" or "keyutf8"; return Open(value, new GoShape("map") { - Key = k, Value = v, + Key = k, Value = v, UniqueKeys = unique, Mode = k.Block && v.Block ? "block" - : Comparable(k) || k.Kind is "keystring" or "keyutf8" ? "unique" : "entries", + : k.Size > 0 && v.Size > 0 ? "fixed" + : unique ? "unique" : "entries", MinSize = 4, }, false); } @@ -133,7 +135,7 @@ internal GoShape Shape(ValueModel value, bool key) case ValueKind.Version: return new GoShape("version") { MinSize = 4 }; case ValueKind.DateTimeOffset: - return new GoShape("datetimeoffset") { MinSize = 10 }; + return new GoShape("datetimeoffset") { MinSize = 10, Size = 10, CheckedWrite = true }; case ValueKind.Unsupported: throw new UnsupportedException(value.Problem!.Replace("{lang}", "Go")); default: @@ -363,6 +365,7 @@ private GoShape Raw(ValueModel value) return new GoShape("prim") { Primitive = p.Name, Size = value.Size, MinSize = value.Size, Block = p.Block, + BlockValue = BlockValues.Contains(p.Name), CheckedWrite = p.Validated && p.Name != "Bool", // Read in a run of fixed-size members: any bit pattern is valid. Runnable = !p.Validated, }; diff --git a/runtimes/csharp/src/Nino.Codegen/Templates/go/shapes.sbn b/runtimes/csharp/src/Nino.Codegen/Templates/go/shapes.sbn index e99b69c59..df3073932 100644 --- a/runtimes/csharp/src/Nino.Codegen/Templates/go/shapes.sbn +++ b/runtimes/csharp/src/Nino.Codegen/Templates/go/shapes.sbn @@ -204,7 +204,7 @@ func reads_into(s) if s.kind == "seq" ret s.mode != "bytes" && s.mode != "block" && s.mode != "bools" && s.mode != "values" && s.mode != "ninonullables" && s.mode != "nullableslots" && s.mode != "unique" && s.mode != "stringset" && s.mode != "fixed" else if s.kind == "map" - ret s.mode != "block" && s.mode != "unique" + ret s.mode == "entries" || (s.mode == "fixed" && !s.unique_keys) end ret false end @@ -311,6 +311,8 @@ func decode(s, o) ret decode_fn(s) + "(r, " + span(o, s.size) + ")" when "emptystruct" ret name(s.struct) + "{}" + when "datetimeoffset" + ret "r.DateTimeOffsetAt(" + span(o, s.size) + ")" end $a = at(o) case s.primitive @@ -364,6 +366,8 @@ func encode(s, o, x) ret [encode_fn(s) + "(" + span(o, s.size) + ", " + x + ")"] when "emptystruct" ret [] + when "datetimeoffset" + ret [x + ".Put(" + span(o, s.size) + ")"] end $a = at(o) case s.primitive diff --git a/runtimes/csharp/src/Nino.Codegen/Templates/go/types.sbn b/runtimes/csharp/src/Nino.Codegen/Templates/go/types.sbn index 3ac95ec81..c390b0c5a 100644 --- a/runtimes/csharp/src/Nino.Codegen/Templates/go/types.sbn +++ b/runtimes/csharp/src/Nino.Codegen/Templates/go/types.sbn @@ -253,7 +253,7 @@ func helper_body(h) end $each = read_into($s.element, "e") ret $o + read_into_loop(gotype($s.element), $s.element.min, $each, $each != "e = " + read($s.element)) + "}\n" - else if h.mode == "read" && reads_into($s) + else if h.mode == "read" && reads_into($s) && $s.mode != "fixed" # The loop of the into form (a nil slice: a new one). ret "func " + $n + "(r *nino.Reader) (v " + $t + ") {\n\t" + helper($s, "readinto") + "(r, &v)\n\treturn v\n}\n" else if h.mode == "read" @@ -273,21 +273,45 @@ func helper_body(h) ret $o + "\treturn v\n}\n" when "grid" $o = $o + "\tg := readGrid[" + gotype($s.element) + "](r, " + $s.rank + ", " + compact($s.element.min) + ")\n\tif g == nil {\n\t\treturn nil\n\t}\n" + if $s.element.block + ret $o + "\tnino.ReadPrimitivesInto(r, g.Items)\n\tif r.Failed() {\n\t\treturn nil\n\t}\n\treturn g\n}\n" + end + if $s.element.size > 0 + $each = "_ = b[" + ($s.element.size - 1) + "]\n\t\tg.Items[i] = " + decode($s.element, 0) + ret $o + read_fixed_block($s.element.size, "len(g.Items)", "", $each, "", "for i := range g.Items", !$s.element.runnable) + "\treturn g\n}\n" + end ret $o + "\tfor i := range g.Items {\n\t\tg.Items[i] = " + read($s.element) + "\n\t\tif r.Failed() {\n\t\t\treturn nil\n\t\t}\n\t}\n\treturn g\n}\n" when "map" $e = "nino.Entry[" + gotype($s.key) + ", " + gotype($s.value) + "]" - $o = $o + read_loop($e, plus($s.key, $s.value), "k := " + read($s.key) + "\n\t\te = " + $e + "{Key: k, Value: " + read($s.value) + "}") + if $s.mode == "fixed" + $z = $s.key.size + $s.value.size + $each = "e = " + $e + "{Key: " + decode($s.key, 0) + ", Value: " + decode($s.value, $s.key.size) + "}" + $o = $o + read_fixed($e, $z, $each, !$s.key.runnable || !$s.value.runnable) + else + $o = $o + read_loop($e, plus($s.key, $s.value), "k := " + read($s.key) + "\n\t\te = " + $e + "{Key: k, Value: " + read($s.value) + "}") + end # Keys read twice fail, checked once over the pairs. - ret $o + ($s.mode == "unique" ? "\treturn nino.CheckUniqueKeys(r, v)\n}\n" : "\treturn v\n}\n") + ret $o + ($s.unique_keys ? "\treturn nino.CheckUniqueKeys(r, v)\n}\n" : "\treturn v\n}\n") end # A sequence. case $s.mode - when "unique" + when "unique", "fixed" # Elements read twice fail, checked once over the elements (primitives read as one block). - if $s.element.block + if $s.mode == "unique" && $s.element.block ret $o + "\treturn nino.CheckUniqueValues(r, nino.ReadPrimitives[" + gotype($s.element) + "](r))\n}\n" end - ret $o + read_loop(gotype($s.element), $s.element.min, "e = " + read($s.element)) + "\treturn nino.CheckUniqueValues(r, v)\n}\n" + if $s.element.block_value + ret $o + "\treturn nino.CheckUniqueValues(r, nino.ReadBlock[" + gotype($s.element) + "](r))\n}\n" + end + if $s.element.kind == "prim" && $s.element.primitive == "Bool" + ret $o + "\treturn nino.CheckUniqueValues(r, nino.ReadBools(r))\n}\n" + end + $unique = $s.mode == "unique" || $s.unique_slots + $b = $s.element.raw_block + if $b + $o = $o + "\tif v, ok := nino.TryReadRaw[" + gotype($s.element) + "](r, " + $s.element.size + ", " + $b.as_is + ", " + $b.bools + "); ok {\n\t\treturn " + ($unique ? "nino.CheckUniqueValues(r, v)" : "v") + "\n\t}\n" + end + ret $o + read_fixed(gotype($s.element), $s.element.size, "e = " + decode($s.element, 0), !$s.element.runnable) + "\treturn " + ($unique ? "nino.CheckUniqueValues(r, v)" : "v") + "\n}\n" when "stringset" # A set of strings in the order of the data: a string (or null) read twice fails. ret $o + read_loop(gotype($s.element), $s.element.min, "e = " + read($s.element)) + "\treturn nino.CheckUniqueStrings(r, v)\n}\n" @@ -295,16 +319,6 @@ func helper_body(h) # A set of the slots of a number (any other sequence of them calls the block directly): an element read twice # fails, null included. ret $o + "\treturn nino.CheckUniqueValues(r, nino.ReadNullableSlots[" + gotype($s.element.inner) + "](r))\n}\n" - when "fixed" - $b = $s.element.raw_block - if $b - ret $o + "\treturn nino.ReadRaw(r, " + $s.element.size + ", " + $b.as_is + ", " + $b.bools + ", " + decode_fn($s.element) + ")\n}\n" - end - # The elements' bytes with one bounds check, then each element's from a cursor. - $z = $s.element.size - $o = $o + "\tn := r.Length(" + $z + ")\n\tif n < 0 {\n\t\treturn nil\n\t}\n\tb := r.Take(n * " + $z + ")\n\tif len(b) != n*" + $z + " {\n\t\treturn nil\n\t}\n" - $o = $o + make_slice(gotype($s.element)) + "\tfor len(b) >= " + $z + " {\n\t\te = " + decode_fn($s.element) + "(r, b[:" + $z + ":" + $z + "])\n" - ret $o + "\t\tif r.Failed() {\n\t\t\treturn nil\n\t\t}\n\t\tv = append(v, e)\n\t\tb = b[" + $z + ":]\n\t}\n\treturn " + ($s.unique_slots ? "nino.CheckUniqueValues(r, v)" : "v") + "\n}\n" end ret $o + read_loop(gotype($s.element), $s.element.min, "e = " + read($s.element)) + "\treturn v\n}\n" end @@ -323,21 +337,32 @@ func helper_body(h) end ret $o + "}\n" when "grid" - ret $o + "\tif !writeGrid(w, v, " + $s.rank + ") {\n\t\treturn\n\t}\n\tfor _, e := range v.Items {\n\t\t" + write($s.element, "e") + "\n\t}\n}\n" + $o = $o + "\tif !writeGrid(w, v, " + $s.rank + ") {\n\t\treturn\n\t}\n" + if $s.element.block + ret $o + "\tnino.WritePrimitivesRaw(w, v.Items)\n}\n" + end + if $s.element.size > 0 + ret $o + write_fixed_block("v.Items", $s.element.size, $s.element, "e", null, "") + "}\n" + end + ret $o + "\tfor _, e := range v.Items {\n\t\t" + write($s.element, "e") + "\n\t}\n}\n" when "map" + if $s.mode == "fixed" + ret $o + write_length() + write_fixed_block("v", $s.key.size + $s.value.size, $s.key, "e.Key", $s.value, "e.Value") + "}\n" + end ret $o + write_loop(write($s.key, "e.Key") + "\n\t\t" + write($s.value, "e.Value")) end - if $s.mode == "fixed" + if $s.element.block + ret $o + "\tnino.WritePrimitives(w, v)\n}\n" + else if $s.element.block_value + ret $o + "\tnino.WriteBlock(w, v)\n}\n" + else if $s.element.kind == "prim" && $s.element.primitive == "Bool" + ret $o + "\tnino.WriteBools(w, v)\n}\n" + else if $s.mode == "fixed" || $s.mode == "unique" $b = $s.element.raw_block if $b - ret $o + "\tnino.WriteRaw(w, v, " + $s.element.size + ", " + $b.as_is + ", " + $b.bools + ", " + $b.pads + ", " + encode_fn($s.element) + ")\n}\n" + $o = $o + "\tif nino.TryWriteRaw(w, v, " + $s.element.size + ", " + $b.as_is + ", " + $b.bools + ", " + $b.pads + ") {\n\t\treturn\n\t}\n" end - # One reservation, cleared (padding is written as zeros), then each element's bytes from a cursor. - $z = $s.element.size - $o = $o + "\tif v == nil {\n\t\tw.NullLength()\n\t\treturn\n\t}\n\tw.Length(len(v))\n\tb := w.ExtendZero(len(v) * " + $z + ")\n\tif len(b) != len(v)*" + $z + " {\n\t\treturn\n\t}\n" - ret $o + "\tfor _, e := range v {\n\t\t" + encode_fn($s.element) + "(b[:" + $z + ":" + $z + "], e)\n\t\tb = b[" + $z + ":]\n\t}\n}\n" - else if $s.element.block - ret $o + "\tnino.WritePrimitives(w, v)\n}\n" + ret $o + write_length() + write_fixed_block("v", $s.element.size, $s.element, "e", null, "") + "}\n" else if $s.element.kind == "string" && !$s.element.field ret $o + "\tnino.WriteStringPtrs(w, v)\n}\n" else if $s.element.kind == "keystring" && !$s.element.field @@ -346,6 +371,52 @@ func helper_body(h) ret $o + write_loop(write($s.element, "e")) end +# A fixed run's cursor. The count was checked against the input by Length or ReadShape. +func read_fixed_block(size, n, setup, each, after, loop, checked) + $o = "\tb := r.Take(" + n + " * " + size + ")\n\tif r.Failed() {\n\t\treturn nil\n\t}\n" + setup + "\t" + loop + " {\n\t\t" + each + "\n" + if checked + $o = $o + "\t\tif r.Failed() {\n\t\t\treturn nil\n\t\t}\n" + end + ret $o + after + "\t\tb = b[" + size + ":]\n\t}\n" +end + +func read_fixed(t, size, each, checked) + $o = "\tn := r.Length(" + size + ")\n\tif n < 0 {\n\t\treturn nil\n\t}\n" + ret $o + read_fixed_block(size, "n", make_slice(t), each, "\t\tv = append(v, e)\n", "for len(b) >= " + size, checked) +end + +# Preflight range-limited fields. If one is invalid, use the scalar writer on the prefix ending at that field +# so it reports the same offset as the element loop. +func write_fixed_block(values, size, first, a, second, b) + $o = "" + if first.checked_write || (second && second.checked_write) + $test = first.checked_write ? "!" + a + ".Valid()" : "" + if second && second.checked_write + $test = $test + ($test == "" ? "" : " || ") + "!" + b + ".Valid()" + end + $scalar = "\t\t\t\t" + write(first, a) + "\n" + if second + $scalar = $scalar + "\t\t\t\t" + write(second, b) + "\n" + end + $o = "\tfor i, e := range " + values + " {\n\t\tif " + $test + " {\n\t\t\tfor _, e := range " + values + "[:i+1] {\n" + $scalar + "\t\t\t}\n\t\t\treturn\n\t\t}\n\t}\n" + end + $code = encode(first, 0, a) + if second + $code = array.concat $code (encode(second, first.size, b)) + end + $zero = first.needs_zero || (second && second.needs_zero) ? "true" : "false" + $o = $o + "\tb := w.ExtendFixed(len(" + values + "), " + size + ", " + $zero + ")\n\tif b == nil {\n\t\treturn\n\t}\n" + if $code.size != 0 + if second + $o = $o + "\tfor i := range " + values + " {\n\t\te := &" + values + "[i]\n" + else + $o = $o + "\tfor _, e := range " + values + " {\n" + end + $o = $o + "\t\t_ = b[" + (size - 1) + "]\n" + lines($code, "\t\t") + "\t\tb = b[" + size + ":]\n\t}\n" + end + ret $o +end + # The loop of a sequence's read helper: its length (n), then each element, read by `each` into `e` (of type `t`) # with direct calls (no func value an element), appended to `v`. As the runtime's own loops do: nil for null and on a # failure, the slice presized only as far as the bytes left allow (Reader.SliceCap). @@ -374,7 +445,11 @@ end # The rest of a sequence's write helper: null for nil, else its length and each element `e`, written by `each`. func write_loop(each) - ret "\tif v == nil {\n\t\tw.NullLength()\n\t\treturn\n\t}\n\tw.Length(len(v))\n\tfor _, e := range v {\n\t\t" + each + "\n\t}\n}\n" + ret write_length() + "\tfor _, e := range v {\n\t\t" + each + "\n\t}\n}\n" +end + +func write_length() + ret "\tif v == nil {\n\t\tw.NullLength()\n\t\treturn\n\t}\n\tw.Length(len(v))\n" end # A slot's dispatch: the type id, then the body of one of the types the declared type allows. `read` and `write` diff --git a/runtimes/csharp/tests/Nino.Codegen.Tests/Shapes.cs b/runtimes/csharp/tests/Nino.Codegen.Tests/Shapes.cs index a0f29585d..6f55671be 100644 --- a/runtimes/csharp/tests/Nino.Codegen.Tests/Shapes.cs +++ b/runtimes/csharp/tests/Nino.Codegen.Tests/Shapes.cs @@ -111,6 +111,17 @@ public struct Marked public short Code; } + /// Fixed-width collections whose Go element memory is not necessarily the wire layout. + [NinoType] + public sealed class FixedCollections + { + public Dictionary Ids; + public HashSet UniqueIds; + public byte[,] Grid; + public Dictionary Pairs; + public System.DateTimeOffset[] Offsets; + } + /// Keys Rust cannot hash: Rust leaves the type out, with a warning; Go and TypeScript keep it. [NinoType] public sealed class FloatKeys diff --git a/runtimes/go/AGENTS.md b/runtimes/go/AGENTS.md index 45a96b438..8d64c0bfb 100644 --- a/runtimes/go/AGENTS.md +++ b/runtimes/go/AGENTS.md @@ -29,9 +29,9 @@ nullable.go NullableSlot[T] (a T? as the element of a sequence) where Go's layout is the wire's) endian_little.go littleEndian = true on little-endian architectures (blocks copied as memory) endian_other.go littleEndian = false elsewhere (blocks converted element by element) -unique.go duplicate keys of sets and maps read in data order: numbers, strings and NullableSlots of - numbers (a set of T?) compared as .NET does, pairwise or in a seeded open-addressing table - (the reader's scratch), no map +unique.go duplicate keys of sets and maps read in data order: numbers, strings, NullableSlots of + numbers (a set of T?) and keys whose equality is their bytes, pairwise or in a seeded + open-addressing table (the reader's scratch); key metadata cached by Go type collections.go slices, maps, sets, entries, fixed-size runs, multidimensional shapes (the func-value helpers unexported, for the runtime's rare paths); counts checked against the bytes left depth.go class bodies (Class, ReadClass, WriteClass), deferral past 128, the 512 limit @@ -142,8 +142,10 @@ requirements: of allocations (`bench`, `-benchmem`). A collection of fixed-size elements takes a block helper (`ReadPrimitives`, `ReadPrimitiveEntries`, `ReadPrimitiveMap`), never the generic helpers that take element functions: those are an indirect call per element (`(*Reader).I32` is never inlined through a func value) and a - bounds check per value. Any other collection loop in generated code is written out with the element's call made directly - (nino-gen's `read_loop` / `write_loop`), never a helper taking a func value (the runtime keeps `readSlice` and the like unexported, for its own rare paths) (`optimize-runtimes`, references/dispatch.md). + bounds check per value. Generated fixed-width maps, sequences, sets and grids without a matching bulk copy + share a cursor loop at constant offsets. Raw sequences still attempt the memory copy through `TryReadRaw` / + `TryWriteRaw`, then take the same cursor on other hosts. Other generated collection loops also call the + element's codec directly (nino-gen's `read_loop` / `write_loop`; `optimize-runtimes`, references/dispatch.md). `ReadPrimitiveMap` read a 10-pair `map[int32]int32` 31 % faster than `ReadMap` (now unexported), and SimpleClass 4-7 % faster on runners (7ac8b46). Walk a block with a cursor (`for len(b) >= wire { ...; b = b[wire:] }`): indexing `b[i*wire:]` kept a bounds check per pair. A runner A/B can move code you did not touch by diff --git a/runtimes/go/bench/model/nino_types.go b/runtimes/go/bench/model/nino_types.go index 145b6a820..b56c94481 100644 --- a/runtimes/go/bench/model/nino_types.go +++ b/runtimes/go/bench/model/nino_types.go @@ -26738,11 +26738,48 @@ func writeV8(w *nino.Writer, v []*CardDef) { } func readV9(r *nino.Reader) []Buff { - return nino.ReadRaw(r, 8, asIsBuff, nil, decodeBuff) + if v, ok := nino.TryReadRaw[Buff](r, 8, asIsBuff, nil); ok { + return v + } + n := r.Length(8) + if n < 0 { + return nil + } + b := r.Take(n * 8) + if r.Failed() { + return nil + } + var e Buff + v := make([]Buff, 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) + for len(b) >= 8 { + e = decodeBuff(r, b[0:8]) + if r.Failed() { + return nil + } + v = append(v, e) + b = b[8:] + } + return v } func writeV9(w *nino.Writer, v []Buff) { - nino.WriteRaw(w, v, 8, asIsBuff, nil, []int{3}, encodeBuff) + if nino.TryWriteRaw(w, v, 8, asIsBuff, nil, []int{3}) { + return + } + if v == nil { + w.NullLength() + return + } + w.Length(len(v)) + b := w.ExtendFixed(len(v), 8, true) + if b == nil { + return + } + for _, e := range v { + _ = b[7] + encodeBuff(b[0:8], e) + b = b[8:] + } } func readintoV10(r *nino.Reader, p *[]*BattlePlayer) { @@ -27129,7 +27166,28 @@ func readV22(r *nino.Reader) MarchKind { } func readV23(r *nino.Reader) []MapPoint { - return nino.ReadRaw(r, 4, asIsMapPoint, nil, decodeMapPoint) + if v, ok := nino.TryReadRaw[MapPoint](r, 4, asIsMapPoint, nil); ok { + return v + } + n := r.Length(4) + if n < 0 { + return nil + } + b := r.Take(n * 4) + if r.Failed() { + return nil + } + var e MapPoint + v := make([]MapPoint, 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) + for len(b) >= 4 { + e = decodeMapPoint(r, b[0:4]) + if r.Failed() { + return nil + } + v = append(v, e) + b = b[4:] + } + return v } func writeV22(w *nino.Writer, v MarchKind) { @@ -27137,7 +27195,23 @@ func writeV22(w *nino.Writer, v MarchKind) { } func writeV23(w *nino.Writer, v []MapPoint) { - nino.WriteRaw(w, v, 4, asIsMapPoint, nil, nil, encodeMapPoint) + if nino.TryWriteRaw(w, v, 4, asIsMapPoint, nil, nil) { + return + } + if v == nil { + w.NullLength() + return + } + w.Length(len(v)) + b := w.ExtendFixed(len(v), 4, true) + if b == nil { + return + } + for _, e := range v { + _ = b[3] + encodeMapPoint(b[0:4], e) + b = b[4:] + } } func readV24(r *nino.Reader) MediaPlayer { @@ -27187,11 +27261,48 @@ func writeV25(w *nino.Writer, v []*Image) { } func readV26(r *nino.Reader) []Vec3 { - return nino.ReadRaw(r, 12, asIsVec3, nil, decodeVec3) + if v, ok := nino.TryReadRaw[Vec3](r, 12, asIsVec3, nil); ok { + return v + } + n := r.Length(12) + if n < 0 { + return nil + } + b := r.Take(n * 12) + if r.Failed() { + return nil + } + var e Vec3 + v := make([]Vec3, 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) + for len(b) >= 12 { + e = decodeVec3(r, b[0:12]) + if r.Failed() { + return nil + } + v = append(v, e) + b = b[12:] + } + return v } func writeV26(w *nino.Writer, v []Vec3) { - nino.WriteRaw(w, v, 12, asIsVec3, nil, nil, encodeVec3) + if nino.TryWriteRaw(w, v, 12, asIsVec3, nil, nil) { + return + } + if v == nil { + w.NullLength() + return + } + w.Length(len(v)) + b := w.ExtendFixed(len(v), 12, true) + if b == nil { + return + } + for _, e := range v { + _ = b[11] + encodeVec3(b[0:12], e) + b = b[12:] + } } func readintoV27(r *nino.Reader, p *[]IComponent) { @@ -27607,11 +27718,48 @@ func writeV45(w *nino.Writer, v UserType) { } func readV46(r *nino.Reader) []DamageHit { - return nino.ReadRaw(r, 12, asIsDamageHit, []int{8}, decodeDamageHit) + if v, ok := nino.TryReadRaw[DamageHit](r, 12, asIsDamageHit, []int{8}); ok { + return v + } + n := r.Length(12) + if n < 0 { + return nil + } + b := r.Take(n * 12) + if r.Failed() { + return nil + } + var e DamageHit + v := make([]DamageHit, 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) + for len(b) >= 12 { + e = decodeDamageHit(r, b[0:12]) + if r.Failed() { + return nil + } + v = append(v, e) + b = b[12:] + } + return v } func writeV46(w *nino.Writer, v []DamageHit) { - nino.WriteRaw(w, v, 12, asIsDamageHit, []int{8}, []int{9, 10, 11}, encodeDamageHit) + if nino.TryWriteRaw(w, v, 12, asIsDamageHit, []int{8}, []int{9, 10, 11}) { + return + } + if v == nil { + w.NullLength() + return + } + w.Length(len(v)) + b := w.ExtendFixed(len(v), 12, true) + if b == nil { + return + } + for _, e := range v { + _ = b[11] + encodeDamageHit(b[0:12], e) + b = b[12:] + } } func readintoV47(r *nino.Reader, p *[]*Question) { @@ -27814,7 +27962,28 @@ func writeV52(w *nino.Writer, v NinoTuple2[int32, int16]) { } func readV53(r *nino.Reader) []Tile { - return nino.ReadRaw(r, 8, asIsTile, nil, decodeTile) + if v, ok := nino.TryReadRaw[Tile](r, 8, asIsTile, nil); ok { + return v + } + n := r.Length(8) + if n < 0 { + return nil + } + b := r.Take(n * 8) + if r.Failed() { + return nil + } + var e Tile + v := make([]Tile, 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) + for len(b) >= 8 { + e = decodeTile(r, b[0:8]) + if r.Failed() { + return nil + } + v = append(v, e) + b = b[8:] + } + return v } func readintoV54(r *nino.Reader, p *[]*Alliance) { @@ -27896,7 +28065,23 @@ func readintoV56(r *nino.Reader, p *[]*Army) { } func writeV53(w *nino.Writer, v []Tile) { - nino.WriteRaw(w, v, 8, asIsTile, nil, []int{2, 3}, encodeTile) + if nino.TryWriteRaw(w, v, 8, asIsTile, nil, []int{2, 3}) { + return + } + if v == nil { + w.NullLength() + return + } + w.Length(len(v)) + b := w.ExtendFixed(len(v), 8, true) + if b == nil { + return + } + for _, e := range v { + _ = b[7] + encodeTile(b[0:8], e) + b = b[8:] + } } func writeV54(w *nino.Writer, v []*Alliance) { @@ -28104,13 +28289,13 @@ func readV66(r *nino.Reader) []nino.NullableSlot[nino.Decimal] { return nil } b := r.Take(n * 24) - if len(b) != n*24 { + if r.Failed() { return nil } var e nino.NullableSlot[nino.Decimal] v := make([]nino.NullableSlot[nino.Decimal], 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) for len(b) >= 24 { - e = decodeV100(r, b[:24:24]) + e = decodeV100(r, b[0:24]) if r.Failed() { return nil } @@ -28126,12 +28311,13 @@ func writeV66(w *nino.Writer, v []nino.NullableSlot[nino.Decimal]) { return } w.Length(len(v)) - b := w.ExtendZero(len(v) * 24) - if len(b) != len(v)*24 { + b := w.ExtendFixed(len(v), 24, true) + if b == nil { return } for _, e := range v { - encodeV100(b[:24:24], e) + _ = b[23] + encodeV100(b[0:24], e) b = b[24:] } } @@ -28142,13 +28328,13 @@ func readV67(r *nino.Reader) []nino.NullableSlot[Vec3] { return nil } b := r.Take(n * 16) - if len(b) != n*16 { + if r.Failed() { return nil } var e nino.NullableSlot[Vec3] v := make([]nino.NullableSlot[Vec3], 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) for len(b) >= 16 { - e = decodeV101(r, b[:16:16]) + e = decodeV101(r, b[0:16]) if r.Failed() { return nil } @@ -28164,12 +28350,13 @@ func writeV67(w *nino.Writer, v []nino.NullableSlot[Vec3]) { return } w.Length(len(v)) - b := w.ExtendZero(len(v) * 16) - if len(b) != len(v)*16 { + b := w.ExtendFixed(len(v), 16, true) + if b == nil { return } for _, e := range v { - encodeV101(b[:16:16], e) + _ = b[15] + encodeV101(b[0:16], e) b = b[16:] } } @@ -28232,11 +28419,48 @@ func readV71(r *nino.Reader) []nino.NullableSlot[int32] { } func readV72(r *nino.Reader) []InventoryItem { - return nino.ReadRaw(r, 8, asIsInventoryItem, []int{6}, decodeInventoryItem) + if v, ok := nino.TryReadRaw[InventoryItem](r, 8, asIsInventoryItem, []int{6}); ok { + return v + } + n := r.Length(8) + if n < 0 { + return nil + } + b := r.Take(n * 8) + if r.Failed() { + return nil + } + var e InventoryItem + v := make([]InventoryItem, 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) + for len(b) >= 8 { + e = decodeInventoryItem(r, b[0:8]) + if r.Failed() { + return nil + } + v = append(v, e) + b = b[8:] + } + return v } func writeV72(w *nino.Writer, v []InventoryItem) { - nino.WriteRaw(w, v, 8, asIsInventoryItem, []int{6}, []int{7}, encodeInventoryItem) + if nino.TryWriteRaw(w, v, 8, asIsInventoryItem, []int{6}, []int{7}) { + return + } + if v == nil { + w.NullLength() + return + } + w.Length(len(v)) + b := w.ExtendFixed(len(v), 8, true) + if b == nil { + return + } + for _, e := range v { + _ = b[7] + encodeInventoryItem(b[0:8], e) + b = b[8:] + } } func readV73(r *nino.Reader) (v []Waypoint) { @@ -28404,13 +28628,13 @@ func readV83(r *nino.Reader) []nino.NullableSlot[SimpleStruct] { return nil } b := r.Take(n * 16) - if len(b) != n*16 { + if r.Failed() { return nil } var e nino.NullableSlot[SimpleStruct] v := make([]nino.NullableSlot[SimpleStruct], 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) for len(b) >= 16 { - e = decodeV103(r, b[:16:16]) + e = decodeV103(r, b[0:16]) if r.Failed() { return nil } @@ -28426,12 +28650,13 @@ func writeV83(w *nino.Writer, v []nino.NullableSlot[SimpleStruct]) { return } w.Length(len(v)) - b := w.ExtendZero(len(v) * 16) - if len(b) != len(v)*16 { + b := w.ExtendFixed(len(v), 16, true) + if b == nil { return } for _, e := range v { - encodeV103(b[:16:16], e) + _ = b[15] + encodeV103(b[0:16], e) b = b[16:] } } @@ -28510,13 +28735,13 @@ func readV88(r *nino.Reader) []RawNullable { return nil } b := r.Take(n * 40) - if len(b) != n*40 { + if r.Failed() { return nil } var e RawNullable v := make([]RawNullable, 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) for len(b) >= 40 { - e = decodeRawNullable(r, b[:40:40]) + e = decodeRawNullable(r, b[0:40]) if r.Failed() { return nil } @@ -28532,12 +28757,13 @@ func writeV88(w *nino.Writer, v []RawNullable) { return } w.Length(len(v)) - b := w.ExtendZero(len(v) * 40) - if len(b) != len(v)*40 { + b := w.ExtendFixed(len(v), 40, true) + if b == nil { return } for _, e := range v { - encodeRawNullable(b[:40:40], e) + _ = b[39] + encodeRawNullable(b[0:40], e) b = b[40:] } } @@ -28628,11 +28854,48 @@ func writeV93(w *nino.Writer, v []NinoTuple5[float64, int64, float64, float32, u } func readV94(r *nino.Reader) []PaddedRaw { - return nino.ReadRaw(r, 16, asIsPaddedRaw, nil, decodePaddedRaw) + if v, ok := nino.TryReadRaw[PaddedRaw](r, 16, asIsPaddedRaw, nil); ok { + return v + } + n := r.Length(16) + if n < 0 { + return nil + } + b := r.Take(n * 16) + if r.Failed() { + return nil + } + var e PaddedRaw + v := make([]PaddedRaw, 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) + for len(b) >= 16 { + e = decodePaddedRaw(r, b[0:16]) + if r.Failed() { + return nil + } + v = append(v, e) + b = b[16:] + } + return v } func writeV94(w *nino.Writer, v []PaddedRaw) { - nino.WriteRaw(w, v, 16, asIsPaddedRaw, nil, []int{2, 3, 4, 5, 6, 7}, encodePaddedRaw) + if nino.TryWriteRaw(w, v, 16, asIsPaddedRaw, nil, []int{2, 3, 4, 5, 6, 7}) { + return + } + if v == nil { + w.NullLength() + return + } + w.Length(len(v)) + b := w.ExtendFixed(len(v), 16, true) + if b == nil { + return + } + for _, e := range v { + _ = b[15] + encodePaddedRaw(b[0:16], e) + b = b[16:] + } } func readV95(r *nino.Reader) (v []*Box[int64]) { @@ -28673,13 +28936,13 @@ func readV97(r *nino.Reader) []SimpleStruct { return nil } b := r.Take(n * 12) - if len(b) != n*12 { + if r.Failed() { return nil } var e SimpleStruct v := make([]SimpleStruct, 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) for len(b) >= 12 { - e = decodeSimpleStruct(r, b[:12:12]) + e = decodeSimpleStruct(r, b[0:12]) if r.Failed() { return nil } @@ -28695,12 +28958,13 @@ func writeV97(w *nino.Writer, v []SimpleStruct) { return } w.Length(len(v)) - b := w.ExtendZero(len(v) * 12) - if len(b) != len(v)*12 { + b := w.ExtendFixed(len(v), 12, true) + if b == nil { return } for _, e := range v { - encodeSimpleStruct(b[:12:12], e) + _ = b[11] + encodeSimpleStruct(b[0:12], e) b = b[12:] } } diff --git a/runtimes/go/collections.go b/runtimes/go/collections.go index a1b717e71..43151d5dc 100644 --- a/runtimes/go/collections.go +++ b/runtimes/go/collections.go @@ -161,26 +161,35 @@ func writeFixed[T any](w *Writer, v []T, size int, encode func(b []byte, e T)) { // an element, whose bytes must be 0 or 1; and decode, for the hosts where the block is not the memory (big-endian // ones) and asIs false (a 32-bit host that aligns an int64 to 4 bytes). Never pass asIs true for a T with pointers. func ReadRaw[T any](r *Reader, size int, asIs bool, bools []int, decode func(r *Reader, b []byte) T) []T { + if v, ok := TryReadRaw[T](r, size, asIs, bools); ok { + return v + } + return readFixed(r, size, decode) +} + +// TryReadRaw is the raw-memory path of [ReadRaw]. When ok is false it leaves the reader untouched so a +// generated caller can decode each element directly on hosts where Go memory does not match the wire. +func TryReadRaw[T any](r *Reader, size int, asIs bool, bools []int) (v []T, ok bool) { var zero T - if !asIs || !littleEndian || int(unsafe.Sizeof(zero)) != size { - return readFixed(r, size, decode) + if !asIs || !littleEndian || size <= 0 || int(unsafe.Sizeof(zero)) != size { + return nil, false } n := r.Length(size) if n < 0 { - return nil + return nil, true } b := r.Take(n * size) if len(b) != n*size { - return nil + return nil, true } if len(bools) != 0 && !rawBools(b, size, bools) { r.Fail(CodeInvalidData, "invalid bool") - return nil + return nil, true } // As many bytes of memory as of data: no more than readFixed's bound. - v := make([]T, n) + v = make([]T, n) copy(unsafe.Slice((*byte)(unsafe.Pointer(unsafe.SliceData(v))), n*size), b) - return v + return v, true } // rawBools reports whether the bytes at each offset of bools in each element (size bytes) of b are 0 or 1: ORed into @@ -221,19 +230,26 @@ func rawBools(b []byte, size int, bools []int) bool { // (padding), which [writeFixed] writes as zeros and so does the block once copied. A bool whose byte is not 0 or 1 // (set through unsafe) is written as 1. func WriteRaw[T any](w *Writer, v []T, size int, asIs bool, bools, pads []int, encode func(b []byte, e T)) { - var zero T - if !asIs || !littleEndian || int(unsafe.Sizeof(zero)) != size { + if !TryWriteRaw(w, v, size, asIs, bools, pads) { writeFixed(w, v, size, encode) - return + } +} + +// TryWriteRaw is the raw-memory path of [WriteRaw]. When it returns false it leaves the writer untouched +// so a generated caller can encode each element directly on hosts where Go memory does not match the wire. +func TryWriteRaw[T any](w *Writer, v []T, size int, asIs bool, bools, pads []int) bool { + var zero T + if !asIs || !littleEndian || size <= 0 || int(unsafe.Sizeof(zero)) != size { + return false } if v == nil { w.NullLength() - return + return true } w.Length(len(v)) - b := w.Extend(len(v) * size) - if len(b) != len(v)*size { - return + b := w.ExtendFixed(len(v), size, false) + if b == nil { + return true } copy(b, unsafe.Slice((*byte)(unsafe.Pointer(unsafe.SliceData(v))), len(v)*size)) if len(pads) != 0 { @@ -242,6 +258,7 @@ func WriteRaw[T any](w *Writer, v []T, size int, asIs bool, bools, pads []int, e if len(bools) != 0 && !rawBools(b, size, bools) { normalizeRawBools(b, size, bools) } + return true } // clearPads sets the bytes at the offsets pads in each element (size bytes) of b to 0. Elements of up to 32 bytes diff --git a/runtimes/go/fuzz_test.go b/runtimes/go/fuzz_test.go index 101ad5222..879dae976 100644 --- a/runtimes/go/fuzz_test.go +++ b/runtimes/go/fuzz_test.go @@ -160,7 +160,7 @@ func fuzzOp(t *testing.T, op byte, r *Reader, w *Writer) { s, ok := r.ReadShape(2+int(r.U8()%3), 4) if ok { items := make([]int32, s.Total) - readPrimitivesInto(r, items) + ReadPrimitivesInto(r, items) } case 19: v := r.Guid() diff --git a/runtimes/go/internal/generated/nino_types.go b/runtimes/go/internal/generated/nino_types.go index b009cda01..558eb1c84 100644 --- a/runtimes/go/internal/generated/nino_types.go +++ b/runtimes/go/internal/generated/nino_types.go @@ -12490,13 +12490,13 @@ func readV19(r *nino.Reader) []nino.NullableSlot[Vec2] { return nil } b := r.Take(n * 12) - if len(b) != n*12 { + if r.Failed() { return nil } var e nino.NullableSlot[Vec2] v := make([]nino.NullableSlot[Vec2], 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) for len(b) >= 12 { - e = decodeV90(r, b[:12:12]) + e = decodeV90(r, b[0:12]) if r.Failed() { return nil } @@ -12512,12 +12512,13 @@ func writeV19(w *nino.Writer, v []nino.NullableSlot[Vec2]) { return } w.Length(len(v)) - b := w.ExtendZero(len(v) * 12) - if len(b) != len(v)*12 { + b := w.ExtendFixed(len(v), 12, true) + if b == nil { return } for _, e := range v { - encodeV90(b[:12:12], e) + _ = b[11] + encodeV90(b[0:12], e) b = b[12:] } } @@ -12644,13 +12645,13 @@ func readV25(r *nino.Reader) []HoldsTuples { return nil } b := r.Take(n * 48) - if len(b) != n*48 { + if r.Failed() { return nil } var e HoldsTuples v := make([]HoldsTuples, 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) for len(b) >= 48 { - e = decodeHoldsTuples(r, b[:48:48]) + e = decodeHoldsTuples(r, b[0:48]) if r.Failed() { return nil } @@ -12666,13 +12667,13 @@ func readV26(r *nino.Reader) []HoldsPairs { return nil } b := r.Take(n * 40) - if len(b) != n*40 { + if r.Failed() { return nil } var e HoldsPairs v := make([]HoldsPairs, 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) for len(b) >= 40 { - e = decodeHoldsPairs(r, b[:40:40]) + e = decodeHoldsPairs(r, b[0:40]) if r.Failed() { return nil } @@ -12688,12 +12689,13 @@ func writeV25(w *nino.Writer, v []HoldsTuples) { return } w.Length(len(v)) - b := w.ExtendZero(len(v) * 48) - if len(b) != len(v)*48 { + b := w.ExtendFixed(len(v), 48, true) + if b == nil { return } for _, e := range v { - encodeHoldsTuples(b[:48:48], e) + _ = b[47] + encodeHoldsTuples(b[0:48], e) b = b[48:] } } @@ -12704,18 +12706,40 @@ func writeV26(w *nino.Writer, v []HoldsPairs) { return } w.Length(len(v)) - b := w.ExtendZero(len(v) * 40) - if len(b) != len(v)*40 { + b := w.ExtendFixed(len(v), 40, true) + if b == nil { return } for _, e := range v { - encodeHoldsPairs(b[:40:40], e) + _ = b[39] + encodeHoldsPairs(b[0:40], e) b = b[40:] } } func readV27(r *nino.Reader) []HoldsWide { - return nino.ReadRaw(r, 48, asIsHoldsWide, nil, decodeHoldsWide) + if v, ok := nino.TryReadRaw[HoldsWide](r, 48, asIsHoldsWide, nil); ok { + return v + } + n := r.Length(48) + if n < 0 { + return nil + } + b := r.Take(n * 48) + if r.Failed() { + return nil + } + var e HoldsWide + v := make([]HoldsWide, 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) + for len(b) >= 48 { + e = decodeHoldsWide(r, b[0:48]) + if r.Failed() { + return nil + } + v = append(v, e) + b = b[48:] + } + return v } func readV28(r *nino.Reader) []nino.NullableSlot[nino.Int128] { @@ -12724,13 +12748,13 @@ func readV28(r *nino.Reader) []nino.NullableSlot[nino.Int128] { return nil } b := r.Take(n * 32) - if len(b) != n*32 { + if r.Failed() { return nil } var e nino.NullableSlot[nino.Int128] v := make([]nino.NullableSlot[nino.Int128], 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) for len(b) >= 32 { - e = decodeV93(r, b[:32:32]) + e = decodeV93(r, b[0:32]) if r.Failed() { return nil } @@ -12741,7 +12765,23 @@ func readV28(r *nino.Reader) []nino.NullableSlot[nino.Int128] { } func writeV27(w *nino.Writer, v []HoldsWide) { - nino.WriteRaw(w, v, 48, asIsHoldsWide, nil, []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, encodeHoldsWide) + if nino.TryWriteRaw(w, v, 48, asIsHoldsWide, nil, []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}) { + return + } + if v == nil { + w.NullLength() + return + } + w.Length(len(v)) + b := w.ExtendFixed(len(v), 48, true) + if b == nil { + return + } + for _, e := range v { + _ = b[47] + encodeHoldsWide(b[0:48], e) + b = b[48:] + } } func writeV28(w *nino.Writer, v []nino.NullableSlot[nino.Int128]) { @@ -12750,12 +12790,13 @@ func writeV28(w *nino.Writer, v []nino.NullableSlot[nino.Int128]) { return } w.Length(len(v)) - b := w.ExtendZero(len(v) * 32) - if len(b) != len(v)*32 { + b := w.ExtendFixed(len(v), 32, true) + if b == nil { return } for _, e := range v { - encodeV93(b[:32:32], e) + _ = b[31] + encodeV93(b[0:32], e) b = b[32:] } } @@ -12766,13 +12807,13 @@ func readV29(r *nino.Reader) []HoldsNullables { return nil } b := r.Take(n * 40) - if len(b) != n*40 { + if r.Failed() { return nil } var e HoldsNullables v := make([]HoldsNullables, 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) for len(b) >= 40 { - e = decodeHoldsNullables(r, b[:40:40]) + e = decodeHoldsNullables(r, b[0:40]) if r.Failed() { return nil } @@ -12788,12 +12829,13 @@ func writeV29(w *nino.Writer, v []HoldsNullables) { return } w.Length(len(v)) - b := w.ExtendZero(len(v) * 40) - if len(b) != len(v)*40 { + b := w.ExtendFixed(len(v), 40, true) + if b == nil { return } for _, e := range v { - encodeHoldsNullables(b[:40:40], e) + _ = b[39] + encodeHoldsNullables(b[0:40], e) b = b[40:] } } @@ -12804,13 +12846,13 @@ func readV30(r *nino.Reader) []HoldsOffset { return nil } b := r.Take(n * 24) - if len(b) != n*24 { + if r.Failed() { return nil } var e HoldsOffset v := make([]HoldsOffset, 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) for len(b) >= 24 { - e = decodeHoldsOffset(r, b[:24:24]) + e = decodeHoldsOffset(r, b[0:24]) if r.Failed() { return nil } @@ -12826,12 +12868,13 @@ func writeV30(w *nino.Writer, v []HoldsOffset) { return } w.Length(len(v)) - b := w.ExtendZero(len(v) * 24) - if len(b) != len(v)*24 { + b := w.ExtendFixed(len(v), 24, true) + if b == nil { return } for _, e := range v { - encodeHoldsOffset(b[:24:24], e) + _ = b[23] + encodeHoldsOffset(b[0:24], e) b = b[24:] } } @@ -13042,11 +13085,9 @@ func readV41(r *nino.Reader) *NinoGrid[int32] { if g == nil { return nil } - for i := range g.Items { - g.Items[i] = r.I32() - if r.Failed() { - return nil - } + nino.ReadPrimitivesInto(r, g.Items) + if r.Failed() { + return nil } return g } @@ -13152,9 +13193,7 @@ func writeV41(w *nino.Writer, v *NinoGrid[int32]) { if !writeGrid(w, v, 2) { return } - for _, e := range v.Items { - w.I32(e) - } + nino.WritePrimitivesRaw(w, v.Items) } func writeV42(w *nino.Writer, v *NinoGrid[*string]) { @@ -13332,11 +13371,17 @@ func readV48(r *nino.Reader) *NinoGrid[nino.NullableSlot[int32]] { if g == nil { return nil } + b := r.Take(len(g.Items) * 8) + if r.Failed() { + return nil + } for i := range g.Items { - g.Items[i] = readV94(r) + _ = b[7] + g.Items[i] = decodeV94(r, b[0:8]) if r.Failed() { return nil } + b = b[8:] } return g } @@ -13345,8 +13390,14 @@ func writeV48(w *nino.Writer, v *NinoGrid[nino.NullableSlot[int32]]) { if !writeGrid(w, v, 2) { return } + b := w.ExtendFixed(len(v.Items), 8, true) + if b == nil { + return + } for _, e := range v.Items { - writeV94(w, e) + _ = b[7] + encodeV94(b[0:8], e) + b = b[8:] } } @@ -13388,13 +13439,13 @@ func readV52(r *nino.Reader) []nino.NinoNullable[nino.Decimal] { return nil } b := r.Take(n * 32) - if len(b) != n*32 { + if r.Failed() { return nil } var e nino.NinoNullable[nino.Decimal] v := make([]nino.NinoNullable[nino.Decimal], 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) for len(b) >= 32 { - e = decodeV13(r, b[:32:32]) + e = decodeV13(r, b[0:32]) if r.Failed() { return nil } @@ -13410,13 +13461,13 @@ func readV53(r *nino.Reader) []nino.NinoNullable[nino.Guid] { return nil } b := r.Take(n * 32) - if len(b) != n*32 { + if r.Failed() { return nil } var e nino.NinoNullable[nino.Guid] v := make([]nino.NinoNullable[nino.Guid], 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) for len(b) >= 32 { - e = decodeV50(r, b[:32:32]) + e = decodeV50(r, b[0:32]) if r.Failed() { return nil } @@ -13432,13 +13483,13 @@ func readV54(r *nino.Reader) []nino.NinoNullable[Padded] { return nil } b := r.Take(n * 32) - if len(b) != n*32 { + if r.Failed() { return nil } var e nino.NinoNullable[Padded] v := make([]nino.NinoNullable[Padded], 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) for len(b) >= 32 { - e = decodeV51(r, b[:32:32]) + e = decodeV51(r, b[0:32]) if r.Failed() { return nil } @@ -13453,15 +13504,19 @@ func readV55(r *nino.Reader) []nino.Entry[int32, nino.NinoNullable[nino.Decimal] if n < 0 { return nil } + b := r.Take(n * 36) + if r.Failed() { + return nil + } var e nino.Entry[int32, nino.NinoNullable[nino.Decimal]] v := make([]nino.Entry[int32, nino.NinoNullable[nino.Decimal]], 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) - for range n { - k := r.I32() - e = nino.Entry[int32, nino.NinoNullable[nino.Decimal]]{Key: k, Value: readV13(r)} + for len(b) >= 36 { + e = nino.Entry[int32, nino.NinoNullable[nino.Decimal]]{Key: int32(le.Uint32(b)), Value: decodeV13(r, b[4:36])} if r.Failed() { return nil } v = append(v, e) + b = b[36:] } return nino.CheckUniqueKeys(r, v) } @@ -13472,13 +13527,13 @@ func readV56(r *nino.Reader) []NinoNullableFieldsType { return nil } b := r.Take(n * 48) - if len(b) != n*48 { + if r.Failed() { return nil } var e NinoNullableFieldsType v := make([]NinoNullableFieldsType, 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) for len(b) >= 48 { - e = decodeNinoNullableFieldsType(r, b[:48:48]) + e = decodeNinoNullableFieldsType(r, b[0:48]) if r.Failed() { return nil } @@ -13518,12 +13573,13 @@ func writeV52(w *nino.Writer, v []nino.NinoNullable[nino.Decimal]) { return } w.Length(len(v)) - b := w.ExtendZero(len(v) * 32) - if len(b) != len(v)*32 { + b := w.ExtendFixed(len(v), 32, true) + if b == nil { return } for _, e := range v { - encodeV13(b[:32:32], e) + _ = b[31] + encodeV13(b[0:32], e) b = b[32:] } } @@ -13534,12 +13590,13 @@ func writeV53(w *nino.Writer, v []nino.NinoNullable[nino.Guid]) { return } w.Length(len(v)) - b := w.ExtendZero(len(v) * 32) - if len(b) != len(v)*32 { + b := w.ExtendFixed(len(v), 32, true) + if b == nil { return } for _, e := range v { - encodeV50(b[:32:32], e) + _ = b[31] + encodeV50(b[0:32], e) b = b[32:] } } @@ -13550,12 +13607,13 @@ func writeV54(w *nino.Writer, v []nino.NinoNullable[Padded]) { return } w.Length(len(v)) - b := w.ExtendZero(len(v) * 32) - if len(b) != len(v)*32 { + b := w.ExtendFixed(len(v), 32, true) + if b == nil { return } for _, e := range v { - encodeV51(b[:32:32], e) + _ = b[31] + encodeV51(b[0:32], e) b = b[32:] } } @@ -13566,9 +13624,16 @@ func writeV55(w *nino.Writer, v []nino.Entry[int32, nino.NinoNullable[nino.Decim return } w.Length(len(v)) - for _, e := range v { - w.I32(e.Key) - writeV13(w, e.Value) + b := w.ExtendFixed(len(v), 36, true) + if b == nil { + return + } + for i := range v { + e := &v[i] + _ = b[35] + le.PutUint32(b, uint32(e.Key)) + encodeV13(b[4:36], e.Value) + b = b[36:] } } @@ -13578,12 +13643,13 @@ func writeV56(w *nino.Writer, v []NinoNullableFieldsType) { return } w.Length(len(v)) - b := w.ExtendZero(len(v) * 48) - if len(b) != len(v)*48 { + b := w.ExtendFixed(len(v), 48, true) + if b == nil { return } for _, e := range v { - encodeNinoNullableFieldsType(b[:48:48], e) + _ = b[47] + encodeNinoNullableFieldsType(b[0:48], e) b = b[48:] } } @@ -13597,11 +13663,17 @@ func readV58(r *nino.Reader) *NinoGrid[nino.NullableSlot[Padded]] { if g == nil { return nil } + b := r.Take(len(g.Items) * 24) + if r.Failed() { + return nil + } for i := range g.Items { - g.Items[i] = readV95(r) + _ = b[23] + g.Items[i] = decodeV95(r, b[0:24]) if r.Failed() { return nil } + b = b[24:] } return g } @@ -13676,8 +13748,14 @@ func writeV58(w *nino.Writer, v *NinoGrid[nino.NullableSlot[Padded]]) { if !writeGrid(w, v, 2) { return } + b := w.ExtendFixed(len(v.Items), 24, true) + if b == nil { + return + } for _, e := range v.Items { - writeV95(w, e) + _ = b[23] + encodeV95(b[0:24], e) + b = b[24:] } } @@ -13777,13 +13855,13 @@ func readV69(r *nino.Reader) []nino.NullableSlot[Padded] { return nil } b := r.Take(n * 24) - if len(b) != n*24 { + if r.Failed() { return nil } var e nino.NullableSlot[Padded] v := make([]nino.NullableSlot[Padded], 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) for len(b) >= 24 { - e = decodeV95(r, b[:24:24]) + e = decodeV95(r, b[0:24]) if r.Failed() { return nil } @@ -13866,12 +13944,13 @@ func writeV69(w *nino.Writer, v []nino.NullableSlot[Padded]) { return } w.Length(len(v)) - b := w.ExtendZero(len(v) * 24) - if len(b) != len(v)*24 { + b := w.ExtendFixed(len(v), 24, true) + if b == nil { return } for _, e := range v { - encodeV95(b[:24:24], e) + _ = b[23] + encodeV95(b[0:24], e) b = b[24:] } } @@ -13889,11 +13968,48 @@ func writeV70(w *nino.Writer, v []nino.Entry[int32, *int32]) { } func readV71(r *nino.Reader) []Padded { - return nino.ReadRaw(r, 16, asIsPadded, nil, decodePadded) + if v, ok := nino.TryReadRaw[Padded](r, 16, asIsPadded, nil); ok { + return v + } + n := r.Length(16) + if n < 0 { + return nil + } + b := r.Take(n * 16) + if r.Failed() { + return nil + } + var e Padded + v := make([]Padded, 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) + for len(b) >= 16 { + e = decodePadded(r, b[0:16]) + if r.Failed() { + return nil + } + v = append(v, e) + b = b[16:] + } + return v } func writeV71(w *nino.Writer, v []Padded) { - nino.WriteRaw(w, v, 16, asIsPadded, nil, []int{1, 2, 3, 4, 5, 6, 7}, encodePadded) + if nino.TryWriteRaw(w, v, 16, asIsPadded, nil, []int{1, 2, 3, 4, 5, 6, 7}) { + return + } + if v == nil { + w.NullLength() + return + } + w.Length(len(v)) + b := w.ExtendFixed(len(v), 16, true) + if b == nil { + return + } + for _, e := range v { + _ = b[15] + encodePadded(b[0:16], e) + b = b[16:] + } } func readV72(r *nino.Reader) []RawOptional { @@ -13902,13 +14018,13 @@ func readV72(r *nino.Reader) []RawOptional { return nil } b := r.Take(n * 56) - if len(b) != n*56 { + if r.Failed() { return nil } var e RawOptional v := make([]RawOptional, 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) for len(b) >= 56 { - e = decodeRawOptional(r, b[:56:56]) + e = decodeRawOptional(r, b[0:56]) if r.Failed() { return nil } @@ -13932,12 +14048,13 @@ func writeV72(w *nino.Writer, v []RawOptional) { return } w.Length(len(v)) - b := w.ExtendZero(len(v) * 56) - if len(b) != len(v)*56 { + b := w.ExtendFixed(len(v), 56, true) + if b == nil { return } for _, e := range v { - encodeRawOptional(b[:56:56], e) + _ = b[55] + encodeRawOptional(b[0:56], e) b = b[56:] } } @@ -13950,11 +14067,53 @@ func writeV73(w *nino.Writer, v *RawOptional) { } func readV74(r *nino.Reader) []Vec2 { - return nino.ReadRaw(r, 8, asIsVec2, nil, decodeVec2) + if v, ok := nino.TryReadRaw[Vec2](r, 8, asIsVec2, nil); ok { + return v + } + n := r.Length(8) + if n < 0 { + return nil + } + b := r.Take(n * 8) + if r.Failed() { + return nil + } + var e Vec2 + v := make([]Vec2, 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) + for len(b) >= 8 { + e = decodeVec2(r, b[0:8]) + if r.Failed() { + return nil + } + v = append(v, e) + b = b[8:] + } + return v } func readV75(r *nino.Reader) []Mixed { - return nino.ReadRaw(r, 12, asIsMixed, nil, decodeMixed) + if v, ok := nino.TryReadRaw[Mixed](r, 12, asIsMixed, nil); ok { + return v + } + n := r.Length(12) + if n < 0 { + return nil + } + b := r.Take(n * 12) + if r.Failed() { + return nil + } + var e Mixed + v := make([]Mixed, 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) + for len(b) >= 12 { + e = decodeMixed(r, b[0:12]) + if r.Failed() { + return nil + } + v = append(v, e) + b = b[12:] + } + return v } func readintoV76(r *nino.Reader, p *[]Label) { @@ -14006,11 +14165,43 @@ func readV79(r *nino.Reader) nino.Entry[*string, Vec2] { } func writeV74(w *nino.Writer, v []Vec2) { - nino.WriteRaw(w, v, 8, asIsVec2, nil, nil, encodeVec2) + if nino.TryWriteRaw(w, v, 8, asIsVec2, nil, nil) { + return + } + if v == nil { + w.NullLength() + return + } + w.Length(len(v)) + b := w.ExtendFixed(len(v), 8, true) + if b == nil { + return + } + for _, e := range v { + _ = b[7] + encodeVec2(b[0:8], e) + b = b[8:] + } } func writeV75(w *nino.Writer, v []Mixed) { - nino.WriteRaw(w, v, 12, asIsMixed, nil, []int{1, 9, 10, 11}, encodeMixed) + if nino.TryWriteRaw(w, v, 12, asIsMixed, nil, []int{1, 9, 10, 11}) { + return + } + if v == nil { + w.NullLength() + return + } + w.Length(len(v)) + b := w.ExtendFixed(len(v), 12, true) + if b == nil { + return + } + for _, e := range v { + _ = b[11] + encodeMixed(b[0:12], e) + b = b[12:] + } } func writeV76(w *nino.Writer, v []Label) { @@ -14473,17 +14664,20 @@ func encodeV93(b []byte, v nino.NullableSlot[nino.Int128]) { } } -func readV94(r *nino.Reader) nino.NullableSlot[int32] { - var v nino.NullableSlot[int32] - if b := r.Take(8); len(b) == 8 { - v = decodeV94(r, b) +func decodeV94(r *nino.Reader, b []byte) nino.NullableSlot[int32] { + _ = b[7] + if !r.BoolAt(b[0]) { + return nino.NullableSlot[int32]{} } - return v + return nino.NullableSlot[int32]{HasValue: true, Value: int32(le.Uint32(b[4:]))} } -func writeV94(w *nino.Writer, v nino.NullableSlot[int32]) { - if b := w.ExtendZero(8); len(b) == 8 { - encodeV94(b, v) +func encodeV94(b []byte, v nino.NullableSlot[int32]) { + _ = b[7] + if v.HasValue { + b[0] = 1 + x := v.Value + le.PutUint32(b[4:], uint32(x)) } } @@ -14538,12 +14732,12 @@ func encodeV51(b []byte, v nino.NinoNullable[Padded]) { } } -func readV95(r *nino.Reader) nino.NullableSlot[Padded] { - var v nino.NullableSlot[Padded] - if b := r.Take(24); len(b) == 24 { - v = decodeV95(r, b) +func decodeV95(r *nino.Reader, b []byte) nino.NullableSlot[Padded] { + _ = b[23] + if !r.BoolAt(b[0]) { + return nino.NullableSlot[Padded]{} } - return v + return nino.NullableSlot[Padded]{HasValue: true, Value: decodePadded(r, b[8:24])} } func readV96(r *nino.Reader) nino.Entry[int32, *int32] { @@ -14553,9 +14747,12 @@ func readV96(r *nino.Reader) nino.Entry[int32, *int32] { return v } -func writeV95(w *nino.Writer, v nino.NullableSlot[Padded]) { - if b := w.ExtendZero(24); len(b) == 24 { - encodeV95(b, v) +func encodeV95(b []byte, v nino.NullableSlot[Padded]) { + _ = b[23] + if v.HasValue { + b[0] = 1 + x := v.Value + encodePadded(b[8:24], x) } } @@ -14568,27 +14765,10 @@ func readV97(r *nino.Reader) E16 { return E16(r.I16()) } -func decodeV95(r *nino.Reader, b []byte) nino.NullableSlot[Padded] { - _ = b[23] - if !r.BoolAt(b[0]) { - return nino.NullableSlot[Padded]{} - } - return nino.NullableSlot[Padded]{HasValue: true, Value: decodePadded(r, b[8:24])} -} - func writeV97(w *nino.Writer, v E16) { w.I16(int16(v)) } -func encodeV95(b []byte, v nino.NullableSlot[Padded]) { - _ = b[23] - if v.HasValue { - b[0] = 1 - x := v.Value - encodePadded(b[8:24], x) - } -} - func readintoV84(r *nino.Reader, p *[]UnionTree) { n := r.Length(4) if n < 0 { @@ -14630,23 +14810,6 @@ func readV92(r *nino.Reader) nino.Entry[*string, *int32] { return v } -func decodeV94(r *nino.Reader, b []byte) nino.NullableSlot[int32] { - _ = b[7] - if !r.BoolAt(b[0]) { - return nino.NullableSlot[int32]{} - } - return nino.NullableSlot[int32]{HasValue: true, Value: int32(le.Uint32(b[4:]))} -} - -func encodeV94(b []byte, v nino.NullableSlot[int32]) { - _ = b[7] - if v.HasValue { - b[0] = 1 - x := v.Value - le.PutUint32(b[4:], uint32(x)) - } -} - // NinoTuple2 is a ValueTuple or Tuple of 2 items. type NinoTuple2[T1, T2 any] struct { Item1 T1 diff --git a/runtimes/go/internal/generated/shapes/nino_types.go b/runtimes/go/internal/generated/shapes/nino_types.go index 897806c05..ac733cf0d 100644 --- a/runtimes/go/internal/generated/shapes/nino_types.go +++ b/runtimes/go/internal/generated/shapes/nino_types.go @@ -480,6 +480,7 @@ func writeForest(w *nino.Writer, v Forest) { var ( basedIntClass nino.Class[BasedInt] emptyClass nino.Class[Empty] + fixedCollectionsClass nino.Class[FixedCollections] floatKeysClass nino.Class[FloatKeys] forestHolderClass nino.Class[ForestHolder] holderClass nino.Class[Holder] @@ -544,6 +545,7 @@ var ( func init() { basedIntClass = nino.Class[BasedInt]{Read: readBasedIntBody, Write: writeBasedIntBody, Deferrable: true} emptyClass = nino.Class[Empty]{Read: readEmptyBody, Write: writeEmptyBody, Deferrable: true} + fixedCollectionsClass = nino.Class[FixedCollections]{Read: readFixedCollectionsBody, Write: writeFixedCollectionsBody, Deferrable: true} floatKeysClass = nino.Class[FloatKeys]{Read: readFloatKeysBody, Write: writeFloatKeysBody, Deferrable: true} forestHolderClass = nino.Class[ForestHolder]{Read: readForestHolderBody, Write: writeForestHolderBody, Deferrable: true} holderClass = nino.Class[Holder]{Read: readHolderBody, Write: writeHolderBody, Deferrable: true} @@ -1030,6 +1032,110 @@ func readEmptyBody(r *nino.Reader, v *Empty) { func writeEmptyBody(w *nino.Writer, v *Empty) { } +// FixedCollections is `Shapes.FixedCollections`. +type FixedCollections struct { + Ids []nino.Entry[nino.Guid, Marked] `nino:"0" json:"ids" yaml:"ids"` + UniqueIds []nino.Guid `nino:"1" json:"uniqueIds" yaml:"uniqueIds"` + Grid *NinoGrid[uint8] `nino:"2" json:"grid" yaml:"grid"` + Pairs []nino.Entry[int32, int64] `nino:"3" json:"pairs" yaml:"pairs"` + Offsets []nino.DateTimeOffset `nino:"4" json:"offsets" yaml:"offsets"` +} + +func (FixedCollections) NinoLayout() string { + return "format=Positional; header=Presence; trackReferences=false; raw=false; id=0x9B5DCD24; deferrable=true; members=Ids:System.Collections.Generic.Dictionary:map(raw(16),raw(8){Id:int@0:raw(4),On:bool@4:raw(1),Kind:byte@5:raw(1),Code:short@6:raw(2)});UniqueIds:System.Collections.Generic.HashSet:seq(raw(16));Grid:byte[,]:grid(2,raw(1));Pairs:System.Collections.Generic.Dictionary:map(raw(4),raw(8));Offsets:System.DateTimeOffset[]:seq(datetimeoffset)" +} + +func (FixedCollections) NinoTypeName() string { + return "Shapes.FixedCollections" +} + +func (*FixedCollections) NinoTypeID() int32 { + return -1688351452 +} + +func ReadFixedCollections(r *nino.Reader) *FixedCollections { + if !r.Present() { + return nil + } + v := new(FixedCollections) + if d, ok := r.EnterBody(); ok { + readFixedCollectionsBody(r, v) + r.ExitBody(d) + } else { + nino.ReadClassInto(r, v, &fixedCollectionsClass) + } + return v +} + +func WriteFixedCollections(w *nino.Writer, v *FixedCollections) { + if v == nil { + w.U8(0) + return + } + w.U8(1) + if d, ok := w.EnterBody(); ok { + writeFixedCollectionsBody(w, v) + w.ExitBody(d) + } else { + nino.WriteClass(w, v, &fixedCollectionsClass) + } +} + +// ReadFixedCollectionsInto reads a value into *v, the object it points to read in place (DeserializeInto). +func ReadFixedCollectionsInto(r *nino.Reader, v **FixedCollections) { + if !r.Present() { + *v = nil + return + } + if *v == nil { + *v = new(FixedCollections) + } + if d, ok := r.EnterBody(); ok { + readFixedCollectionsBody(r, *v) + r.ExitBody(d) + } else { + nino.ReadClassInto(r, *v, &fixedCollectionsClass) + } +} + +// readFixedCollectionsClass reads the body of a FixedCollections (after its type id) into a new instance. +func readFixedCollectionsClass(r *nino.Reader) *FixedCollections { + v := new(FixedCollections) + if d, ok := r.EnterBody(); ok { + readFixedCollectionsBody(r, v) + r.ExitBody(d) + } else { + nino.ReadClassInto(r, v, &fixedCollectionsClass) + } + return v +} + +// writeFixedCollectionsClass writes the body of v (not nil, after its type id). +func writeFixedCollectionsClass(w *nino.Writer, v *FixedCollections) { + if d, ok := w.EnterBody(); ok { + writeFixedCollectionsBody(w, v) + w.ExitBody(d) + } else { + nino.WriteClass(w, v, &fixedCollectionsClass) + } +} + +func readFixedCollectionsBody(r *nino.Reader, v *FixedCollections) { + v.Ids = readV14(r) + v.UniqueIds = readV15(r) + v.Grid = readV16(r) + v.Pairs = nino.ReadPrimitiveEntries[int32, int64](r) + v.Offsets = readV17(r) +} + +func writeFixedCollectionsBody(w *nino.Writer, v *FixedCollections) { + writeV14(w, v.Ids) + writeV15(w, v.UniqueIds) + writeV16(w, v.Grid) + nino.WritePrimitiveEntries[int32, int64](w, v.Pairs) + writeV17(w, v.Offsets) +} + // FloatKeys is `Shapes.FloatKeys`. type FloatKeys struct { Map []nino.Entry[float32, int32] `nino:"0" json:"map" yaml:"map"` @@ -1339,36 +1445,36 @@ func writeHolderClass(w *nino.Writer, v *Holder) { func readHolderBody(r *nino.Reader, v *Holder) { ReadIThingInto(r, &v.Thing) - readintoV14(r, &v.Things) + readintoV18(r, &v.Things) ReadRecursiveInto(r, &v.Tree) ReadOuterInnerInto(r, &v.Inner) ReadShapesLeftItemInto(r, &v.LeftItem) ReadShapesRightItemInto(r, &v.RightItem) - v.Flags = readV15(r) - v.Gaps = readV16(r) + v.Flags = readV19(r) + v.Gaps = readV20(r) v.Names = readV9(r) v.Tags = readV13(r) - v.Utf8Tags = readV17(r) + v.Utf8Tags = readV21(r) v.Pair = readV10(r) - v.Entry = readV18(r) + v.Entry = readV22(r) v.Maybe = readV11(r) ReadKeywordsInto(r, &v.Keywords) } func writeHolderBody(w *nino.Writer, v *Holder) { WriteIThing(w, v.Thing) - writeV14(w, v.Things) + writeV18(w, v.Things) WriteRecursive(w, v.Tree) WriteOuterInner(w, v.Inner) WriteShapesLeftItem(w, v.LeftItem) WriteShapesRightItem(w, v.RightItem) - writeV15(w, v.Flags) - writeV16(w, v.Gaps) + writeV19(w, v.Flags) + writeV20(w, v.Gaps) writeV9(w, v.Names) writeV13(w, v.Tags) - writeV17(w, v.Utf8Tags) + writeV21(w, v.Utf8Tags) writeV10(w, v.Pair) - writeV18(w, v.Entry) + writeV22(w, v.Entry) writeV11(w, v.Maybe) WriteKeywords(w, v.Keywords) } @@ -1460,12 +1566,12 @@ func writeHostHolderClass(w *nino.Writer, v *HostHolder) { func readHostHolderBody(r *nino.Reader, v *HostHolder) { v.Leaves = readHostLeaves(r) - v.Gaps = readV19(r) + v.Gaps = readV23(r) } func writeHostHolderBody(w *nino.Writer, v *HostHolder) { writeHostLeaves(w, v.Leaves) - writeV19(w, v.Gaps) + writeV23(w, v.Gaps) } // IThing is a value of a slot declared as `Shapes.IThing`. @@ -1873,7 +1979,7 @@ func ReadMeasure(r *nino.Reader) Measure { r.Fail(nino.CodeInvalidData, "a union case without a value") } case -1803246716: - if value := readV20(r); value != nil { + if value := readV24(r); value != nil { v = MeasureListString{Value: value} } else { r.Fail(nino.CodeInvalidData, "a union case without a value") @@ -1930,7 +2036,7 @@ func WriteMeasure(w *nino.Writer, v Measure) { if !w.EnterStruct() { return } - writeV20(w, v.Value) + writeV24(w, v.Value) w.ExitStruct() return } @@ -2190,29 +2296,29 @@ func writeNinoNullableArgsTypeClass(w *nino.Writer, v *NinoNullableArgsType) { } func readNinoNullableArgsTypeBody(r *nino.Reader, v *NinoNullableArgsType) { - v.Enum = readV21(r) + v.Enum = readV25(r) v.Enums = nino.ReadNinoNullables[Flags](r) - v.Cell = readV22(r) + v.Cell = readV26(r) v.One = codecV4.Read(r) v.Wide = codecV5.Read(r) v.Array = codecV6.Read(r) v.List = codecV7.Read(r) v.Set = nino.ReadNinoNullables[int32](r) - v.Map = readV23(r) - v.Tuple = readV24(r) + v.Map = readV27(r) + v.Tuple = readV28(r) } func writeNinoNullableArgsTypeBody(w *nino.Writer, v *NinoNullableArgsType) { - writeV21(w, v.Enum) + writeV25(w, v.Enum) nino.WriteNinoNullables[Flags](w, v.Enums) - writeV22(w, v.Cell) + writeV26(w, v.Cell) codecV4.Write(w, v.One) codecV5.Write(w, v.Wide) codecV6.Write(w, v.Array) codecV7.Write(w, v.List) nino.WriteNinoNullables[int32](w, v.Set) - writeV23(w, v.Map) - writeV24(w, v.Tuple) + writeV27(w, v.Map) + writeV28(w, v.Tuple) } // NinoNullableRawType is `Shapes.NinoNullableRaw`. @@ -2302,12 +2408,12 @@ func writeNinoNullableRawTypeClass(w *nino.Writer, v *NinoNullableRawType) { func readNinoNullableRawTypeBody(r *nino.Reader, v *NinoNullableRawType) { v.One = readHoldsNinoNullable(r) - v.Many = readV25(r) + v.Many = readV29(r) } func writeNinoNullableRawTypeBody(w *nino.Writer, v *NinoNullableRawType) { writeHoldsNinoNullable(w, v.One) - writeV25(w, v.Many) + writeV29(w, v.Many) } // NinoNullableRawWideType is `Shapes.NinoNullableRawWide`. @@ -2397,12 +2503,12 @@ func writeNinoNullableRawWideTypeClass(w *nino.Writer, v *NinoNullableRawWideTyp func readNinoNullableRawWideTypeBody(r *nino.Reader, v *NinoNullableRawWideType) { v.One = readHoldsWideNinoNullable(r) - v.Many = readV26(r) + v.Many = readV30(r) } func writeNinoNullableRawWideTypeBody(w *nino.Writer, v *NinoNullableRawWideType) { writeHoldsWideNinoNullable(w, v.One) - writeV26(w, v.Many) + writeV30(w, v.Many) } // Node is `Shapes.Generic.Node`. @@ -2565,15 +2671,15 @@ func writeNullableGridsClass(w *nino.Writer, v *NullableGrids) { } func readNullableGridsBody(r *nino.Reader, v *NullableGrids) { - v.Grid = readV27(r) - v.Cube = readV28(r) - v.Cells = readV29(r) + v.Grid = readV31(r) + v.Cube = readV32(r) + v.Cells = readV33(r) } func writeNullableGridsBody(w *nino.Writer, v *NullableGrids) { - writeV27(w, v.Grid) - writeV28(w, v.Cube) - writeV29(w, v.Cells) + writeV31(w, v.Grid) + writeV32(w, v.Cube) + writeV33(w, v.Cells) } // NullableSlots is `Shapes.NullableSlots`. @@ -2676,12 +2782,12 @@ func readNullableSlotsBody(r *nino.Reader, v *NullableSlots) { v.Linked = nino.ReadNullableSlots[uint8](r) v.Sorted = readV5(r) v.ReadOnly = readV4(r) - readintoV30(r, &v.Nested) + readintoV34(r, &v.Nested) v.BoxedSet = codecV1.Read(r) v.BoxedNested = codecV2.Read(r) v.Map = readV7(r) v.BoxedMap = codecV3.Read(r) - readintoV31(r, &v.Tuples) + readintoV35(r, &v.Tuples) } func writeNullableSlotsBody(w *nino.Writer, v *NullableSlots) { @@ -2690,12 +2796,12 @@ func writeNullableSlotsBody(w *nino.Writer, v *NullableSlots) { nino.WriteNullableSlots[uint8](w, v.Linked) nino.WriteNullableSlots[int32](w, v.Sorted) writeV4(w, v.ReadOnly) - writeV30(w, v.Nested) + writeV34(w, v.Nested) codecV1.Write(w, v.BoxedSet) codecV2.Write(w, v.BoxedNested) writeV7(w, v.Map) codecV3.Write(w, v.BoxedMap) - writeV31(w, v.Tuples) + writeV35(w, v.Tuples) } // OffsetHolder is `Shapes.OffsetHolder`. @@ -3470,13 +3576,13 @@ func writePicksClass(w *nino.Writer, v *Picks) { func readPicksBody(r *nino.Reader, v *Picks) { ReadPickInto(r, &v.Pick) - readintoV32(r, &v.Many) + readintoV36(r, &v.Many) ReadMeasureInto(r, &v.Measure) } func writePicksBody(w *nino.Writer, v *Picks) { WritePick(w, v.Pick) - writeV32(w, v.Many) + writeV36(w, v.Many) WriteMeasure(w, v.Measure) } @@ -3556,7 +3662,7 @@ func ReadRecursiveInto(r *nino.Reader, v *Recursive) { return } v.Value = r.I32() - readintoV33(r, &v.Children) + readintoV37(r, &v.Children) r.ExitStruct() } @@ -3565,7 +3671,7 @@ func WriteRecursive(w *nino.Writer, v Recursive) { return } w.I32(v.Value) - writeV33(w, v.Children) + writeV37(w, v.Children) w.ExitStruct() } @@ -4074,7 +4180,7 @@ func readStampsBody(r *nino.Reader, v *Stamps) { v.Ids = nino.ReadBlock[nino.Guid](r) v.Signed = nino.ReadBlock[nino.Int128](r) v.Unsigned = nino.ReadBlock[nino.UInt128](r) - v.Marks = readV34(r) + v.Marks = readV38(r) } func writeStampsBody(w *nino.Writer, v *Stamps) { @@ -4085,7 +4191,7 @@ func writeStampsBody(w *nino.Writer, v *Stamps) { nino.WriteBlock[nino.Guid](w, v.Ids) nino.WriteBlock[nino.Int128](w, v.Signed) nino.WriteBlock[nino.UInt128](w, v.Unsigned) - writeV34(w, v.Marks) + writeV38(w, v.Marks) } // Strides is `Shapes.Strides`. @@ -4629,13 +4735,13 @@ func readUsesBody(r *nino.Reader, v *Uses) { v.Pair = codecV12.Read(r) v.Nested = codecV13.Read(r) v.Mixed = codecV15.Read(r) - readintoV35(r, &v.Boxes) + readintoV39(r, &v.Boxes) v.Bag = codecV16.Read(r) v.Chain = codecV17.Read(r) v.Thing = codecV18.Read(r) v.Array = codecV19.Read(r) v.Complex = codecV20.Read(r) - v.Pairs = readV36(r) + v.Pairs = readV40(r) v.Raw = codecV22.Read(r) v.Tuple = codecV23.Read(r) v.Maybe = codecV24.Read(r) @@ -4651,13 +4757,13 @@ func writeUsesBody(w *nino.Writer, v *Uses) { codecV12.Write(w, v.Pair) codecV13.Write(w, v.Nested) codecV15.Write(w, v.Mixed) - writeV35(w, v.Boxes) + writeV39(w, v.Boxes) codecV16.Write(w, v.Bag) codecV17.Write(w, v.Chain) codecV18.Write(w, v.Thing) codecV19.Write(w, v.Array) codecV20.Write(w, v.Complex) - writeV36(w, v.Pairs) + writeV40(w, v.Pairs) codecV22.Write(w, v.Raw) codecV23.Write(w, v.Tuple) codecV24.Write(w, v.Maybe) @@ -4823,13 +4929,13 @@ func readV4(r *nino.Reader) []nino.NullableSlot[TupleCell] { return nil } b := r.Take(n * 16) - if len(b) != n*16 { + if r.Failed() { return nil } var e nino.NullableSlot[TupleCell] v := make([]nino.NullableSlot[TupleCell], 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) for len(b) >= 16 { - e = decodeV37(r, b[:16:16]) + e = decodeV41(r, b[0:16]) if r.Failed() { return nil } @@ -4845,12 +4951,13 @@ func writeV4(w *nino.Writer, v []nino.NullableSlot[TupleCell]) { return } w.Length(len(v)) - b := w.ExtendZero(len(v) * 16) - if len(b) != len(v)*16 { + b := w.ExtendFixed(len(v), 16, true) + if b == nil { return } for _, e := range v { - encodeV37(b[:16:16], e) + _ = b[15] + encodeV41(b[0:16], e) b = b[16:] } } @@ -4884,7 +4991,7 @@ func readV7(r *nino.Reader) []nino.Entry[int32, *int64] { v := make([]nino.Entry[int32, *int64], 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) for range n { k := r.I32() - e = nino.Entry[int32, *int64]{Key: k, Value: readV38(r)} + e = nino.Entry[int32, *int64]{Key: k, Value: readV42(r)} if r.Failed() { return nil } @@ -4901,7 +5008,7 @@ func writeV7(w *nino.Writer, v []nino.Entry[int32, *int64]) { w.Length(len(v)) for _, e := range v { w.I32(e.Key) - writeV38(w, e.Value) + writeV42(w, e.Value) } } @@ -4939,13 +5046,13 @@ func readV8(r *nino.Reader) []nino.NinoNullable[TupleCell] { return nil } b := r.Take(n * 24) - if len(b) != n*24 { + if r.Failed() { return nil } var e nino.NinoNullable[TupleCell] v := make([]nino.NinoNullable[TupleCell], 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) for len(b) >= 24 { - e = decodeV22(r, b[:24:24]) + e = decodeV26(r, b[0:24]) if r.Failed() { return nil } @@ -4961,12 +5068,13 @@ func writeV8(w *nino.Writer, v []nino.NinoNullable[TupleCell]) { return } w.Length(len(v)) - b := w.ExtendZero(len(v) * 24) - if len(b) != len(v)*24 { + b := w.ExtendFixed(len(v), 24, true) + if b == nil { return } for _, e := range v { - encodeV22(b[:24:24], e) + _ = b[23] + encodeV26(b[0:24], e) b = b[24:] } } @@ -5061,6 +5169,121 @@ func writeV13(w *nino.Writer, v []*string) { nino.WriteStringPtrs(w, v) } +func readV14(r *nino.Reader) []nino.Entry[nino.Guid, Marked] { + n := r.Length(24) + if n < 0 { + return nil + } + b := r.Take(n * 24) + if r.Failed() { + return nil + } + var e nino.Entry[nino.Guid, Marked] + v := make([]nino.Entry[nino.Guid, Marked], 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) + for len(b) >= 24 { + e = nino.Entry[nino.Guid, Marked]{Key: nino.Guid(b[0:16]), Value: decodeMarked(r, b[16:24])} + if r.Failed() { + return nil + } + v = append(v, e) + b = b[24:] + } + return nino.CheckUniqueKeys(r, v) +} + +func readV15(r *nino.Reader) []nino.Guid { + return nino.CheckUniqueValues(r, nino.ReadBlock[nino.Guid](r)) +} + +func readV16(r *nino.Reader) *NinoGrid[uint8] { + g := readGrid[uint8](r, 2, 1) + if g == nil { + return nil + } + nino.ReadPrimitivesInto(r, g.Items) + if r.Failed() { + return nil + } + return g +} + +func readV17(r *nino.Reader) []nino.DateTimeOffset { + n := r.Length(10) + if n < 0 { + return nil + } + b := r.Take(n * 10) + if r.Failed() { + return nil + } + var e nino.DateTimeOffset + v := make([]nino.DateTimeOffset, 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) + for len(b) >= 10 { + e = r.DateTimeOffsetAt(b[0:10]) + if r.Failed() { + return nil + } + v = append(v, e) + b = b[10:] + } + return v +} + +func writeV14(w *nino.Writer, v []nino.Entry[nino.Guid, Marked]) { + if v == nil { + w.NullLength() + return + } + w.Length(len(v)) + b := w.ExtendFixed(len(v), 24, true) + if b == nil { + return + } + for i := range v { + e := &v[i] + _ = b[23] + copy(b, e.Key[:]) + encodeMarked(b[16:24], e.Value) + b = b[24:] + } +} + +func writeV15(w *nino.Writer, v []nino.Guid) { + nino.WriteBlock(w, v) +} + +func writeV16(w *nino.Writer, v *NinoGrid[uint8]) { + if !writeGrid(w, v, 2) { + return + } + nino.WritePrimitivesRaw(w, v.Items) +} + +func writeV17(w *nino.Writer, v []nino.DateTimeOffset) { + if v == nil { + w.NullLength() + return + } + w.Length(len(v)) + for i, e := range v { + if !e.Valid() { + for _, e := range v[:i+1] { + w.DateTimeOffset(e) + } + return + } + } + b := w.ExtendFixed(len(v), 10, false) + if b == nil { + return + } + for _, e := range v { + _ = b[9] + e.Put(b[0:10]) + b = b[10:] + } +} + func readintoV3(r *nino.Reader, p *[]Forest) { n := r.Length(4) if n < 0 { @@ -5085,7 +5308,7 @@ func readintoV3(r *nino.Reader, p *[]Forest) { *p = v } -func readintoV14(r *nino.Reader, p *[]IThing) { +func readintoV18(r *nino.Reader, p *[]IThing) { n := r.Length(4) if n < 0 { *p = nil @@ -5112,15 +5335,36 @@ func readintoV14(r *nino.Reader, p *[]IThing) { *p = v } -func readV15(r *nino.Reader) Flags { +func readV19(r *nino.Reader) Flags { return Flags(r.I64()) } -func readV16(r *nino.Reader) []Gappy { - return nino.ReadRaw(r, 8, asIsGappy, nil, decodeGappy) +func readV20(r *nino.Reader) []Gappy { + if v, ok := nino.TryReadRaw[Gappy](r, 8, asIsGappy, nil); ok { + return v + } + n := r.Length(8) + if n < 0 { + return nil + } + b := r.Take(n * 8) + if r.Failed() { + return nil + } + var e Gappy + v := make([]Gappy, 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) + for len(b) >= 8 { + e = decodeGappy(r, b[0:8]) + if r.Failed() { + return nil + } + v = append(v, e) + b = b[8:] + } + return v } -func readV17(r *nino.Reader) []*string { +func readV21(r *nino.Reader) []*string { n := r.Length(1) if n < 0 { return nil @@ -5137,14 +5381,14 @@ func readV17(r *nino.Reader) []*string { return nino.CheckUniqueStrings(r, v) } -func readV18(r *nino.Reader) nino.Entry[*string, int32] { +func readV22(r *nino.Reader) nino.Entry[*string, int32] { var v nino.Entry[*string, int32] v.Key = r.StringPtr() v.Value = r.I32() return v } -func writeV14(w *nino.Writer, v []IThing) { +func writeV18(w *nino.Writer, v []IThing) { if v == nil { w.NullLength() return @@ -5155,15 +5399,31 @@ func writeV14(w *nino.Writer, v []IThing) { } } -func writeV15(w *nino.Writer, v Flags) { +func writeV19(w *nino.Writer, v Flags) { w.I64(int64(v)) } -func writeV16(w *nino.Writer, v []Gappy) { - nino.WriteRaw(w, v, 8, asIsGappy, nil, []int{1, 2, 3}, encodeGappy) +func writeV20(w *nino.Writer, v []Gappy) { + if nino.TryWriteRaw(w, v, 8, asIsGappy, nil, []int{1, 2, 3}) { + return + } + if v == nil { + w.NullLength() + return + } + w.Length(len(v)) + b := w.ExtendFixed(len(v), 8, true) + if b == nil { + return + } + for _, e := range v { + _ = b[7] + encodeGappy(b[0:8], e) + b = b[8:] + } } -func writeV17(w *nino.Writer, v []*string) { +func writeV21(w *nino.Writer, v []*string) { if v == nil { w.NullLength() return @@ -5174,24 +5434,24 @@ func writeV17(w *nino.Writer, v []*string) { } } -func writeV18(w *nino.Writer, v nino.Entry[*string, int32]) { +func writeV22(w *nino.Writer, v nino.Entry[*string, int32]) { w.StringPtr(v.Key) w.I32(v.Value) } -func readV19(r *nino.Reader) []nino.NullableSlot[nino.Int128] { +func readV23(r *nino.Reader) []nino.NullableSlot[nino.Int128] { n := r.Length(32) if n < 0 { return nil } b := r.Take(n * 32) - if len(b) != n*32 { + if r.Failed() { return nil } var e nino.NullableSlot[nino.Int128] v := make([]nino.NullableSlot[nino.Int128], 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) for len(b) >= 32 { - e = decodeV39(r, b[:32:32]) + e = decodeV43(r, b[0:32]) if r.Failed() { return nil } @@ -5201,114 +5461,126 @@ func readV19(r *nino.Reader) []nino.NullableSlot[nino.Int128] { return v } -func writeV19(w *nino.Writer, v []nino.NullableSlot[nino.Int128]) { +func writeV23(w *nino.Writer, v []nino.NullableSlot[nino.Int128]) { if v == nil { w.NullLength() return } w.Length(len(v)) - b := w.ExtendZero(len(v) * 32) - if len(b) != len(v)*32 { + b := w.ExtendFixed(len(v), 32, true) + if b == nil { return } for _, e := range v { - encodeV39(b[:32:32], e) + _ = b[31] + encodeV43(b[0:32], e) b = b[32:] } } -func readV20(r *nino.Reader) (v []*string) { - readintoV20(r, &v) +func readV24(r *nino.Reader) (v []*string) { + readintoV24(r, &v) return v } -func writeV20(w *nino.Writer, v []*string) { +func writeV24(w *nino.Writer, v []*string) { nino.WriteStringPtrs(w, v) } -func readV21(r *nino.Reader) nino.NinoNullable[Flags] { +func readV25(r *nino.Reader) nino.NinoNullable[Flags] { var v nino.NinoNullable[Flags] if b := r.Take(16); len(b) == 16 { - v = decodeV21(r, b) + v = decodeV25(r, b) } return v } -func readV22(r *nino.Reader) nino.NinoNullable[TupleCell] { +func readV26(r *nino.Reader) nino.NinoNullable[TupleCell] { var v nino.NinoNullable[TupleCell] if b := r.Take(24); len(b) == 24 { - v = decodeV22(r, b) + v = decodeV26(r, b) } return v } -func readV23(r *nino.Reader) []nino.Entry[int32, nino.NinoNullable[float64]] { +func readV27(r *nino.Reader) []nino.Entry[int32, nino.NinoNullable[float64]] { n := r.Length(20) if n < 0 { return nil } + b := r.Take(n * 20) + if r.Failed() { + return nil + } var e nino.Entry[int32, nino.NinoNullable[float64]] v := make([]nino.Entry[int32, nino.NinoNullable[float64]], 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) - for range n { - k := r.I32() - e = nino.Entry[int32, nino.NinoNullable[float64]]{Key: k, Value: readV40(r)} + for len(b) >= 20 { + e = nino.Entry[int32, nino.NinoNullable[float64]]{Key: int32(le.Uint32(b)), Value: decodeV44(r, b[4:20])} if r.Failed() { return nil } v = append(v, e) + b = b[20:] } return nino.CheckUniqueKeys(r, v) } -func readV24(r *nino.Reader) NinoTuple2[uint8, nino.NinoNullable[nino.Guid]] { +func readV28(r *nino.Reader) NinoTuple2[uint8, nino.NinoNullable[nino.Guid]] { var v NinoTuple2[uint8, nino.NinoNullable[nino.Guid]] v.Item1 = r.U8() - v.Item2 = readV41(r) + v.Item2 = readV45(r) return v } -func writeV21(w *nino.Writer, v nino.NinoNullable[Flags]) { +func writeV25(w *nino.Writer, v nino.NinoNullable[Flags]) { if b := w.ExtendZero(16); len(b) == 16 { - encodeV21(b, v) + encodeV25(b, v) } } -func writeV22(w *nino.Writer, v nino.NinoNullable[TupleCell]) { +func writeV26(w *nino.Writer, v nino.NinoNullable[TupleCell]) { if b := w.ExtendZero(24); len(b) == 24 { - encodeV22(b, v) + encodeV26(b, v) } } -func writeV23(w *nino.Writer, v []nino.Entry[int32, nino.NinoNullable[float64]]) { +func writeV27(w *nino.Writer, v []nino.Entry[int32, nino.NinoNullable[float64]]) { if v == nil { w.NullLength() return } w.Length(len(v)) - for _, e := range v { - w.I32(e.Key) - writeV40(w, e.Value) + b := w.ExtendFixed(len(v), 20, true) + if b == nil { + return + } + for i := range v { + e := &v[i] + _ = b[19] + le.PutUint32(b, uint32(e.Key)) + encodeV44(b[4:20], e.Value) + b = b[20:] } } -func writeV24(w *nino.Writer, v NinoTuple2[uint8, nino.NinoNullable[nino.Guid]]) { +func writeV28(w *nino.Writer, v NinoTuple2[uint8, nino.NinoNullable[nino.Guid]]) { w.U8(v.Item1) - writeV41(w, v.Item2) + writeV45(w, v.Item2) } -func readV25(r *nino.Reader) []HoldsNinoNullable { +func readV29(r *nino.Reader) []HoldsNinoNullable { n := r.Length(12) if n < 0 { return nil } b := r.Take(n * 12) - if len(b) != n*12 { + if r.Failed() { return nil } var e HoldsNinoNullable v := make([]HoldsNinoNullable, 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) for len(b) >= 12 { - e = decodeHoldsNinoNullable(r, b[:12:12]) + e = decodeHoldsNinoNullable(r, b[0:12]) if r.Failed() { return nil } @@ -5318,35 +5590,36 @@ func readV25(r *nino.Reader) []HoldsNinoNullable { return v } -func writeV25(w *nino.Writer, v []HoldsNinoNullable) { +func writeV29(w *nino.Writer, v []HoldsNinoNullable) { if v == nil { w.NullLength() return } w.Length(len(v)) - b := w.ExtendZero(len(v) * 12) - if len(b) != len(v)*12 { + b := w.ExtendFixed(len(v), 12, true) + if b == nil { return } for _, e := range v { - encodeHoldsNinoNullable(b[:12:12], e) + _ = b[11] + encodeHoldsNinoNullable(b[0:12], e) b = b[12:] } } -func readV26(r *nino.Reader) []HoldsWideNinoNullable { +func readV30(r *nino.Reader) []HoldsWideNinoNullable { n := r.Length(40) if n < 0 { return nil } b := r.Take(n * 40) - if len(b) != n*40 { + if r.Failed() { return nil } var e HoldsWideNinoNullable v := make([]HoldsWideNinoNullable, 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) for len(b) >= 40 { - e = decodeHoldsWideNinoNullable(r, b[:40:40]) + e = decodeHoldsWideNinoNullable(r, b[0:40]) if r.Failed() { return nil } @@ -5356,92 +5629,129 @@ func readV26(r *nino.Reader) []HoldsWideNinoNullable { return v } -func writeV26(w *nino.Writer, v []HoldsWideNinoNullable) { +func writeV30(w *nino.Writer, v []HoldsWideNinoNullable) { if v == nil { w.NullLength() return } w.Length(len(v)) - b := w.ExtendZero(len(v) * 40) - if len(b) != len(v)*40 { + b := w.ExtendFixed(len(v), 40, true) + if b == nil { return } for _, e := range v { - encodeHoldsWideNinoNullable(b[:40:40], e) + _ = b[39] + encodeHoldsWideNinoNullable(b[0:40], e) b = b[40:] } } -func readV27(r *nino.Reader) *NinoGrid[nino.NullableSlot[int32]] { +func readV31(r *nino.Reader) *NinoGrid[nino.NullableSlot[int32]] { g := readGrid[nino.NullableSlot[int32]](r, 2, 8) if g == nil { return nil } + b := r.Take(len(g.Items) * 8) + if r.Failed() { + return nil + } for i := range g.Items { - g.Items[i] = readV42(r) + _ = b[7] + g.Items[i] = decodeV46(r, b[0:8]) if r.Failed() { return nil } + b = b[8:] } return g } -func readV28(r *nino.Reader) *NinoGrid[nino.NullableSlot[int64]] { +func readV32(r *nino.Reader) *NinoGrid[nino.NullableSlot[int64]] { g := readGrid[nino.NullableSlot[int64]](r, 3, 16) if g == nil { return nil } + b := r.Take(len(g.Items) * 16) + if r.Failed() { + return nil + } for i := range g.Items { - g.Items[i] = readV43(r) + _ = b[15] + g.Items[i] = decodeV47(r, b[0:16]) if r.Failed() { return nil } + b = b[16:] } return g } -func readV29(r *nino.Reader) *NinoGrid[nino.NullableSlot[TupleCell]] { +func readV33(r *nino.Reader) *NinoGrid[nino.NullableSlot[TupleCell]] { g := readGrid[nino.NullableSlot[TupleCell]](r, 2, 16) if g == nil { return nil } + b := r.Take(len(g.Items) * 16) + if r.Failed() { + return nil + } for i := range g.Items { - g.Items[i] = readV37(r) + _ = b[15] + g.Items[i] = decodeV41(r, b[0:16]) if r.Failed() { return nil } + b = b[16:] } return g } -func writeV27(w *nino.Writer, v *NinoGrid[nino.NullableSlot[int32]]) { +func writeV31(w *nino.Writer, v *NinoGrid[nino.NullableSlot[int32]]) { if !writeGrid(w, v, 2) { return } + b := w.ExtendFixed(len(v.Items), 8, true) + if b == nil { + return + } for _, e := range v.Items { - writeV42(w, e) + _ = b[7] + encodeV46(b[0:8], e) + b = b[8:] } } -func writeV28(w *nino.Writer, v *NinoGrid[nino.NullableSlot[int64]]) { +func writeV32(w *nino.Writer, v *NinoGrid[nino.NullableSlot[int64]]) { if !writeGrid(w, v, 3) { return } + b := w.ExtendFixed(len(v.Items), 16, true) + if b == nil { + return + } for _, e := range v.Items { - writeV43(w, e) + _ = b[15] + encodeV47(b[0:16], e) + b = b[16:] } } -func writeV29(w *nino.Writer, v *NinoGrid[nino.NullableSlot[TupleCell]]) { +func writeV33(w *nino.Writer, v *NinoGrid[nino.NullableSlot[TupleCell]]) { if !writeGrid(w, v, 2) { return } + b := w.ExtendFixed(len(v.Items), 16, true) + if b == nil { + return + } for _, e := range v.Items { - writeV37(w, e) + _ = b[15] + encodeV41(b[0:16], e) + b = b[16:] } } -func readintoV30(r *nino.Reader, p *[][]nino.NullableSlot[int32]) { +func readintoV34(r *nino.Reader, p *[][]nino.NullableSlot[int32]) { n := r.Length(4) if n < 0 { *p = nil @@ -5465,7 +5775,7 @@ func readintoV30(r *nino.Reader, p *[][]nino.NullableSlot[int32]) { *p = v } -func readintoV31(r *nino.Reader, p *[]NinoTuple2[int32, *int32]) { +func readintoV35(r *nino.Reader, p *[]NinoTuple2[int32, *int32]) { n := r.Length(5) if n < 0 { *p = nil @@ -5479,7 +5789,7 @@ func readintoV31(r *nino.Reader, p *[]NinoTuple2[int32, *int32]) { } var e NinoTuple2[int32, *int32] for range n { - e = readV44(r) + e = readV48(r) if r.Failed() { *p = nil return @@ -5489,7 +5799,7 @@ func readintoV31(r *nino.Reader, p *[]NinoTuple2[int32, *int32]) { *p = v } -func writeV30(w *nino.Writer, v [][]nino.NullableSlot[int32]) { +func writeV34(w *nino.Writer, v [][]nino.NullableSlot[int32]) { if v == nil { w.NullLength() return @@ -5500,18 +5810,18 @@ func writeV30(w *nino.Writer, v [][]nino.NullableSlot[int32]) { } } -func writeV31(w *nino.Writer, v []NinoTuple2[int32, *int32]) { +func writeV35(w *nino.Writer, v []NinoTuple2[int32, *int32]) { if v == nil { w.NullLength() return } w.Length(len(v)) for _, e := range v { - writeV44(w, e) + writeV48(w, e) } } -func readintoV32(r *nino.Reader, p *[]Pick) { +func readintoV36(r *nino.Reader, p *[]Pick) { n := r.Length(4) if n < 0 { *p = nil @@ -5538,7 +5848,7 @@ func readintoV32(r *nino.Reader, p *[]Pick) { *p = v } -func writeV32(w *nino.Writer, v []Pick) { +func writeV36(w *nino.Writer, v []Pick) { if v == nil { w.NullLength() return @@ -5549,7 +5859,7 @@ func writeV32(w *nino.Writer, v []Pick) { } } -func readintoV33(r *nino.Reader, p *[]Recursive) { +func readintoV37(r *nino.Reader, p *[]Recursive) { n := r.Length(8) if n < 0 { *p = nil @@ -5576,7 +5886,7 @@ func readintoV33(r *nino.Reader, p *[]Recursive) { *p = v } -func writeV33(w *nino.Writer, v []Recursive) { +func writeV37(w *nino.Writer, v []Recursive) { if v == nil { w.NullLength() return @@ -5587,15 +5897,52 @@ func writeV33(w *nino.Writer, v []Recursive) { } } -func readV34(r *nino.Reader) []Marked { - return nino.ReadRaw(r, 8, asIsMarked, []int{4}, decodeMarked) +func readV38(r *nino.Reader) []Marked { + if v, ok := nino.TryReadRaw[Marked](r, 8, asIsMarked, []int{4}); ok { + return v + } + n := r.Length(8) + if n < 0 { + return nil + } + b := r.Take(n * 8) + if r.Failed() { + return nil + } + var e Marked + v := make([]Marked, 0, r.SliceCap(n, int(unsafe.Sizeof(e)))) + for len(b) >= 8 { + e = decodeMarked(r, b[0:8]) + if r.Failed() { + return nil + } + v = append(v, e) + b = b[8:] + } + return v } -func writeV34(w *nino.Writer, v []Marked) { - nino.WriteRaw(w, v, 8, asIsMarked, []int{4}, nil, encodeMarked) +func writeV38(w *nino.Writer, v []Marked) { + if nino.TryWriteRaw(w, v, 8, asIsMarked, []int{4}, nil) { + return + } + if v == nil { + w.NullLength() + return + } + w.Length(len(v)) + b := w.ExtendFixed(len(v), 8, true) + if b == nil { + return + } + for _, e := range v { + _ = b[7] + encodeMarked(b[0:8], e) + b = b[8:] + } } -func readintoV35(r *nino.Reader, p *[]*Box[int32]) { +func readintoV39(r *nino.Reader, p *[]*Box[int32]) { n := r.Length(1) if n < 0 { *p = nil @@ -5619,7 +5966,7 @@ func readintoV35(r *nino.Reader, p *[]*Box[int32]) { *p = v } -func readV36(r *nino.Reader) []nino.Entry[string, Pair[int32, int32]] { +func readV40(r *nino.Reader) []nino.Entry[string, Pair[int32, int32]] { n := r.Length(9) if n < 0 { return nil @@ -5637,7 +5984,7 @@ func readV36(r *nino.Reader) []nino.Entry[string, Pair[int32, int32]] { return nino.CheckUniqueKeys(r, v) } -func writeV35(w *nino.Writer, v []*Box[int32]) { +func writeV39(w *nino.Writer, v []*Box[int32]) { if v == nil { w.NullLength() return @@ -5648,7 +5995,7 @@ func writeV35(w *nino.Writer, v []*Box[int32]) { } } -func writeV36(w *nino.Writer, v []nino.Entry[string, Pair[int32, int32]]) { +func writeV40(w *nino.Writer, v []nino.Entry[string, Pair[int32, int32]]) { if v == nil { w.NullLength() return @@ -5660,7 +6007,7 @@ func writeV36(w *nino.Writer, v []nino.Entry[string, Pair[int32, int32]]) { } } -func decodeV37(r *nino.Reader, b []byte) nino.NullableSlot[TupleCell] { +func decodeV41(r *nino.Reader, b []byte) nino.NullableSlot[TupleCell] { _ = b[15] if !r.BoolAt(b[0]) { return nino.NullableSlot[TupleCell]{} @@ -5668,7 +6015,7 @@ func decodeV37(r *nino.Reader, b []byte) nino.NullableSlot[TupleCell] { return nino.NullableSlot[TupleCell]{HasValue: true, Value: decodeTupleCell(r, b[4:16])} } -func encodeV37(b []byte, v nino.NullableSlot[TupleCell]) { +func encodeV41(b []byte, v nino.NullableSlot[TupleCell]) { _ = b[15] if v.HasValue { b[0] = 1 @@ -5691,7 +6038,7 @@ func readintoV6(r *nino.Reader, p *[][]nino.NullableSlot[int64]) { } var e []nino.NullableSlot[int64] for range n { - e = readV45(r) + e = readV49(r) if r.Failed() { *p = nil return @@ -5701,7 +6048,7 @@ func readintoV6(r *nino.Reader, p *[][]nino.NullableSlot[int64]) { *p = v } -func readV38(r *nino.Reader) *int64 { +func readV42(r *nino.Reader) *int64 { if !r.Present() { return nil } @@ -5709,14 +6056,14 @@ func readV38(r *nino.Reader) *int64 { return &x } -func writeV38(w *nino.Writer, v *int64) { +func writeV42(w *nino.Writer, v *int64) { w.Present(v != nil) if v != nil { w.I64(*v) } } -func decodeV22(r *nino.Reader, b []byte) nino.NinoNullable[TupleCell] { +func decodeV26(r *nino.Reader, b []byte) nino.NinoNullable[TupleCell] { _ = b[23] if !r.NinoNullableAt(b[0:12], b[12:24]) { return nino.NinoNullable[TupleCell]{} @@ -5724,7 +6071,7 @@ func decodeV22(r *nino.Reader, b []byte) nino.NinoNullable[TupleCell] { return nino.NinoNullable[TupleCell]{HasValue: true, Value: decodeTupleCell(r, b[12:24])} } -func encodeV22(b []byte, v nino.NinoNullable[TupleCell]) { +func encodeV26(b []byte, v nino.NinoNullable[TupleCell]) { _ = b[23] if v.HasValue { b[0] = 1 @@ -5733,7 +6080,7 @@ func encodeV22(b []byte, v nino.NinoNullable[TupleCell]) { } } -func decodeV39(r *nino.Reader, b []byte) nino.NullableSlot[nino.Int128] { +func decodeV43(r *nino.Reader, b []byte) nino.NullableSlot[nino.Int128] { _ = b[31] if !r.BoolAt(b[0]) { return nino.NullableSlot[nino.Int128]{} @@ -5741,7 +6088,7 @@ func decodeV39(r *nino.Reader, b []byte) nino.NullableSlot[nino.Int128] { return nino.NullableSlot[nino.Int128]{HasValue: true, Value: nino.Int128{Lo: le.Uint64(b[16:]), Hi: le.Uint64(b[24:])}} } -func encodeV39(b []byte, v nino.NullableSlot[nino.Int128]) { +func encodeV43(b []byte, v nino.NullableSlot[nino.Int128]) { _ = b[31] if v.HasValue { b[0] = 1 @@ -5751,7 +6098,7 @@ func encodeV39(b []byte, v nino.NullableSlot[nino.Int128]) { } } -func readintoV20(r *nino.Reader, p *[]*string) { +func readintoV24(r *nino.Reader, p *[]*string) { n := r.Length(1) if n < 0 { *p = nil @@ -5775,7 +6122,7 @@ func readintoV20(r *nino.Reader, p *[]*string) { *p = v } -func decodeV21(r *nino.Reader, b []byte) nino.NinoNullable[Flags] { +func decodeV25(r *nino.Reader, b []byte) nino.NinoNullable[Flags] { _ = b[15] if !r.NinoNullableAt(b[0:8], b[8:16]) { return nino.NinoNullable[Flags]{} @@ -5783,23 +6130,23 @@ func decodeV21(r *nino.Reader, b []byte) nino.NinoNullable[Flags] { return nino.NinoNullable[Flags]{HasValue: true, Value: Flags(int64(le.Uint64(b[8:])))} } -func readV40(r *nino.Reader) nino.NinoNullable[float64] { - var v nino.NinoNullable[float64] - if b := r.Take(16); len(b) == 16 { - v = decodeV40(r, b) +func decodeV44(r *nino.Reader, b []byte) nino.NinoNullable[float64] { + _ = b[15] + if !r.NinoNullableAt(b[0:8], b[8:16]) { + return nino.NinoNullable[float64]{} } - return v + return nino.NinoNullable[float64]{HasValue: true, Value: math.Float64frombits(le.Uint64(b[8:]))} } -func readV41(r *nino.Reader) nino.NinoNullable[nino.Guid] { +func readV45(r *nino.Reader) nino.NinoNullable[nino.Guid] { var v nino.NinoNullable[nino.Guid] if b := r.Take(32); len(b) == 32 { - v = decodeV41(r, b) + v = decodeV45(r, b) } return v } -func encodeV21(b []byte, v nino.NinoNullable[Flags]) { +func encodeV25(b []byte, v nino.NinoNullable[Flags]) { _ = b[15] if v.HasValue { b[0] = 1 @@ -5808,85 +6155,72 @@ func encodeV21(b []byte, v nino.NinoNullable[Flags]) { } } -func writeV40(w *nino.Writer, v nino.NinoNullable[float64]) { - if b := w.ExtendZero(16); len(b) == 16 { - encodeV40(b, v) +func encodeV44(b []byte, v nino.NinoNullable[float64]) { + _ = b[15] + if v.HasValue { + b[0] = 1 + x := v.Value + le.PutUint64(b[8:], math.Float64bits(x)) } } -func writeV41(w *nino.Writer, v nino.NinoNullable[nino.Guid]) { +func writeV45(w *nino.Writer, v nino.NinoNullable[nino.Guid]) { if b := w.ExtendZero(32); len(b) == 32 { - encodeV41(b, v) - } -} - -func readV42(r *nino.Reader) nino.NullableSlot[int32] { - var v nino.NullableSlot[int32] - if b := r.Take(8); len(b) == 8 { - v = decodeV42(r, b) - } - return v -} - -func readV43(r *nino.Reader) nino.NullableSlot[int64] { - var v nino.NullableSlot[int64] - if b := r.Take(16); len(b) == 16 { - v = decodeV43(r, b) + encodeV45(b, v) } - return v } -func readV37(r *nino.Reader) nino.NullableSlot[TupleCell] { - var v nino.NullableSlot[TupleCell] - if b := r.Take(16); len(b) == 16 { - v = decodeV37(r, b) +func decodeV46(r *nino.Reader, b []byte) nino.NullableSlot[int32] { + _ = b[7] + if !r.BoolAt(b[0]) { + return nino.NullableSlot[int32]{} } - return v + return nino.NullableSlot[int32]{HasValue: true, Value: int32(le.Uint32(b[4:]))} } -func writeV42(w *nino.Writer, v nino.NullableSlot[int32]) { - if b := w.ExtendZero(8); len(b) == 8 { - encodeV42(b, v) +func decodeV47(r *nino.Reader, b []byte) nino.NullableSlot[int64] { + _ = b[15] + if !r.BoolAt(b[0]) { + return nino.NullableSlot[int64]{} } + return nino.NullableSlot[int64]{HasValue: true, Value: int64(le.Uint64(b[8:]))} } -func writeV43(w *nino.Writer, v nino.NullableSlot[int64]) { - if b := w.ExtendZero(16); len(b) == 16 { - encodeV43(b, v) +func encodeV46(b []byte, v nino.NullableSlot[int32]) { + _ = b[7] + if v.HasValue { + b[0] = 1 + x := v.Value + le.PutUint32(b[4:], uint32(x)) } } -func writeV37(w *nino.Writer, v nino.NullableSlot[TupleCell]) { - if b := w.ExtendZero(16); len(b) == 16 { - encodeV37(b, v) +func encodeV47(b []byte, v nino.NullableSlot[int64]) { + _ = b[15] + if v.HasValue { + b[0] = 1 + x := v.Value + le.PutUint64(b[8:], uint64(x)) } } -func readV44(r *nino.Reader) NinoTuple2[int32, *int32] { +func readV48(r *nino.Reader) NinoTuple2[int32, *int32] { var v NinoTuple2[int32, *int32] v.Item1 = r.I32() v.Item2 = readV11(r) return v } -func writeV44(w *nino.Writer, v NinoTuple2[int32, *int32]) { +func writeV48(w *nino.Writer, v NinoTuple2[int32, *int32]) { w.I32(v.Item1) writeV11(w, v.Item2) } -func readV45(r *nino.Reader) []nino.NullableSlot[int64] { +func readV49(r *nino.Reader) []nino.NullableSlot[int64] { return nino.CheckUniqueValues(r, nino.ReadNullableSlots[int64](r)) } -func decodeV40(r *nino.Reader, b []byte) nino.NinoNullable[float64] { - _ = b[15] - if !r.NinoNullableAt(b[0:8], b[8:16]) { - return nino.NinoNullable[float64]{} - } - return nino.NinoNullable[float64]{HasValue: true, Value: math.Float64frombits(le.Uint64(b[8:]))} -} - -func decodeV41(r *nino.Reader, b []byte) nino.NinoNullable[nino.Guid] { +func decodeV45(r *nino.Reader, b []byte) nino.NinoNullable[nino.Guid] { _ = b[31] if !r.NinoNullableAt(b[0:16], b[16:32]) { return nino.NinoNullable[nino.Guid]{} @@ -5894,16 +6228,7 @@ func decodeV41(r *nino.Reader, b []byte) nino.NinoNullable[nino.Guid] { return nino.NinoNullable[nino.Guid]{HasValue: true, Value: nino.Guid(b[16:32])} } -func encodeV40(b []byte, v nino.NinoNullable[float64]) { - _ = b[15] - if v.HasValue { - b[0] = 1 - x := v.Value - le.PutUint64(b[8:], math.Float64bits(x)) - } -} - -func encodeV41(b []byte, v nino.NinoNullable[nino.Guid]) { +func encodeV45(b []byte, v nino.NinoNullable[nino.Guid]) { _ = b[31] if v.HasValue { b[0] = 1 @@ -5912,40 +6237,6 @@ func encodeV41(b []byte, v nino.NinoNullable[nino.Guid]) { } } -func decodeV42(r *nino.Reader, b []byte) nino.NullableSlot[int32] { - _ = b[7] - if !r.BoolAt(b[0]) { - return nino.NullableSlot[int32]{} - } - return nino.NullableSlot[int32]{HasValue: true, Value: int32(le.Uint32(b[4:]))} -} - -func decodeV43(r *nino.Reader, b []byte) nino.NullableSlot[int64] { - _ = b[15] - if !r.BoolAt(b[0]) { - return nino.NullableSlot[int64]{} - } - return nino.NullableSlot[int64]{HasValue: true, Value: int64(le.Uint64(b[8:]))} -} - -func encodeV42(b []byte, v nino.NullableSlot[int32]) { - _ = b[7] - if v.HasValue { - b[0] = 1 - x := v.Value - le.PutUint32(b[4:], uint32(x)) - } -} - -func encodeV43(b []byte, v nino.NullableSlot[int64]) { - _ = b[15] - if v.HasValue { - b[0] = 1 - x := v.Value - le.PutUint64(b[8:], uint64(x)) - } -} - // NinoTuple2 is a ValueTuple or Tuple of 2 items. type NinoTuple2[T1, T2 any] struct { Item1 T1 @@ -6087,6 +6378,8 @@ func NinoCodecOf(name string) (NinoCodec, bool) { return codecOf(ReadBasedInt, ReadBasedIntInto, WriteBasedInt), true case "Shapes.Empty": return codecOf(ReadEmpty, ReadEmptyInto, WriteEmpty), true + case "Shapes.FixedCollections": + return codecOf(ReadFixedCollections, ReadFixedCollectionsInto, WriteFixedCollections), true case "Shapes.FloatKeys": return codecOf(ReadFloatKeys, ReadFloatKeysInto, WriteFloatKeys), true case "Shapes.ForestHolder": diff --git a/runtimes/go/internal/generated/shapes/shapes_test.go b/runtimes/go/internal/generated/shapes/shapes_test.go index d90f3914e..6522aafe9 100644 --- a/runtimes/go/internal/generated/shapes/shapes_test.go +++ b/runtimes/go/internal/generated/shapes/shapes_test.go @@ -99,6 +99,73 @@ func TestBlockShapesRoundTrip(t *testing.T) { } } +func TestFixedCollections(t *testing.T) { + ids := []nino.Guid{{1}, {2}, {3}} + want := &FixedCollections{ + Ids: []nino.Entry[nino.Guid, Marked]{ + {Key: ids[0], Value: Marked{Id: 1, On: true, Kind: 2, Code: -3}}, + {Key: ids[1], Value: Marked{Id: -4, Kind: 5, Code: 6}}, + }, + UniqueIds: ids, + Grid: &NinoGrid[uint8]{Lengths: []int{1, 2}, Items: []uint8{0x80, 0xFF}}, + Pairs: []nino.Entry[int32, int64]{{Key: 7, Value: -9}}, + Offsets: []nino.DateTimeOffset{{UtcTicks: 638712864000000000, OffsetMinutes: -60}, {}}, + } + got, err := nino.Serialize(want, WriteFixedCollections) + if err != nil { + t.Fatal(err) + } + scalar, err := nino.Serialize(want, func(w *nino.Writer, v *FixedCollections) { + w.Present(true) + w.Length(len(v.Ids)) + for _, e := range v.Ids { + w.Guid(e.Key) + w.I32(e.Value.Id) + w.Bool(e.Value.On) + w.U8(e.Value.Kind) + w.I16(e.Value.Code) + } + writeEach(w, v.UniqueIds, (*nino.Writer).Guid) + w.WriteShape(v.Grid.Lengths...) + for _, e := range v.Grid.Items { + w.U8(e) + } + w.Length(len(v.Pairs)) + for _, e := range v.Pairs { + w.I32(e.Key) + w.I64(e.Value) + } + writeEach(w, v.Offsets, (*nino.Writer).DateTimeOffset) + }) + if err != nil || !reflect.DeepEqual(got, scalar) { + t.Fatalf("fixed bytes %x, scalar bytes %x (%v)", got, scalar, err) + } + if v, err := nino.DeserializeExact(got, ReadFixedCollections); err != nil || !reflect.DeepEqual(v, want) { + t.Fatalf("read back %+v (%v)", v, err) + } + const mapStart, pair = 5, 16 + 8 + bad := append([]byte(nil), got...) + copy(bad[mapStart+pair:mapStart+pair+16], bad[mapStart:mapStart+16]) + if _, err := nino.DeserializeExact(bad, ReadFixedCollections); !errors.Is(err, nino.ErrDuplicateKey) { + t.Fatalf("read duplicate Guid key: %v", err) + } + copy(bad, got) + bad[mapStart+16+4] = 2 + if _, err := nino.DeserializeExact(bad, ReadFixedCollections); !errors.Is(err, nino.ErrInvalidData) { + t.Fatalf("read invalid bool in raw map value: %v", err) + } + // The second DateTimeOffset has its UTC ticks at zero, so an offset of -1 minute is invalid. + copy(bad, got) + bad[len(bad)-2], bad[len(bad)-1] = 0xFF, 0xFF + if _, err := nino.DeserializeExact(bad, ReadFixedCollections); !errors.Is(err, nino.ErrInvalidData) { + t.Fatalf("read invalid DateTimeOffset: %v", err) + } + want.Offsets[1].OffsetMinutes = -1 + if _, err := nino.Serialize(want, WriteFixedCollections); !errors.Is(err, nino.ErrInvalidValue) { + t.Fatalf("wrote invalid DateTimeOffset: %v", err) + } +} + // Generic types: closed uses read and written with the codecs built from those of their arguments. func TestGenericShapesRoundTrip(t *testing.T) { s := func(v string) *string { return &v } diff --git a/runtimes/go/raw.go b/runtimes/go/raw.go index 6fb73becf..a6a876337 100644 --- a/runtimes/go/raw.go +++ b/runtimes/go/raw.go @@ -29,8 +29,8 @@ func ReadPrimitives[T Primitive](r *Reader) []T { return v } -// readPrimitivesInto reads len(dst) primitives (a block without a length) into dst. -func readPrimitivesInto[T Primitive](r *Reader, dst []T) { +// ReadPrimitivesInto reads len(dst) primitives, a block without a length, into dst. +func ReadPrimitivesInto[T Primitive](r *Reader, dst []T) { var zero T size := int(unsafe.Sizeof(zero)) b := r.Take(len(dst) * size) @@ -47,11 +47,11 @@ func WritePrimitives[T Primitive](w *Writer, v []T) { return } w.Length(len(v)) - writePrimitivesRaw(w, v) + WritePrimitivesRaw(w, v) } -// writePrimitivesRaw writes primitives as one block, without a length. -func writePrimitivesRaw[T Primitive](w *Writer, v []T) { +// WritePrimitivesRaw writes primitives as one block without a length. +func WritePrimitivesRaw[T Primitive](w *Writer, v []T) { var zero T size := int(unsafe.Sizeof(zero)) b := w.Extend(len(v) * size) @@ -219,20 +219,27 @@ func normalizeBools(b []byte) { func ReadPrimitiveEntries[K, V Primitive](r *Reader) []Entry[K, V] { var e Entry[K, V] size := int(unsafe.Sizeof(e)) - wire := int(unsafe.Sizeof(e.Key) + unsafe.Sizeof(e.Value)) - if !littleEndian || size != wire { - return readUniqueEntries(r, wire, readPrimitive[K], readPrimitive[V]) - } - n := r.Length(size) + ks := int(unsafe.Sizeof(e.Key)) + wire := ks + int(unsafe.Sizeof(e.Value)) + n := r.Length(wire) if n < 0 { return nil } - b := r.Take(n * size) - if len(b) != n*size { + b := r.Take(n * wire) + if len(b) != n*wire { return nil } - v := make([]Entry[K, V], n) - copy(unsafe.Slice((*byte)(unsafe.Pointer(unsafe.SliceData(v))), n*size), b) + var v []Entry[K, V] + if littleEndian && size == wire { + v = make([]Entry[K, V], n) + copy(unsafe.Slice((*byte)(unsafe.Pointer(unsafe.SliceData(v))), n*wire), b) + } else { + v = make([]Entry[K, V], 0, r.SliceCap(n, size)) + for len(b) >= wire { + v = append(v, Entry[K, V]{Key: loadPrimitive[K](b), Value: loadPrimitive[V](b[ks:])}) + b = b[wire:] + } + } if repeated[K](unsafe.Pointer(unsafe.SliceData(v)), n, size, &r.keys) { r.Fail(CodeDuplicateKey, "") return nil @@ -243,22 +250,28 @@ func ReadPrimitiveEntries[K, V Primitive](r *Reader) []Entry[K, V] { // WritePrimitiveEntries writes a dictionary of primitive keys and values as its pairs, in order (nil is null): one // block copied from memory where [ReadPrimitiveEntries] reads one, else one pair at a time. func WritePrimitiveEntries[K, V Primitive](w *Writer, e []Entry[K, V]) { - var p Entry[K, V] - size := int(unsafe.Sizeof(p)) - if !littleEndian || size != int(unsafe.Sizeof(p.Key)+unsafe.Sizeof(p.Value)) { - writeEntries(w, e, writePrimitive[K], writePrimitive[V]) - return - } if e == nil { w.NullLength() return } + var p Entry[K, V] + size := int(unsafe.Sizeof(p)) + ks := int(unsafe.Sizeof(p.Key)) + wire := ks + int(unsafe.Sizeof(p.Value)) w.Length(len(e)) - b := w.Extend(len(e) * size) - if len(b) != len(e)*size { + b := w.Extend(len(e) * wire) + if len(b) != len(e)*wire { return } - copy(b, unsafe.Slice((*byte)(unsafe.Pointer(unsafe.SliceData(e))), len(e)*size)) + if littleEndian && size == wire { + copy(b, unsafe.Slice((*byte)(unsafe.Pointer(unsafe.SliceData(e))), len(e)*wire)) + return + } + for _, pair := range e { + storePrimitive(b, pair.Key) + storePrimitive(b[ks:], pair.Value) + b = b[wire:] + } } // ReadPrimitiveMap reads a dictionary of primitive keys and values into a map (nil for null): a key read twice @@ -354,12 +367,12 @@ func storePrimitive[T Primitive](b []byte, v T) { // readPrimitive reads one primitive in little-endian order. func readPrimitive[T Primitive](r *Reader) T { var v [1]T - readPrimitivesInto(r, v[:]) + ReadPrimitivesInto(r, v[:]) return v[0] } // writePrimitive writes one primitive in little-endian order. func writePrimitive[T Primitive](w *Writer, x T) { v := [1]T{x} - writePrimitivesRaw(w, v[:]) + WritePrimitivesRaw(w, v[:]) } diff --git a/runtimes/go/types_time.go b/runtimes/go/types_time.go index 3acd3a166..abada11b2 100644 --- a/runtimes/go/types_time.go +++ b/runtimes/go/types_time.go @@ -168,7 +168,16 @@ func DateTimeOffsetOf(t time.Time) (DateTimeOffset, bool) { // DateTimeOffset reads a DateTimeOffset; one .NET cannot hold fails with CodeInvalidData, as in .NET. func (r *Reader) DateTimeOffset() DateTimeOffset { - o := DateTimeOffsetAt(r.Take(DateTimeOffsetSize)) + return r.DateTimeOffsetAt(r.Take(DateTimeOffsetSize)) +} + +// DateTimeOffsetAt checks and decodes a DateTimeOffset from a block taken by the caller. +func (r *Reader) DateTimeOffsetAt(b []byte) DateTimeOffset { + if len(b) < DateTimeOffsetSize { + r.eof() + return DateTimeOffset{} + } + o := DateTimeOffsetAt(b) if !o.Valid() { r.Fail(CodeInvalidData, "invalid DateTimeOffset") return DateTimeOffset{} @@ -197,6 +206,11 @@ func (w *Writer) DateTimeOffset(o DateTimeOffset) { if len(b) < DateTimeOffsetSize { return } + o.Put(b) +} + +// Put writes o into an existing block of at least DateTimeOffsetSize bytes. The caller checks Valid first. +func (o DateTimeOffset) Put(b []byte) { binary.LittleEndian.PutUint64(b, uint64(o.UtcTicks)) binary.LittleEndian.PutUint16(b[8:], uint16(o.OffsetMinutes)) } diff --git a/runtimes/go/unique.go b/runtimes/go/unique.go index 539aad0a8..235f02ab6 100644 --- a/runtimes/go/unique.go +++ b/runtimes/go/unique.go @@ -5,6 +5,7 @@ import ( "math/bits" "reflect" "slices" + "sync" "unsafe" ) @@ -17,7 +18,7 @@ import ( // hash seeded per process: integers multiplied by a random odd number, strings through hash/maphash. Data cannot choose // keys that share a slot without knowing the seed, and a key that still probes past maxProbes slots sends the whole // check to a path whose cost the data cannot raise: a sort for numbers (pdqsort falls back to heapsort), a Go map -// (seeded too) for strings. Other comparable keys go through a Go map. +// (seeded too) for strings and bytewise keys. Other comparable keys go through a Go map. // maxProbes bounds the slots one key may probe in a table before the check falls back (see above). With the table at // most half full and a seeded hash, honest data almost never comes near it. @@ -90,7 +91,7 @@ func repeated[K comparable](p unsafe.Pointer, n, stride int, scratch *[]uint64) case k.text: return repeatedStrings(p, n, stride, false, scratch) } - return repeatedValues[K](p, n, stride) + return repeatedOtherKeys[K](p, n, stride, scratch) } // repeatedSlots is repeated for NullableSlots of a number (k): two nulls are equal, and the values present are @@ -415,3 +416,105 @@ func repeatedNaN[K comparable](k K, nan *bool) bool { *nan = true return false } + +var bytewiseKeySizes sync.Map // reflect.Type -> int, 0 for keys that need Go equality + +// bytewiseKeySize caches the result of walking a composite key's fields. Numeric and text keys +// take their existing paths before they get here. +func bytewiseKeySize[K comparable]() int { + t := reflect.TypeFor[K]() + switch t.Kind() { + case reflect.Array, reflect.Struct: + default: + return 0 + } + if size, ok := bytewiseKeySizes.Load(t); ok { + return size.(int) + } + size := 0 + if bytewiseKey(t) { + size = int(t.Size()) + } + actual, _ := bytewiseKeySizes.LoadOrStore(t, size) + return actual.(int) +} + +// bytewiseKey proves that equality is a comparison of every byte, including all fields of a nested value. +// Floats, blank fields, padding and pointers rule it out. DateTime, DateTimeOffset, Half and Decimal carry +// more than one representation of some values in .NET. +func bytewiseKey(t reflect.Type) bool { + switch t { + case reflect.TypeFor[DateTime](), reflect.TypeFor[DateTimeOffset](), reflect.TypeFor[Half](), reflect.TypeFor[Decimal](): + return false + } + switch t.Kind() { + case reflect.Bool, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int, + reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint: + return true + case reflect.Array: + return bytewiseKey(t.Elem()) + case reflect.Struct: + var end uintptr + for i := 0; i < t.NumField(); i++ { + f := t.Field(i) + if f.Name == "_" || f.Offset != end || !bytewiseKey(f.Type) { + return false + } + end += f.Type.Size() + } + return end == t.Size() + } + return false +} + +// repeatedOtherKeys keeps bytewise key handling off the scalar and string paths. +// +//go:noinline +func repeatedOtherKeys[K comparable](p unsafe.Pointer, n, stride int, scratch *[]uint64) bool { + if size := bytewiseKeySize[K](); size != 0 && n <= 1<<(bits.UintSize-6) && int64(n) < 1<<31 { + if result, bounded := repeatedBytewise(p, n, stride, size, scratch); bounded { + return result + } + } + return repeatedValues[K](p, n, stride) +} + +// repeatedBytewise uses the reader's seeded, probe-bounded table and a fixed-width view of each key. +// The caller has proved that the key covers its full memory representation and contains no pointers. +func repeatedBytewise(p unsafe.Pointer, n, stride, size int, scratch *[]uint64) (repeated, bounded bool) { + if n <= 16 { + for i := 1; i < n; i++ { + key := unsafe.String((*byte)(unsafe.Add(p, i*stride)), size) + for j := 0; j < i; j++ { + if key == unsafe.String((*byte)(unsafe.Add(p, j*stride)), size) { + return true, true + } + } + } + return false, true + } + t := table(scratch, tableBits(n)) + mask := uint64(len(t) - 1) + for i := 0; i < n; i++ { + key := unsafe.String((*byte)(unsafe.Add(p, i*stride)), size) + h := maphash.String(hashSeed, key) + tag := h &^ 0xFFFFFFFF + for at, probes := h, 0; ; at, probes = at+1, probes+1 { + slot := t[at&mask] + if slot == 0 { + t[at&mask] = tag | uint64(i+1) + break + } + if slot&^0xFFFFFFFF == tag { + other := unsafe.Add(p, int(uint32(slot)-1)*stride) + if key == unsafe.String((*byte)(other), size) { + return true, true + } + } + if probes == maxProbes { + return false, false + } + } + } + return false, true +} diff --git a/runtimes/go/unique_test.go b/runtimes/go/unique_test.go index c1c3d9a5a..5b638c5e2 100644 --- a/runtimes/go/unique_test.go +++ b/runtimes/go/unique_test.go @@ -127,6 +127,34 @@ func TestUniqueIntegerKeys(t *testing.T) { (*Writer).String, (*Reader).String, 1) } +func TestUniqueBytewiseKeys(t *testing.T) { + type padded struct { + A byte + B uint64 + } + type nested struct { + Id Guid + Hi [2]uint64 + } + if bytewiseKeySize[Guid]() != 16 || bytewiseKeySize[nested]() != 32 { + t.Fatal("packed pointer-free keys did not use the bytewise check") + } + if bytewiseKeySize[padded]() != 0 || bytewiseKeySize[Decimal]() != 0 || + bytewiseKeySize[struct{ F float64 }]() != 0 || bytewiseKeySize[struct{ P *int }]() != 0 || + bytewiseKeySize[DateTimeOffset]() != 0 { + t.Fatal("noncanonical or pointer-bearing key used the bytewise check") + } + for _, n := range []int{2, 16, 17, 1024} { + keys := make([]Guid, n) + for i := range keys { + keys[i][0], keys[i][15] = byte(i), byte(i>>8) + } + checkUnique(t, keys, (*Writer).Guid, (*Reader).Guid, 16) + keys[n-1] = keys[0] + checkUnique(t, keys, (*Writer).Guid, (*Reader).Guid, 16) + } +} + // TestUniqueLargeSets covers larger sets: distinct keys, one repeated pair at both ends and in // the middle, keys that differ only in their highest byte, and random keys. func TestUniqueLargeSets(t *testing.T) { diff --git a/runtimes/go/writer.go b/runtimes/go/writer.go index b419f257c..8953b6af0 100644 --- a/runtimes/go/writer.go +++ b/runtimes/go/writer.go @@ -83,6 +83,22 @@ func (w *Writer) ExtendZero(n int) []byte { return b } +// ExtendFixed reserves one block for count elements of size bytes each. It clears the block when zero is true. +func (w *Writer) ExtendFixed(count, size int, zero bool) []byte { + if w.err != nil { + return nil + } + if count < 0 || size <= 0 || count > (int(^uint(0)>>1)-len(w.buf))/size { + w.Fail(CodeTooLarge, "fixed-size block") + return nil + } + b := w.Extend(count * size) + if zero { + clear(b) + } + return b +} + //go:noinline func (w *Writer) grow(n int) { need := len(w.buf) + n diff --git a/runtimes/rust/tests/generated/shapes.rs b/runtimes/rust/tests/generated/shapes.rs index 86a3d089d..c68c371f5 100644 --- a/runtimes/rust/tests/generated/shapes.rs +++ b/runtimes/rust/tests/generated/shapes.rs @@ -764,6 +764,70 @@ impl Empty { ); } +/// `Shapes.FixedCollections`: Positional, header Presence. +#[derive(Debug, Default, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct FixedCollections { + pub ids: Option>, + pub unique_ids: Option>, + pub grid: Option>, + pub pairs: Option>, + pub offsets: Option>, +} + +impl NinoReadBody for FixedCollections { + const TYPE_ID: i32 = Self::NINO_TYPE_ID; + + fn read_body(&mut self, r: &mut nino::Reader<'_>) -> nino::Result<()> { + r.read_into(&mut self.ids)?; + r.read_into(&mut self.unique_ids)?; + r.read_into(&mut self.grid)?; + r.read_into(&mut self.pairs)?; + r.read_into(&mut self.offsets)?; + Ok(()) + } +} + +impl NinoWriteBody for FixedCollections { + const TYPE_ID: i32 = Self::NINO_TYPE_ID; + + fn write_body<'a>(&'a self, w: &mut nino::Writer<'a>) -> nino::Result<()> { + w.write(&self.ids)?; + w.write(&self.unique_ids)?; + w.write(&self.grid)?; + w.write(&self.pairs)?; + w.write(&self.offsets)?; + Ok(()) + } +} + +impl NinoRead for FixedCollections { + const MAY_DEFER: bool = true; + nino::sealed_read!(); +} + +impl NinoWrite for FixedCollections { + const PREFETCH_BYTES: usize = 0usize + .saturating_add(> as NinoWrite>::PREFETCH_BYTES) + .saturating_add(> as NinoWrite>::PREFETCH_BYTES); + + fn prefetch(&self) { + self.unique_ids.prefetch(); + self.offsets.prefetch(); + } + + fn prefetch_members(&self) { + self.unique_ids.prefetch_members(); + self.offsets.prefetch_members(); + } + + nino::sealed_write!(); +} + +impl FixedCollections { + nino::type_consts!(0x9B5DCD24u32 as i32, "Shapes.FixedCollections", "format=Positional; header=Presence; trackReferences=false; raw=false; id=0x9B5DCD24; deferrable=true; members=Ids:System.Collections.Generic.Dictionary:map(raw(16),raw(8){Id:int@0:raw(4),On:bool@4:raw(1),Kind:byte@5:raw(1),Code:short@6:raw(2)});UniqueIds:System.Collections.Generic.HashSet:seq(raw(16));Grid:byte[,]:grid(2,raw(1));Pairs:System.Collections.Generic.Dictionary:map(raw(4),raw(8));Offsets:System.DateTimeOffset[]:seq(datetimeoffset)"); +} + /// `Shapes.ForestHolder`: Positional, header Presence. #[derive(Debug, Default, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -3290,6 +3354,7 @@ pub trait NinoVisit { pub fn with_nino_type(name: &str, f: impl NinoVisit) -> Option { Some(match name { "Shapes.Empty" => f.visit::>>(), + "Shapes.FixedCollections" => f.visit::>>(), "Shapes.ForestHolder" => f.visit::>>(), "Shapes.Gappy" => f.visit::(), "Shapes.Generic.BasedInt" => f.visit::>>(), @@ -3339,6 +3404,7 @@ pub trait NinoSerdeVisit { pub fn with_nino_serde_type(name: &str, f: impl NinoSerdeVisit) -> Option { Some(match name { "Shapes.Empty" => f.visit::>>(), + "Shapes.FixedCollections" => f.visit::>>(), "Shapes.ForestHolder" => f.visit::>>(), "Shapes.Gappy" => f.visit::(), "Shapes.Generic.BasedInt" => f.visit::>>(),