Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add optimization hints to EvaluatorStack and switch some to FATAL #594

Merged
merged 1 commit into from
Feb 7, 2024
Merged
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
27 changes: 20 additions & 7 deletions eval/eval/evaluator_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class EvaluatorStack {
// Checking that stack has enough elements is caller's responsibility.
// Please note that calls to Push may invalidate returned Span object.
absl::Span<const cel::Value> GetSpan(size_t size) const {
if (!HasEnough(size)) {
ABSL_LOG(ERROR) << "Requested span size (" << size
if (ABSL_PREDICT_FALSE(!HasEnough(size))) {
ABSL_LOG(FATAL) << "Requested span size (" << size
<< ") exceeds current stack size: " << current_size_;
}
return absl::Span<const cel::Value>(stack_.data() + current_size_ - size,
Expand All @@ -57,24 +57,37 @@ class EvaluatorStack {
// Checking that stack has enough elements is caller's responsibility.
// Please note that calls to Push may invalidate returned Span object.
absl::Span<const AttributeTrail> GetAttributeSpan(size_t size) const {
if (ABSL_PREDICT_FALSE(!HasEnough(size))) {
ABSL_LOG(FATAL) << "Requested span size (" << size
<< ") exceeds current stack size: " << current_size_;
}
return absl::Span<const AttributeTrail>(
attribute_stack_.data() + current_size_ - size, size);
}

// Peeks the last element of the stack.
// Checking that stack is not empty is caller's responsibility.
cel::Value& Peek() {
if (ABSL_PREDICT_FALSE(empty())) {
ABSL_LOG(FATAL) << "Peeking on empty EvaluatorStack";
}
return stack_[current_size_ - 1];
}

// Peeks the last element of the stack.
// Checking that stack is not empty is caller's responsibility.
const cel::Value& Peek() const {
if (empty()) {
ABSL_LOG(ERROR) << "Peeking on empty EvaluatorStack";
if (ABSL_PREDICT_FALSE(empty())) {
ABSL_LOG(FATAL) << "Peeking on empty EvaluatorStack";
}
return stack_[current_size_ - 1];
}

// Peeks the last element of the attribute stack.
// Checking that stack is not empty is caller's responsibility.
const AttributeTrail& PeekAttribute() const {
if (empty()) {
ABSL_LOG(ERROR) << "Peeking on empty EvaluatorStack";
if (ABSL_PREDICT_FALSE(empty())) {
ABSL_LOG(FATAL) << "Peeking on empty EvaluatorStack";
}
return attribute_stack_[current_size_ - 1];
}
Expand All @@ -83,7 +96,7 @@ class EvaluatorStack {
// Checking that stack has enough elements is caller's responsibility.
void Pop(size_t size) {
if (ABSL_PREDICT_FALSE(!HasEnough(size))) {
ABSL_LOG(ERROR) << "Trying to pop more elements (" << size
ABSL_LOG(FATAL) << "Trying to pop more elements (" << size
<< ") than the current stack size: " << current_size_;
}
while (size > 0) {
Expand Down