diff --git a/common/types/message_type.h b/common/types/message_type.h index 782af87aa..acf5045b7 100644 --- a/common/types/message_type.h +++ b/common/types/message_type.h @@ -151,7 +151,7 @@ class MessageTypeField final { std::string DebugString() const; absl::string_view name() const ABSL_ATTRIBUTE_LIFETIME_BOUND { - return (*this)->name(); + return (*this)->is_extension() ? (*this)->full_name() : (*this)->name(); } int32_t number() const ABSL_ATTRIBUTE_LIFETIME_BOUND { diff --git a/extensions/BUILD b/extensions/BUILD index d84881716..1d67e49b3 100644 --- a/extensions/BUILD +++ b/extensions/BUILD @@ -314,7 +314,6 @@ cc_library( "//base:builtins", "//common:ast", "//common:ast_rewrite", - "//common:casting", "//common:constant", "//common:expr", "//common:function_descriptor", @@ -332,6 +331,7 @@ cc_library( "//internal:number", "//internal:status_macros", "//runtime:runtime_builder", + "//runtime:runtime_options", "//runtime/internal:errors", "//runtime/internal:runtime_friend_access", "//runtime/internal:runtime_impl", @@ -367,6 +367,7 @@ cc_test( "//common:kind", "//common:memory", "//common:value", + "//common:value_testing", "//compiler", "//compiler:compiler_factory", "//compiler:optional", @@ -408,6 +409,7 @@ cc_test( "@com_google_cel_spec//proto/cel/expr:checked_cc_proto", "@com_google_cel_spec//proto/cel/expr:syntax_cc_proto", "@com_google_cel_spec//proto/cel/expr/conformance/proto2:test_all_types_cc_proto", + "@com_google_cel_spec//proto/cel/expr/conformance/proto3:test_all_types_cc_proto", "@com_google_protobuf//:empty_cc_proto", "@com_google_protobuf//:protobuf", ], diff --git a/extensions/select_optimization.cc b/extensions/select_optimization.cc index 0f09773ae..e4a318ff6 100644 --- a/extensions/select_optimization.cc +++ b/extensions/select_optimization.cc @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -38,7 +39,6 @@ #include "base/builtins.h" #include "common/ast.h" #include "common/ast_rewrite.h" -#include "common/casting.h" #include "common/constant.h" #include "common/expr.h" #include "common/function_descriptor.h" @@ -59,6 +59,7 @@ #include "runtime/internal/runtime_friend_access.h" #include "runtime/internal/runtime_impl.h" #include "runtime/runtime_builder.h" +#include "runtime/runtime_options.h" #include "google/protobuf/arena.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/message.h" @@ -89,6 +90,9 @@ struct SelectInstruction { std::string name; }; +constexpr ProtoWrapperTypeOptions kSpecWrapperUnboxing = + ProtoWrapperTypeOptions::kUnsetNull; + // Represents a single qualifier in a traversal path. // TODO(uncreated-issue/51): support variable indexes. using QualifierInstruction = @@ -165,6 +169,22 @@ absl::optional GetSelectInstruction( return absl::nullopt; } +struct ProtoSelectStep { + const google::protobuf::FieldDescriptor* absl_nonnull field; + bool is_index; +}; + +struct SelectPlan { + // selection path to the target field (supported by Qualify). + std::vector select_path; + // Selection path in terms of proto field descriptors. Must be a prefix of the + // select_path. + // Used when the operand matches the expected google::protobuf::Descriptor exactly to + // avoid looking up the field descriptors at runtime. + std::vector proto_select_path; + const google::protobuf::Descriptor* absl_nullable operand_descriptor; +}; + absl::StatusOr SelectQualifierFromList(const ListExpr& list) { if (list.elements().size() != 2) { return absl::InvalidArgumentError("Invalid cel.attribute select list"); @@ -267,6 +287,7 @@ absl::StatusOr MapKeyFromQualifier(const AttributeQualifier& qual, } } +// Implementation used when the StructValue does not support Qualify. absl::StatusOr ApplyQualifier( const Value& operand, const SelectQualifier& qualifier, const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, @@ -275,7 +296,7 @@ absl::StatusOr ApplyQualifier( return absl::visit( absl::Overload( [&](const FieldSpecifier& field_specifier) -> absl::StatusOr { - if (!operand.Is()) { + if (!operand.IsStruct()) { return cel::ErrorValue( cel::runtime_internal::CreateNoMatchingOverloadError( "