Skip to content

Commit

Permalink
Remove more cruft
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 718055885
  • Loading branch information
jcking authored and copybara-github committed Jan 21, 2025
1 parent 3aef50a commit 9a8b79d
Show file tree
Hide file tree
Showing 13 changed files with 0 additions and 213 deletions.
18 changes: 0 additions & 18 deletions common/type_reflector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
#include "absl/base/no_destructor.h"
#include "absl/base/nullability.h"
#include "absl/status/statusor.h"
#include "absl/strings/cord.h"
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "common/memory.h"
#include "common/type.h"
#include "common/value.h"
Expand All @@ -33,28 +31,12 @@ absl::StatusOr<absl::Nullable<ValueBuilderPtr>> TypeReflector::NewValueBuilder(
return nullptr;
}

absl::StatusOr<absl::optional<Value>> TypeReflector::DeserializeValue(
ValueFactory& value_factory, absl::string_view type_url,
const absl::Cord& value) const {
return DeserializeValueImpl(value_factory, type_url, value);
}

absl::StatusOr<absl::optional<Value>> TypeReflector::DeserializeValueImpl(
ValueFactory&, absl::string_view, const absl::Cord&) const {
return absl::nullopt;
}

absl::StatusOr<absl::Nullable<StructValueBuilderPtr>>
TypeReflector::NewStructValueBuilder(ValueFactory& value_factory,
const StructType& type) const {
return nullptr;
}

absl::StatusOr<bool> TypeReflector::FindValue(ValueFactory&, absl::string_view,
Value&) const {
return false;
}

TypeReflector& TypeReflector::Builtin() {
static absl::NoDestructor<TypeReflector> instance;
return *instance;
Expand Down
17 changes: 0 additions & 17 deletions common/type_reflector.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,10 @@ class TypeReflector : public virtual TypeIntrospector {
virtual absl::StatusOr<absl::Nullable<ValueBuilderPtr>> NewValueBuilder(
ValueFactory& value_factory, absl::string_view name) const;

// `FindValue` returns a new `Value` for the corresponding name `name`. This
// can be used to translate enum names to numeric values.
virtual absl::StatusOr<bool> FindValue(ValueFactory& value_factory,
absl::string_view name,
Value& result) const;

// `DeserializeValue` deserializes the bytes of `value` according to
// `type_url`. Returns `NOT_FOUND` if `type_url` is unrecognized.
virtual absl::StatusOr<absl::optional<Value>> DeserializeValue(
ValueFactory& value_factory, absl::string_view type_url,
const absl::Cord& value) const;

virtual absl::Nullable<const google::protobuf::DescriptorPool*> descriptor_pool()
const {
return nullptr;
}

protected:
virtual absl::StatusOr<absl::optional<Value>> DeserializeValueImpl(
ValueFactory& value_factory, absl::string_view type_url,
const absl::Cord& value) const;
};

Shared<TypeReflector> NewThreadCompatibleTypeReflector(
Expand Down
13 changes: 0 additions & 13 deletions common/value_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@

#include "absl/base/nullability.h"
#include "absl/status/statusor.h"
#include "absl/strings/cord.h"
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "common/json.h"
#include "common/memory.h"
#include "common/type.h"
Expand Down Expand Up @@ -63,17 +61,6 @@ class ValueManager : public virtual ValueFactory,
return GetTypeReflector().NewValueBuilder(*this, name);
}

// See `TypeReflector::FindValue`.
absl::StatusOr<bool> FindValue(absl::string_view name, Value& result) {
return GetTypeReflector().FindValue(*this, name, result);
}

// See `TypeReflector::DeserializeValue`.
absl::StatusOr<absl::optional<Value>> DeserializeValue(
absl::string_view type_url, const absl::Cord& value) {
return GetTypeReflector().DeserializeValue(*this, type_url, value);
}

absl::Nullable<google::protobuf::MessageFactory*> message_factory() const override = 0;

protected:
Expand Down
31 changes: 0 additions & 31 deletions common/values/struct_value_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,37 +145,6 @@ class CompatTypeReflector final : public TypeReflector {
name);
}

absl::StatusOr<absl::optional<Value>> DeserializeValue(
ValueFactory& value_factory, absl::string_view type_url,
const absl::Cord& value) const override {
const auto* descriptor_pool = this->descriptor_pool();
auto* message_factory = value_factory.message_factory();
if (message_factory == nullptr) {
return absl::nullopt;
}
absl::string_view type_name;
if (!ParseTypeUrl(type_url, &type_name)) {
return absl::InvalidArgumentError("invalid type URL");
}
const auto* descriptor = descriptor_pool->FindMessageTypeByName(type_name);
if (descriptor == nullptr) {
return absl::nullopt;
}
const auto* prototype = message_factory->GetPrototype(descriptor);
if (prototype == nullptr) {
return absl::nullopt;
}
absl::Nullable<google::protobuf::Arena*> arena =
value_factory.GetMemoryManager().arena();
auto message = WrapShared(prototype->New(arena), arena);
if (!message->ParsePartialFromCord(value)) {
return absl::InvalidArgumentError(
absl::StrCat("failed to parse `", type_url, "`"));
}
return Value::Message(WrapShared(prototype->New(arena), arena),
descriptor_pool, message_factory);
}

private:
const google::protobuf::DescriptorPool* const pool_;
};
Expand Down
9 changes: 0 additions & 9 deletions common/values/thread_compatible_type_reflector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

#include "absl/base/nullability.h"
#include "absl/status/statusor.h"
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "common/memory.h"
#include "common/type.h"
#include "common/value.h"

Expand All @@ -30,10 +27,4 @@ ThreadCompatibleTypeReflector::NewStructValueBuilder(ValueFactory&,
return nullptr;
}

absl::StatusOr<bool> ThreadCompatibleTypeReflector::FindValue(ValueFactory&,
absl::string_view,
Value&) const {
return false;
}

} // namespace cel::common_internal
5 changes: 0 additions & 5 deletions common/values/thread_compatible_type_reflector.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

#include "absl/base/nullability.h"
#include "absl/status/statusor.h"
#include "absl/strings/string_view.h"
#include "common/type.h"
#include "common/type_reflector.h"
#include "common/types/thread_compatible_type_introspector.h"
Expand All @@ -38,10 +37,6 @@ class ThreadCompatibleTypeReflector : public ThreadCompatibleTypeIntrospector,

absl::StatusOr<absl::Nullable<StructValueBuilderPtr>> NewStructValueBuilder(
ValueFactory& value_factory, const StructType& type) const override;

absl::StatusOr<bool> FindValue(ValueFactory& value_factory,
absl::string_view name,
Value& result) const override;
};

} // namespace common_internal
Expand Down
36 changes: 0 additions & 36 deletions eval/public/structs/legacy_type_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@
#include "absl/base/nullability.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/cord.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "absl/strings/strip.h"
#include "absl/types/optional.h"
#include "common/any.h"
#include "common/legacy_value.h"
#include "common/memory.h"
#include "common/type.h"
Expand Down Expand Up @@ -173,39 +170,6 @@ LegacyTypeProvider::NewStructValueBuilder(cel::ValueFactory& value_factory,
return nullptr;
}

absl::StatusOr<absl::optional<cel::Value>>
LegacyTypeProvider::DeserializeValueImpl(cel::ValueFactory& value_factory,
absl::string_view type_url,
const absl::Cord& value) const {
auto type_name = absl::StripPrefix(type_url, cel::kTypeGoogleApisComPrefix);
if (auto type_info = ProvideLegacyTypeInfo(type_name);
type_info.has_value()) {
if (auto type_adapter = ProvideLegacyType(type_name);
type_adapter.has_value()) {
const auto* mutation_apis = type_adapter->mutation_apis();
if (mutation_apis == nullptr) {
return absl::FailedPreconditionError(absl::StrCat(
"LegacyTypeMutationApis missing for type: ", type_name));
}
CEL_ASSIGN_OR_RETURN(auto builder, mutation_apis->NewInstance(
value_factory.GetMemoryManager()));
if (!builder.message_ptr()->ParsePartialFromCord(value)) {
return absl::UnknownError("failed to parse protocol buffer message");
}
CEL_ASSIGN_OR_RETURN(
auto legacy_value,
mutation_apis->AdaptFromWellKnownType(
value_factory.GetMemoryManager(), std::move(builder)));
cel::Value modern_value;
CEL_RETURN_IF_ERROR(ModernValue(cel::extensions::ProtoMemoryManagerArena(
value_factory.GetMemoryManager()),
legacy_value, modern_value));
return modern_value;
}
}
return absl::nullopt;
}

absl::StatusOr<absl::optional<cel::Type>> LegacyTypeProvider::FindTypeImpl(
absl::string_view name) const {
if (auto type_info = ProvideLegacyTypeInfo(name); type_info.has_value()) {
Expand Down
5 changes: 0 additions & 5 deletions eval/public/structs/legacy_type_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "absl/base/attributes.h"
#include "absl/base/nullability.h"
#include "absl/status/statusor.h"
#include "absl/strings/cord.h"
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "common/type.h"
Expand Down Expand Up @@ -68,10 +67,6 @@ class LegacyTypeProvider : public cel::TypeReflector {
const cel::StructType& type) const final;

protected:
absl::StatusOr<absl::optional<cel::Value>> DeserializeValueImpl(
cel::ValueFactory& value_factory, absl::string_view type_url,
const absl::Cord& value) const final;

absl::StatusOr<absl::optional<cel::Type>> FindTypeImpl(
absl::string_view name) const final;

Expand Down
3 changes: 0 additions & 3 deletions extensions/protobuf/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,6 @@ cc_test(

cc_library(
name = "value",
srcs = [
"type_reflector.cc",
],
hdrs = [
"type_reflector.h",
"value.h",
Expand Down
34 changes: 0 additions & 34 deletions extensions/protobuf/type_reflector.cc

This file was deleted.

5 changes: 0 additions & 5 deletions extensions/protobuf/type_reflector.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ class ProtoTypeReflector : public TypeReflector, public ProtoTypeIntrospector {
const override {
return ProtoTypeIntrospector::descriptor_pool();
}

private:
absl::StatusOr<absl::optional<Value>> DeserializeValueImpl(
ValueFactory& value_factory, absl::string_view type_url,
const absl::Cord& value) const final;
};

} // namespace cel::extensions
Expand Down
31 changes: 0 additions & 31 deletions runtime/internal/runtime_type_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,35 +127,4 @@ RuntimeTypeProvider::NewValueBuilder(ValueFactory& value_factory,
name);
}

absl::StatusOr<absl::optional<Value>> RuntimeTypeProvider::DeserializeValue(
ValueFactory& value_factory, absl::string_view type_url,
const absl::Cord& value) const {
const auto* descriptor_pool = this->descriptor_pool();
auto* message_factory = value_factory.message_factory();
if (message_factory == nullptr) {
return absl::nullopt;
}
absl::string_view type_name;
if (!ParseTypeUrl(type_url, &type_name)) {
return absl::InvalidArgumentError("invalid type URL");
}
const auto* descriptor = descriptor_pool->FindMessageTypeByName(type_name);
if (descriptor == nullptr) {
return absl::nullopt;
}
const auto* prototype = message_factory->GetPrototype(descriptor);
if (prototype == nullptr) {
return absl::nullopt;
}
absl::Nullable<google::protobuf::Arena*> arena =
value_factory.GetMemoryManager().arena();
auto message = WrapShared(prototype->New(arena), arena);
if (!message->ParsePartialFromCord(value)) {
return absl::InvalidArgumentError(
absl::StrCat("failed to parse `", type_url, "`"));
}
return Value::Message(WrapShared(prototype->New(arena), arena),
descriptor_pool, message_factory);
}

} // namespace cel::runtime_internal
6 changes: 0 additions & 6 deletions runtime/internal/runtime_type_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ class RuntimeTypeProvider final : public TypeReflector {
absl::StatusOr<absl::Nullable<ValueBuilderPtr>> NewValueBuilder(
ValueFactory& value_factory, absl::string_view name) const override;

// `DeserializeValue` deserializes the bytes of `value` according to
// `type_url`. Returns `NOT_FOUND` if `type_url` is unrecognized.
absl::StatusOr<absl::optional<Value>> DeserializeValue(
ValueFactory& value_factory, absl::string_view type_url,
const absl::Cord& value) const override;

absl::Nonnull<const google::protobuf::DescriptorPool*> descriptor_pool()
const override {
return descriptor_pool_;
Expand Down

0 comments on commit 9a8b79d

Please sign in to comment.