Commit Graph

321 Commits (main)

Author SHA1 Message Date
Marcel Hlopko eca477a0f1 Internal change.
PiperOrigin-RevId: 634495582
2024-05-16 12:39:36 -07:00
Marcel Hlopko 69a26b217d Use the name of the rust_proto_library as the crate name
PiperOrigin-RevId: 634414403
2024-05-16 09:00:50 -07:00
Marcel Hlopko e71c811a3a Extract crate name mangling function
PiperOrigin-RevId: 634055637
2024-05-15 13:29:52 -07:00
Marcel Hlopko a8cb5833aa Verify rust_proto_library name
PiperOrigin-RevId: 634006714
2024-05-15 10:52:51 -07:00
Protobuf Team Bot 2238cdc091 Add impl Clone for Rust proto owned messages.
PiperOrigin-RevId: 633265290
2024-05-13 10:57:10 -07:00
Derek Benson 904266db57 inline repeated field methods
PiperOrigin-RevId: 633199701
2024-05-13 07:19:09 -07:00
Derek Benson f2d8c2bdd8 Add a reserve method on ProxiedInRepeated
PiperOrigin-RevId: 633179853
2024-05-13 05:50:14 -07:00
Protobuf Team Bot d8329b68e4 Add .to_owned(&self)->Msg functions to MsgMut and MsgView
PiperOrigin-RevId: 631686314
2024-05-08 00:54:28 -07:00
Jakob Buchgraber b6e0a48b02 Implement `IntoProxied` for repeated field setters
We modify set_<repeated_field> to accept the IntoProxied type as the value and move the value (avoid copying) whenever possible.

For UPB:
 - We fuse the arena of Repeated<T> with the parent message arena.
 - We use upb_Message_SetBaseField to set the upb_Array contained in the Repeated<T>.

For C++:
 - We generate an additional setter thunk that moves the value.
 - The move assignment operator of RepeatedField/RepeatedPtrField is specialized. In order to adhere to the layering check we need to add '#include' statements for all .proto imports to the generated thunks.pb.cc.

PiperOrigin-RevId: 631010333
2024-05-06 05:31:08 -07:00
Bastien Jacot-Guillarmod 7b3682fcf2 Pin the rev of googletest to the GitHub main branch
PiperOrigin-RevId: 630417312
2024-05-03 09:54:29 -07:00
Adrian Sadłocha 733b9c54e9 Implement `is_known` method on the `Enum` trait
This is equivalent to C++'s `_IsValid` functions. Since proto3 enums are open,
`is_known` seems to be a better name than the misleading `is_valid`.

C++-specific Protocol Buffers documentation already uses "known fields" and
"unknown enum values" expressions.

PiperOrigin-RevId: 630344180
2024-05-03 03:52:51 -07:00
Jakob Buchgraber 959903d199 Remove the now unused vtable types. In particular,
* SettableValue
 * ProxiedWithPresence
 * FieldEntry

PiperOrigin-RevId: 629363417
2024-04-30 04:03:50 -07:00
Jakob Buchgraber e181855abe Implement flat setters for map and repeated fields.
This doesn't yet use the new IntoProxied trait, but is functionaly equivalent with MutProxy::set() and always copies.

PiperOrigin-RevId: 629358666
2024-04-30 03:45:08 -07:00
Jakob Buchgraber f9ed22055e Remove MutProxied for bytes/string fields.
This change then also makes the BytesMut/ProtoStrMut types unused. It removes them and related code.

PiperOrigin-RevId: 629023886
2024-04-29 04:16:00 -07:00
Jakob Buchgraber 1980e025eb Remove PrimitiveMut and related vtable types
The last callside that used PrimitiveMut was in our enums code. This change makes it so that enums nolonger implement MutProxied and thus no longer need the PrimitiveMut type.

PiperOrigin-RevId: 629017282
2024-04-29 03:42:06 -07:00
Jakob Buchgraber d76fdc56bb Implement IntoProxied for messages
PiperOrigin-RevId: 628992357
2024-04-29 01:33:56 -07:00
Protobuf Team Bot 1d0028ddda Fix unused warnings in Rust Proto
PiperOrigin-RevId: 628973552
2024-04-29 00:02:43 -07:00
Marcel Hlopko 93bd4bb012 Ensure that the rust_proto_library is in the same package as proto_library
PiperOrigin-RevId: 628308230
2024-04-25 23:49:53 -07:00
Marcel Hlopko 419824d26b Remove obsolete logic related to cc_proto_library
PiperOrigin-RevId: 628151973
2024-04-25 12:19:14 -07:00
Jakob Buchgraber dcc5db4c56 Implement Arena::fuse()
PiperOrigin-RevId: 627983487
2024-04-25 00:49:02 -07:00
Marcel Hlopko 59d8afde6b Use the main/proper proto_common
PiperOrigin-RevId: 627833411
2024-04-24 13:36:59 -07:00
Protobuf Team Bot 734729afc2 Create the concept of 'owned data' in upb/rust as a generalization of the upb.rs SerializedData (which is a arena + data for arbitrary types, both thin and wide ref types), use that for the wire parse/serialize path.
PiperOrigin-RevId: 627814154
2024-04-24 12:28:07 -07:00
Protobuf Team Bot 55875598f7 Add a collision-avoidance behavior to the Rust Proto codegen.
The intent is to avoid codegen issues for simple cases where a message of the shape:
message M {
   int32 x = 3
   string set_x = 8;
}

Which would otherwise break due to the first field having a setter whose name collides with the second field's getter.

By seeing that 'set_x' matches another field with a common accessor prefixed, it will generate all accessors for that field as though it was named `set_x_8`.

This does not avoid all possible collisions, but should mitigate the vast majority of situations of an accidental collision.

PiperOrigin-RevId: 627776907
2024-04-24 10:41:46 -07:00
Jakob Buchgraber 849b975e5f Temporarily use AsRef<{ProtoStr, [u8]}> for string/bytes accessors
This change removes the only remaining instance of SettableValue in a generated accessor. The principled fix is to implement IntoProxied for ProtoStr/[u8], but this will have to wait until we have agreed on & implemented the 1.0 string types. So we'll use AsRef in the meantime in order to not break any user code while allowing us to make progress on IntoProxied and Proxied changes.

PiperOrigin-RevId: 627735404
2024-04-24 08:22:33 -07:00
Jakob Buchgraber 1a7ce61061 Split Proxied into Proxied and MutProxied traits.
Proxied is not marked as Sized yet, because ProtoStr is still dynamically sized. We will wait for clarity for the string types before marking Proxied Sized.

PiperOrigin-RevId: 627707544
2024-04-24 06:23:49 -07:00
Protobuf Team Bot c413b1231c Change upb::Arena to be Send (but still not Sync)
PiperOrigin-RevId: 626409752
2024-04-19 10:46:45 -07:00
Derek Benson b4bd664b07 Rust: fix proto! msgtype matcher to look for :: separated idents instead of a ty to avoid syntax errors during parse
PiperOrigin-RevId: 626093074
2024-04-18 11:17:22 -07:00
Derek Benson a2d4a4af2c proto! doc comment and copyright
PiperOrigin-RevId: 626092060
2024-04-18 11:14:08 -07:00
Marcel Hlopko 1a7ea70730 Add test coverage for UTF-8 behavior
PiperOrigin-RevId: 625650220
2024-04-17 05:39:28 -07:00
Protobuf Team Bot d44ba9090c Refactor upb/rust directory to introduce separate files for each concept instead of a single blob.
PiperOrigin-RevId: 625333833
2024-04-16 08:08:06 -07:00
Protobuf Team Bot 5c7a9fd997 Move the Rust `Arena` type which wraps a upb_Arena into the upb directory.
PiperOrigin-RevId: 625317910
2024-04-16 07:08:47 -07:00
Derek Benson e485d4f03d Adds an initial version of the proto! macro to simplify construction of proto messages in Rust. Currently supports all field types except Repeated and Map
PiperOrigin-RevId: 624995511
2024-04-15 10:03:48 -07:00
Alyssa Haroldsen 3f493d9e52 Use the same set of exports as regular users in shared tests
The shared tests which access `protobuf_upb` or `protobuf_cpp`
have access to more items than the `protobuf` library itself.
This is because the former don't go through the same re-exporting based
on kernel.

I fix this by creating two test-only libraries that perform the same re-exporting
as the `protobuf` library, but with the kernel explicitly set, and changing the shared
tests to reference that instead of the inner runtime library.

This is needed to reliably test macros, where item paths are relative to the invocation,
not eagerly checked at the macro source.

PiperOrigin-RevId: 624328817
2024-04-12 16:51:49 -07:00
Protobuf Team Bot 2678e10c99 Create a upb rust directory.
The intent of this directory would be for a layer of Rust bindings that directly map to upb semantics; Rust Protobuf runtime would be layer on top of that Rust, instead of directly on the upb C api.

PiperOrigin-RevId: 624282429
2024-04-12 13:57:44 -07:00
Jakob Buchgraber 42a49a8589 Implement the Error trait for ParseError. This makes it compatible with anyhow.
PiperOrigin-RevId: 624137709
2024-04-12 05:05:53 -07:00
Bastien Jacot-Guillarmod d172859878 Copybara import of the project:
--
4b67c374d49b00860a8f285aae2e064cc58a0dc7 by Bastien Jacot-Guillarmod <bjacotg@gmail.com>:

Make `ActualT` in `Matcher` a generic type parameter.

--
7e34d847f2cda5387e55ac436ded30cc6d07bcaa by Bastien Jacot-Guillarmod <bjacotg@gmail.com>:

Accept all `Copy` type for `ActualT` instead of only reference.

PiperOrigin-RevId: 624094573
2024-04-12 02:01:00 -07:00
Protobuf Team Bot b8bb56df4c Change Rust-upb to use upb_Encode and upb_Decode directly, instead of going through the upb C gencode.
PiperOrigin-RevId: 623474125
2024-04-10 06:27:06 -07:00
Protobuf Team Bot 21d75f861c Remove references to rules_proto
They are not needed after the rules are move into protobuf repo.
Except for the reference to toolchain type, which is currently in rules_proto and can be moved after the implementation is moved into protobuf repo.

PiperOrigin-RevId: 622176865
2024-04-05 07:50:25 -07:00
Protobuf Team Bot f421dc42b5 Change the Rust > C++ interop fns to be consuming-self, add a 'leak' to the name and a ManuallyDrop(self) on the owned message case.
PiperOrigin-RevId: 622159280
2024-04-05 06:17:14 -07:00
Protobuf Team Bot b0c4dfc5ee Remove Arena definition in cpp.rs
PiperOrigin-RevId: 621901674
2024-04-04 10:32:42 -07:00
Marcel Hlopko b4bf6b22e5 Add missing map thunks for nested enums.
While at it, remove the code for emitting map thunks for bytes map keys - bytes are not supported map keys.

PiperOrigin-RevId: 621806332
2024-04-04 03:48:05 -07:00
Protobuf Team Bot dc5053acc4 Automated Code Change
PiperOrigin-RevId: 621379968
2024-04-02 20:42:07 -07:00
Protobuf Team Bot 063c198f59 add empty case to extend repeated and map tests, fix map methods that consumed self
PiperOrigin-RevId: 621158946
2024-04-02 06:52:55 -07:00
Protobuf Team Bot 7f6a0ba347 Implement Extend for Repeated
PiperOrigin-RevId: 620277895
2024-03-29 10:29:17 -07:00
Protobuf Team Bot 83ec410d30 Internal change
PiperOrigin-RevId: 619377672
2024-03-27 05:50:55 -07:00
Protobuf Team Bot 7df9d5d970 Use $Msg$::parse() where sensible.
PiperOrigin-RevId: 618838455
2024-03-25 07:46:41 -07:00
Protobuf Team Bot 847d31afb2 Add a convenience SomeMsg::parse(bytes) -> Result<SomeMsg, ParseErr>
Rename .deserialize(&mut self) method to .clear_and_parse() (by marking the .deserialized deprecated pointing at the new name, will clean up usages separately)
END_PUBLIC

Per discussion in the team chat, parse/serialize is the most typical terminology for protobuf impls, we don't have much local reason to diverge.

I'm proposing giving the 'better' name to the named ctor since I think that is the one that we expect people to reach for by default; it is generally cleaner than "new then deserialize" pattern since after a parse failure there's not any message still hanging around with implementation-defined contents, along with some other smaller ergonomics benefits.

In C++ (when exceptions aren't enabled) all constructors must be infallible, so it can't have it. In Rust there's no language idiom reason why we shouldn't have an associated fn that returns Result<Msg, ParseErr>.

PiperOrigin-RevId: 618823998
2024-03-25 06:43:04 -07:00
Protobuf Team Bot 0c8f970fc9 Implement Default::default() for owned messages.
PiperOrigin-RevId: 618758568
2024-03-25 01:14:43 -07:00
Protobuf Team Bot 7c4d89e115 Implement Map::copy_from and implement the Extend trait for Maps
PiperOrigin-RevId: 617218421
2024-03-19 10:35:14 -07:00
Protobuf Team Bot fa0d25a707 Add has_field() accessors for any field that supports presence.
PiperOrigin-RevId: 617170589
2024-03-19 07:54:55 -07:00