Repository navigation
Bounds and char: runtime checks, depth limit, conformance 0.3 (core#98) - #78
Merged
Merged
Conversation
This was referenced Nov 3, 2026
added 5 commits
November 3, 2026 16:08
…@1's error stays one byte
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 7 of the bounds rollout (ComlineProject/core#98; resume note ComlineProject/core#197): the runtime side of
charand bounds, and their conformance vectors.charon the wireAs decided on 2026-11-02:
charpacked@1packed@1'schar, which used to be a one-character string with a length. No generator emitscharyet: comline-rust and comline-typescript refuse it.msgpack@1fixstr), unchanged (rmp-serde's own)json@1serde_json's own)comline_runtime::bounds(new,no_std)The checks generated code will call in steps 8–9:
check_chars(&str, max)(counts characters, not bytes; a string of at mostmaxbytes isn't counted, and one over 4 ×maxbytes is refused without counting),check_items(len, max),chars_from_utf8(&[u8], max)(refuses a byte length over 4 ×maxbefore the UTF-8 check, then counts),char_from_utf8/utf8_width(a singlechar).Depth::new(max), withenter()before each value of the recursive type andleave()after it. The outermost value is level 1, and entering levelmax + 1is refused before anything deeper is read.serdeseeds that refuse before allocating:CharsSeed<T>(&strorString) measures a borrowed string where it lies.ItemsSeed<S, C>refuses a count prefix abovemax(its size hint, inpacked@1andmsgpack@1) before allocating. Injson@1it stops at itemmax + 1, which it skips without building it (IgnoredAny).char[max 32][max 10]work.#[serde(deserialize_with/serialize_with)]:decode::string::<_, N>,decode::vec::<_, T, N>,encode::string::<_, N>andencode::vec::<_, T, N>. An encoder refuses an over-bound value before writing anything.RuntimeError::BoundExceeded { measure: Measure }, whereMeasureisChars,ItemsorDepth. Every format'sencodeanddecodereturn it for a bound failure, instead ofSerialization.bounds::BoundExceeded { measure, max }, maximum included.RuntimeErroritself. Carrying it grewpacked@1's internal error from 1 byte to 8, and everyResulton the decode path grew with it. The first CI run measured +15% to +20% onformat/decode/*/packed@1. The caller knows the maximum from the type anyway.packed@1's error at 1 byte andRuntimeErrorat 4.serdeas theBoundExceededmessage ("more than 4 characters"). Each format recognises it in its error's first 128 bytes, without allocating.RuntimeErroris#[non_exhaustive], and the ffi'sstatus_ofalready has a catch-all, so the ffi is unchanged: no bound check runs across that ABI.Conformance: spec 0.2 → 0.3
"char",{"bounded_string": {"max": N}},{"bounded_array": {"of": T, "max": N}}, and{"recursive": {"max_depth": D, "of": T}}, with"self"insideT.{"char": "é"}.encodecase may carry atype. Anencoderejection asks only to encode, and the encode must fail.TypeSeeddecodes the bounded types through the runtime's ownCharsSeed,ItemsSeedandDepth, so the vectors prove the primitives that generated code will use.packed@1msgpack@1json@1char, encode (ASCII, 2-, 3-, 4-byte)char, decodechar(refused)"é€😀a": 4 characters in 10 bytes (under by characters, over by bytes);"😀😀😀😀": 16 bytes, exactly 4 × N;"ééééé": over by characters, under 4 × N bytes;max 0;char[max 2][max 2];optionalchain and a tree under@max_depth, at and over the limit.charis bytes, not a version-comparison fact.comline-referencepasses every vector. Its replay test now expects anerrorreply for anencoderejection (README updated).VECTORS_REV. Its runtime will fail the new cases until steps 8–9 implement them, and those steps bump it.Benchmarks
The instruction-count gate passes with two accepted regressions, recorded in
accepted-regressions.toml:format/decode/small-scalar/packed@1packed@1now tells a bound failure apart from other malformed input when it maps its error toRuntimeError. That's a few instructions, which shows only on the smallest message.format/encode/small-scalar/packed@1Every other benchmark is within 1%.
Two other attempts measured worse:
RuntimeError:packed@1's error grew from 1 byte to 8, which cost +15% to +20% onpacked@1decoding.#[cold]): +14% to +16% on decoding. It was reverted.