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
4 changes: 2 additions & 2 deletions eval/compiler/constant_folding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,18 +201,18 @@ absl::Status ConstantFoldingExtension::OnPostVisit(PlannerContext& context,
// This subexpression is already optimized out or suppressed.
return absl::OkStatus();
}
// copy string to managed handle if backed by the original program.
// Ensure that string constants are copied to the constant folding arena
Value value;
if (node.has_const_expr()) {
CEL_ASSIGN_OR_RETURN(value,
ConvertConstant(node.const_expr(), state_.arena()));
} else {
ExecutionFrame frame(subplan, empty_, context.options(), state_);
state_.Reset();
// Update stack size to accommodate sub expression.
// This only results in a vector resize if the new maxsize is greater than
// the current capacity.
state_.value_stack().SetMaxSize(subplan.size());
ExecutionFrame frame(subplan, empty_, context.options(), state_);

auto result = frame.Evaluate();
// If this would be a runtime error, then don't adjust the program plan, but
Expand Down
4 changes: 4 additions & 0 deletions eval/eval/evaluator_core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@
namespace google::api::expr::runtime {

void FlatExpressionEvaluatorState::Reset() {
if (!dirty_) {
return;
}
value_stack_.Clear();
iterator_stack_.Clear();
comprehension_slots_.Reset();
dirty_ = false;
}

const ExpressionStep* ExecutionFrame::NextSlow() {
Expand Down
7 changes: 6 additions & 1 deletion eval/eval/evaluator_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ class FlatExpressionEvaluatorState {
arena_(arena) {}

void Reset();
void MarkDirty() { dirty_ = true; }

EvaluatorStack& value_stack() { return value_stack_; }

Expand Down Expand Up @@ -527,6 +528,7 @@ class FlatExpressionEvaluatorState {
const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool_;
google::protobuf::MessageFactory* absl_nullability_unknown message_factory_ = nullptr;
google::protobuf::Arena* absl_nullability_unknown arena_ = nullptr;
bool dirty_ = false;
};

// Context needed for evaluation. This is sufficient for supporting
Expand Down Expand Up @@ -728,7 +730,9 @@ class ExecutionFrame : public ExecutionFrameBase {
execution_path_(flat),
value_stack_(&state.value_stack()),
iterator_stack_(&state.iterator_stack()),
subexpressions_(&execution_path_, 1) {}
subexpressions_(&execution_path_, 1) {
state.MarkDirty();
}

ExecutionFrame(
absl::Span<const ExecutionPathView> subexpressions,
Expand All @@ -746,6 +750,7 @@ class ExecutionFrame : public ExecutionFrameBase {
iterator_stack_(&state.iterator_stack()),
subexpressions_(subexpressions) {
ABSL_DCHECK(!subexpressions.empty());
state.MarkDirty();
}

// Returns next expression to evaluate.
Expand Down
Loading