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
6 changes: 3 additions & 3 deletions eval/compiler/cel_expression_builder_flat_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ namespace google::api::expr::runtime {
class CelExpressionBuilderFlatImpl : public CelExpressionBuilder {
public:
CelExpressionBuilderFlatImpl(
absl::Nonnull<std::shared_ptr<cel::runtime_internal::RuntimeEnv>> env,
ABSL_NONNULL std::shared_ptr<cel::runtime_internal::RuntimeEnv> env,
const cel::RuntimeOptions& options)
: env_(std::move(env)),
flat_expr_builder_(env_, options, /*use_legacy_type_provider=*/true) {
ABSL_DCHECK(env_->IsInitialized());
}

explicit CelExpressionBuilderFlatImpl(
absl::Nonnull<std::shared_ptr<cel::runtime_internal::RuntimeEnv>> env)
ABSL_NONNULL std::shared_ptr<cel::runtime_internal::RuntimeEnv> env)
: CelExpressionBuilderFlatImpl(std::move(env), cel::RuntimeOptions()) {}

absl::StatusOr<std::unique_ptr<CelExpression>> CreateExpression(
Expand Down Expand Up @@ -99,7 +99,7 @@ class CelExpressionBuilderFlatImpl : public CelExpressionBuilder {
std::unique_ptr<cel::Ast> converted_ast,
std::vector<absl::Status>* warnings) const;

absl::Nonnull<std::shared_ptr<cel::runtime_internal::RuntimeEnv>> env_;
ABSL_NONNULL std::shared_ptr<cel::runtime_internal::RuntimeEnv> env_;
FlatExprBuilder flat_expr_builder_;
};

Expand Down
23 changes: 11 additions & 12 deletions eval/compiler/constant_folding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ enum class IsConst {
class ConstantFoldingExtension : public ProgramOptimizer {
public:
ConstantFoldingExtension(
absl::Nonnull<const google::protobuf::DescriptorPool*> descriptor_pool,
absl::Nullable<std::shared_ptr<google::protobuf::Arena>> shared_arena,
absl::Nonnull<google::protobuf::Arena*> arena,
absl::Nullable<std::shared_ptr<google::protobuf::MessageFactory>>
const google::protobuf::DescriptorPool* ABSL_NONNULL descriptor_pool,
ABSL_NULLABLE std::shared_ptr<google::protobuf::Arena> shared_arena,
google::protobuf::Arena* ABSL_NONNULL arena,
ABSL_NULLABLE std::shared_ptr<google::protobuf::MessageFactory>
shared_message_factory,
absl::Nonnull<google::protobuf::MessageFactory*> message_factory,
google::protobuf::MessageFactory* ABSL_NONNULL message_factory,
const TypeProvider& type_provider)
: shared_arena_(std::move(shared_arena)),
shared_message_factory_(std::move(shared_message_factory)),
Expand All @@ -105,10 +105,9 @@ class ConstantFoldingExtension : public ProgramOptimizer {
// if the comprehension variables are only used in a const way.
static constexpr size_t kComprehensionSlotCount = 0;

absl::Nullable<std::shared_ptr<google::protobuf::Arena>> shared_arena_;
ABSL_NULLABLE std::shared_ptr<google::protobuf::Arena> shared_arena_;
ABSL_ATTRIBUTE_UNUSED
absl::Nullable<std::shared_ptr<google::protobuf::MessageFactory>>
shared_message_factory_;
ABSL_NULLABLE std::shared_ptr<google::protobuf::MessageFactory> shared_message_factory_;
Activation empty_;
FlatExpressionEvaluatorState state_;

Expand Down Expand Up @@ -252,8 +251,8 @@ absl::Status ConstantFoldingExtension::OnPostVisit(PlannerContext& context,
} // namespace

ProgramOptimizerFactory CreateConstantFoldingOptimizer(
absl::Nullable<std::shared_ptr<google::protobuf::Arena>> arena,
absl::Nullable<std::shared_ptr<google::protobuf::MessageFactory>> message_factory) {
ABSL_NULLABLE std::shared_ptr<google::protobuf::Arena> arena,
ABSL_NULLABLE std::shared_ptr<google::protobuf::MessageFactory> message_factory) {
return
[shared_arena = std::move(arena),
shared_message_factory = std::move(message_factory)](
Expand All @@ -262,11 +261,11 @@ ProgramOptimizerFactory CreateConstantFoldingOptimizer(
// If one was explicitly provided during planning or none was explicitly
// provided during configuration, request one from the planning context.
// Otherwise use the one provided during configuration.
absl::Nonnull<google::protobuf::Arena*> arena =
google::protobuf::Arena* ABSL_NONNULL arena =
context.HasExplicitArena() || shared_arena == nullptr
? context.MutableArena()
: shared_arena.get();
absl::Nonnull<google::protobuf::MessageFactory*> message_factory =
google::protobuf::MessageFactory* ABSL_NONNULL message_factory =
context.HasExplicitMessageFactory() ||
shared_message_factory == nullptr
? context.MutableMessageFactory()
Expand Down
4 changes: 2 additions & 2 deletions eval/compiler/constant_folding.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ namespace cel::runtime_internal {
// extension.
google::api::expr::runtime::ProgramOptimizerFactory
CreateConstantFoldingOptimizer(
absl::Nullable<std::shared_ptr<google::protobuf::Arena>> arena = nullptr,
absl::Nullable<std::shared_ptr<google::protobuf::MessageFactory>> message_factory =
ABSL_NULLABLE std::shared_ptr<google::protobuf::Arena> arena = nullptr,
ABSL_NULLABLE std::shared_ptr<google::protobuf::MessageFactory> message_factory =
nullptr);

} // namespace cel::runtime_internal
Expand Down
2 changes: 1 addition & 1 deletion eval/compiler/constant_folding_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class UpdatedConstantFoldingTest : public testing::Test {
type_registry_.GetComposedTypeProvider()) {}

protected:
absl::Nonnull<std::shared_ptr<RuntimeEnv>> env_;
ABSL_NONNULL std::shared_ptr<RuntimeEnv> env_;
google::protobuf::Arena arena_;
cel::FunctionRegistry& function_registry_;
cel::TypeRegistry& type_registry_;
Expand Down
8 changes: 3 additions & 5 deletions eval/compiler/flat_expr_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ namespace google::api::expr::runtime {
class FlatExprBuilder {
public:
FlatExprBuilder(
absl::Nonnull<std::shared_ptr<const cel::runtime_internal::RuntimeEnv>>
env,
ABSL_NONNULL std::shared_ptr<const cel::runtime_internal::RuntimeEnv> env,
const cel::RuntimeOptions& options, bool use_legacy_type_provider = false)
: env_(std::move(env)),
options_(options),
Expand All @@ -55,8 +54,7 @@ class FlatExprBuilder {
use_legacy_type_provider_(use_legacy_type_provider) {}

FlatExprBuilder(
absl::Nonnull<std::shared_ptr<const cel::runtime_internal::RuntimeEnv>>
env,
ABSL_NONNULL std::shared_ptr<const cel::runtime_internal::RuntimeEnv> env,
const cel::FunctionRegistry& function_registry,
const cel::TypeRegistry& type_registry,
const cel::RuntimeOptions& options, bool use_legacy_type_provider = false)
Expand Down Expand Up @@ -98,7 +96,7 @@ class FlatExprBuilder {
private:
const cel::TypeProvider& GetTypeProvider() const;

const absl::Nonnull<std::shared_ptr<const cel::runtime_internal::RuntimeEnv>>
const ABSL_NONNULL std::shared_ptr<const cel::runtime_internal::RuntimeEnv>
env_;

cel::RuntimeOptions options_;
Expand Down
6 changes: 3 additions & 3 deletions eval/compiler/flat_expr_builder_extensions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ std::vector<ExecutionPath> ProgramBuilder::FlattenSubexpressions() {
return out;
}

absl::Nullable<Subexpression*> ProgramBuilder::EnterSubexpression(
Subexpression* ABSL_NULLABLE ProgramBuilder::EnterSubexpression(
const cel::Expr* expr, size_t size_hint) {
Subexpression* subexpr = MakeSubexpression(expr);
if (subexpr == nullptr) {
Expand All @@ -320,7 +320,7 @@ absl::Nullable<Subexpression*> ProgramBuilder::EnterSubexpression(
return subexpr;
}

absl::Nullable<Subexpression*> ProgramBuilder::ExitSubexpression(
Subexpression* ABSL_NULLABLE ProgramBuilder::ExitSubexpression(
const cel::Expr* expr) {
ABSL_DCHECK(expr == current_->self_);
ABSL_DCHECK(GetSubexpression(expr) == current_);
Expand All @@ -333,7 +333,7 @@ absl::Nullable<Subexpression*> ProgramBuilder::ExitSubexpression(
return result;
}

absl::Nullable<Subexpression*> ProgramBuilder::GetSubexpression(
Subexpression* ABSL_NULLABLE ProgramBuilder::GetSubexpression(
const cel::Expr* expr) {
auto it = subprogram_map_.find(expr);
if (it == subprogram_map_.end()) {
Expand Down
36 changes: 18 additions & 18 deletions eval/compiler/flat_expr_builder_extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ProgramBuilder {
class Subexpression {
private:
using Element = absl::variant<std::unique_ptr<ExpressionStep>,
absl::Nonnull<Subexpression*>>;
Subexpression* ABSL_NONNULL>;

using TreePlan = std::vector<Element>;
using FlattenedPlan = std::vector<std::unique_ptr<const ExpressionStep>>;
Expand Down Expand Up @@ -120,7 +120,7 @@ class ProgramBuilder {
return true;
}

void AddSubexpression(absl::Nonnull<Subexpression*> expr) {
void AddSubexpression(Subexpression* ABSL_NONNULL expr) {
ABSL_DCHECK(absl::holds_alternative<TreePlan>(program_));
ABSL_DCHECK(owner_ == expr->owner_);
elements().push_back(expr);
Expand Down Expand Up @@ -187,7 +187,7 @@ class ProgramBuilder {
// The expression is removed from the elements array.
//
// Returns nullptr if child is not an element of this subexpression.
absl::Nullable<Subexpression*> ExtractChild(Subexpression* child);
Subexpression* ABSL_NULLABLE ExtractChild(Subexpression* child);

// Flatten the subexpression.
//
Expand Down Expand Up @@ -217,7 +217,7 @@ class ProgramBuilder {
absl::variant<TreePlan, FlattenedPlan, RecursiveProgram> program_;

const cel::Expr* self_;
absl::Nullable<const cel::Expr*> parent_;
const cel::Expr* ABSL_NULLABLE parent_;
ProgramBuilder* owner_;
};

Expand All @@ -239,7 +239,7 @@ class ProgramBuilder {
// added.
//
// May return null if the builder is not currently planning an expression.
absl::Nullable<Subexpression*> current() { return current_; }
Subexpression* ABSL_NULLABLE current() { return current_; }

// Enter a subexpression context.
//
Expand All @@ -250,26 +250,26 @@ class ProgramBuilder {
//
// May return nullptr if the expression is already indexed in the program
// builder.
absl::Nullable<Subexpression*> EnterSubexpression(const cel::Expr* expr,
size_t size_hint = 0);
Subexpression* ABSL_NULLABLE EnterSubexpression(const cel::Expr* expr,
size_t size_hint = 0);

// Exit a subexpression context.
//
// Sets insertion point to parent.
//
// Returns the new current() value or nullptr if called out of order.
absl::Nullable<Subexpression*> ExitSubexpression(const cel::Expr* expr);
Subexpression* ABSL_NULLABLE ExitSubexpression(const cel::Expr* expr);

// Return the subexpression mapped to the given expression.
//
// Returns nullptr if the mapping doesn't exist either due to the
// program being overwritten or not encountering the expression.
absl::Nullable<Subexpression*> GetSubexpression(const cel::Expr* expr);
Subexpression* ABSL_NULLABLE GetSubexpression(const cel::Expr* expr);

// Return the extracted subexpression mapped to the given index.
//
// Returns nullptr if the mapping doesn't exist
absl::Nullable<Subexpression*> GetExtractedSubexpression(size_t index) {
Subexpression* ABSL_NULLABLE GetExtractedSubexpression(size_t index) {
if (index >= extracted_subexpressions_.size()) {
return nullptr;
}
Expand All @@ -289,13 +289,13 @@ class ProgramBuilder {

private:
static std::vector<std::unique_ptr<const ExpressionStep>>
FlattenSubexpression(absl::Nonnull<Subexpression*> expr);
FlattenSubexpression(Subexpression* ABSL_NONNULL expr);

absl::Nullable<Subexpression*> MakeSubexpression(const cel::Expr* expr);
Subexpression* ABSL_NULLABLE MakeSubexpression(const cel::Expr* expr);

absl::Nullable<Subexpression*> root_;
std::vector<absl::Nonnull<Subexpression*>> extracted_subexpressions_;
absl::Nullable<Subexpression*> current_;
Subexpression* ABSL_NULLABLE root_;
std::vector<Subexpression* ABSL_NONNULL> extracted_subexpressions_;
Subexpression* ABSL_NULLABLE current_;
SubprogramMap subprogram_map_;
};

Expand Down Expand Up @@ -391,14 +391,14 @@ class PlannerContext {
return issue_collector_;
}

absl::Nonnull<const google::protobuf::DescriptorPool*> descriptor_pool() const {
const google::protobuf::DescriptorPool* ABSL_NONNULL descriptor_pool() const {
return environment_->descriptor_pool.get();
}

// Returns `true` if an arena was explicitly provided during planning.
bool HasExplicitArena() const { return explicit_arena_; }

absl::Nonnull<google::protobuf::Arena*> MutableArena() {
google::protobuf::Arena* ABSL_NONNULL MutableArena() {
if (!explicit_arena_ && arena_ == nullptr) {
arena_ = std::make_shared<google::protobuf::Arena>();
}
Expand All @@ -410,7 +410,7 @@ class PlannerContext {
// planning.
bool HasExplicitMessageFactory() const { return message_factory_ != nullptr; }

absl::Nonnull<google::protobuf::MessageFactory*> MutableMessageFactory() {
google::protobuf::MessageFactory* ABSL_NONNULL MutableMessageFactory() {
return HasExplicitMessageFactory() ? message_factory_.get()
: environment_->MutableMessageFactory();
}
Expand Down
2 changes: 1 addition & 1 deletion eval/compiler/flat_expr_builder_extensions_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class PlannerContextTest : public testing::Test {
issue_collector_(RuntimeIssue::Severity::kError) {}

protected:
absl::Nonnull<std::shared_ptr<RuntimeEnv>> env_;
ABSL_NONNULL std::shared_ptr<RuntimeEnv> env_;
cel::TypeRegistry& type_registry_;
cel::FunctionRegistry& function_registry_;
cel::RuntimeOptions options_;
Expand Down
6 changes: 3 additions & 3 deletions eval/compiler/flat_expr_builder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2395,9 +2395,9 @@ struct ConstantFoldingTestCase {

class UnknownFunctionImpl : public cel::Function {
absl::StatusOr<Value> Invoke(absl::Span<const Value> args,
absl::Nonnull<const google::protobuf::DescriptorPool*>,
absl::Nonnull<google::protobuf::MessageFactory*>,
absl::Nonnull<google::protobuf::Arena*>) const override {
const google::protobuf::DescriptorPool* ABSL_NONNULL,
google::protobuf::MessageFactory* ABSL_NONNULL,
google::protobuf::Arena* ABSL_NONNULL) const override {
return cel::UnknownValue();
}
};
Expand Down
2 changes: 1 addition & 1 deletion eval/compiler/instrumentation_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class InstrumentationTest : public ::testing::Test {
}

protected:
absl::Nonnull<std::shared_ptr<RuntimeEnv>> env_;
ABSL_NONNULL std::shared_ptr<RuntimeEnv> env_;
cel::RuntimeOptions options_;
cel::FunctionRegistry& function_registry_;
cel::TypeRegistry& type_registry_;
Expand Down
6 changes: 3 additions & 3 deletions eval/compiler/regex_precompilation_optimization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class RegexPrecompilationOptimization : public ProgramOptimizer {
private:
absl::optional<std::string> GetConstantString(
PlannerContext& context,
absl::Nullable<ProgramBuilder::Subexpression*> subexpression,
ProgramBuilder::Subexpression* ABSL_NULLABLE subexpression,
const Expr& call_expr, const Expr& re_expr) const {
if (re_expr.has_const_expr() && re_expr.const_expr().has_string_value()) {
return re_expr.const_expr().string_value();
Expand Down Expand Up @@ -215,7 +215,7 @@ class RegexPrecompilationOptimization : public ProgramOptimizer {

absl::Status RewritePlan(
PlannerContext& context,
absl::Nonnull<ProgramBuilder::Subexpression*> subexpression,
ProgramBuilder::Subexpression* ABSL_NONNULL subexpression,
const Expr& call, const Expr& subject,
std::shared_ptr<const RE2> regex_program) {
if (subexpression->IsRecursive()) {
Expand All @@ -227,7 +227,7 @@ class RegexPrecompilationOptimization : public ProgramOptimizer {
}

absl::Status RewriteRecursivePlan(
absl::Nonnull<ProgramBuilder::Subexpression*> subexpression,
ProgramBuilder::Subexpression* ABSL_NONNULL subexpression,
const Expr& call, const Expr& subject,
std::shared_ptr<const RE2> regex_program) {
auto program = subexpression->ExtractRecursiveProgram();
Expand Down
2 changes: 1 addition & 1 deletion eval/compiler/regex_precompilation_optimization_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class RegexPrecompilationExtensionTest : public testing::TestWithParam<bool> {
};
}

absl::Nonnull<std::shared_ptr<RuntimeEnv>> env_;
ABSL_NONNULL std::shared_ptr<RuntimeEnv> env_;
CelExpressionBuilderFlatImpl builder_;
CelTypeRegistry& type_registry_;
CelFunctionRegistry& function_registry_;
Expand Down
12 changes: 6 additions & 6 deletions eval/eval/cel_expression_flat_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ using ::cel::runtime_internal::RuntimeEnv;
EvaluationListener AdaptListener(const CelEvaluationListener& listener) {
if (!listener) return nullptr;
return [&](int64_t expr_id, const Value& value,
absl::Nonnull<const google::protobuf::DescriptorPool*>,
absl::Nonnull<google::protobuf::MessageFactory*>,
absl::Nonnull<google::protobuf::Arena*> arena) -> absl::Status {
const google::protobuf::DescriptorPool* ABSL_NONNULL,
google::protobuf::MessageFactory* ABSL_NONNULL,
google::protobuf::Arena* ABSL_NONNULL arena) -> absl::Status {
if (value->Is<cel::OpaqueValue>()) {
// Opaque types are used to implement some optimized operations.
// These aren't representable as legacy values and shouldn't be
Expand All @@ -68,8 +68,8 @@ EvaluationListener AdaptListener(const CelEvaluationListener& listener) {

CelExpressionFlatEvaluationState::CelExpressionFlatEvaluationState(
google::protobuf::Arena* arena,
absl::Nonnull<const google::protobuf::DescriptorPool*> descriptor_pool,
absl::Nonnull<google::protobuf::MessageFactory*> message_factory,
const google::protobuf::DescriptorPool* ABSL_NONNULL descriptor_pool,
google::protobuf::MessageFactory* ABSL_NONNULL message_factory,
const FlatExpression& expression)
: state_(expression.MakeEvaluatorState(descriptor_pool, message_factory,
arena)) {}
Expand Down Expand Up @@ -105,7 +105,7 @@ absl::StatusOr<CelValue> CelExpressionFlatImpl::Evaluate(

absl::StatusOr<std::unique_ptr<CelExpressionRecursiveImpl>>
CelExpressionRecursiveImpl::Create(
absl::Nonnull<std::shared_ptr<const RuntimeEnv>> env,
ABSL_NONNULL std::shared_ptr<const RuntimeEnv> env,
FlatExpression flat_expr) {
if (flat_expr.path().empty() ||
flat_expr.path().front()->GetNativeTypeId() !=
Expand Down
Loading