10
10
#include " absl/types/span.h"
11
11
#include " absl/types/variant.h"
12
12
#include " base/ast_internal.h"
13
+ #include " base/builtins.h"
13
14
#include " base/function.h"
14
15
#include " base/handle.h"
15
16
#include " base/internal/ast_impl.h"
16
17
#include " base/kind.h"
18
+ #include " base/type_provider.h"
17
19
#include " base/value.h"
18
20
#include " base/values/bytes_value.h"
19
21
#include " base/values/error_value.h"
25
27
#include " eval/eval/evaluator_core.h"
26
28
#include " eval/internal/errors.h"
27
29
#include " eval/internal/interop.h"
28
- #include " eval/public/activation.h"
29
- #include " eval/public/cel_builtins.h"
30
- #include " eval/public/cel_expression.h"
31
30
#include " eval/public/cel_value.h"
32
31
#include " eval/public/containers/container_backed_list_impl.h"
33
32
#include " extensions/protobuf/memory_manager.h"
34
33
#include " internal/status_macros.h"
34
+ #include " runtime/activation.h"
35
35
#include " runtime/function_overload_reference.h"
36
36
#include " runtime/function_registry.h"
37
37
38
38
namespace cel ::ast::internal {
39
39
40
40
namespace {
41
41
42
+ using ::cel::builtin::kAnd ;
43
+ using ::cel::builtin::kOr ;
44
+ using ::cel::builtin::kTernary ;
45
+ using ::cel::extensions::ProtoMemoryManager;
42
46
using ::cel::interop_internal::CreateErrorValueFromView;
43
47
using ::cel::interop_internal::CreateLegacyListValue;
44
48
using ::cel::interop_internal::CreateNoMatchingOverloadError;
45
49
using ::cel::interop_internal::ModernValueToLegacyValueOrDie;
46
- using ::google::api::expr::runtime::Activation;
47
- using ::google::api::expr::runtime::CelEvaluationListener;
48
- using ::google::api::expr::runtime::CelExpressionFlatEvaluationState;
49
50
using ::google::api::expr::runtime::CelValue;
50
51
using ::google::api::expr::runtime::ContainerBackedListImpl;
52
+ using ::google::api::expr::runtime::EvaluationListener;
51
53
using ::google::api::expr::runtime::ExecutionFrame;
52
54
using ::google::api::expr::runtime::ExecutionPath;
53
55
using ::google::api::expr::runtime::ExecutionPathView;
56
+ using ::google::api::expr::runtime::FlatExpressionEvaluatorState;
54
57
using ::google::api::expr::runtime::PlannerContext;
55
58
using ::google::api::expr::runtime::ProgramOptimizer;
56
59
using ::google::api::expr::runtime::Resolver;
57
- using ::google::api::expr::runtime::builtin::kAnd ;
58
- using ::google::api::expr::runtime::builtin::kOr ;
59
- using ::google::api::expr::runtime::builtin::kTernary ;
60
60
61
61
using ::google::protobuf::Arena;
62
62
@@ -201,11 +201,8 @@ class ConstantFoldingTransform {
201
201
}
202
202
// short-circuiting affects evaluation of logic combinators, so we do
203
203
// not fold them here
204
- if (!all_constant ||
205
- call_expr.function () == google::api::expr::runtime::builtin::kAnd ||
206
- call_expr.function () == google::api::expr::runtime::builtin::kOr ||
207
- call_expr.function () ==
208
- google::api::expr::runtime::builtin::kTernary ) {
204
+ if (!all_constant || call_expr.function () == cel::builtin::kAnd ||
205
+ call_expr.function () == kOr || call_expr.function () == kTernary ) {
209
206
return false ;
210
207
}
211
208
@@ -392,8 +389,11 @@ bool ConstantFoldingTransform::Transform(const Expr& expr, Expr& out_) {
392
389
393
390
class ConstantFoldingExtension : public ProgramOptimizer {
394
391
public:
395
- explicit ConstantFoldingExtension (google::protobuf::Arena* arena)
396
- : arena_(arena), state_(kDefaultStackLimit , arena) {}
392
+ explicit ConstantFoldingExtension (google::protobuf::Arena* arena,
393
+ const TypeProvider& type_provider)
394
+ : arena_(arena),
395
+ memory_manager_(arena),
396
+ state_(kDefaultStackLimit , type_provider, memory_manager_) {}
397
397
398
398
absl::Status OnPreVisit (google::api::expr::runtime::PlannerContext& context,
399
399
const Expr& node) override ;
@@ -410,9 +410,10 @@ class ConstantFoldingExtension : public ProgramOptimizer {
410
410
static constexpr size_t kDefaultStackLimit = 4 ;
411
411
412
412
google::protobuf::Arena* arena_;
413
+ ProtoMemoryManager memory_manager_;
413
414
Activation empty_;
414
- CelEvaluationListener null_listener_;
415
- CelExpressionFlatEvaluationState state_;
415
+ EvaluationListener null_listener_;
416
+ FlatExpressionEvaluatorState state_;
416
417
417
418
std::vector<IsConst> is_const_;
418
419
};
@@ -498,7 +499,7 @@ absl::Status ConstantFoldingExtension::OnPostVisit(PlannerContext& context,
498
499
node.const_expr ().constant_kind ());
499
500
} else {
500
501
ExecutionPathView subplan = context.GetSubplan (node);
501
- ExecutionFrame frame (subplan, empty_, context.options (), & state_);
502
+ ExecutionFrame frame (subplan, empty_, context.options (), state_);
502
503
state_.Reset ();
503
504
// Update stack size to accommodate sub expression.
504
505
// This only results in a vector resize if the new maxsize is greater than
@@ -531,8 +532,9 @@ void FoldConstants(
531
532
532
533
google::api::expr::runtime::ProgramOptimizerFactory
533
534
CreateConstantFoldingExtension (google::protobuf::Arena* arena) {
534
- return [=](PlannerContext&, const AstImpl&) {
535
- return std::make_unique<ConstantFoldingExtension>(arena);
535
+ return [=](PlannerContext& ctx, const AstImpl&) {
536
+ return std::make_unique<ConstantFoldingExtension>(
537
+ arena, ctx.type_registry ().GetTypeProvider ());
536
538
};
537
539
}
538
540
0 commit comments