diff --git a/runtime/BUILD b/runtime/BUILD index 3079bcdd0..cfd8cd361 100644 --- a/runtime/BUILD +++ b/runtime/BUILD @@ -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", ], diff --git a/runtime/runtime.h b/runtime/runtime.h index c06301e99..a112d6aa8 100644 --- a/runtime/runtime.h +++ b/runtime/runtime.h @@ -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 { diff --git a/runtime/runtime_builder.h b/runtime/runtime_builder.h index a19ddd531..ff1db7b82 100644 --- a/runtime/runtime_builder.h +++ b/runtime/runtime_builder.h @@ -19,6 +19,7 @@ #include #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" @@ -42,8 +43,6 @@ absl::StatusOr 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 @@ -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> Build() && { + absl::StatusOr> Build() && { return std::move(runtime_); }