Skip to content

Commit e7fe362

Browse files
jnthntatumcopybara-github
authored andcommitted
Drop const qualification on built cel::Runtime.
Const qualification doesn't help much here and makes working with the type a bit awkward in some cases. Added some comments on cases that can cause problems. PiperOrigin-RevId: 826247250
1 parent 7519eb1 commit e7fe362

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

runtime/runtime.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ class TraceableProgram : public Program {
142142
//
143143
// Runtime instances should be created from a RuntimeBuilder rather than
144144
// instantiated directly.
145+
//
146+
// Implementations provided by CEL will be thread-compatible, but write
147+
// operations on the underlying environment (TypeRegistry, FunctionRegistry) or
148+
// on the implementation via down casting must be synchronized by the caller and
149+
// may invalidate any Programs created from the Runtime.
145150
class Runtime {
146151
public:
147152
struct CreateProgramOptions {

runtime/runtime_builder.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <utility>
2020

2121
#include "absl/base/nullability.h"
22+
#include "absl/log/absl_check.h"
2223
#include "absl/status/statusor.h"
2324
#include "runtime/function_registry.h"
2425
#include "runtime/runtime.h"
@@ -42,8 +43,6 @@ absl::StatusOr<RuntimeBuilder> CreateRuntimeBuilder(
4243
// RuntimeBuilder provides mutable accessors to configure a new runtime.
4344
//
4445
// Instances of this class are consumed when built.
45-
//
46-
// This class is move-only.
4746
class RuntimeBuilder {
4847
public:
4948
// Move-only
@@ -52,13 +51,21 @@ class RuntimeBuilder {
5251
RuntimeBuilder(RuntimeBuilder&&) = default;
5352
RuntimeBuilder& operator=(RuntimeBuilder&&) = default;
5453

55-
TypeRegistry& type_registry() { return *type_registry_; }
56-
FunctionRegistry& function_registry() { return *function_registry_; }
54+
TypeRegistry& type_registry() {
55+
ABSL_DCHECK(runtime_ != nullptr);
56+
return *type_registry_;
57+
}
58+
59+
FunctionRegistry& function_registry() {
60+
ABSL_DCHECK(runtime_ != nullptr);
61+
return *function_registry_;
62+
}
5763

5864
// Return the built runtime.
65+
//
5966
// The builder is left in an undefined state after this call and cannot be
6067
// reused.
61-
absl::StatusOr<std::unique_ptr<const Runtime>> Build() && {
68+
absl::StatusOr<std::unique_ptr<Runtime>> Build() && {
6269
return std::move(runtime_);
6370
}
6471

0 commit comments

Comments
 (0)