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
3 changes: 1 addition & 2 deletions eval/eval/create_struct_step_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ namespace {

using ::absl_testing::IsOk;
using ::absl_testing::StatusIs;
using ::cel::Expr;
using ::cel::TypeProvider;
using ::cel::internal::test::EqualsProto;
using ::cel::runtime_internal::NewTestingRuntimeEnv;
Expand Down Expand Up @@ -200,7 +199,7 @@ TEST_P(CreateCreateStructStepTest, TestEmptyMessageCreation) {

auto adapter = env_->legacy_type_registry.FindTypeAdapter(
"google.api.expr.runtime.TestMessage");
ASSERT_TRUE(adapter.has_value() && adapter->mutation_apis() != nullptr);
ASSERT_TRUE(adapter.has_value() && adapter->access_apis() != nullptr);

ASSERT_OK_AND_ASSIGN(auto maybe_type,
env_->type_registry.GetComposedTypeProvider().FindType(
Expand Down
2 changes: 1 addition & 1 deletion eval/public/cel_type_registry_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TestTypeProvider : public LegacyTypeProvider {
absl::string_view name) const override {
for (const auto& type : types_) {
if (name == type) {
return LegacyTypeAdapter(/*access=*/nullptr, /*mutation=*/nullptr);
return LegacyTypeAdapter(/*access=*/nullptr);
}
}
return std::nullopt;
Expand Down
4 changes: 0 additions & 4 deletions eval/public/structs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ cc_library(
srcs = ["proto_message_type_adapter.cc"],
hdrs = ["proto_message_type_adapter.h"],
deps = [
":cel_proto_wrap_util",
":field_access_impl",
":legacy_type_adapter",
":legacy_type_info_apis",
Expand Down Expand Up @@ -311,12 +310,9 @@ cc_test(
"//common:value_testing",
"//eval/public:cel_value",
"//eval/public:message_wrapper",
"//eval/public/containers:container_backed_list_impl",
"//eval/public/containers:container_backed_map_impl",
"//eval/public/testing:matchers",
"//eval/testutil:test_message_cc_proto",
"//extensions/protobuf:memory_manager",
"//internal:proto_matchers",
"//internal:testing",
"//runtime:runtime_options",
"@com_google_absl//absl/status",
Expand Down
68 changes: 7 additions & 61 deletions eval/public/structs/legacy_type_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#ifndef THIRD_PARTY_CEL_CPP_EVAL_PUBLIC_STRUCTS_LEGACY_TYPE_ADPATER_H_
#define THIRD_PARTY_CEL_CPP_EVAL_PUBLIC_STRUCTS_LEGACY_TYPE_ADPATER_H_

#include <cstdint>
#include <cstddef>
#include <vector>

#include "absl/status/status.h"
Expand All @@ -36,54 +36,6 @@ namespace google::api::expr::runtime {
class DucktypedMessageAdapter;
class ProtoMessageTypeAdapter;

// Interface for mutation apis.
// Note: in the new type system, a type provider represents this by returning
// a cel::Type and cel::ValueManager for the type.
class LegacyTypeMutationApis {
public:
virtual ~LegacyTypeMutationApis() = default;

// Return whether the type defines the given field.
// TODO(uncreated-issue/3): This is only used to eagerly fail during the planning
// phase. Check if it's safe to remove this behavior and fail at runtime.
virtual bool DefinesField(absl::string_view field_name) const = 0;

// Create a new empty instance of the type.
// May return a status if the type is not possible to create.
virtual absl::StatusOr<CelValue::MessageWrapper::Builder> NewInstance(
cel::MemoryManagerRef memory_manager) const = 0;

// Normalize special types to a native CEL value after building.
// The interpreter guarantees that instance is uniquely owned by the
// interpreter, and can be safely mutated.
virtual absl::StatusOr<CelValue> AdaptFromWellKnownType(
cel::MemoryManagerRef memory_manager,
CelValue::MessageWrapper::Builder instance) const = 0;

// Set field on instance to value.
// The interpreter guarantees that instance is uniquely owned by the
// interpreter, and can be safely mutated.
virtual absl::Status SetField(
absl::string_view field_name, const CelValue& value,
cel::MemoryManagerRef memory_manager,
CelValue::MessageWrapper::Builder& instance) const = 0;

virtual absl::Status SetFieldByNumber(
int64_t field_number [[maybe_unused]],
const CelValue& value [[maybe_unused]],
cel::MemoryManagerRef memory_manager [[maybe_unused]],
CelValue::MessageWrapper::Builder& instance [[maybe_unused]]) const {
return absl::UnimplementedError("SetFieldByNumber is not yet implemented");
}

private:
// This class should only be implemented by CEL. Custom structs are only
// supported using the cel::Value APIs.
friend class ProtoMessageTypeAdapter;

LegacyTypeMutationApis() = default;
};

// Interface for access apis.
// Note: in new type system this is integrated into the StructValue (via
// dynamic dispatch to concrete implementations).
Expand Down Expand Up @@ -162,9 +114,6 @@ class LegacyTypeAccessApis {
// Type information about a legacy Struct type.
// Provides methods to the interpreter for interacting with a custom type.
//
// mutation_apis() provide equivalent behavior to a cel::Type and
// cel::ValueManager (resolved from a type name).
//
// access_apis() provide equivalent behavior to cel::StructValue accessors
// (virtual dispatch to a concrete implementation for accessing underlying
// values).
Expand All @@ -174,21 +123,18 @@ class LegacyTypeAccessApis {
// the type provider that returned this object.
class LegacyTypeAdapter {
public:
LegacyTypeAdapter(const LegacyTypeAccessApis* access,
const LegacyTypeMutationApis* mutation)
: access_apis_(access), mutation_apis_(mutation) {}
explicit LegacyTypeAdapter(const LegacyTypeAccessApis* access)
: access_apis_(access) {}
// Temporary constructor to support fakes in client tests.
LegacyTypeAdapter(const LegacyTypeAccessApis* access, std::nullptr_t)
: access_apis_(access) {}

// Apis for access for the represented type.
// If null, access is not supported (this is an opaque type).
const LegacyTypeAccessApis* access_apis() { return access_apis_; }

// Apis for mutation for the represented type.
// If null, mutation is not supported (this type cannot be created).
const LegacyTypeMutationApis* mutation_apis() { return mutation_apis_; }
const LegacyTypeAccessApis* access_apis() const { return access_apis_; }

private:
const LegacyTypeAccessApis* access_apis_;
const LegacyTypeMutationApis* mutation_apis_;
};

} // namespace google::api::expr::runtime
Expand Down
3 changes: 1 addition & 2 deletions eval/public/structs/legacy_type_adapter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ namespace {

TEST(LegacyTypeAdapter, Basic) {
ProtoMessageTypeAdapter adapter(TestMessage::descriptor(), nullptr);
LegacyTypeAdapter type_adapter(&adapter, &adapter);
LegacyTypeAdapter type_adapter(&adapter);

EXPECT_EQ(type_adapter.access_apis(), &adapter);
EXPECT_EQ(type_adapter.mutation_apis(), &adapter);
}

} // namespace
Expand Down
16 changes: 2 additions & 14 deletions eval/public/structs/legacy_type_info_apis.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ namespace google::api::expr::runtime {

// Forward declared to resolve cyclic dependency.
class LegacyTypeAccessApis;
class LegacyTypeMutationApis;

// Forward declare permitted subclasses.
class DucktypedMessageAdapter;
Expand All @@ -40,8 +39,8 @@ class TrivialTypeInfo;
// Provides ability to obtain field access apis, type info, and debug
// representation of a message.
//
// The message parameter may wrap a nullptr to request generic accessors /
// mutators for the TypeInfo instance if it is available.
// The message parameter may wrap a nullptr to request generic accessors for
// the TypeInfo instance if it is available.
//
// This is implemented as a separate class from LegacyTypeAccessApis to resolve
// cyclic dependency between CelValue (which needs to access these apis to
Expand Down Expand Up @@ -87,17 +86,6 @@ class LegacyTypeInfoApis {
virtual const LegacyTypeAccessApis* GetAccessApis(
const MessageWrapper& wrapped_message) const = 0;

// Return a pointer to the wrapped message's mutation api implementation.
//
// The CEL interpreter assumes that the returned pointer is owned externally
// and will outlive any CelValues created by the interpreter.
//
// Nullptr signals that the value does not provide mutation apis.
virtual const LegacyTypeMutationApis* GetMutationApis(
const MessageWrapper& wrapped_message [[maybe_unused]]) const {
return nullptr;
}

// Return a description of the underlying field if defined.
//
// The underlying string is expected to remain valid as long as the
Expand Down
2 changes: 1 addition & 1 deletion eval/public/structs/legacy_type_provider_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class LegacyTypeProviderTestImpl : public LegacyTypeProvider {
absl::optional<LegacyTypeAdapter> ProvideLegacyType(
absl::string_view name) const override {
if (name == "test") {
return LegacyTypeAdapter(nullptr, nullptr);
return LegacyTypeAdapter(nullptr);
}
return std::nullopt;
}
Expand Down
Loading
Loading