Skip to content

Commit

Permalink
Rename Thunk to ThunkName
Browse files Browse the repository at this point in the history
Let's hint at returning a name as opposed to a computed chunk / lambda

PiperOrigin-RevId: 594074865
  • Loading branch information
honglooker authored and copybara-github committed Dec 28, 2023
1 parent 27cccac commit be68828
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 92 deletions.
12 changes: 6 additions & 6 deletions src/google/protobuf/compiler/rust/accessors/map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ void Map::InMsgImpl(Context& ctx, const FieldDescriptor& field) const {
ctx.Emit({{"field", field.name()},
{"Key", PrimitiveRsTypeName(key_type)},
{"Value", PrimitiveRsTypeName(value_type)},
{"getter_thunk", Thunk(ctx, field, "get")},
{"getter_mut_thunk", Thunk(ctx, field, "get_mut")},
{"getter_thunk", ThunkName(ctx, field, "get")},
{"getter_mut_thunk", ThunkName(ctx, field, "get_mut")},
{"getter",
[&] {
if (ctx.is_upb()) {
Expand Down Expand Up @@ -97,8 +97,8 @@ void Map::InMsgImpl(Context& ctx, const FieldDescriptor& field) const {
void Map::InExternC(Context& ctx, const FieldDescriptor& field) const {
ctx.Emit(
{
{"getter_thunk", Thunk(ctx, field, "get")},
{"getter_mut_thunk", Thunk(ctx, field, "get_mut")},
{"getter_thunk", ThunkName(ctx, field, "get")},
{"getter_mut_thunk", ThunkName(ctx, field, "get_mut")},
{"getter",
[&] {
if (ctx.is_upb()) {
Expand Down Expand Up @@ -129,8 +129,8 @@ void Map::InThunkCc(Context& ctx, const FieldDescriptor& field) const {
{"Value",
cpp::PrimitiveTypeName(field.message_type()->map_value()->cpp_type())},
{"QualifiedMsg", cpp::QualifiedClassName(field.containing_type())},
{"getter_thunk", Thunk(ctx, field, "get")},
{"getter_mut_thunk", Thunk(ctx, field, "get_mut")},
{"getter_thunk", ThunkName(ctx, field, "get")},
{"getter_mut_thunk", ThunkName(ctx, field, "get_mut")},
{"impls",
[&] {
ctx.Emit(
Expand Down
18 changes: 9 additions & 9 deletions src/google/protobuf/compiler/rust/accessors/repeated_scalar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ void RepeatedScalar::InMsgImpl(Context& ctx,
const FieldDescriptor& field) const {
ctx.Emit({{"field", field.name()},
{"Scalar", PrimitiveRsTypeName(field)},
{"getter_thunk", Thunk(ctx, field, "get")},
{"getter_mut_thunk", Thunk(ctx, field, "get_mut")},
{"getter_thunk", ThunkName(ctx, field, "get")},
{"getter_mut_thunk", ThunkName(ctx, field, "get_mut")},
{"getter",
[&] {
if (ctx.is_upb()) {
Expand Down Expand Up @@ -54,7 +54,7 @@ void RepeatedScalar::InMsgImpl(Context& ctx,
)rs");
}
}},
{"clearer_thunk", Thunk(ctx, field, "clear")},
{"clearer_thunk", ThunkName(ctx, field, "clear")},
{"field_mutator_getter",
[&] {
if (ctx.is_upb()) {
Expand Down Expand Up @@ -101,8 +101,8 @@ void RepeatedScalar::InMsgImpl(Context& ctx,
void RepeatedScalar::InExternC(Context& ctx,
const FieldDescriptor& field) const {
ctx.Emit({{"Scalar", PrimitiveRsTypeName(field)},
{"getter_thunk", Thunk(ctx, field, "get")},
{"getter_mut_thunk", Thunk(ctx, field, "get_mut")},
{"getter_thunk", ThunkName(ctx, field, "get")},
{"getter_mut_thunk", ThunkName(ctx, field, "get_mut")},
{"getter",
[&] {
if (ctx.is_upb()) {
Expand All @@ -125,7 +125,7 @@ void RepeatedScalar::InExternC(Context& ctx,
)rs");
}
}},
{"clearer_thunk", Thunk(ctx, field, "clear")}},
{"clearer_thunk", ThunkName(ctx, field, "clear")}},
R"rs(
fn $clearer_thunk$(raw_msg: $pbi$::RawMessage);
$getter$
Expand All @@ -137,9 +137,9 @@ void RepeatedScalar::InThunkCc(Context& ctx,
ctx.Emit({{"field", cpp::FieldName(&field)},
{"Scalar", cpp::PrimitiveTypeName(field.cpp_type())},
{"QualifiedMsg", cpp::QualifiedClassName(field.containing_type())},
{"clearer_thunk", Thunk(ctx, field, "clear")},
{"getter_thunk", Thunk(ctx, field, "get")},
{"getter_mut_thunk", Thunk(ctx, field, "get_mut")},
{"clearer_thunk", ThunkName(ctx, field, "clear")},
{"getter_thunk", ThunkName(ctx, field, "get")},
{"getter_mut_thunk", ThunkName(ctx, field, "get_mut")},
{"impls",
[&] {
ctx.Emit(
Expand Down
18 changes: 9 additions & 9 deletions src/google/protobuf/compiler/rust/accessors/singular_message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ void SingularMessage::InMsgImpl(Context& ctx,
{
{"prefix", prefix},
{"field", field.name()},
{"getter_thunk", Thunk(ctx, field, "get")},
{"getter_mut_thunk", Thunk(ctx, field, "get_mut")},
{"clearer_thunk", Thunk(ctx, field, "clear")},
{"getter_thunk", ThunkName(ctx, field, "get")},
{"getter_mut_thunk", ThunkName(ctx, field, "get_mut")},
{"clearer_thunk", ThunkName(ctx, field, "clear")},
{
"view_body",
[&] {
Expand Down Expand Up @@ -91,9 +91,9 @@ void SingularMessage::InExternC(Context& ctx,
const FieldDescriptor& field) const {
ctx.Emit(
{
{"getter_thunk", Thunk(ctx, field, "get")},
{"getter_mut_thunk", Thunk(ctx, field, "get_mut")},
{"clearer_thunk", Thunk(ctx, field, "clear")},
{"getter_thunk", ThunkName(ctx, field, "get")},
{"getter_mut_thunk", ThunkName(ctx, field, "get_mut")},
{"clearer_thunk", ThunkName(ctx, field, "clear")},
{"getter_mut",
[&] {
if (ctx.is_cpp()) {
Expand Down Expand Up @@ -130,9 +130,9 @@ void SingularMessage::InExternC(Context& ctx,
void SingularMessage::InThunkCc(Context& ctx,
const FieldDescriptor& field) const {
ctx.Emit({{"QualifiedMsg", cpp::QualifiedClassName(field.containing_type())},
{"getter_thunk", Thunk(ctx, field, "get")},
{"getter_mut_thunk", Thunk(ctx, field, "get_mut")},
{"clearer_thunk", Thunk(ctx, field, "clear")},
{"getter_thunk", ThunkName(ctx, field, "get")},
{"getter_mut_thunk", ThunkName(ctx, field, "get_mut")},
{"clearer_thunk", ThunkName(ctx, field, "clear")},
{"field", cpp::FieldName(&field)}},
R"cc(
const void* $getter_thunk$($QualifiedMsg$* msg) {
Expand Down
24 changes: 12 additions & 12 deletions src/google/protobuf/compiler/rust/accessors/singular_scalar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void SingularScalar::InMsgImpl(Context& ctx,
{
{"field", field.name()},
{"Scalar", PrimitiveRsTypeName(field)},
{"hazzer_thunk", Thunk(ctx, field, "has")},
{"hazzer_thunk", ThunkName(ctx, field, "has")},
{"default_value", DefaultValue(field)},
{"getter",
[&] {
Expand All @@ -48,9 +48,9 @@ void SingularScalar::InMsgImpl(Context& ctx,
}
)rs");
}},
{"getter_thunk", Thunk(ctx, field, "get")},
{"setter_thunk", Thunk(ctx, field, "set")},
{"clearer_thunk", Thunk(ctx, field, "clear")},
{"getter_thunk", ThunkName(ctx, field, "get")},
{"setter_thunk", ThunkName(ctx, field, "set")},
{"clearer_thunk", ThunkName(ctx, field, "clear")},
{"field_mutator_getter",
[&] {
if (field.has_presence()) {
Expand Down Expand Up @@ -118,10 +118,10 @@ void SingularScalar::InMsgImpl(Context& ctx,
void SingularScalar::InExternC(Context& ctx,
const FieldDescriptor& field) const {
ctx.Emit({{"Scalar", PrimitiveRsTypeName(field)},
{"hazzer_thunk", Thunk(ctx, field, "has")},
{"getter_thunk", Thunk(ctx, field, "get")},
{"setter_thunk", Thunk(ctx, field, "set")},
{"clearer_thunk", Thunk(ctx, field, "clear")},
{"hazzer_thunk", ThunkName(ctx, field, "has")},
{"getter_thunk", ThunkName(ctx, field, "get")},
{"setter_thunk", ThunkName(ctx, field, "set")},
{"clearer_thunk", ThunkName(ctx, field, "clear")},
{"with_presence_fields_thunks",
[&] {
if (field.has_presence()) {
Expand All @@ -144,10 +144,10 @@ void SingularScalar::InThunkCc(Context& ctx,
ctx.Emit({{"field", cpp::FieldName(&field)},
{"Scalar", cpp::PrimitiveTypeName(field.cpp_type())},
{"QualifiedMsg", cpp::QualifiedClassName(field.containing_type())},
{"hazzer_thunk", Thunk(ctx, field, "has")},
{"getter_thunk", Thunk(ctx, field, "get")},
{"setter_thunk", Thunk(ctx, field, "set")},
{"clearer_thunk", Thunk(ctx, field, "clear")},
{"hazzer_thunk", ThunkName(ctx, field, "has")},
{"getter_thunk", ThunkName(ctx, field, "get")},
{"setter_thunk", ThunkName(ctx, field, "set")},
{"clearer_thunk", ThunkName(ctx, field, "clear")},
{"with_presence_fields_thunks",
[&] {
if (field.has_presence()) {
Expand Down
24 changes: 12 additions & 12 deletions src/google/protobuf/compiler/rust/accessors/singular_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ namespace rust {

void SingularString::InMsgImpl(Context& ctx,
const FieldDescriptor& field) const {
std::string hazzer_thunk = Thunk(ctx, field, "has");
std::string getter_thunk = Thunk(ctx, field, "get");
std::string setter_thunk = Thunk(ctx, field, "set");
std::string hazzer_thunk = ThunkName(ctx, field, "has");
std::string getter_thunk = ThunkName(ctx, field, "get");
std::string setter_thunk = ThunkName(ctx, field, "set");
std::string proxied_type = PrimitiveRsTypeName(field);
auto transform_view = [&] {
if (field.type() == FieldDescriptor::TYPE_STRING) {
Expand Down Expand Up @@ -85,7 +85,7 @@ void SingularString::InMsgImpl(Context& ctx,
{"hazzer_thunk", hazzer_thunk},
{"getter_thunk", getter_thunk},
{"setter_thunk", setter_thunk},
{"clearer_thunk", Thunk(ctx, field, "clear")},
{"clearer_thunk", ThunkName(ctx, field, "clear")},
},
R"rs(
pub fn $field$_mut(&mut self) -> $pb$::FieldEntry<'_, $proxied_type$> {
Expand Down Expand Up @@ -153,10 +153,10 @@ void SingularString::InMsgImpl(Context& ctx,

void SingularString::InExternC(Context& ctx,
const FieldDescriptor& field) const {
ctx.Emit({{"hazzer_thunk", Thunk(ctx, field, "has")},
{"getter_thunk", Thunk(ctx, field, "get")},
{"setter_thunk", Thunk(ctx, field, "set")},
{"clearer_thunk", Thunk(ctx, field, "clear")},
ctx.Emit({{"hazzer_thunk", ThunkName(ctx, field, "has")},
{"getter_thunk", ThunkName(ctx, field, "get")},
{"setter_thunk", ThunkName(ctx, field, "set")},
{"clearer_thunk", ThunkName(ctx, field, "clear")},
{"with_presence_fields_thunks",
[&] {
if (field.has_presence()) {
Expand All @@ -177,10 +177,10 @@ void SingularString::InThunkCc(Context& ctx,
const FieldDescriptor& field) const {
ctx.Emit({{"field", cpp::FieldName(&field)},
{"QualifiedMsg", cpp::QualifiedClassName(field.containing_type())},
{"hazzer_thunk", Thunk(ctx, field, "has")},
{"getter_thunk", Thunk(ctx, field, "get")},
{"setter_thunk", Thunk(ctx, field, "set")},
{"clearer_thunk", Thunk(ctx, field, "clear")},
{"hazzer_thunk", ThunkName(ctx, field, "has")},
{"getter_thunk", ThunkName(ctx, field, "get")},
{"setter_thunk", ThunkName(ctx, field, "set")},
{"clearer_thunk", ThunkName(ctx, field, "clear")},
{"with_presence_fields_thunks",
[&] {
if (field.has_presence()) {
Expand Down
40 changes: 20 additions & 20 deletions src/google/protobuf/compiler/rust/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ namespace {
void MessageNew(Context& ctx, const Descriptor& msg) {
switch (ctx.opts().kernel) {
case Kernel::kCpp:
ctx.Emit({{"new_thunk", Thunk(ctx, msg, "new")}}, R"rs(
ctx.Emit({{"new_thunk", ThunkName(ctx, msg, "new")}}, R"rs(
Self { inner: $pbr$::MessageInner { msg: unsafe { $new_thunk$() } } }
)rs");
return;

case Kernel::kUpb:
ctx.Emit({{"new_thunk", Thunk(ctx, msg, "new")}}, R"rs(
ctx.Emit({{"new_thunk", ThunkName(ctx, msg, "new")}}, R"rs(
let arena = $pbr$::Arena::new();
Self {
inner: $pbr$::MessageInner {
Expand All @@ -53,13 +53,13 @@ void MessageNew(Context& ctx, const Descriptor& msg) {
void MessageSerialize(Context& ctx, const Descriptor& msg) {
switch (ctx.opts().kernel) {
case Kernel::kCpp:
ctx.Emit({{"serialize_thunk", Thunk(ctx, msg, "serialize")}}, R"rs(
ctx.Emit({{"serialize_thunk", ThunkName(ctx, msg, "serialize")}}, R"rs(
unsafe { $serialize_thunk$(self.inner.msg) }
)rs");
return;

case Kernel::kUpb:
ctx.Emit({{"serialize_thunk", Thunk(ctx, msg, "serialize")}}, R"rs(
ctx.Emit({{"serialize_thunk", ThunkName(ctx, msg, "serialize")}}, R"rs(
let arena = $pbr$::Arena::new();
let mut len = 0;
unsafe {
Expand All @@ -78,7 +78,7 @@ void MessageDeserialize(Context& ctx, const Descriptor& msg) {
case Kernel::kCpp:
ctx.Emit(
{
{"deserialize_thunk", Thunk(ctx, msg, "deserialize")},
{"deserialize_thunk", ThunkName(ctx, msg, "deserialize")},
},
R"rs(
let success = unsafe {
Expand All @@ -94,7 +94,7 @@ void MessageDeserialize(Context& ctx, const Descriptor& msg) {
return;

case Kernel::kUpb:
ctx.Emit({{"deserialize_thunk", Thunk(ctx, msg, "parse")}}, R"rs(
ctx.Emit({{"deserialize_thunk", ThunkName(ctx, msg, "parse")}}, R"rs(
let arena = $pbr$::Arena::new();
let msg = unsafe {
$deserialize_thunk$(data.as_ptr(), data.len(), arena.raw())
Expand Down Expand Up @@ -122,10 +122,10 @@ void MessageExterns(Context& ctx, const Descriptor& msg) {
case Kernel::kCpp:
ctx.Emit(
{
{"new_thunk", Thunk(ctx, msg, "new")},
{"delete_thunk", Thunk(ctx, msg, "delete")},
{"serialize_thunk", Thunk(ctx, msg, "serialize")},
{"deserialize_thunk", Thunk(ctx, msg, "deserialize")},
{"new_thunk", ThunkName(ctx, msg, "new")},
{"delete_thunk", ThunkName(ctx, msg, "delete")},
{"serialize_thunk", ThunkName(ctx, msg, "serialize")},
{"deserialize_thunk", ThunkName(ctx, msg, "deserialize")},
},
R"rs(
fn $new_thunk$() -> $pbi$::RawMessage;
Expand All @@ -138,9 +138,9 @@ void MessageExterns(Context& ctx, const Descriptor& msg) {
case Kernel::kUpb:
ctx.Emit(
{
{"new_thunk", Thunk(ctx, msg, "new")},
{"serialize_thunk", Thunk(ctx, msg, "serialize")},
{"deserialize_thunk", Thunk(ctx, msg, "parse")},
{"new_thunk", ThunkName(ctx, msg, "new")},
{"serialize_thunk", ThunkName(ctx, msg, "serialize")},
{"deserialize_thunk", ThunkName(ctx, msg, "parse")},
},
R"rs(
fn $new_thunk$(arena: $pbi$::RawArena) -> $pbi$::RawMessage;
Expand All @@ -160,7 +160,7 @@ void MessageDrop(Context& ctx, const Descriptor& msg) {
return;
}

ctx.Emit({{"delete_thunk", Thunk(ctx, msg, "delete")}}, R"rs(
ctx.Emit({{"delete_thunk", ThunkName(ctx, msg, "delete")}}, R"rs(
unsafe { $delete_thunk$(self.inner.msg); }
)rs");
}
Expand All @@ -173,8 +173,8 @@ void GetterForViewOrMut(Context& ctx, const FieldDescriptor& field,
bool is_mut) {
auto fieldName = field.name();
auto fieldType = field.type();
auto getter_thunk = Thunk(ctx, field, "get");
auto setter_thunk = Thunk(ctx, field, "set");
auto getter_thunk = ThunkName(ctx, field, "get");
auto setter_thunk = ThunkName(ctx, field, "set");
// If we're dealing with a Mut, the getter must be supplied
// self.inner.msg() whereas a View has to be supplied self.msg
auto self = is_mut ? "self.inner.msg()" : "self.msg";
Expand Down Expand Up @@ -552,10 +552,10 @@ void GenerateThunksCc(Context& ctx, const Descriptor& msg) {
{{"abi", "\"C\""}, // Workaround for syntax highlight bug in VSCode.
{"Msg", msg.name()},
{"QualifiedMsg", cpp::QualifiedClassName(&msg)},
{"new_thunk", Thunk(ctx, msg, "new")},
{"delete_thunk", Thunk(ctx, msg, "delete")},
{"serialize_thunk", Thunk(ctx, msg, "serialize")},
{"deserialize_thunk", Thunk(ctx, msg, "deserialize")},
{"new_thunk", ThunkName(ctx, msg, "new")},
{"delete_thunk", ThunkName(ctx, msg, "delete")},
{"serialize_thunk", ThunkName(ctx, msg, "serialize")},
{"deserialize_thunk", ThunkName(ctx, msg, "deserialize")},
{"nested_msg_thunks",
[&] {
for (int i = 0; i < msg.nested_type_count(); ++i) {
Expand Down
Loading

0 comments on commit be68828

Please sign in to comment.