Initialize scaffolding for ProxiedWithPresence for Messages

We want to return $pb$::FieldEntry<'_, $msg_type$> for msg_mut accessors as opposed to the current state (returning $Msg$Mut directly).
In this CL, we pave the way to implementing field entry returns.

We introduce { MessagePresentMutData, MessageAbsentMutData } and impl { ProxiedWithRawVTable, ProxiedWithRawOptionalVTable }. I initially tried a blanket impl approach, but it collided with the already existing PrimitiveVTable constructs; perhaps worth revisiting post 0.6.

In a followup, we'll flesh out the bodies. Lastly, we'll perform the swapover by
replacing $field$_mut with $field$_entry, updating all related tests.

PiperOrigin-RevId: 599282850
pull/15464/head
Hong Shin 1 year ago committed by Copybara-Service
parent e16dd47999
commit 808487918c
  1. 2
      rust/cpp.rs
  2. 6
      rust/internal.rs
  3. 2
      rust/upb.rs
  4. 9
      rust/vtable.rs
  5. 10
      src/google/protobuf/compiler/rust/accessors/singular_message.cc
  6. 41
      src/google/protobuf/compiler/rust/message.cc

@ -152,6 +152,8 @@ impl SettableValue<[u8]> for SerializedData {
}
}
pub type MessagePresentMutData<'msg, T> = crate::vtable::RawVTableOptionalMutatorData<'msg, T>;
pub type MessageAbsentMutData<'msg, T> = crate::vtable::RawVTableOptionalMutatorData<'msg, T>;
pub type BytesPresentMutData<'msg> = crate::vtable::RawVTableOptionalMutatorData<'msg, [u8]>;
pub type BytesAbsentMutData<'msg> = crate::vtable::RawVTableOptionalMutatorData<'msg, [u8]>;
pub type InnerBytesMut<'msg> = crate::vtable::RawVTableMutator<'msg, [u8]>;

@ -11,8 +11,10 @@
pub use crate::r#enum::Enum;
pub use crate::vtable::{
new_vtable_field_entry, BytesMutVTable, BytesOptionalMutVTable, PrimitiveOptionalMutVTable,
PrimitiveVTable, PrimitiveWithRawVTable, RawVTableMutator, RawVTableOptionalMutatorData,
new_vtable_field_entry, BytesMutVTable, BytesOptionalMutVTable, MessageOptionalVTable,
MessageVTable, PrimitiveOptionalMutVTable, PrimitiveVTable, PrimitiveWithRawVTable,
ProxiedWithRawOptionalVTable, ProxiedWithRawVTable, RawVTableMutator,
RawVTableOptionalMutatorData,
};
use std::ptr::NonNull;
use std::slice;

@ -233,6 +233,8 @@ impl SettableValue<[u8]> for SerializedData {
}
// TODO: Investigate replacing this with direct access to UPB bits.
pub type MessagePresentMutData<'msg, T> = crate::vtable::RawVTableOptionalMutatorData<'msg, T>;
pub type MessageAbsentMutData<'msg, T> = crate::vtable::RawVTableOptionalMutatorData<'msg, T>;
pub type BytesPresentMutData<'msg> = crate::vtable::RawVTableOptionalMutatorData<'msg, [u8]>;
pub type BytesAbsentMutData<'msg> = crate::vtable::RawVTableOptionalMutatorData<'msg, [u8]>;
pub type InnerBytesMut<'msg> = crate::vtable::RawVTableMutator<'msg, [u8]>;

@ -505,3 +505,12 @@ impl<'msg, T: PrimitiveWithRawVTable> RawVTableOptionalMutatorData<'msg, T> {
self
}
}
#[derive(Debug)]
#[allow(unused)]
pub struct MessageOptionalVTable {
pub base: MessageVTable,
}
#[derive(Debug)]
pub struct MessageVTable {}

@ -87,7 +87,15 @@ void SingularMessage::InMsgImpl(Context& ctx, const FieldDescriptor& field,
ctx.Emit({}, R"rs(
pub fn $field$_mut(&mut self) -> $msg_type$Mut {
$getter_mut_body$
})rs");
}
//~ TODO: b/319472103 - delete $field_mut$, then rename
//~ this to $field$_mut and update all unit tests
pub fn $field$_entry(&mut self)
-> $pb$::FieldEntry<'_, $msg_type$> {
todo!()
}
)rs");
}},
{"clearer",
[&] {

@ -582,6 +582,47 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {
}
}
impl $pbi$::ProxiedWithRawVTable for $Msg$ {
type VTable = $pbi$::MessageVTable;
fn make_view(_private: $pbi$::Private,
_mut_inner: $pbi$::RawVTableMutator<'_, Self>)
-> $pb$::View<'_, Self> {
todo!()
}
fn make_mut(_private: $pbi$::Private,
_inner: $pbi$::RawVTableMutator<'_, Self>)
-> $pb$::Mut<'_, Self> {
todo!()
}
}
impl $pbi$::ProxiedWithRawOptionalVTable for $Msg$ {
type OptionalVTable = $pbi$::MessageOptionalVTable;
fn upcast_vtable(_private: $pbi$::Private,
optional_vtable: &'static Self::OptionalVTable)
-> &'static Self::VTable {
&optional_vtable.base
}
}
impl $pb$::ProxiedWithPresence for $Msg$ {
type PresentMutData<'a> = $pbr$::MessagePresentMutData<'a, $Msg$>;
type AbsentMutData<'a> = $pbr$::MessageAbsentMutData<'a, $Msg$>;
fn clear_present_field(_present_mutator: Self::PresentMutData<'_>)
-> Self::AbsentMutData<'_> {
todo!();
}
fn set_absent_to_default(_absent_mutator: Self::AbsentMutData<'_>)
-> Self::PresentMutData<'_> {
todo!();
}
}
$settable_impl$
$repeated_impl$

Loading…
Cancel
Save