Repository navigation
fix(empty payload): a message with no fields works in every backend - #740
Merged
Merged
Conversation
`payload: {}` has always validated, and MESSAGE_SPEC §2 omits every field equal
to its default -- so the all-default message IS the empty byte string, a message
with no fields is a legal schema whose every value encodes to zero bytes (the
ping, the keep-alive), and MAX_SIZE is 0 for it. Nothing in tests/ or examples/
had one, so the shape reached eleven backends untested and got eleven answers
(#738). The declaration was not the coverage.
Per backend:
cpp the header did not compile under the -Wall -Wextra -Werror the
suites build generated code with: deserialize's stream parameter
is unused when a type binds no field. Named only where an arm
reads it now -- the rule _size and _count already follow -- and
the harness's to_json gets the discard from_json already had.
typescript `emit: project` PANICKED: the bench sink folds one cheap scalar of
the decoded message and indexed fields[0]. And the module named a
visitor and a Decoder it did not emit -- a guard kept from #160,
where its only job was to leave an unused WireType import out,
which the rendered-text import scan decides on its own now. By the
time the flat-visitor surface landed, that guard was suppressing
the very decode surface decode() and decoder() name.
zig the harness did not compile: an unused parameter and a `var` that
is never mutated are errors there. Both discards now sit where the
alloc/obj ones already did.
rust two warnings: serialize's stream is `_os` when nothing is written,
and the visitor's destination borrow -- which it must still hold
-- says why no arm reads it.
c the header declared an empty struct and a zero-length descriptor
table: GCC extensions, not ISO C, and an empty struct's sizeof is
0 in C and 1 in C++, so the two views of one type did not even
agree. A placeholder member and a one-entry table the field COUNT
keeps unread; the harness sizes its MAX_SIZE buffers through
_SOFAB_BUF and discards what it does not read. Generated library
and harness now compile under -std=c11 -pedantic-errors.
The two RUNTIME failures are the corelib half, fixed there because §5.1 puts the
rule there: corelib-c-cpp#195 (a zero-length buffer may be handed over as NULL;
std::vector::data() is null at size 0 and C++ encode() aborted in the install
assert) and corelib-java#128 (OStream.overScratch(0) threw). lang-cpp and
lang-java pin corelib main, so this needs both merged to go green.
Tests. tests/conformance/lib/check_empty_payload.py, wired into all eleven
suites (inside cpp's variant loop, rust's label loop and python's engine loop):
`{}` encodes to exactly zero bytes and the encode SUCCEEDS, zero bytes decode as
a complete message and re-encode to zero bytes -- the path any relay takes --
and a `{ s: struct {}, n: u32 }` message omits the field-less struct as any
default is, so `{"n": 7}` is 08 07 whether the struct is sent or not. Verified by
hand against all twelve target legs: c, cpp (both corelibs), csharp, dart, go,
java, kotlin, python, rust, typescript, zig.
The COMPILE half is tests/matrix/corpus/defs/empty_payload.yaml, which every
suite's corpus leg builds and round-trips -- and which found one more hole, in
the test tooling rather than a backend: check_corpus_roundtrip.py read
`named[key]["fields"]` (--dump-ir omits an empty list) and demanded that a
value-filled message encode to non-zero bytes, which the one message that has no
values cannot. Both fixed, and the carve-out says why.
Five backend unit tests pin the emitted shapes, each with the with-a-field case
beside it so the rule stays "unused", not "always".
Closes #738
lang-typescript on #740 was the one job the hand-verified legs missed: the suite compiles every corpus definition with --noUnusedLocals --noUnusedParameters (tsc_strict), and four things go unread in a type that declares no fields -- `serialize`'s stream, `fromJSON`'s object, the visitor's current-scope register `_c`, and the location constants that exist for it. The first two take the `_` spelling tsc exempts. The register joins the index and row registers that are already emitted only where a hook READS them (dropUnreadRegister), and the constants follow the register: the hook rendering moved above them so the decision can be made from the rendered arms, which is how every other "is this read" question in this file is answered. Emitted text is unchanged for every type that has a field. Verified with the suite's own flags: all 26 corpus definitions compile clean, and the field-less one round-trips through check_empty_payload.py and check_corpus_roundtrip.py as before. My earlier local check ran --strict without the two --noUnused* flags, which is why CI found this and I did not.
lang-zig gate 10 regenerates every schema and checks it with `zig fmt --check`: the blank line that separates a struct's member list from the declarations below it opens the container when there is no member list, and the formatter removes it (generator#738). Emitted only where there is a list to separate. Verified with zig 0.16.0 -- `zig fmt --check` clean for every corpus definition and for example.yaml -- and the zig conformance leg for the field-less message passed on CI already, so this is the formatter gate alone.
Andste82
added a commit
that referenced
this pull request
Oct 12, 2026
lang-typescript on #740 was the one job the hand-verified legs missed: the suite compiles every corpus definition with --noUnusedLocals --noUnusedParameters (tsc_strict), and four things go unread in a type that declares no fields -- `serialize`'s stream, `fromJSON`'s object, the visitor's current-scope register `_c`, and the location constants that exist for it. The first two take the `_` spelling tsc exempts. The register joins the index and row registers that are already emitted only where a hook READS them (dropUnreadRegister), and the constants follow the register: the hook rendering moved above them so the decision can be made from the rendered arms, which is how every other "is this read" question in this file is answered. Emitted text is unchanged for every type that has a field. Verified with the suite's own flags: all 26 corpus definitions compile clean, and the field-less one round-trips through check_empty_payload.py and check_corpus_roundtrip.py as before. My earlier local check ran --strict without the two --noUnused* flags, which is why CI found this and I did not.
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.
Closes #738. The corelib half is already on main: sofa-buffers/corelib-c-cpp#195 and sofa-buffers/corelib-java#128.
payload: {}has always validated, and MESSAGE_SPEC §2 omits every field equal to its default — so the all-default message is the empty byte string, a message with no fields is a legal schema whose every value encodes to zero bytes (the ping, the signal, the keep-alive), andMAX_SIZE == 0for it.Nothing in
tests/orexamples/had one. So the shape reached eleven backends untested and got eleven answers. The declaration was not the coverage.Per backend
-Wall -Wextra -Werrorthe suites build generated code with:deserialize's stream parameter is unused when a type binds no field. The harness'sto_jsonthe same._sizeand_countalready follow — and the harness gets the discardfrom_jsonalready hademit: projectpanicked (the bench sink folds one cheap scalar of the decoded message and indexedfields[0]), and the module named a visitor and aDecoderit did not emitvarthat is never mutated are errors therealloc/objones already wereunused variable: os,field m is never read)_os, and the destination borrow the visitor must still hold says why no arm reads it_SOFAB_BUFin the harness. Generated library and harness compile under-std=c11 -pedantic-errorsThe TypeScript decode surface deserves its own line: the guard that suppressed it came from #160, where its only job was to leave an unused
WireTypeimport out — which the rendered-text import scan decides on its own now. By the time the flat-visitor surface landed, that guard was suppressing the very visitor andDecoderthatdecode()anddecoder()name.Tests
tests/conformance/lib/check_empty_payload.py, wired into all eleven suites (insidecpp's variant loop,rust's label loop andpython's engine loop):{}encodes to exactly zero bytes and the encode succeeds — a refusal and this message produce the same bytes, so the status is the only thing separating them (cpp: encode() / encodeTo() cannot report a #656 refusal — it is indistinguishable from the all-default message, and the doc comment points at a surface that cannot tell either #736);{ s: struct {}, n: u32 }message: the field-less struct is equal to its default and omitted (§2), so{"n": 7}is08 07whether the struct is sent explicitly or not, and reads back withn == 7.Verified by hand against all twelve target legs — c, cpp (both corelibs), csharp, dart, go, java, kotlin, python, rust, typescript, zig — both through this driver and through the corpus round-trip. The
goandcsuites were run in full.The COMPILE half is
tests/matrix/corpus/defs/empty_payload.yaml, which every suite's corpus leg builds and round-trips, asarray_lengths.yamlis for #550.And it immediately found one more hole — in the test tooling rather than a backend:
check_corpus_roundtrip.pyreadnamed[key]["fields"](--dump-iromits an empty list) and demanded that a value-filled message encode to non-zero bytes, which the one message that has no values cannot. Both fixed, with the carve-out saying why.Five backend unit tests pin the emitted shapes, each with the with-a-field case beside it, so the rule stays "unused", not "always".