1010#include " absl/types/span.h"
1111#include " absl/types/variant.h"
1212#include " base/ast_internal.h"
13+ #include " base/builtins.h"
1314#include " base/function.h"
1415#include " base/handle.h"
1516#include " base/internal/ast_impl.h"
1617#include " base/kind.h"
18+ #include " base/type_provider.h"
1719#include " base/value.h"
1820#include " base/values/bytes_value.h"
1921#include " base/values/error_value.h"
2527#include " eval/eval/evaluator_core.h"
2628#include " eval/internal/errors.h"
2729#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"
3130#include " eval/public/cel_value.h"
3231#include " eval/public/containers/container_backed_list_impl.h"
3332#include " extensions/protobuf/memory_manager.h"
3433#include " internal/status_macros.h"
34+ #include " runtime/activation.h"
3535#include " runtime/function_overload_reference.h"
3636#include " runtime/function_registry.h"
3737
3838namespace cel ::ast::internal {
3939
4040namespace {
4141
42+ using ::cel::builtin::kAnd ;
43+ using ::cel::builtin::kOr ;
44+ using ::cel::builtin::kTernary ;
45+ using ::cel::extensions::ProtoMemoryManager;
4246using ::cel::interop_internal::CreateErrorValueFromView;
4347using ::cel::interop_internal::CreateLegacyListValue;
4448using ::cel::interop_internal::CreateNoMatchingOverloadError;
4549using ::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;
4950using ::google::api::expr::runtime::CelValue;
5051using ::google::api::expr::runtime::ContainerBackedListImpl;
52+ using ::google::api::expr::runtime::EvaluationListener;
5153using ::google::api::expr::runtime::ExecutionFrame;
5254using ::google::api::expr::runtime::ExecutionPath;
5355using ::google::api::expr::runtime::ExecutionPathView;
56+ using ::google::api::expr::runtime::FlatExpressionEvaluatorState;
5457using ::google::api::expr::runtime::PlannerContext;
5558using ::google::api::expr::runtime::ProgramOptimizer;
5659using ::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 ;
6060
6161using ::google::protobuf::Arena;
6262
@@ -201,11 +201,8 @@ class ConstantFoldingTransform {
201201 }
202202 // short-circuiting affects evaluation of logic combinators, so we do
203203 // 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 ) {
209206 return false ;
210207 }
211208
@@ -392,8 +389,11 @@ bool ConstantFoldingTransform::Transform(const Expr& expr, Expr& out_) {
392389
393390class ConstantFoldingExtension : public ProgramOptimizer {
394391 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_) {}
397397
398398 absl::Status OnPreVisit (google::api::expr::runtime::PlannerContext& context,
399399 const Expr& node) override ;
@@ -410,9 +410,10 @@ class ConstantFoldingExtension : public ProgramOptimizer {
410410 static constexpr size_t kDefaultStackLimit = 4 ;
411411
412412 google::protobuf::Arena* arena_;
413+ ProtoMemoryManager memory_manager_;
413414 Activation empty_;
414- CelEvaluationListener null_listener_;
415- CelExpressionFlatEvaluationState state_;
415+ EvaluationListener null_listener_;
416+ FlatExpressionEvaluatorState state_;
416417
417418 std::vector<IsConst> is_const_;
418419};
@@ -498,7 +499,7 @@ absl::Status ConstantFoldingExtension::OnPostVisit(PlannerContext& context,
498499 node.const_expr ().constant_kind ());
499500 } else {
500501 ExecutionPathView subplan = context.GetSubplan (node);
501- ExecutionFrame frame (subplan, empty_, context.options (), & state_);
502+ ExecutionFrame frame (subplan, empty_, context.options (), state_);
502503 state_.Reset ();
503504 // Update stack size to accommodate sub expression.
504505 // This only results in a vector resize if the new maxsize is greater than
@@ -531,8 +532,9 @@ void FoldConstants(
531532
532533google::api::expr::runtime::ProgramOptimizerFactory
533534CreateConstantFoldingExtension (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 ());
536538 };
537539}
538540
0 commit comments