Skip to content
Merged
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: 1 addition & 0 deletions runtime/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ cc_library(
":runtime_options",
":type_registry",
"@com_google_absl//absl/base:nullability",
"@com_google_absl//absl/log:absl_check",
"@com_google_absl//absl/status:statusor",
"@com_google_protobuf//:protobuf",
],
Expand Down
5 changes: 5 additions & 0 deletions runtime/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ class TraceableProgram : public Program {
//
// Runtime instances should be created from a RuntimeBuilder rather than
// instantiated directly.
//
// Implementations provided by CEL will be thread-compatible, but write
// operations on the underlying environment (TypeRegistry, FunctionRegistry) or
// on the implementation via down casting must be synchronized by the caller and
// may invalidate any Programs created from the Runtime.
class Runtime {
public:
struct CreateProgramOptions {
Expand Down
17 changes: 12 additions & 5 deletions runtime/runtime_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <utility>

#include "absl/base/nullability.h"
#include "absl/log/absl_check.h"
#include "absl/status/statusor.h"
#include "runtime/function_registry.h"
#include "runtime/runtime.h"
Expand All @@ -42,8 +43,6 @@ absl::StatusOr<RuntimeBuilder> CreateRuntimeBuilder(
// RuntimeBuilder provides mutable accessors to configure a new runtime.
//
// Instances of this class are consumed when built.
//
// This class is move-only.
class RuntimeBuilder {
public:
// Move-only
Expand All @@ -52,13 +51,21 @@ class RuntimeBuilder {
RuntimeBuilder(RuntimeBuilder&&) = default;
RuntimeBuilder& operator=(RuntimeBuilder&&) = default;

TypeRegistry& type_registry() { return *type_registry_; }
FunctionRegistry& function_registry() { return *function_registry_; }
TypeRegistry& type_registry() {
ABSL_DCHECK(runtime_ != nullptr);
return *type_registry_;
}

FunctionRegistry& function_registry() {
ABSL_DCHECK(runtime_ != nullptr);
return *function_registry_;
}

// Return the built runtime.
//
// The builder is left in an undefined state after this call and cannot be
// reused.
absl::StatusOr<std::unique_ptr<const Runtime>> Build() && {
absl::StatusOr<std::unique_ptr<Runtime>> Build() && {
return std::move(runtime_);
}

Expand Down