Rust: codegen + runtime support for vectors of unions (#5024)#9062
Draft
MukundaKatta wants to merge 1 commit intogoogle:masterfrom
Draft
Rust: codegen + runtime support for vectors of unions (#5024)#9062MukundaKatta wants to merge 1 commit intogoogle:masterfrom
MukundaKatta wants to merge 1 commit intogoogle:masterfrom
Conversation
Implements the read side of vector-of-union codegen in idl_gen_rust.cpp, following the paired-vectors layout used by C++/Go/Java codegen. Adds a Rust runtime accessor and round-trip test. Write-side codegen is scaffolded with TODOs. Refs google#5024.
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.
Summary
Refs #5024. Adds Rust codegen and runtime support for vectors of unions, following the paired-vectors layout used by C++/Go/Java codegen.
What's done
idl_parser.cppwhitelists Rust for[Union]schemas viaSupportsAdvancedUnionFeatures().idl_gen_rust.cppemits_type(Vector) and value vector accessors plus per-variant<field>_as_<variant>(idx)helpers.flatbuffers::TableVerifier::visit_union_vectorruntime helper verifies discriminant and value vectors in lockstep, enforces same-length invariant (matches C++ PR Ensure the two vectors in a vector of unions are the same size in verifier #8853), and dispatches per-variant verifiers.RUST_VECTORS_OF_UNIONS_DESIGN.mdwalks the wire format, generated Rust shape, verifier contract, forward-compat handling, and aliased-variant behavior.What's TODO
create_vector_of_unionsbuilder helper plus matching codegen wiring (four sites scaffolded withunimplemented!()andTODO(#5024)markers).Vec<UnionT>.union_vector.fbstoscripts/generate_code.py's Rust block.flatcwas not available locally to regenerate.rstest files; CI will need to do that.--rust-serialize) for[Union]fields is currently askip_fieldstub.Test plan
cargo test --testsintests/rust_usage_test: 322 tests pass (276 + 21 + 13 + 5 + 4 + 1 + 1 + 1). The pre-existingwith_internal_capacity_preallocates_vecslib unit test fails on master too, unrelated to this branch.Marking draft until write-side lands.