Skip to content

Commit 450ddab

Browse files
jckingcopybara-github
authored andcommitted
Cleanup Legacy values
PiperOrigin-RevId: 732932448
1 parent 51b1eb3 commit 450ddab

File tree

13 files changed

+136
-170
lines changed

13 files changed

+136
-170
lines changed

common/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,6 @@ cc_library(
594594
":unknown",
595595
":value_kind",
596596
"//base:attributes",
597-
"//base/internal:message_wrapper",
598597
"//common/internal:byte_string",
599598
"//common/internal:reference_count",
600599
"//eval/internal:cel_value_equal",

common/legacy_value.cc

Lines changed: 62 additions & 89 deletions
Large diffs are not rendered by default.

common/legacy_value.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ inline DoubleValue CreateDoubleValue(double value) {
7979

8080
inline ListValue CreateLegacyListValue(
8181
const google::api::expr::runtime::CelList* value) {
82-
return common_internal::LegacyListValue{reinterpret_cast<uintptr_t>(value)};
82+
return common_internal::LegacyListValue(value);
8383
}
8484

8585
inline MapValue CreateLegacyMapValue(
8686
const google::api::expr::runtime::CelMap* value) {
87-
return common_internal::LegacyMapValue{reinterpret_cast<uintptr_t>(value)};
87+
return common_internal::LegacyMapValue(value);
8888
}
8989

9090
inline Value CreateDurationValue(absl::Duration value, bool unchecked = false) {

common/values/legacy_list_value.cc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
#include "common/values/legacy_list_value.h"
1616

17-
#include <cstdint>
18-
1917
#include "absl/base/nullability.h"
2018
#include "absl/log/absl_check.h"
2119
#include "absl/status/status.h"
@@ -62,15 +60,15 @@ absl::optional<LegacyListValue> AsLegacyListValue(const Value& value) {
6260
if (auto custom_list_value = value.AsCustomList(); custom_list_value) {
6361
NativeTypeId native_type_id = NativeTypeId::Of(*custom_list_value);
6462
if (native_type_id == NativeTypeId::For<CompatListValue>()) {
65-
return LegacyListValue(reinterpret_cast<uintptr_t>(
63+
return LegacyListValue(
6664
static_cast<const google::api::expr::runtime::CelList*>(
6765
cel::internal::down_cast<const CompatListValue*>(
68-
(*custom_list_value).operator->()))));
66+
(*custom_list_value).operator->())));
6967
} else if (native_type_id == NativeTypeId::For<MutableCompatListValue>()) {
70-
return LegacyListValue(reinterpret_cast<uintptr_t>(
68+
return LegacyListValue(
7169
static_cast<const google::api::expr::runtime::CelList*>(
7270
cel::internal::down_cast<const MutableCompatListValue*>(
73-
(*custom_list_value).operator->()))));
71+
(*custom_list_value).operator->())));
7472
}
7573
}
7674
return absl::nullopt;

common/values/legacy_list_value.h

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#define THIRD_PARTY_CEL_CPP_COMMON_VALUES_LEGACY_LIST_VALUE_H_
2020

2121
#include <cstddef>
22-
#include <cstdint>
2322
#include <ostream>
2423
#include <string>
2524

@@ -36,6 +35,10 @@
3635
#include "google/protobuf/descriptor.h"
3736
#include "google/protobuf/message.h"
3837

38+
namespace google::api::expr::runtime {
39+
class CelList;
40+
}
41+
3942
namespace cel {
4043

4144
class TypeManager;
@@ -50,8 +53,9 @@ class LegacyListValue final
5053
public:
5154
static constexpr ValueKind kKind = ValueKind::kList;
5255

53-
// NOLINTNEXTLINE(google-explicit-constructor)
54-
explicit LegacyListValue(uintptr_t impl) : impl_(impl) {}
56+
explicit LegacyListValue(
57+
absl::NullabilityUnknown<const google::api::expr::runtime::CelList*> impl)
58+
: impl_(impl) {}
5559

5660
// By default, this creates an empty list whose type is `list(dyn)`. Unless
5761
// you can help it, you should use a more specific typed list value.
@@ -127,24 +131,23 @@ class LegacyListValue final
127131
absl::Nonnull<google::protobuf::Arena*> arena, absl::Nonnull<Value*> result) const;
128132
using ListValueMixin::Contains;
129133

130-
void swap(LegacyListValue& other) noexcept {
131-
using std::swap;
132-
swap(impl_, other.impl_);
134+
absl::NullabilityUnknown<const google::api::expr::runtime::CelList*>
135+
cel_list() const {
136+
return impl_;
133137
}
134138

135-
uintptr_t NativeValue() const { return impl_; }
139+
friend void swap(LegacyListValue& lhs, LegacyListValue& rhs) noexcept {
140+
using std::swap;
141+
swap(lhs.impl_, rhs.impl_);
142+
}
136143

137144
private:
138145
friend class common_internal::ValueMixin<LegacyListValue>;
139146
friend class common_internal::ListValueMixin<LegacyListValue>;
140147

141-
uintptr_t impl_;
148+
absl::NullabilityUnknown<const google::api::expr::runtime::CelList*> impl_;
142149
};
143150

144-
inline void swap(LegacyListValue& lhs, LegacyListValue& rhs) noexcept {
145-
lhs.swap(rhs);
146-
}
147-
148151
inline std::ostream& operator<<(std::ostream& out,
149152
const LegacyListValue& type) {
150153
return out << type.DebugString();

common/values/legacy_map_value.cc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
#include "common/values/legacy_map_value.h"
1616

17-
#include <cstdint>
18-
1917
#include "absl/base/nullability.h"
2018
#include "absl/log/absl_check.h"
2119
#include "absl/status/status.h"
@@ -62,15 +60,15 @@ absl::optional<LegacyMapValue> AsLegacyMapValue(const Value& value) {
6260
if (auto custom_map_value = value.AsCustomMap(); custom_map_value) {
6361
NativeTypeId native_type_id = NativeTypeId::Of(*custom_map_value);
6462
if (native_type_id == NativeTypeId::For<CompatMapValue>()) {
65-
return LegacyMapValue(reinterpret_cast<uintptr_t>(
63+
return LegacyMapValue(
6664
static_cast<const google::api::expr::runtime::CelMap*>(
6765
cel::internal::down_cast<const CompatMapValue*>(
68-
(*custom_map_value).operator->()))));
66+
(*custom_map_value).operator->())));
6967
} else if (native_type_id == NativeTypeId::For<MutableCompatMapValue>()) {
70-
return LegacyMapValue(reinterpret_cast<uintptr_t>(
68+
return LegacyMapValue(
7169
static_cast<const google::api::expr::runtime::CelMap*>(
7270
cel::internal::down_cast<const MutableCompatMapValue*>(
73-
(*custom_map_value).operator->()))));
71+
(*custom_map_value).operator->())));
7472
}
7573
}
7674
return absl::nullopt;

common/values/legacy_map_value.h

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#define THIRD_PARTY_CEL_CPP_COMMON_VALUES_LEGACY_MAP_VALUE_H_
2020

2121
#include <cstddef>
22-
#include <cstdint>
2322
#include <ostream>
2423
#include <string>
2524

@@ -36,6 +35,10 @@
3635
#include "google/protobuf/descriptor.h"
3736
#include "google/protobuf/message.h"
3837

38+
namespace google::api::expr::runtime {
39+
class CelMap;
40+
}
41+
3942
namespace cel {
4043

4144
class TypeManager;
@@ -50,8 +53,9 @@ class LegacyMapValue final
5053
public:
5154
static constexpr ValueKind kKind = ValueKind::kMap;
5255

53-
// NOLINTNEXTLINE(google-explicit-constructor)
54-
explicit LegacyMapValue(uintptr_t impl) : impl_(impl) {}
56+
explicit LegacyMapValue(
57+
absl::NullabilityUnknown<const google::api::expr::runtime::CelMap*> impl)
58+
: impl_(impl) {}
5559

5660
// By default, this creates an empty map whose type is `map(dyn, dyn)`.
5761
// Unless you can help it, you should use a more specific typed map value.
@@ -148,24 +152,22 @@ class LegacyMapValue final
148152

149153
absl::StatusOr<absl::Nonnull<ValueIteratorPtr>> NewIterator() const;
150154

151-
void swap(LegacyMapValue& other) noexcept {
152-
using std::swap;
153-
swap(impl_, other.impl_);
155+
absl::Nonnull<const google::api::expr::runtime::CelMap*> cel_map() const {
156+
return impl_;
154157
}
155158

156-
uintptr_t NativeValue() const { return impl_; }
159+
friend void swap(LegacyMapValue& lhs, LegacyMapValue& rhs) noexcept {
160+
using std::swap;
161+
swap(lhs.impl_, rhs.impl_);
162+
}
157163

158164
private:
159165
friend class common_internal::ValueMixin<LegacyMapValue>;
160166
friend class common_internal::MapValueMixin<LegacyMapValue>;
161167

162-
uintptr_t impl_;
168+
absl::NullabilityUnknown<const google::api::expr::runtime::CelMap*> impl_;
163169
};
164170

165-
inline void swap(LegacyMapValue& lhs, LegacyMapValue& rhs) noexcept {
166-
lhs.swap(rhs);
167-
}
168-
169171
inline std::ostream& operator<<(std::ostream& out, const LegacyMapValue& type) {
170172
return out << type.DebugString();
171173
}

common/values/legacy_struct_value.cc

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,14 @@
1515
#include "absl/log/absl_check.h"
1616
#include "absl/types/optional.h"
1717
#include "absl/types/variant.h"
18-
#include "base/internal/message_wrapper.h"
1918
#include "common/type.h"
2019
#include "common/value.h"
2120
#include "google/protobuf/message.h"
22-
#include "google/protobuf/message_lite.h"
2321

2422
namespace cel::common_internal {
2523

2624
StructType LegacyStructValue::GetRuntimeType() const {
27-
if ((message_ptr_ & ::cel::base_internal::kMessageWrapperTagMask) ==
28-
::cel::base_internal::kMessageWrapperTagMessageValue) {
29-
return MessageType(
30-
google::protobuf::DownCastMessage<google::protobuf::Message>(
31-
reinterpret_cast<const google::protobuf::MessageLite*>(
32-
message_ptr_ & ::cel::base_internal::kMessageWrapperPtrMask))
33-
->GetDescriptor());
34-
}
35-
return common_internal::MakeBasicStructType(GetTypeName());
25+
return MessageType(message_ptr_->GetDescriptor());
3626
}
3727

3828
bool IsLegacyStructValue(const Value& value) {

common/values/legacy_struct_value.h

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
#include "google/protobuf/descriptor.h"
4141
#include "google/protobuf/message.h"
4242

43+
namespace google::api::expr::runtime {
44+
class LegacyTypeInfoApis;
45+
}
46+
4347
namespace cel {
4448

4549
class Value;
@@ -57,8 +61,12 @@ class LegacyStructValue final
5761
public:
5862
static constexpr ValueKind kKind = ValueKind::kStruct;
5963

60-
LegacyStructValue(uintptr_t message_ptr, uintptr_t type_info)
61-
: message_ptr_(message_ptr), type_info_(type_info) {}
64+
LegacyStructValue(
65+
absl::NullabilityUnknown<const google::protobuf::Message*> message_ptr,
66+
absl::NullabilityUnknown<
67+
const google::api::expr::runtime::LegacyTypeInfoApis*>
68+
legacy_type_info)
69+
: message_ptr_(message_ptr), legacy_type_info_(legacy_type_info) {}
6270

6371
LegacyStructValue(const LegacyStructValue&) = default;
6472
LegacyStructValue& operator=(const LegacyStructValue&) = default;
@@ -98,12 +106,6 @@ class LegacyStructValue final
98106

99107
bool IsZeroValue() const;
100108

101-
void swap(LegacyStructValue& other) noexcept {
102-
using std::swap;
103-
swap(message_ptr_, other.message_ptr_);
104-
swap(type_info_, other.type_info_);
105-
}
106-
107109
absl::Status GetFieldByName(
108110
absl::string_view name, ProtoWrapperTypeOptions unboxing_options,
109111
absl::Nonnull<const google::protobuf::DescriptorPool*> descriptor_pool,
@@ -138,22 +140,32 @@ class LegacyStructValue final
138140
absl::Nonnull<int*> count) const;
139141
using StructValueMixin::Qualify;
140142

141-
uintptr_t message_ptr() const { return message_ptr_; }
143+
absl::NullabilityUnknown<const google::protobuf::Message*> message_ptr() const {
144+
return message_ptr_;
145+
}
146+
147+
absl::NullabilityUnknown<
148+
const google::api::expr::runtime::LegacyTypeInfoApis*>
149+
legacy_type_info() const {
150+
return legacy_type_info_;
151+
}
142152

143-
uintptr_t legacy_type_info() const { return type_info_; }
153+
friend void swap(LegacyStructValue& lhs, LegacyStructValue& rhs) noexcept {
154+
using std::swap;
155+
swap(lhs.message_ptr_, rhs.message_ptr_);
156+
swap(lhs.legacy_type_info_, rhs.legacy_type_info_);
157+
}
144158

145159
private:
146160
friend class common_internal::ValueMixin<LegacyStructValue>;
147161
friend class common_internal::StructValueMixin<LegacyStructValue>;
148162

149-
uintptr_t message_ptr_;
150-
uintptr_t type_info_;
163+
absl::NullabilityUnknown<const google::protobuf::Message*> message_ptr_;
164+
absl::NullabilityUnknown<
165+
const google::api::expr::runtime::LegacyTypeInfoApis*>
166+
legacy_type_info_;
151167
};
152168

153-
inline void swap(LegacyStructValue& lhs, LegacyStructValue& rhs) noexcept {
154-
lhs.swap(rhs);
155-
}
156-
157169
inline std::ostream& operator<<(std::ostream& out,
158170
const LegacyStructValue& value) {
159171
return out << value.DebugString();

common/values/struct_value_builder.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
#include "absl/strings/cord.h"
3131
#include "absl/strings/str_cat.h"
3232
#include "absl/strings/string_view.h"
33-
#include "absl/types/optional.h"
34-
#include "base/internal/message_wrapper.h"
3533
#include "common/allocator.h"
3634
#include "common/any.h"
3735
#include "common/memory.h"
@@ -297,8 +295,7 @@ absl::Status ProtoMessageFromValueImpl(
297295
// Deal with legacy values.
298296
if (auto legacy_value = common_internal::AsLegacyStructValue(value);
299297
legacy_value) {
300-
const auto* from_message = reinterpret_cast<const google::protobuf::Message*>(
301-
legacy_value->message_ptr() & base_internal::kMessageWrapperPtrMask);
298+
const auto* from_message = legacy_value->message_ptr();
302299
return ProtoMessageCopy(message, to_desc, from_message);
303300
}
304301

0 commit comments

Comments
 (0)