Repository navigation
Decode single-item pointers, fix wide structs failing to compile - #3
Merged
Merged
Conversation
Inline loops over a struct's fields count every comptime branch they take, including escaping each key, against the enclosing function's quota. A struct with a few dozen fields ran past the default 1000 and failed to compile.
A *T is allocated and decoded in place, which is what recursive types like a status that embeds another status need. Encoding already dereferenced them.
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.
Two problems found while porting the twitter and canada schemas from serde-rs/json-benchmark.
Wide structs failed to compile
A struct with a few dozen fields and a
jsonFormatfailed with "evaluation exceeded 1000 backwards branches". The inline loops over a struct's fields run comptime code for every field (escaping its key, among other things), and all of it counts against the enclosing function's branch quota. twitter'sUserhas 40 fields.encodeStruct,encodeStructFieldsAfter,objectMembersandmaxKeyLennow raise the quota in proportion to the fields and their name lengths, viafieldsBranchQuota.*Tcould not be decodedEncoding already dereferenced single-item pointers, but decoding hit
@compileError. A*Tis now allocated and decoded in place. That is what recursive types need: twitter'sStatusholds aretweeted_status: ?*Status.Tests
Both cases have a test that fails without the fix: a 48-field struct with
jsonFormat, and a recursive node type plus a bare*const u32.zig build testpasses on 0.16 and 0.17.