Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 1 addition & 21 deletions eval/public/structs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -229,26 +229,12 @@ cc_test(

cc_library(
name = "legacy_type_provider",
srcs = ["legacy_type_provider.cc"],
hdrs = ["legacy_type_provider.h"],
deps = [
":legacy_type_adapter",
":legacy_type_info_apis",
"//common:legacy_value",
"//common:memory",
"//common:type",
"//common:value",
"//eval/public:message_wrapper",
"//extensions/protobuf:memory_manager",
"//internal:status_macros",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/base:nullability",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:string_view",
"@com_google_absl//absl/types:optional",
"@com_google_protobuf//:protobuf",
],
)

Expand Down Expand Up @@ -359,15 +345,11 @@ cc_test(
deps = [
":legacy_type_info_apis",
":protobuf_descriptor_type_provider",
"//common:type",
"//eval/public:cel_value",
"//eval/public/testing:matchers",
"//extensions/protobuf:memory_manager",
"//internal:testing",
"//internal:testing_descriptor_pool",
"//internal:testing_message_factory",
"@com_google_absl//absl/status:status_matchers",
"@com_google_cel_spec//proto/cel/expr/conformance/proto3:test_all_types_cc_proto",
"@com_google_protobuf//:protobuf",
"@com_google_protobuf//:wrappers_cc_proto",
],
Expand Down Expand Up @@ -413,12 +395,10 @@ cc_test(
":legacy_type_adapter",
":legacy_type_info_apis",
":legacy_type_provider",
":proto_message_type_adapter",
":trivial_legacy_type_info",
"//common:type",
"//eval/testutil:test_message_cc_proto",
"//internal:testing",
"@com_google_absl//absl/strings:string_view",
"@com_google_absl//absl/types:optional",
],
)

Expand Down
232 changes: 0 additions & 232 deletions eval/public/structs/legacy_type_provider.cc

This file was deleted.

31 changes: 7 additions & 24 deletions eval/public/structs/legacy_type_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,20 @@
#include <optional>

#include "absl/base/attributes.h"
#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/value.h"
#include "eval/public/structs/legacy_type_adapter.h"
#include "eval/public/structs/legacy_type_info_apis.h"
#include "google/protobuf/arena.h"
#include "google/protobuf/message.h"

namespace google::api::expr::runtime {

// An internal extension of cel::TypeProvider that also deals with legacy types.
// Provides legacy type adapters for google::api::expr::runtime::CelValue
// wrapping messages.
//
// Note: This API is not finalized. Consult the CEL team before introducing new
// implementations.
class LegacyTypeProvider : public cel::TypeReflector {
// Note: internal use of this type is limited to interop with the Legacy
// (CelValue) runtime with an internal implementation.
//
// New implementations cannot be registered with the evaluator.
class LegacyTypeProvider {
public:
virtual ~LegacyTypeProvider() = default;

Expand All @@ -60,19 +56,6 @@ class LegacyTypeProvider : public cel::TypeReflector {
ABSL_ATTRIBUTE_UNUSED absl::string_view name) const {
return std::nullopt;
}

absl::StatusOr<absl_nullable cel::ValueBuilderPtr> NewValueBuilder(
absl::string_view name,
google::protobuf::MessageFactory* absl_nonnull message_factory,
google::protobuf::Arena* absl_nonnull arena) const final;

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

absl::StatusOr<std::optional<cel::StructTypeField>>
FindStructTypeFieldByNameImpl(absl::string_view type,
absl::string_view name) const final;
};

} // namespace google::api::expr::runtime
Expand Down
22 changes: 1 addition & 21 deletions eval/public/structs/legacy_type_provider_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@
#include <optional>

#include "absl/strings/string_view.h"
#include "common/type.h"
#include "absl/types/optional.h"
#include "eval/public/structs/legacy_type_adapter.h"
#include "eval/public/structs/legacy_type_info_apis.h"
#include "eval/public/structs/proto_message_type_adapter.h"
#include "eval/public/structs/trivial_legacy_type_info.h"
#include "eval/testutil/test_message.pb.h"
#include "internal/testing.h"

namespace google::api::expr::runtime {
Expand Down Expand Up @@ -73,23 +71,5 @@ TEST(LegacyTypeProviderTest, NonEmptyTypeProviderProvidesSomeTypes) {
EXPECT_EQ(provider.ProvideLegacyTypeInfo("other"), std::nullopt);
}

TEST(LegacyTypeProviderTest, FindStructTypeFieldByName) {
ProtoMessageTypeAdapter adapter(TestMessage::descriptor(), nullptr);
LegacyTypeProviderTestImpl provider(&adapter);

ASSERT_OK_AND_ASSIGN(
absl::optional<cel::StructTypeField> field,
provider.FindStructTypeFieldByName("test", "int32_value"));
ASSERT_TRUE(field.has_value());
EXPECT_EQ(field->name(), "int32_value");
EXPECT_EQ(field->number(), 1);
EXPECT_EQ(field->GetType(), cel::IntType());

ASSERT_OK_AND_ASSIGN(
absl::optional<cel::StructTypeField> not_found_field,
provider.FindStructTypeFieldByName("test", "unknown_field"));
EXPECT_FALSE(not_found_field.has_value());
}

} // namespace
} // namespace google::api::expr::runtime
Loading
Loading