Repository navigation
Conversation
added 2 commits
November 11, 2026 08:40
Replace the codec-independent wire-size estimate (WireSize, size_of_type) with a sizer over the frozen IR that computes, for a type, the least and most bytes it takes in a format, from the format's `sizes` in the catalog (comline-catalog bumped to the spec's 9a7142c). - schema::ir::size: Range, Lookup/FrozenLookup, range(), witnesses(). Headers are applied to the byte count at each end, a count above 2^32-1 is cut or unwritable, @max_depth expands a recursive type (each level sized once), a union, a non-unit enum or an unresolved name has no size. One code path builds the range and the min/max witness values in the spec's typed notation. - schema::idl::size: the editor's entry over the grammar, through TypeRef::from_grammar_sized: one sizer. WireSize, size_of_type, size_of_struct and size_of_enum are gone; SizeLookup/SizeTarget stay. - doc model: per-format `sizes` on structs, enums, aliases and each function's arguments and reply (returns_sizes); schema re-blessed. - tests: every case of the spec's size vectors (vendored under tests/spec with REV and vendor.sh --check, checked in CI against the catalog pin), plus tier boundaries, JSON escaping, recursion, limits.
… the vendor check through bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Step 3 of per-format sizes (docs plan: real data-format sizes). Replaces the codec-independent wire-size estimate with a per-format byte range, driven by the specification's size rules (
comline-catalogbumped to specification@9a7142c, ComlineProject/specification#4).What it does
schema::ir::sizeworks on the frozen IR and returnsRange { min, max: Option<u64>, upper_bound }for aTypeRef, a format'sSizesand aLookupfor the names in it.Nonemeans it can't be sized: a union, a non-unit enum or an enum with no variants, a format withoutsizes, an unresolved name, a type that has to contain itself.varint_leb128,msgpack_str,msgpack_array,delimited) are applied to the byte or item count at each end: the least uses the header for 0 or the minimum, the most the header for the maximum (char[max N]isheader(4N) + 4Nin UTF-8,2 + 6Nin JSON).@max_depthexpands a recursive struct to its depth (an option at level D+1 is absent, an array empty); each level is sized once, so a tree of 8 children 20 deep is instant. Without a limit the maximum isNone. Each struct in a cycle counts its own nesting.u64::MAXisNone; a minimum above it isn't sized. Documented in the module header, tested inwhere_the_formats_stop.witnesses()builds a least and a most value in the spec's typed notation ({"u8": 0}, ...) from the same code as the range, for the runtime's differential test (step 4). Bounded by a budget; a value too large to write down is left out.FrozenLookupresolves names across schemas (own declarations,uses with aliases and globs, qualified paths, then any schema's), the waycompatfinds declarations.Replaced
schema::idl::size:WireSize,size_of_type,size_of_structandsize_of_enumare gone. The editor's entry is nowrange_of_type,range_of_field,range_of_structandrange_of_enum, which freeze the grammar throughTypeRef::from_grammar_sizedand call the same sizer.SizeLookupandSizeTargetare unchanged. A constant a size names that the caller can't resolve is "no size", not 0.The language server uses all of it in
handlers/hover.rs; its next core bump has to change that (see below).Doc model
Additive (
DOC_MODEL_VERSIONstays 1;schemas/doc-model.jsonre-blessed):SizeRange { format, min, max?, upper_bound? }assizeson struct, enum and type alias units,sizeson each function argument andreturns_sizeson the function, for each official format the package's protocols use (the package default when it has none). Absent where it can't be told, for a dependency's units, and inmodel_frozen(a built version keeps no protocol to say which formats).Tests
[min, max]andupper_bound; the min/max witnesses conform to the case's type; for each primitive, core's witnesses are values the case itself measures as the least and most.None, msgpack tier boundaries (strings, arrays, struct field counts), JSON escaping worst case, recursion with and without@max_depth(mutual, deep, too deep), union / non-unit enum / no variants / unknown formatNone, limits, aliases across schemas, witnesses.packed@1and onjson@1.How the vectors reach the tests
The git dependency's checkout isn't reachable from a test without asking cargo, and
comline-catalogdoesn't expose a path, so the threesizes-*.jsonfiles (about 1 MB) are vendored incore/tests/spec/vectorswith aREV.core/tests/spec/vendor.sh --check(a new CI job) compares them with the spec at that rev, and a test fails whenREVand thecomline-catalogrev inCargo.tomldiffer, so a bump can't leave stale vectors.Language server
handlers/hover.rsimportsWireSize,size_of_type,size_of_structandsize_of_enum. On its next bump it replaces them withsize::range_of_type/range_of_field/range_of_struct/range_of_enum(takingsize::rules("packed@1"), or the package's format, and a constant resolver,&|_| Noneto keep today's behaviour) and rendersOption<Range>instead ofWireSize::{Fixed, Variable, Unknown}.field_size'soptionalspecial case goes:range_of_fieldhandles it.HoverSizeLookupstays as is.Local work
The checkout's uncommitted edits to
schema/idl/size.rsand thesize2.rsstub are superseded by this; rebase will conflict onsize.rs.