Skip to content
Open
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
2 changes: 2 additions & 0 deletions common/type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include "common/types/types.h"
#include "google/protobuf/descriptor.h"

#undef GetMessage

namespace cel {

using ::google::protobuf::Descriptor;
Expand Down
6 changes: 6 additions & 0 deletions common/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
#include "google/protobuf/arena.h"
#include "google/protobuf/descriptor.h"

// GetMessage in windows API headers might be defined as a macro.
#pragma push_macro("GetMessage")
#undef GetMessage

namespace cel {

class Type;
Expand Down Expand Up @@ -1300,4 +1304,6 @@ Type LegacyRuntimeType(absl::string_view name);

} // namespace cel

#pragma pop_macro("GetMessage")

#endif // THIRD_PARTY_CEL_CPP_COMMON_TYPE_H_
2 changes: 2 additions & 0 deletions common/type_spec_resolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include "google/protobuf/arena.h"
#include "google/protobuf/descriptor.h"

#undef GetMessage

namespace cel {
namespace {

Expand Down
2 changes: 2 additions & 0 deletions common/types/struct_type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "common/type.h"
#include "common/types/types.h"

#undef GetMessage

namespace cel {

absl::string_view StructType::name() const {
Expand Down
5 changes: 5 additions & 0 deletions common/types/struct_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
#include "common/types/message_type.h"
#include "common/types/types.h"

#pragma push_macro("GetMessage")
#undef GetMessage

namespace cel {

class Type;
Expand Down Expand Up @@ -155,4 +158,6 @@ inline std::ostream& operator<<(std::ostream& out, const StructType& type) {

} // namespace cel

#pragma pop_macro("GetMessage")

#endif // THIRD_PARTY_CEL_CPP_COMMON_TYPES_STRUCT_TYPE_H_
2 changes: 2 additions & 0 deletions common/values/struct_value.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#include "google/protobuf/io/zero_copy_stream.h"
#include "google/protobuf/message.h"

#undef GetMessage

namespace cel {

StructType StructValue::GetRuntimeType() const {
Expand Down
5 changes: 5 additions & 0 deletions common/values/struct_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
#include "google/protobuf/io/zero_copy_stream.h"
#include "google/protobuf/message.h"

#pragma push_macro("GetMessage")
#undef GetMessage

namespace cel {

class StructValue;
Expand Down Expand Up @@ -370,4 +373,6 @@ using StructValueBuilderPtr = std::unique_ptr<StructValueBuilder>;

} // namespace cel

#pragma pop_macro("GetMessage")

#endif // THIRD_PARTY_CEL_CPP_COMMON_VALUES_STRUCT_VALUE_H_
2 changes: 2 additions & 0 deletions eval/compiler/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ cc_library(
":resolver",
"//base:ast",
"//base:data",
"//common:ast",
"//common:expr",
"//common:type",
"//common:type_spec_resolver",
"//common:value",
"//eval/eval:evaluator_core",
"//eval/eval:expression_step_logic",
Expand Down
8 changes: 1 addition & 7 deletions eval/compiler/flat_expr_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1878,13 +1878,7 @@ void FlatExprVisitor::MaybeResolveType(const cel::Expr& expr) {
if (it == type_map_.end()) {
return;
}
absl::StatusOr<cel::Type> type = cel::ConvertTypeSpecToType(
it->second, extension_context_.type_reflector(),
extension_context_.MutableArena());
if (!type.ok()) {
return;
}
extension_context_.SetResolvedType(expr.id(), *type);
extension_context_.TryResolveType(expr.id(), it->second);
}

size_t FlatExprVisitor::AddOrUpdateIdentifier(absl::string_view name) {
Expand Down
20 changes: 20 additions & 0 deletions eval/compiler/flat_expr_builder_extensions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
#include "eval/compiler/flat_expr_builder_extensions.h"

#include <cstddef>
#include <cstdint>
#include <iterator>
#include <memory>
#include <optional>
#include <utility>
#include <vector>

Expand All @@ -27,7 +29,10 @@
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/types/variant.h"
#include "common/ast.h"
#include "common/expr.h"
#include "common/type.h"
#include "common/type_spec_resolver.h"
#include "eval/eval/evaluator_core.h"

namespace google::api::expr::runtime {
Expand Down Expand Up @@ -350,6 +355,21 @@ absl::Status PlannerContext::ReplaceSubplan(const cel::Expr& node,
return absl::OkStatus();
}

std::optional<cel::Type> PlannerContext::TryResolveType(
int64_t expr_id, const cel::TypeSpec& ast_type) {
auto it = resolved_types_.find(expr_id);
if (it != resolved_types_.end()) {
return it->second;
}
absl::StatusOr<cel::Type> type =
cel::ConvertTypeSpecToType(ast_type, type_reflector_, MutableArena());
if (!type.ok()) {
return std::nullopt;
}
resolved_types_.insert(it, {expr_id, *type});
return *type;
}

void ProgramBuilder::Reset() {
root_ = nullptr;
current_ = nullptr;
Expand Down
3 changes: 3 additions & 0 deletions eval/compiler/flat_expr_builder_extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,9 @@ class PlannerContext {
return std::nullopt;
}

std::optional<cel::Type> TryResolveType(int64_t expr_id,
const cel::TypeSpec& ast_type);

void SetResolvedType(int64_t expr_id, cel::Type type) {
resolved_types_[expr_id] = std::move(type);
}
Expand Down
2 changes: 2 additions & 0 deletions eval/eval/select_step.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "google/protobuf/descriptor.h"
#include "google/protobuf/message.h"

#undef GetMessage

namespace google::api::expr::runtime {

namespace {
Expand Down
8 changes: 8 additions & 0 deletions extensions/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ cc_library(
"//common:expr",
"//common:function_descriptor",
"//common:kind",
"//common:legacy_value",
"//common:native_type",
"//common:type",
"//common:value",
Expand All @@ -337,6 +338,7 @@ cc_library(
"//eval/eval:attribute_trail",
"//eval/eval:evaluator_core",
"//eval/eval:expression_step_base",
"//extensions/protobuf/internal:map_reflection",
"//internal:casts",
"//internal:number",
"//internal:status_macros",
Expand All @@ -346,6 +348,7 @@ cc_library(
"//runtime/internal:runtime_friend_access",
"//runtime/internal:runtime_impl",
"@com_google_absl//absl/algorithm:container",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/base:nullability",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/functional:overload",
Expand Down Expand Up @@ -375,6 +378,7 @@ cc_test(
"//common:expr",
"//common:kind",
"//common:native_type",
"//common:type",
"//common:typeinfo",
"//common:value",
"//compiler",
Expand All @@ -394,15 +398,19 @@ cc_test(
"//internal:status_macros",
"//internal:testing",
"//parser",
"//runtime",
"//runtime:activation",
"//runtime:function_adapter",
"//runtime:function_registry",
"//runtime:runtime_builder",
"//runtime:runtime_issue",
"//runtime:runtime_options",
"//runtime:standard_runtime_builder_factory",
"//runtime:type_registry",
"//runtime/internal:issue_collector",
"//runtime/internal:runtime_env",
"//runtime/internal:runtime_env_testing",
"//testutil:test_external_extensions_descriptor_set",
"@com_google_absl//absl/base:nullability",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/log:absl_check",
Expand Down
Loading
Loading