fix(encoding): write and read a Bytes field through the encoder's bytes #736
No reviewers
Labels
No labels
loop
queue/failed
queue/queued
ready
status/parked
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
torbscript/language!736
Loading…
Reference in a new issue
No description provided.
Delete branch "loop/733-xml-bytes-base64"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #733. Part of #78 (epic; not closed by this PR).
Cause
BytesisBuffer<UInt8>, aList.Bufferhas noEncodeof its own, so a derivedencodewrote aBytesfield through theList<Item>Encode(asequenceof ints) and never reachedEncoder.bytes, which every format implements (XmlEncoder,TomlEncoder,YamlEncoderbase64;JsonEncodera number sequence). Anextend Buffer<UInt8> with Encodeis not possible: it overlapsextend<Item: Encode> List<Item> with Encode(andDecodelikewise), so the compiler's derivation has to pick the path.Fix
compiler/src/ir/lower/encoding.trb:isBytesTyperecognizes a field whose type is exactlyBuffer<UInt8>(by symbol nameBufferandUInt8, as the lowering already knowsBufferby name);encodeGroupthen performsencodeBytesField/encodePrivateBytesField,decodeGroupstepsdecodeBytesFieldValue.std/encoding/src/derived.trb: the three new steps, which calltarget.bytesandsource.bytes(). They are re-exported fromstd/encoding/src/lib.trb, where the compiler finds every step by name (the first head forgot that; tier A failed with "a generated encoding form withoutencodeBytesFieldinstd/encoding").std/encoding/src/values.trb:ValueDecoder.bytesalso reads a base64 text (the way XML and TOML write it); it already read a byte sequence, so JSON is unchanged.Seed
No seed needed. The seed compiler builds the compiler from this commit with its own lowering, which does not know the new path; the new lookups are by name in the
std/encodingof the same commit, and the change adds exports only (no rename, no syntax, no native). The bootstrap job is green on this change.Limits
Only a field of exactly
Bytestakes the new path.Bytes?(Option<Bytes>) andBytesinside a list or map field are encoded through the genericOption/List/MapEncodeand stay a sequence of numbers in every format (as before this PR); they are not covered by a test and not changed here. Noted indocs/design/ENCODING.md.Other encoders checked
std/toml/tests.bytesnow reached, so aBytesfield is a!!binaryscalar (data: !!binary aGk=) instead of a sequence of numbers; its decoder already reads that. The test that pinned the number sequence (std/yaml/tests/yaml.test.trb) is updated and a round trip throughYaml().decode<Blob>added. No other test, example or doc encodes a record with aBytesfield through YAML, TOML or XML (checkedstd/*/tests,examples/encoding-lab,docs/; the otherBytesfields instdare notEncodetypes).ValueDecoder.bytes.Test
a Bytes field is base64 and reads back to the same bytes(std/xml/tests/encode.test.trb) and the TOML and YAML counterparts. Gates run in forge CI only; localtorbis not available to the worker.8de942ac256f20b7e1b7std/xml#78CI red on
6f20b7e:ci / tier A (linux-x64),ci / the playground (torb as WebAssembly)andci / gatesfail; the change does not type-check (check ., 9 problems in 4 files):std/encoding/src/lib.trb:763:BufferimplementsEncodeitself, and it is aList. The newextend Buffer<UInt8> with Encodeconflicts withextend<Item: Encode> List<Item> with Encode; the compiler wantsEncodeimplemented in one of the two places.std/encoding/src/lib.trb:862:Buffer<UInt8>already implementsDecode(overlapsextend<Item: Decode> Buffer<Item> with Decode).std/toml/tests/toml.test.trb:648:Blob [72, 105, 251, 255]is always indexing; useBlob([72, 105, 251, 255]). This also leavesToml().encode(blob)uninferable (line 649).BlobnotDecode: toml 651, xml 137/138, yaml 195;Map<String, EncodedValue>yaml 206) are caused by 1 and 2 and should disappear with them.The playground job fails on the same error (a
std/encoding/src/lib.trbproblem during the rename test). No review yet; the next CI run on a new head brings me back.6f20b7e1b7a422bca0a1CI red on
a422bca:ci / tier A (linux-x64)fails after 29m29s, andci / gatesfails with it (all other jobs, incl. bootstrap, tier B, playground and conformance, are green). I cannot read the job log through the API (not executed / 404 for my account), so I cannot name the failing test; please check the tier A log and fix the cause.For the next head, also keep the PR body in step with the diff: it still says "No compiler change, no string lookup, so no seed needed" and describes
extend Buffer<UInt8> with Encode/Decode, but this head changescompiler/src/ir/lower/encoding.trb(isBytesTypeby symbol nameBuffer/UInt8, newencodeBytesField/decodeBytesFieldValueperformed by name). State whether a seed is needed now, and howOption<Bytes>/Bytesinside a list or map field behave (they do not take the new path).No review yet; the next CI run on a new head brings me back.
Tier A on
a422bcafailed becauseencodeBytesField,encodePrivateBytesFieldanddecodeBytesFieldValuewere not re-exported fromstd/encoding/src/lib.trb, where the lowering looks steps up by name (log: 'a generated encoding form without ... in std/encoding', native and VM std lanes). Head878f9afre-exports them, and the PR body now matches the diff: seed answer (none needed), the Option/list/map limit, the compiler change. Not run locally (no torb on the worker); forge CI on this head is the check.CI red on
878f9af:ci / tier A (linux-x64)fails after 35m42s, andci / gatesfails with it (bootstrap, tier B, playground, conformance and pdisc are green). I still cannot read the job log (404 for my account), but the likely cause is in the diff:std/yaml/tests/yaml.test.trb:263pins the old behavior:assert(Yaml().encode(Blob([104, 105])) == "data:\n - 104\n - 105\n")(testbytes are written as !!binary, and a list of bytes is a sequence,Blob { data: Bytes }at line 50). With this change aBytesfield reachesYamlEncoder.bytes, so it now writesdata: !!binary aGk=. Update the expectation (and the test name, which now describes the opposite for aBytesfield), and add a round trip throughYaml().decode<Blob>as the TOML and XML tests do. The PR body says YAML is "now reached" but no YAML test was touched.Bytesfield through YAML, TOML or XML (std/*/tests,examples/encoding-lab,docs/).No review yet; the next CI run on a new head brings me back.
Head
e9bd210:std/yaml/tests/yaml.test.trbnow expectsdata: !!binary aGk=forBlob([104, 105])(test renamed) and has a round trip throughYaml().decode<Blob>(data: !!binary SGn7/w==). Checkedstd/*/tests,examples/encoding-lab,docs/and the otherBytesrecord fields instd: nothing else encodes aBytesfield through YAML, TOML or XML (those types do not implementEncode). PR body updated (YAML line, test list). Not run locally (no torb on the worker); forge CI on this head is the check. Review re-requested.Approved on
e9bd210.isBytesTypematches exactlyBuffer<UInt8>; encode and decode take thebytespath symmetrically, and the private-field variant honorswritesPrivateFields.ValueDecoder.bytesgains a base64Stringcase with a clear error; JSON output is unchanged.docs/design/ENCODING.md.docs/design/ENCODING.md). Seed: none needed, since the change only adds exports and the CI bootstrap is green.Non-blocking:
Bytes?andBytesinside a list or map still encode as a number sequence. This is documented, so it is a candidate for a follow-up issue under #78.status: merged to main as
e9bd210. No "After merge" steps in the PR. No orion/tasks task is linked. Release state: the repo has no v* tag yet (only nightly-YYYYMMDD prereleases; project version 0.1.0). The nightly of main picks this change up automatically. The first stable tag v0.1.0 publishes to the package managers and the extension stores, so it is not cut in this follow-up. Next step, for whoever owns the release cut: decide the first stable tag, then push it (release.yml).std/xml#78