Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Update ManagedValueFactory after cel::Value rework. #738

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
1 change: 0 additions & 1 deletion common/values/legacy_value_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "common/types/legacy_type_manager.h"
#include "common/value.h"
#include "common/value_manager.h"
#include "common/values/legacy_type_reflector.h"

namespace cel::common_internal {

Expand Down
19 changes: 13 additions & 6 deletions runtime/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ cc_library(
deps = [
":activation_interface",
":runtime_issue",
"//base:ast",
"//base:data",
"//common:ast",
"//common:native_type",
"//common:value",
"@com_google_absl//absl/functional:any_invocable",
Expand All @@ -204,13 +203,20 @@ cc_library(
)

cc_library(
name = "managed_value_factory",
hdrs = ["managed_value_factory.h"],
name = "runtime_value_manager",
hdrs = ["runtime_value_manager.h"],
deps = [
"//base:data",
"//common:memory",
"//common:type",
"//common:value",
"@com_google_absl//absl/base:core_headers",
],
)

cc_library(
name = "managed_value_factory",
hdrs = ["managed_value_factory.h"],
deps = [
":runtime_value_manager",
],
)

Expand Down Expand Up @@ -252,6 +258,7 @@ cc_test(
":standard_runtime_builder_factory",
"//common:memory",
"//common:source",
"//common:type",
"//common:value",
"//common:value_testing",
"//extensions:bindings_ext",
Expand Down
30 changes: 5 additions & 25 deletions runtime/managed_value_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,14 @@
#ifndef THIRD_PARTY_CEL_CPP_RUNTIME_MANAGED_VALUE_FACTORY_H_
#define THIRD_PARTY_CEL_CPP_RUNTIME_MANAGED_VALUE_FACTORY_H_

#include "base/type_provider.h"
#include "common/memory.h"
#include "common/type_factory.h"
#include "common/type_manager.h"
#include "common/value_manager.h"
#include "common/values/legacy_value_manager.h"
#include "runtime/runtime_value_manager.h" // IWYU pragma: export

namespace cel {

// A convenience class for managing objects associated with a ValueManager.
class ManagedValueFactory {
public:
// type_provider and memory_manager must outlive the ManagedValueFactory.
ManagedValueFactory(const TypeProvider& type_provider,
MemoryManagerRef memory_manager)
: value_manager_(memory_manager, type_provider) {}

// Move-only
ManagedValueFactory(const ManagedValueFactory& other) = delete;
ManagedValueFactory& operator=(const ManagedValueFactory& other) = delete;
ManagedValueFactory(ManagedValueFactory&& other) = delete;
ManagedValueFactory& operator=(ManagedValueFactory&& other) = delete;

ValueManager& get() { return value_manager_; }

private:
common_internal::LegacyValueManager value_manager_;
};
// A convenience class for managing objects associated with a value manager.
//
// Must not outlive the runtime or program that provides the TypeReflector.
using ManagedValueFactory = RuntimeValueManager;

} // namespace cel

Expand Down
13 changes: 9 additions & 4 deletions runtime/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
#include "absl/functional/any_invocable.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "base/ast.h"
#include "base/type_provider.h"
#include "common/ast.h"
#include "common/native_type.h"
#include "common/type_reflector.h"
#include "common/value.h"
#include "common/value_manager.h"
#include "runtime/activation_interface.h"
Expand Down Expand Up @@ -75,7 +75,9 @@ class Program {
virtual absl::StatusOr<Value> Evaluate(const ActivationInterface& activation,
ValueManager& value_factory) const = 0;

virtual const TypeProvider& GetTypeProvider() const = 0;
// Returns the type provider associated with this program.
virtual const TypeReflector& GetTypeProvider() const
ABSL_ATTRIBUTE_LIFETIME_BOUND = 0;
};

// Representation for a traceable CEL expression.
Expand Down Expand Up @@ -142,7 +144,10 @@ class Runtime {
CreateTraceableProgram(std::unique_ptr<cel::Ast> ast,
const CreateProgramOptions& options) const = 0;

virtual const TypeProvider& GetTypeProvider() const = 0;
// Returns the type provider associated with this runtime, used for
// inspecting and creating extended types.
virtual const TypeReflector& GetTypeProvider() const
ABSL_ATTRIBUTE_LIFETIME_BOUND = 0;

private:
friend class runtime_internal::RuntimeFriendAccess;
Expand Down
51 changes: 51 additions & 0 deletions runtime/runtime_value_manager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef THIRD_PARTY_CEL_CPP_RUNTIME_RUNTIME_VALUE_MANAGER_H_
#define THIRD_PARTY_CEL_CPP_RUNTIME_RUNTIME_VALUE_MANAGER_H_

#include "absl/base/attributes.h"
#include "common/memory.h"
#include "common/type_reflector.h"
#include "common/value_manager.h"
#include "common/values/legacy_value_manager.h"

namespace cel {

// A convenience class for managing objects associated with a value manager.
//
// Must not outlive the runtime or program that provides the TypeReflector.
class RuntimeValueManager {
public:
// type_provider and memory_manager must outlive the ManagedValueFactory.
RuntimeValueManager(const TypeReflector& type_provider
ABSL_ATTRIBUTE_LIFETIME_BOUND,
MemoryManagerRef memory_manager)
: value_manager_(memory_manager, type_provider) {}

// Neither moveable nor copyable.
RuntimeValueManager(const RuntimeValueManager& other) = delete;
RuntimeValueManager& operator=(const RuntimeValueManager& other) = delete;
RuntimeValueManager(RuntimeValueManager&& other) = delete;
RuntimeValueManager& operator=(RuntimeValueManager&& other) = delete;

ValueManager& get() { return value_manager_; }

private:
common_internal::LegacyValueManager value_manager_;
};

} // namespace cel

#endif // THIRD_PARTY_CEL_CPP_RUNTIME_RUNTIME_VALUE_MANAGER_H_