Skip to content

Commit e249db7

Browse files
jckingcopybara-github
authored andcommitted
Drop reference counting support from protobuf related values
PiperOrigin-RevId: 738247402
1 parent c2fba5b commit e249db7

37 files changed

+1381
-787
lines changed

common/value.cc

Lines changed: 613 additions & 292 deletions
Large diffs are not rendered by default.

common/value.h

Lines changed: 92 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@
3737
#include "absl/types/variant.h"
3838
#include "absl/utility/utility.h"
3939
#include "base/attribute.h"
40-
#include "common/allocator.h"
4140
#include "common/arena.h"
42-
#include "common/memory.h"
4341
#include "common/native_type.h"
4442
#include "common/optional_ref.h"
4543
#include "common/type.h"
@@ -117,78 +115,111 @@ class Value final : private common_internal::ValueMixin<Value> {
117115
// Returns an appropriate `Value` for the dynamic protobuf message. If
118116
// `message` is the well known type `google.protobuf.Any`, `descriptor_pool`
119117
// and `message_factory` will be used to unpack the value. Both must outlive
120-
// the resulting value and any of its shallow copies.
121-
static Value Message(Allocator<> allocator, const google::protobuf::Message& message,
122-
absl::Nonnull<const google::protobuf::DescriptorPool*>
123-
descriptor_pool ABSL_ATTRIBUTE_LIFETIME_BOUND,
124-
absl::Nonnull<google::protobuf::MessageFactory*> message_factory
125-
ABSL_ATTRIBUTE_LIFETIME_BOUND);
126-
static Value Message(Allocator<> allocator, google::protobuf::Message&& message,
127-
absl::Nonnull<const google::protobuf::DescriptorPool*>
128-
descriptor_pool ABSL_ATTRIBUTE_LIFETIME_BOUND,
129-
absl::Nonnull<google::protobuf::MessageFactory*> message_factory
130-
ABSL_ATTRIBUTE_LIFETIME_BOUND);
131-
static Value Message(Borrowed<const google::protobuf::Message> message,
132-
absl::Nonnull<const google::protobuf::DescriptorPool*>
133-
descriptor_pool ABSL_ATTRIBUTE_LIFETIME_BOUND,
134-
absl::Nonnull<google::protobuf::MessageFactory*> message_factory
135-
ABSL_ATTRIBUTE_LIFETIME_BOUND);
118+
// the resulting value and any of its shallow copies. Otherwise the message is
119+
// copied using `arena`.
120+
static Value FromMessage(
121+
const google::protobuf::Message& message,
122+
absl::Nonnull<const google::protobuf::DescriptorPool*> descriptor_pool
123+
ABSL_ATTRIBUTE_LIFETIME_BOUND,
124+
absl::Nonnull<google::protobuf::MessageFactory*> message_factory
125+
ABSL_ATTRIBUTE_LIFETIME_BOUND,
126+
absl::Nonnull<google::protobuf::Arena*> arena ABSL_ATTRIBUTE_LIFETIME_BOUND);
127+
static Value FromMessage(
128+
google::protobuf::Message&& message,
129+
absl::Nonnull<const google::protobuf::DescriptorPool*> descriptor_pool
130+
ABSL_ATTRIBUTE_LIFETIME_BOUND,
131+
absl::Nonnull<google::protobuf::MessageFactory*> message_factory
132+
ABSL_ATTRIBUTE_LIFETIME_BOUND,
133+
absl::Nonnull<google::protobuf::Arena*> arena ABSL_ATTRIBUTE_LIFETIME_BOUND);
134+
135+
// Returns an appropriate `Value` for the dynamic protobuf message. If
136+
// `message` is the well known type `google.protobuf.Any`, `descriptor_pool`
137+
// and `message_factory` will be used to unpack the value. Both must outlive
138+
// the resulting value and any of its shallow copies. Otherwise the message is
139+
// borrowed (no copying). If the message is on an arena, that arena will be
140+
// attributed as the owner. Otherwise `arena` is used.
141+
static Value WrapMessage(
142+
absl::Nonnull<const google::protobuf::Message*> message
143+
ABSL_ATTRIBUTE_LIFETIME_BOUND,
144+
absl::Nonnull<const google::protobuf::DescriptorPool*> descriptor_pool
145+
ABSL_ATTRIBUTE_LIFETIME_BOUND,
146+
absl::Nonnull<google::protobuf::MessageFactory*> message_factory
147+
ABSL_ATTRIBUTE_LIFETIME_BOUND,
148+
absl::Nonnull<google::protobuf::Arena*> arena ABSL_ATTRIBUTE_LIFETIME_BOUND);
136149

137150
// Returns an appropriate `Value` for the dynamic protobuf message field. If
138151
// `field` in `message` is the well known type `google.protobuf.Any`,
139152
// `descriptor_pool` and `message_factory` will be used to unpack the value.
140153
// Both must outlive the resulting value and any of its shallow copies.
141-
static Value Field(Borrowed<const google::protobuf::Message> message,
142-
absl::Nonnull<const google::protobuf::FieldDescriptor*> field,
143-
ProtoWrapperTypeOptions wrapper_type_options =
144-
ProtoWrapperTypeOptions::kUnsetNull);
145-
static Value Field(Borrowed<const google::protobuf::Message> message,
146-
absl::Nonnull<const google::protobuf::FieldDescriptor*> field,
147-
absl::Nonnull<const google::protobuf::DescriptorPool*>
148-
descriptor_pool ABSL_ATTRIBUTE_LIFETIME_BOUND,
149-
absl::Nonnull<google::protobuf::MessageFactory*> message_factory
150-
ABSL_ATTRIBUTE_LIFETIME_BOUND,
151-
ProtoWrapperTypeOptions wrapper_type_options =
152-
ProtoWrapperTypeOptions::kUnsetNull);
154+
// Otherwise the field is borrowed (no copying). If the message is on an
155+
// arena, that arena will be attributed as the owner. Otherwise `arena` is
156+
// used.
157+
static Value WrapField(
158+
ProtoWrapperTypeOptions wrapper_type_options,
159+
absl::Nonnull<const google::protobuf::Message*> message
160+
ABSL_ATTRIBUTE_LIFETIME_BOUND,
161+
absl::Nonnull<const google::protobuf::FieldDescriptor*> field
162+
ABSL_ATTRIBUTE_LIFETIME_BOUND,
163+
absl::Nonnull<const google::protobuf::DescriptorPool*> descriptor_pool
164+
ABSL_ATTRIBUTE_LIFETIME_BOUND,
165+
absl::Nonnull<google::protobuf::MessageFactory*> message_factory
166+
ABSL_ATTRIBUTE_LIFETIME_BOUND,
167+
absl::Nonnull<google::protobuf::Arena*> arena ABSL_ATTRIBUTE_LIFETIME_BOUND);
168+
static Value WrapField(
169+
absl::Nonnull<const google::protobuf::Message*> message
170+
ABSL_ATTRIBUTE_LIFETIME_BOUND,
171+
absl::Nonnull<const google::protobuf::FieldDescriptor*> field
172+
ABSL_ATTRIBUTE_LIFETIME_BOUND,
173+
absl::Nonnull<const google::protobuf::DescriptorPool*> descriptor_pool
174+
ABSL_ATTRIBUTE_LIFETIME_BOUND,
175+
absl::Nonnull<google::protobuf::MessageFactory*> message_factory
176+
ABSL_ATTRIBUTE_LIFETIME_BOUND,
177+
absl::Nonnull<google::protobuf::Arena*> arena ABSL_ATTRIBUTE_LIFETIME_BOUND) {
178+
return WrapField(ProtoWrapperTypeOptions::kUnsetNull, message, field,
179+
descriptor_pool, message_factory, arena);
180+
}
153181

154182
// Returns an appropriate `Value` for the dynamic protobuf message repeated
155183
// field. If `field` in `message` is the well known type
156184
// `google.protobuf.Any`, `descriptor_pool` and `message_factory` will be used
157185
// to unpack the value. Both must outlive the resulting value and any of its
158186
// shallow copies.
159-
static Value RepeatedField(
160-
Borrowed<const google::protobuf::Message> message,
161-
absl::Nonnull<const google::protobuf::FieldDescriptor*> field, int index);
162-
static Value RepeatedField(
163-
Borrowed<const google::protobuf::Message> message,
164-
absl::Nonnull<const google::protobuf::FieldDescriptor*> field, int index,
187+
static Value WrapRepeatedField(
188+
int index,
189+
absl::Nonnull<const google::protobuf::Message*> message
190+
ABSL_ATTRIBUTE_LIFETIME_BOUND,
191+
absl::Nonnull<const google::protobuf::FieldDescriptor*> field
192+
ABSL_ATTRIBUTE_LIFETIME_BOUND,
165193
absl::Nonnull<const google::protobuf::DescriptorPool*> descriptor_pool
166194
ABSL_ATTRIBUTE_LIFETIME_BOUND,
167195
absl::Nonnull<google::protobuf::MessageFactory*> message_factory
168-
ABSL_ATTRIBUTE_LIFETIME_BOUND);
196+
ABSL_ATTRIBUTE_LIFETIME_BOUND,
197+
absl::Nonnull<google::protobuf::Arena*> arena ABSL_ATTRIBUTE_LIFETIME_BOUND);
169198

170199
// Returns an appropriate `StringValue` for the dynamic protobuf message map
171200
// field key. The map field key must be a string or the behavior is undefined.
172-
static StringValue MapFieldKeyString(Borrowed<const google::protobuf::Message> message,
173-
const google::protobuf::MapKey& key);
201+
static StringValue WrapMapFieldKeyString(
202+
const google::protobuf::MapKey& key,
203+
absl::Nonnull<const google::protobuf::Message*> message
204+
ABSL_ATTRIBUTE_LIFETIME_BOUND,
205+
absl::Nonnull<google::protobuf::Arena*> arena ABSL_ATTRIBUTE_LIFETIME_BOUND);
174206

175207
// Returns an appropriate `Value` for the dynamic protobuf message map
176208
// field value. If `field` in `message`, which is `value`, is the well known
177209
// type `google.protobuf.Any`, `descriptor_pool` and `message_factory` will be
178210
// used to unpack the value. Both must outlive the resulting value and any of
179211
// its shallow copies.
180-
static Value MapFieldValue(
181-
Borrowed<const google::protobuf::Message> message,
182-
absl::Nonnull<const google::protobuf::FieldDescriptor*> field,
183-
const google::protobuf::MapValueConstRef& value);
184-
static Value MapFieldValue(
185-
Borrowed<const google::protobuf::Message> message,
186-
absl::Nonnull<const google::protobuf::FieldDescriptor*> field,
212+
static Value WrapMapFieldValue(
187213
const google::protobuf::MapValueConstRef& value,
214+
absl::Nonnull<const google::protobuf::Message*> message
215+
ABSL_ATTRIBUTE_LIFETIME_BOUND,
216+
absl::Nonnull<const google::protobuf::FieldDescriptor*> field
217+
ABSL_ATTRIBUTE_LIFETIME_BOUND,
188218
absl::Nonnull<const google::protobuf::DescriptorPool*> descriptor_pool
189219
ABSL_ATTRIBUTE_LIFETIME_BOUND,
190220
absl::Nonnull<google::protobuf::MessageFactory*> message_factory
191-
ABSL_ATTRIBUTE_LIFETIME_BOUND);
221+
ABSL_ATTRIBUTE_LIFETIME_BOUND,
222+
absl::Nonnull<google::protobuf::Arena*> arena ABSL_ATTRIBUTE_LIFETIME_BOUND);
192223

193224
Value() = default;
194225
Value(const Value&) = default;
@@ -2898,27 +2929,31 @@ using StructValueBuilderInterface = StructValueBuilder;
28982929

28992930
namespace common_internal {
29002931

2901-
using MapFieldKeyAccessor = void (*)(Allocator<>, Borrower,
2902-
const google::protobuf::MapKey&, Value&);
2932+
using MapFieldKeyAccessor = void (*)(const google::protobuf::MapKey&,
2933+
absl::Nonnull<const google::protobuf::Message*>,
2934+
absl::Nonnull<google::protobuf::Arena*>,
2935+
absl::Nonnull<Value*>);
29032936

29042937
absl::StatusOr<MapFieldKeyAccessor> MapFieldKeyAccessorFor(
29052938
absl::Nonnull<const google::protobuf::FieldDescriptor*> field);
29062939

2907-
using MapFieldValueAccessor =
2908-
void (*)(Borrower, const google::protobuf::MapValueConstRef&,
2909-
absl::Nonnull<const google::protobuf::FieldDescriptor*>,
2910-
absl::Nonnull<const google::protobuf::DescriptorPool*>,
2911-
absl::Nonnull<google::protobuf::MessageFactory*>, Value&);
2940+
using MapFieldValueAccessor = void (*)(
2941+
const google::protobuf::MapValueConstRef&, absl::Nonnull<const google::protobuf::Message*>,
2942+
absl::Nonnull<const google::protobuf::FieldDescriptor*>,
2943+
absl::Nonnull<const google::protobuf::DescriptorPool*>,
2944+
absl::Nonnull<google::protobuf::MessageFactory*>, absl::Nonnull<google::protobuf::Arena*>,
2945+
absl::Nonnull<Value*>);
29122946

29132947
absl::StatusOr<MapFieldValueAccessor> MapFieldValueAccessorFor(
29142948
absl::Nonnull<const google::protobuf::FieldDescriptor*> field);
29152949

29162950
using RepeatedFieldAccessor =
2917-
void (*)(Allocator<>, Borrowed<const google::protobuf::Message>,
2951+
void (*)(int, absl::Nonnull<const google::protobuf::Message*>,
29182952
absl::Nonnull<const google::protobuf::FieldDescriptor*>,
2919-
absl::Nonnull<const google::protobuf::Reflection*>, int,
2953+
absl::Nonnull<const google::protobuf::Reflection*>,
29202954
absl::Nonnull<const google::protobuf::DescriptorPool*>,
2921-
absl::Nonnull<google::protobuf::MessageFactory*>, Value&);
2955+
absl::Nonnull<google::protobuf::MessageFactory*>,
2956+
absl::Nonnull<google::protobuf::Arena*>, absl::Nonnull<Value*>);
29222957

29232958
absl::StatusOr<RepeatedFieldAccessor> RepeatedFieldAccessorFor(
29242959
absl::Nonnull<const google::protobuf::FieldDescriptor*> field);

0 commit comments

Comments
 (0)