We continue our foray into googletest-rust [1], this time with homegrown matchers.
Our unit tests will now be able to check is_unset() and is_set() for all types that implement ProxiedWithPresence. In practice, this boils down to [u8] and ProtoStr.
Note that we've broken out matchers_upb and matchers_cpp, similar to what was done with aliasing here [2].
[1] https://github.com/google/googletest-rust
[2] 9a0bc392b3 (diff-08e5182ff36ad340a3bfb628995524a2a36a89b59a514ba027b0f25e048dd5c3R90)
PiperOrigin-RevId: 573895179
We had previously commented out the upb portion of simple_nested_test.
This is because nonmutable getters have submessages being NULL by default.
This means that trying to fetch anything, like a simple scalar from that nested message would segfault.
This CL makes the externC return an Option<RawMessage> since we've discovered that upb can return NULL. This way, we can check for `None` and handle the NULL case appropriately.
We know that the NULL pathway can only come from terra upb, since
cpp automagically constructs submsgs if they don't exist.
We've augmented upb.rs to contain a scratch space that allocates a zeroed-out contiguous chunk of memory @64KB. Since a block of zeroed-out memory is a legit message from upb's point of view, we can provide $pbr$::ScratchSpace::zeroed_block() to upb in order to get the default submessage behavior we want from upb.
This block is lazily allocated upon first request. This means that a consumer of the cpp kernel will not incur an additional cost.
PiperOrigin-RevId: 573840755
$Msg$View is incorrect, we need to actually invoke the getter_thunks. We'll use void* to get us off to the races.
Sprinkled in TODOs as appropriate; and we'll tackle imports in another CL. For now, its important to return the actual raw message, and that's what this CL does for our base uses.
PiperOrigin-RevId: 564785201
This is predominantly a wrapper around `BytesMut`, for simplicity.
Bytes and string fields are mostly the same, except for possible UTF-8 handling.
This also implements some minor parts of `ProtoStr` that were missed.
PiperOrigin-RevId: 561422951
This makes a few changes:
- It changes generated messages to reference message innards as a type in `__runtime` instead of branching on what fields should be there. That results in much less bifurcation in gencode and lets runtime-agnostic code reference raw message innards.
- It adds a generic mechanism for creating vtable-based mutators. These vtables point to thunks generated for interacting with C++ or upb fields. Right now, the design results in 2-word (msg+vtable) mutators for C++ and 3-word mutators (msg+arena+vtable) for UPB. See upb.rs for an explanation of the design options. I chose the `RawMessage+&Arena` design for mutator data as opposed to a `&MessageInner` design because it did not result in extra-indirection layout changes for message mutators. We could revisit this in the future with performance data, since this results in all field mutators being 3 words large instead of the register-friendly 2 words.
- And lastly, as a nearby change that touches on many of the same topics, it adds some extra SAFETY comments for Send/Sync in message gencode.
PiperOrigin-RevId: 559483437
Only emit has_field() if the field support presence. Only emit field_opt() getter if the field is both optional and supports presence.
PiperOrigin-RevId: 555133374
This CL adds function bodies for: {as_view, into_view, as_mut, into_mut, set_on} [1].
Our prior cl/552609955 didn't have `RawMessage` inside $Msg$Mut, so that's also been rectified in this CL.
[1] Everything in this set is a part of the Proxied trait, except set_on, which belongs to the SettableValue trait.
PiperOrigin-RevId: 553935803
This CL sets up the basic plumbing end-to-end for singular message fields.
We add skeletonized support for `Proxied` messages. This is done
by creating structs for $Msg$View and $Msg$Mut, and providing
stubbed impls.
PiperOrigin-RevId: 552609955
If a proto_library has more than one srcs, we designate the first one as the primary (that file will be passed to rustc as the crate root). All other files will represent (internal) submodules of the crate.
In general, Rust users won't see which .proto file a message came from, they will only see a crate corresponding to the entire proto_library, and in it public submodules for all `package` statements in all .proto files in the proto_library sources. Therefore in this CL we reexport all messages from non primary sources into their corresponding public modules (= packages declared in their owning .proto files).
Besides the common case this CL also handles .proto files without package statement, and a subset of behaviors needed for public import functionality.
PiperOrigin-RevId: 549543321
We were always emitting Optional<T> for accessors, when they should've been behind `_opt`.
We've refactored our previous accessor into `getter` and `getter_opt`. We'll only emit `getter_opt` when we're dealing with optional fields.
PiperOrigin-RevId: 544087591
Needed to lowercase fieldnames and add underscores when they use protected cpp names. Ended up using `cpp::FieldName` from the cpp impl to get this for free.
Also added escaping to Rust accessors, so that protected keywords will compile.
PiperOrigin-RevId: 543995050
Before this CL all messages were generated in the top-level crate module. With
this change we generate messages under the module specified by the package
declaration in the .proto file.
Dots are interpreted as submodule separator in consistency with how C++
namespaces are handled.
Note that name of the proto_library target still remains to be used as the crate name. This CL only adds crate submodules dependeing on the specified package.
PiperOrigin-RevId: 524235162
This turns out to be quite of a yak shave to be able to perfectly test both kernels without having to pass extra Blaze flags.
PiperOrigin-RevId: 521850709