diff --git a/checker/BUILD b/checker/BUILD index ad0b876db..42e37e81d 100644 --- a/checker/BUILD +++ b/checker/BUILD @@ -171,7 +171,6 @@ cc_test( "//common:constant", "//common:decl", "//common:type", - "//common/ast:expr", "//internal:testing", "//internal:testing_descriptor_pool", "@com_google_absl//absl/status", @@ -208,7 +207,7 @@ cc_test( ":type_checker_builder", ":type_checker_builder_factory", "//checker/internal:test_ast_helpers", - "//common/ast:expr", + "//common:ast", "//internal:testing", "//internal:testing_descriptor_pool", "@com_google_absl//absl/status:status_matchers", diff --git a/checker/internal/BUILD b/checker/internal/BUILD index 637fef697..810348aea 100644 --- a/checker/internal/BUILD +++ b/checker/internal/BUILD @@ -138,7 +138,6 @@ cc_library( "//common:source", "//common:type", "//common:type_kind", - "//common/ast:expr", "//internal:lexis", "//internal:status_macros", "//parser:macro", @@ -174,7 +173,6 @@ cc_test( "//common:expr", "//common:source", "//common:type", - "//common/ast:expr", "//internal:status_macros", "//internal:testing", "//internal:testing_descriptor_pool", diff --git a/checker/internal/type_checker_impl.cc b/checker/internal/type_checker_impl.cc index f75ff7ea0..6d77bb2e2 100644 --- a/checker/internal/type_checker_impl.cc +++ b/checker/internal/type_checker_impl.cc @@ -40,7 +40,6 @@ #include "checker/type_check_issue.h" #include "checker/validation_result.h" #include "common/ast.h" -#include "common/ast/expr.h" #include "common/ast_rewrite.h" #include "common/ast_traverse.h" #include "common/ast_visitor.h" @@ -57,7 +56,7 @@ namespace cel::checker_internal { namespace { -using AstType = cel::ast_internal::Type; +using AstType = cel::TypeSpec; using Severity = TypeCheckIssue::Severity; constexpr const char kOptionalSelect[] = "_?._"; @@ -134,28 +133,26 @@ absl::StatusOr FlattenAbstractType(const OpaqueType& type) { parameter_types.push_back(std::move(param_type)); } - return AstType(ast_internal::AbstractType(std::string(type.name()), - std::move(parameter_types))); + return AstType( + AbstractType(std::string(type.name()), std::move(parameter_types))); } absl::StatusOr FlattenMapType(const MapType& type) { CEL_ASSIGN_OR_RETURN(auto key, FlattenType(type.key())); CEL_ASSIGN_OR_RETURN(auto value, FlattenType(type.value())); - return AstType( - ast_internal::MapType(std::make_unique(std::move(key)), - std::make_unique(std::move(value)))); + return AstType(MapTypeSpec(std::make_unique(std::move(key)), + std::make_unique(std::move(value)))); } absl::StatusOr FlattenListType(const ListType& type) { CEL_ASSIGN_OR_RETURN(auto elem, FlattenType(type.element())); - return AstType( - ast_internal::ListType(std::make_unique(std::move(elem)))); + return AstType(ListTypeSpec(std::make_unique(std::move(elem)))); } absl::StatusOr FlattenMessageType(const StructType& type) { - return AstType(ast_internal::MessageType(std::string(type.name()))); + return AstType(MessageTypeSpec(std::string(type.name()))); } absl::StatusOr FlattenTypeType(const TypeType& type) { @@ -173,29 +170,29 @@ absl::StatusOr FlattenTypeType(const TypeType& type) { absl::StatusOr FlattenType(const Type& type) { switch (type.kind()) { case TypeKind::kDyn: - return AstType(ast_internal::DynamicType()); + return AstType(DynTypeSpec()); case TypeKind::kError: - return AstType(ast_internal::ErrorType()); + return AstType(ErrorTypeSpec()); case TypeKind::kNull: - return AstType(ast_internal::NullType()); + return AstType(NullTypeSpec()); case TypeKind::kBool: - return AstType(ast_internal::PrimitiveType::kBool); + return AstType(PrimitiveType::kBool); case TypeKind::kInt: - return AstType(ast_internal::PrimitiveType::kInt64); + return AstType(PrimitiveType::kInt64); case TypeKind::kEnum: - return AstType(ast_internal::PrimitiveType::kInt64); + return AstType(PrimitiveType::kInt64); case TypeKind::kUint: - return AstType(ast_internal::PrimitiveType::kUint64); + return AstType(PrimitiveType::kUint64); case TypeKind::kDouble: - return AstType(ast_internal::PrimitiveType::kDouble); + return AstType(PrimitiveType::kDouble); case TypeKind::kString: - return AstType(ast_internal::PrimitiveType::kString); + return AstType(PrimitiveType::kString); case TypeKind::kBytes: - return AstType(ast_internal::PrimitiveType::kBytes); + return AstType(PrimitiveType::kBytes); case TypeKind::kDuration: - return AstType(ast_internal::WellKnownType::kDuration); + return AstType(WellKnownTypeSpec::kDuration); case TypeKind::kTimestamp: - return AstType(ast_internal::WellKnownType::kTimestamp); + return AstType(WellKnownTypeSpec::kTimestamp); case TypeKind::kStruct: return FlattenMessageType(type.GetStruct()); case TypeKind::kList: @@ -205,30 +202,24 @@ absl::StatusOr FlattenType(const Type& type) { case TypeKind::kOpaque: return FlattenAbstractType(type.GetOpaque()); case TypeKind::kBoolWrapper: - return AstType(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kBool)); + return AstType(PrimitiveTypeWrapper(PrimitiveType::kBool)); case TypeKind::kIntWrapper: - return AstType(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kInt64)); + return AstType(PrimitiveTypeWrapper(PrimitiveType::kInt64)); case TypeKind::kUintWrapper: - return AstType(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kUint64)); + return AstType(PrimitiveTypeWrapper(PrimitiveType::kUint64)); case TypeKind::kDoubleWrapper: - return AstType(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kDouble)); + return AstType(PrimitiveTypeWrapper(PrimitiveType::kDouble)); case TypeKind::kStringWrapper: - return AstType(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kString)); + return AstType(PrimitiveTypeWrapper(PrimitiveType::kString)); case TypeKind::kBytesWrapper: - return AstType(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kBytes)); + return AstType(PrimitiveTypeWrapper(PrimitiveType::kBytes)); case TypeKind::kTypeParam: // Convert any remaining free type params to dyn. - return AstType(ast_internal::DynamicType()); + return AstType(DynTypeSpec()); case TypeKind::kType: return FlattenTypeType(type.GetType()); case TypeKind::kAny: - return AstType(ast_internal::WellKnownType::kAny); + return AstType(WellKnownTypeSpec::kAny); default: return absl::InternalError( absl::StrCat("unsupported type encountered making AST serializable: ", diff --git a/checker/internal/type_checker_impl_test.cc b/checker/internal/type_checker_impl_test.cc index 9f2ccc69c..0f07de75e 100644 --- a/checker/internal/type_checker_impl_test.cc +++ b/checker/internal/type_checker_impl_test.cc @@ -35,7 +35,6 @@ #include "checker/type_check_issue.h" #include "checker/validation_result.h" #include "common/ast.h" -#include "common/ast/expr.h" #include "common/decl.h" #include "common/expr.h" #include "common/source.h" @@ -57,7 +56,7 @@ namespace { using ::absl_testing::IsOk; using ::absl_testing::StatusIs; -using ::cel::ast_internal::Reference; +using ::cel::Reference; using ::cel::expr::conformance::proto3::TestAllTypes; using ::cel::internal::GetSharedTestingDescriptorPool; using ::testing::_; @@ -70,7 +69,7 @@ using ::testing::Pair; using ::testing::Property; using ::testing::SizeIs; -using AstType = ast_internal::Type; +using AstType = cel::TypeSpec; using Severity = TypeCheckIssue::Severity; namespace testpb3 = ::cel::expr::conformance::proto3; @@ -663,7 +662,7 @@ TEST(TypeCheckerImplTest, MapTypeWithMixedKeys) { const auto* checked_ast = result.GetAst(); EXPECT_TRUE(checked_ast->type_map().at(1).map_type().key_type().has_dyn()); EXPECT_EQ(checked_ast->type_map().at(1).map_type().value_type().primitive(), - ast_internal::PrimitiveType::kInt64); + PrimitiveType::kInt64); } TEST(TypeCheckerImplTest, MapTypeUnsupportedKeyWarns) { @@ -698,7 +697,7 @@ TEST(TypeCheckerImplTest, MapTypeWithMixedValues) { EXPECT_THAT(result.GetIssues(), IsEmpty()); ASSERT_OK_AND_ASSIGN(auto checked_ast, result.ReleaseAst()); EXPECT_EQ(checked_ast->type_map().at(1).map_type().key_type().primitive(), - ast_internal::PrimitiveType::kString); + PrimitiveType::kString); EXPECT_TRUE(checked_ast->type_map().at(1).map_type().value_type().has_dyn()); } @@ -843,7 +842,7 @@ TEST(TypeCheckerImplTest, ComprehensionVarsCyclicParamAssignability) { struct PrimitiveLiteralsTestCase { std::string expr; - ast_internal::PrimitiveType expected_type; + PrimitiveType expected_type; }; class PrimitiveLiteralsTest @@ -862,36 +861,35 @@ TEST_P(PrimitiveLiteralsTest, LiteralsTypeInferred) { test_case.expected_type); } -INSTANTIATE_TEST_SUITE_P( - PrimitiveLiteralsTests, PrimitiveLiteralsTest, - ::testing::Values( - PrimitiveLiteralsTestCase{ - .expr = "1", - .expected_type = ast_internal::PrimitiveType::kInt64, - }, - PrimitiveLiteralsTestCase{ - .expr = "1.0", - .expected_type = ast_internal::PrimitiveType::kDouble, - }, - PrimitiveLiteralsTestCase{ - .expr = "1u", - .expected_type = ast_internal::PrimitiveType::kUint64, - }, - PrimitiveLiteralsTestCase{ - .expr = "'string'", - .expected_type = ast_internal::PrimitiveType::kString, - }, - PrimitiveLiteralsTestCase{ - .expr = "b'bytes'", - .expected_type = ast_internal::PrimitiveType::kBytes, - }, - PrimitiveLiteralsTestCase{ - .expr = "false", - .expected_type = ast_internal::PrimitiveType::kBool, - })); +INSTANTIATE_TEST_SUITE_P(PrimitiveLiteralsTests, PrimitiveLiteralsTest, + ::testing::Values( + PrimitiveLiteralsTestCase{ + .expr = "1", + .expected_type = PrimitiveType::kInt64, + }, + PrimitiveLiteralsTestCase{ + .expr = "1.0", + .expected_type = PrimitiveType::kDouble, + }, + PrimitiveLiteralsTestCase{ + .expr = "1u", + .expected_type = PrimitiveType::kUint64, + }, + PrimitiveLiteralsTestCase{ + .expr = "'string'", + .expected_type = PrimitiveType::kString, + }, + PrimitiveLiteralsTestCase{ + .expr = "b'bytes'", + .expected_type = PrimitiveType::kBytes, + }, + PrimitiveLiteralsTestCase{ + .expr = "false", + .expected_type = PrimitiveType::kBool, + })); struct AstTypeConversionTestCase { Type decl_type; - ast_internal::Type expected_type; + TypeSpec expected_type; }; class AstTypeConversionTest @@ -917,43 +915,43 @@ INSTANTIATE_TEST_SUITE_P( ::testing::Values( AstTypeConversionTestCase{ .decl_type = NullType(), - .expected_type = AstType(ast_internal::NullType()), + .expected_type = AstType(NullTypeSpec()), }, AstTypeConversionTestCase{ .decl_type = DynType(), - .expected_type = AstType(ast_internal::DynamicType()), + .expected_type = AstType(DynTypeSpec()), }, AstTypeConversionTestCase{ .decl_type = BoolType(), - .expected_type = AstType(ast_internal::PrimitiveType::kBool), + .expected_type = AstType(PrimitiveType::kBool), }, AstTypeConversionTestCase{ .decl_type = IntType(), - .expected_type = AstType(ast_internal::PrimitiveType::kInt64), + .expected_type = AstType(PrimitiveType::kInt64), }, AstTypeConversionTestCase{ .decl_type = UintType(), - .expected_type = AstType(ast_internal::PrimitiveType::kUint64), + .expected_type = AstType(PrimitiveType::kUint64), }, AstTypeConversionTestCase{ .decl_type = DoubleType(), - .expected_type = AstType(ast_internal::PrimitiveType::kDouble), + .expected_type = AstType(PrimitiveType::kDouble), }, AstTypeConversionTestCase{ .decl_type = StringType(), - .expected_type = AstType(ast_internal::PrimitiveType::kString), + .expected_type = AstType(PrimitiveType::kString), }, AstTypeConversionTestCase{ .decl_type = BytesType(), - .expected_type = AstType(ast_internal::PrimitiveType::kBytes), + .expected_type = AstType(PrimitiveType::kBytes), }, AstTypeConversionTestCase{ .decl_type = TimestampType(), - .expected_type = AstType(ast_internal::WellKnownType::kTimestamp), + .expected_type = AstType(WellKnownTypeSpec::kTimestamp), }, AstTypeConversionTestCase{ .decl_type = DurationType(), - .expected_type = AstType(ast_internal::WellKnownType::kDuration), + .expected_type = AstType(WellKnownTypeSpec::kDuration), })); INSTANTIATE_TEST_SUITE_P( @@ -961,33 +959,33 @@ INSTANTIATE_TEST_SUITE_P( ::testing::Values( AstTypeConversionTestCase{ .decl_type = IntWrapperType(), - .expected_type = AstType(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kInt64)), + .expected_type = + AstType(PrimitiveTypeWrapper(PrimitiveType::kInt64)), }, AstTypeConversionTestCase{ .decl_type = UintWrapperType(), - .expected_type = AstType(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kUint64)), + .expected_type = + AstType(PrimitiveTypeWrapper(PrimitiveType::kUint64)), }, AstTypeConversionTestCase{ .decl_type = DoubleWrapperType(), - .expected_type = AstType(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kDouble)), + .expected_type = + AstType(PrimitiveTypeWrapper(PrimitiveType::kDouble)), }, AstTypeConversionTestCase{ .decl_type = BoolWrapperType(), - .expected_type = AstType(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kBool)), + .expected_type = + AstType(PrimitiveTypeWrapper(PrimitiveType::kBool)), }, AstTypeConversionTestCase{ .decl_type = StringWrapperType(), - .expected_type = AstType(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kString)), + .expected_type = + AstType(PrimitiveTypeWrapper(PrimitiveType::kString)), }, AstTypeConversionTestCase{ .decl_type = BytesWrapperType(), - .expected_type = AstType(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kBytes)), + .expected_type = + AstType(PrimitiveTypeWrapper(PrimitiveType::kBytes)), })); INSTANTIATE_TEST_SUITE_P( @@ -995,33 +993,31 @@ INSTANTIATE_TEST_SUITE_P( ::testing::Values( AstTypeConversionTestCase{ .decl_type = ListType(TestTypeArena(), IntType()), - .expected_type = - AstType(ast_internal::ListType(std::make_unique( - ast_internal::PrimitiveType::kInt64))), + .expected_type = AstType( + ListTypeSpec(std::make_unique(PrimitiveType::kInt64))), }, AstTypeConversionTestCase{ .decl_type = MapType(TestTypeArena(), IntType(), IntType()), - .expected_type = AstType(ast_internal::MapType( - std::make_unique(ast_internal::PrimitiveType::kInt64), - std::make_unique( - ast_internal::PrimitiveType::kInt64))), + .expected_type = AstType( + MapTypeSpec(std::make_unique(PrimitiveType::kInt64), + std::make_unique(PrimitiveType::kInt64))), }, AstTypeConversionTestCase{ .decl_type = TypeType(TestTypeArena(), IntType()), - .expected_type = AstType( - std::make_unique(ast_internal::PrimitiveType::kInt64)), + .expected_type = + AstType(std::make_unique(PrimitiveType::kInt64)), }, AstTypeConversionTestCase{ .decl_type = OpaqueType(TestTypeArena(), "tuple", {IntType(), IntType()}), - .expected_type = AstType(ast_internal::AbstractType( - "tuple", {AstType(ast_internal::PrimitiveType::kInt64), - AstType(ast_internal::PrimitiveType::kInt64)})), + .expected_type = AstType( + AbstractType("tuple", {AstType(PrimitiveType::kInt64), + AstType(PrimitiveType::kInt64)})), }, AstTypeConversionTestCase{ .decl_type = StructType(MessageType(TestAllTypes::descriptor())), - .expected_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes"))})); + .expected_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes"))})); TEST(TypeCheckerImplTest, NullLiteral) { TypeCheckEnv env(GetSharedTestingDescriptorPool()); @@ -1159,7 +1155,7 @@ TEST(TypeCheckerImplTest, BasicFunctionResultTypeResolution) { "_+_", std::vector{"add_double_double"})); int64_t root_id = checked_ast->root_expr().id(); EXPECT_EQ(checked_ast->mutable_type_map()[root_id].primitive(), - ast_internal::PrimitiveType::kDouble); + PrimitiveType::kDouble); } TEST(TypeCheckerImplTest, BasicOvlResolutionNoMatch) { @@ -1239,14 +1235,14 @@ TEST(TypeCheckerImplTest, WellKnownTypeCreation) { ASSERT_OK_AND_ASSIGN(std::unique_ptr checked_ast, result.ReleaseAst()); - EXPECT_THAT(checked_ast->type_map(), - Contains(Pair(checked_ast->root_expr().id(), - Eq(AstType(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kInt64)))))); - EXPECT_THAT(checked_ast->reference_map(), - Contains(Pair(checked_ast->root_expr().id(), - Property(&ast_internal::Reference::name, - "google.protobuf.Int32Value")))); + EXPECT_THAT( + checked_ast->type_map(), + Contains(Pair(checked_ast->root_expr().id(), + Eq(AstType(PrimitiveTypeWrapper(PrimitiveType::kInt64)))))); + EXPECT_THAT( + checked_ast->reference_map(), + Contains(Pair(checked_ast->root_expr().id(), + Property(&Reference::name, "google.protobuf.Int32Value")))); } TEST(TypeCheckerImplTest, TypeInferredFromStructCreation) { @@ -1264,11 +1260,10 @@ TEST(TypeCheckerImplTest, TypeInferredFromStructCreation) { ASSERT_NE(map_expr_id, 0); EXPECT_THAT( checked_ast->type_map(), - Contains(Pair( - map_expr_id, - Eq(AstType(ast_internal::MapType( - std::make_unique(ast_internal::PrimitiveType::kString), - std::make_unique(ast_internal::DynamicType()))))))); + Contains(Pair(map_expr_id, + Eq(AstType(MapTypeSpec( + std::make_unique(PrimitiveType::kString), + std::make_unique(DynTypeSpec()))))))); } TEST(TypeCheckerImplTest, ExpectedTypeMatches) { @@ -1285,12 +1280,10 @@ TEST(TypeCheckerImplTest, ExpectedTypeMatches) { EXPECT_THAT( checked_ast->type_map(), - Contains(Pair( - checked_ast->root_expr().id(), - Eq(AstType(ast_internal::MapType( - std::make_unique(ast_internal::PrimitiveType::kString), - std::make_unique( - ast_internal::PrimitiveType::kString))))))); + Contains(Pair(checked_ast->root_expr().id(), + Eq(AstType(MapTypeSpec( + std::make_unique(PrimitiveType::kString), + std::make_unique(PrimitiveType::kString))))))); } TEST(TypeCheckerImplTest, ExpectedTypeDoesntMatch) { @@ -1399,14 +1392,14 @@ TEST(TypeCheckerImplTest, ContainerLookupForMessageCreation) { ASSERT_OK_AND_ASSIGN(std::unique_ptr checked_ast, result.ReleaseAst()); - EXPECT_THAT(checked_ast->type_map(), - Contains(Pair(checked_ast->root_expr().id(), - Eq(AstType(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kInt64)))))); - EXPECT_THAT(checked_ast->reference_map(), - Contains(Pair(checked_ast->root_expr().id(), - Property(&ast_internal::Reference::name, - "google.protobuf.Int32Value")))); + EXPECT_THAT( + checked_ast->type_map(), + Contains(Pair(checked_ast->root_expr().id(), + Eq(AstType(PrimitiveTypeWrapper(PrimitiveType::kInt64)))))); + EXPECT_THAT( + checked_ast->reference_map(), + Contains(Pair(checked_ast->root_expr().id(), + Property(&Reference::name, "google.protobuf.Int32Value")))); } TEST(TypeCheckerImplTest, ContainerLookupForMessageCreationNoRewrite) { @@ -1422,14 +1415,14 @@ TEST(TypeCheckerImplTest, ContainerLookupForMessageCreationNoRewrite) { ASSERT_OK_AND_ASSIGN(std::unique_ptr checked_ast, result.ReleaseAst()); - EXPECT_THAT(checked_ast->type_map(), - Contains(Pair(checked_ast->root_expr().id(), - Eq(AstType(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kInt64)))))); - EXPECT_THAT(checked_ast->reference_map(), - Contains(Pair(checked_ast->root_expr().id(), - Property(&ast_internal::Reference::name, - "google.protobuf.Int32Value")))); + EXPECT_THAT( + checked_ast->type_map(), + Contains(Pair(checked_ast->root_expr().id(), + Eq(AstType(PrimitiveTypeWrapper(PrimitiveType::kInt64)))))); + EXPECT_THAT( + checked_ast->reference_map(), + Contains(Pair(checked_ast->root_expr().id(), + Property(&Reference::name, "google.protobuf.Int32Value")))); EXPECT_THAT(checked_ast->root_expr().struct_expr(), Property(&StructExpr::name, "Int32Value")); } @@ -1455,7 +1448,7 @@ TEST(TypeCheckerImplTest, EnumValueCopiedToReferenceMap) { struct CheckedExprTestCase { std::string expr; - ast_internal::Type expected_result_type; + TypeSpec expected_result_type; std::string error_substring; }; @@ -1499,18 +1492,18 @@ INSTANTIATE_TEST_SUITE_P( ::testing::Values( CheckedExprTestCase{ .expr = "google.protobuf.Int32Value{value: 10}", - .expected_result_type = AstType(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kInt64)), + .expected_result_type = + AstType(PrimitiveTypeWrapper(PrimitiveType::kInt64)), }, CheckedExprTestCase{ .expr = ".google.protobuf.Int32Value{value: 10}", - .expected_result_type = AstType(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kInt64)), + .expected_result_type = + AstType(PrimitiveTypeWrapper(PrimitiveType::kInt64)), }, CheckedExprTestCase{ .expr = "Int32Value{value: 10}", - .expected_result_type = AstType(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kInt64)), + .expected_result_type = + AstType(PrimitiveTypeWrapper(PrimitiveType::kInt64)), }, CheckedExprTestCase{ .expr = "google.protobuf.Int32Value{value: '10'}", @@ -1542,64 +1535,62 @@ INSTANTIATE_TEST_SUITE_P( "operand of a select operation"}, CheckedExprTestCase{ .expr = "Int64Value{value: 10}", - .expected_result_type = AstType(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kInt64)), + .expected_result_type = + AstType(PrimitiveTypeWrapper(PrimitiveType::kInt64)), }, CheckedExprTestCase{ .expr = "BoolValue{value: true}", - .expected_result_type = AstType(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kBool)), + .expected_result_type = + AstType(PrimitiveTypeWrapper(PrimitiveType::kBool)), }, CheckedExprTestCase{ .expr = "UInt64Value{value: 10u}", - .expected_result_type = AstType(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kUint64)), + .expected_result_type = + AstType(PrimitiveTypeWrapper(PrimitiveType::kUint64)), }, CheckedExprTestCase{ .expr = "UInt32Value{value: 10u}", - .expected_result_type = AstType(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kUint64)), + .expected_result_type = + AstType(PrimitiveTypeWrapper(PrimitiveType::kUint64)), }, CheckedExprTestCase{ .expr = "FloatValue{value: 1.25}", - .expected_result_type = AstType(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kDouble)), + .expected_result_type = + AstType(PrimitiveTypeWrapper(PrimitiveType::kDouble)), }, CheckedExprTestCase{ .expr = "DoubleValue{value: 1.25}", - .expected_result_type = AstType(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kDouble)), + .expected_result_type = + AstType(PrimitiveTypeWrapper(PrimitiveType::kDouble)), }, CheckedExprTestCase{ .expr = "StringValue{value: 'test'}", - .expected_result_type = AstType(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kString)), + .expected_result_type = + AstType(PrimitiveTypeWrapper(PrimitiveType::kString)), }, CheckedExprTestCase{ .expr = "BytesValue{value: b'test'}", - .expected_result_type = AstType(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kBytes)), + .expected_result_type = + AstType(PrimitiveTypeWrapper(PrimitiveType::kBytes)), }, CheckedExprTestCase{ .expr = "Duration{seconds: 10, nanos: 11}", - .expected_result_type = - AstType(ast_internal::WellKnownType::kDuration), + .expected_result_type = AstType(WellKnownTypeSpec::kDuration), }, CheckedExprTestCase{ .expr = "Timestamp{seconds: 10, nanos: 11}", - .expected_result_type = - AstType(ast_internal::WellKnownType::kTimestamp), + .expected_result_type = AstType(WellKnownTypeSpec::kTimestamp), }, CheckedExprTestCase{ .expr = "Struct{fields: {'key': 'value'}}", - .expected_result_type = AstType(ast_internal::MapType( - std::make_unique(ast_internal::PrimitiveType::kString), - std::make_unique(ast_internal::DynamicType()))), + .expected_result_type = AstType( + MapTypeSpec(std::make_unique(PrimitiveType::kString), + std::make_unique(DynTypeSpec()))), }, CheckedExprTestCase{ .expr = "ListValue{values: [1, 2, 3]}", - .expected_result_type = AstType(ast_internal::ListType( - std::make_unique(ast_internal::DynamicType()))), + .expected_result_type = + AstType(ListTypeSpec(std::make_unique(DynTypeSpec()))), }, CheckedExprTestCase{ .expr = R"cel( @@ -1607,16 +1598,15 @@ INSTANTIATE_TEST_SUITE_P( type_url:'type.googleapis.com/google.protobuf.Int32Value', value: b'' })cel", - .expected_result_type = AstType(ast_internal::WellKnownType::kAny), + .expected_result_type = AstType(WellKnownTypeSpec::kAny), }, CheckedExprTestCase{ .expr = "Int64Value{value: 10} + 1", - .expected_result_type = - AstType(ast_internal::PrimitiveType::kInt64), + .expected_result_type = AstType(PrimitiveType::kInt64), }, CheckedExprTestCase{ .expr = "BoolValue{value: false} || true", - .expected_result_type = AstType(ast_internal::PrimitiveType::kBool), + .expected_result_type = AstType(PrimitiveType::kBool), })); class GenericMessagesTest : public testing::TestWithParam { @@ -1670,8 +1660,8 @@ INSTANTIATE_TEST_SUITE_P( "struct 'cel.expr.conformance.proto3.TestAllTypes'"}, CheckedExprTestCase{ .expr = "TestAllTypes{single_int64: 10}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_int64: 'string'}", @@ -1681,114 +1671,114 @@ INSTANTIATE_TEST_SUITE_P( "provided type is 'string'"}, CheckedExprTestCase{ .expr = "TestAllTypes{single_int32: 10}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_uint64: 10u}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_uint32: 10u}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_sint64: 10}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_sint32: 10}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_fixed64: 10u}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_fixed32: 10u}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_sfixed64: 10}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_sfixed32: 10}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_double: 1.25}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_float: 1.25}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_string: 'string'}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_bool: true}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_bytes: b'string'}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, // Well-known CheckedExprTestCase{ .expr = "TestAllTypes{single_any: TestAllTypes{single_int64: 10}}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_any: 1}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_any: 'string'}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_any: ['string']}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_duration: duration('1s')}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_timestamp: timestamp(0)}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_struct: {}}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_struct: {'key': 'value'}}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_struct: {1: 2}}", @@ -1798,13 +1788,13 @@ INSTANTIATE_TEST_SUITE_P( "provided type is 'map(int, int)'"}, CheckedExprTestCase{ .expr = "TestAllTypes{list_value: [1, 2, 3]}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{list_value: []}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{list_value: 1}", @@ -1814,43 +1804,43 @@ INSTANTIATE_TEST_SUITE_P( "provided type is 'int'"}, CheckedExprTestCase{ .expr = "TestAllTypes{single_int64_wrapper: 1}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_int64_wrapper: null}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_value: null}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_value: 1.0}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_value: 'string'}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_value: {'string': 'string'}}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_value: ['string']}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{repeated_int64: [1, 2, 3]}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{repeated_int64: ['string']}", @@ -1864,73 +1854,71 @@ INSTANTIATE_TEST_SUITE_P( "'map(string, int)'"}, CheckedExprTestCase{ .expr = "TestAllTypes{map_string_int64: {'string': 1}}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_nested_enum: 1}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_nested_enum: TestAllTypes.NestedEnum.BAR}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes.NestedEnum.BAR", - .expected_result_type = - AstType(ast_internal::PrimitiveType::kInt64), + .expected_result_type = AstType(PrimitiveType::kInt64), }, CheckedExprTestCase{ .expr = "TestAllTypes", - .expected_result_type = - AstType(std::make_unique(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes"))), + .expected_result_type = AstType(std::make_unique( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes"))), }, CheckedExprTestCase{ .expr = "TestAllTypes == type(TestAllTypes{})", - .expected_result_type = AstType(ast_internal::PrimitiveType::kBool), + .expected_result_type = AstType(PrimitiveType::kBool), }, // Special case for the NullValue enum. CheckedExprTestCase{ .expr = "TestAllTypes{null_value: 0}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{null_value: null}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, // Legacy nullability behaviors. CheckedExprTestCase{ .expr = "TestAllTypes{single_duration: null}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_timestamp: null}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{single_nested_message: null}", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes")), + .expected_result_type = AstType( + MessageTypeSpec("cel.expr.conformance.proto3.TestAllTypes")), }, CheckedExprTestCase{ .expr = "TestAllTypes{}.single_duration == null", - .expected_result_type = AstType(ast_internal::PrimitiveType::kBool), + .expected_result_type = AstType(PrimitiveType::kBool), }, CheckedExprTestCase{ .expr = "TestAllTypes{}.single_timestamp == null", - .expected_result_type = AstType(ast_internal::PrimitiveType::kBool), + .expected_result_type = AstType(PrimitiveType::kBool), }, CheckedExprTestCase{ .expr = "TestAllTypes{}.single_nested_message == null", - .expected_result_type = AstType(ast_internal::PrimitiveType::kBool), + .expected_result_type = AstType(PrimitiveType::kBool), })); INSTANTIATE_TEST_SUITE_P( @@ -1944,22 +1932,20 @@ INSTANTIATE_TEST_SUITE_P( "struct 'cel.expr.conformance.proto3.TestAllTypes'"}, CheckedExprTestCase{ .expr = "test_msg.single_int64", - .expected_result_type = - AstType(ast_internal::PrimitiveType::kInt64), + .expected_result_type = AstType(PrimitiveType::kInt64), }, CheckedExprTestCase{ .expr = "test_msg.single_nested_enum", - .expected_result_type = - AstType(ast_internal::PrimitiveType::kInt64), + .expected_result_type = AstType(PrimitiveType::kInt64), }, CheckedExprTestCase{ .expr = "test_msg.single_nested_enum == 1", - .expected_result_type = AstType(ast_internal::PrimitiveType::kBool), + .expected_result_type = AstType(PrimitiveType::kBool), }, CheckedExprTestCase{ .expr = "test_msg.single_nested_enum == TestAllTypes.NestedEnum.BAR", - .expected_result_type = AstType(ast_internal::PrimitiveType::kBool), + .expected_result_type = AstType(PrimitiveType::kBool), }, CheckedExprTestCase{ .expr = "has(test_msg.not_a_field)", @@ -1969,242 +1955,214 @@ INSTANTIATE_TEST_SUITE_P( "struct 'cel.expr.conformance.proto3.TestAllTypes'"}, CheckedExprTestCase{ .expr = "has(test_msg.single_int64)", - .expected_result_type = AstType(ast_internal::PrimitiveType::kBool), + .expected_result_type = AstType(PrimitiveType::kBool), }, CheckedExprTestCase{ .expr = "test_msg.single_int32", - .expected_result_type = - AstType(ast_internal::PrimitiveType::kInt64), + .expected_result_type = AstType(PrimitiveType::kInt64), }, CheckedExprTestCase{ .expr = "test_msg.single_uint64", - .expected_result_type = - AstType(ast_internal::PrimitiveType::kUint64), + .expected_result_type = AstType(PrimitiveType::kUint64), }, CheckedExprTestCase{ .expr = "test_msg.single_uint32", - .expected_result_type = - AstType(ast_internal::PrimitiveType::kUint64), + .expected_result_type = AstType(PrimitiveType::kUint64), }, CheckedExprTestCase{ .expr = "test_msg.single_sint64", - .expected_result_type = - AstType(ast_internal::PrimitiveType::kInt64), + .expected_result_type = AstType(PrimitiveType::kInt64), }, CheckedExprTestCase{ .expr = "test_msg.single_sint32", - .expected_result_type = - AstType(ast_internal::PrimitiveType::kInt64), + .expected_result_type = AstType(PrimitiveType::kInt64), }, CheckedExprTestCase{ .expr = "test_msg.single_fixed64", - .expected_result_type = - AstType(ast_internal::PrimitiveType::kUint64), + .expected_result_type = AstType(PrimitiveType::kUint64), }, CheckedExprTestCase{ .expr = "test_msg.single_fixed32", - .expected_result_type = - AstType(ast_internal::PrimitiveType::kUint64), + .expected_result_type = AstType(PrimitiveType::kUint64), }, CheckedExprTestCase{ .expr = "test_msg.single_sfixed64", - .expected_result_type = - AstType(ast_internal::PrimitiveType::kInt64), + .expected_result_type = AstType(PrimitiveType::kInt64), }, CheckedExprTestCase{ .expr = "test_msg.single_sfixed32", - .expected_result_type = - AstType(ast_internal::PrimitiveType::kInt64), + .expected_result_type = AstType(PrimitiveType::kInt64), }, CheckedExprTestCase{ .expr = "test_msg.single_float", - .expected_result_type = - AstType(ast_internal::PrimitiveType::kDouble), + .expected_result_type = AstType(PrimitiveType::kDouble), }, CheckedExprTestCase{ .expr = "test_msg.single_double", - .expected_result_type = - AstType(ast_internal::PrimitiveType::kDouble), + .expected_result_type = AstType(PrimitiveType::kDouble), }, CheckedExprTestCase{ .expr = "test_msg.single_string", - .expected_result_type = - AstType(ast_internal::PrimitiveType::kString), + .expected_result_type = AstType(PrimitiveType::kString), }, CheckedExprTestCase{ .expr = "test_msg.single_bool", - .expected_result_type = AstType(ast_internal::PrimitiveType::kBool), + .expected_result_type = AstType(PrimitiveType::kBool), }, CheckedExprTestCase{ .expr = "test_msg.single_bytes", - .expected_result_type = - AstType(ast_internal::PrimitiveType::kBytes), + .expected_result_type = AstType(PrimitiveType::kBytes), }, // Basic tests for containers. This is covered in more detail in // conformance tests and the type provider implementation. CheckedExprTestCase{ .expr = "test_msg.repeated_int32", - .expected_result_type = - AstType(ast_internal::ListType(std::make_unique( - ast_internal::PrimitiveType::kInt64))), + .expected_result_type = AstType( + ListTypeSpec(std::make_unique(PrimitiveType::kInt64))), }, CheckedExprTestCase{ .expr = "test_msg.repeated_string", - .expected_result_type = - AstType(ast_internal::ListType(std::make_unique( - ast_internal::PrimitiveType::kString))), + .expected_result_type = AstType(ListTypeSpec( + std::make_unique(PrimitiveType::kString))), }, CheckedExprTestCase{ .expr = "test_msg.map_bool_bool", - .expected_result_type = AstType(ast_internal::MapType( - std::make_unique(ast_internal::PrimitiveType::kBool), - std::make_unique(ast_internal::PrimitiveType::kBool))), + .expected_result_type = AstType( + MapTypeSpec(std::make_unique(PrimitiveType::kBool), + std::make_unique(PrimitiveType::kBool))), }, // Note: The Go type checker permits this so C++ does as well. Some // test cases expect that field selection on a map is always allowed, // even if a specific, non-string key type is known. CheckedExprTestCase{ .expr = "test_msg.map_bool_bool.field_like_key", - .expected_result_type = AstType(ast_internal::PrimitiveType::kBool), + .expected_result_type = AstType(PrimitiveType::kBool), }, CheckedExprTestCase{ .expr = "test_msg.map_string_int64", - .expected_result_type = AstType(ast_internal::MapType( - std::make_unique(ast_internal::PrimitiveType::kString), - std::make_unique( - ast_internal::PrimitiveType::kInt64))), + .expected_result_type = AstType( + MapTypeSpec(std::make_unique(PrimitiveType::kString), + std::make_unique(PrimitiveType::kInt64))), }, CheckedExprTestCase{ .expr = "test_msg.map_string_int64.field_like_key", - .expected_result_type = - AstType(ast_internal::PrimitiveType::kInt64), + .expected_result_type = AstType(PrimitiveType::kInt64), }, // Well-known CheckedExprTestCase{ .expr = "test_msg.single_duration", - .expected_result_type = - AstType(ast_internal::WellKnownType::kDuration), + .expected_result_type = AstType(WellKnownTypeSpec::kDuration), }, CheckedExprTestCase{ .expr = "test_msg.single_timestamp", - .expected_result_type = - AstType(ast_internal::WellKnownType::kTimestamp), + .expected_result_type = AstType(WellKnownTypeSpec::kTimestamp), }, CheckedExprTestCase{ .expr = "test_msg.single_any", - .expected_result_type = AstType(ast_internal::WellKnownType::kAny), + .expected_result_type = AstType(WellKnownTypeSpec::kAny), }, CheckedExprTestCase{ .expr = "test_msg.single_int64_wrapper", - .expected_result_type = AstType(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kInt64)), + .expected_result_type = + AstType(PrimitiveTypeWrapper(PrimitiveType::kInt64)), }, CheckedExprTestCase{ .expr = "test_msg.single_struct", - .expected_result_type = AstType(ast_internal::MapType( - std::make_unique(ast_internal::PrimitiveType::kString), - std::make_unique(ast_internal::DynamicType()))), + .expected_result_type = AstType( + MapTypeSpec(std::make_unique(PrimitiveType::kString), + std::make_unique(DynTypeSpec()))), }, CheckedExprTestCase{ .expr = "test_msg.list_value", - .expected_result_type = AstType(ast_internal::ListType( - std::make_unique(ast_internal::DynamicType()))), + .expected_result_type = + AstType(ListTypeSpec(std::make_unique(DynTypeSpec()))), }, CheckedExprTestCase{ .expr = "test_msg.list_value", - .expected_result_type = AstType(ast_internal::ListType( - std::make_unique(ast_internal::DynamicType()))), + .expected_result_type = + AstType(ListTypeSpec(std::make_unique(DynTypeSpec()))), }, // Basic tests for nested messages. CheckedExprTestCase{ .expr = "NestedTestAllTypes{}.child.child.payload.single_int64", - .expected_result_type = - AstType(ast_internal::PrimitiveType::kInt64), + .expected_result_type = AstType(PrimitiveType::kInt64), }, CheckedExprTestCase{ .expr = "test_msg.single_struct.field.nested_field", - .expected_result_type = AstType(ast_internal::DynamicType()), + .expected_result_type = AstType(DynTypeSpec()), }, CheckedExprTestCase{ .expr = "{}.field.nested_field", - .expected_result_type = AstType(ast_internal::DynamicType()), + .expected_result_type = AstType(DynTypeSpec()), })); INSTANTIATE_TEST_SUITE_P( TypeInferences, GenericMessagesTest, ::testing::Values( - CheckedExprTestCase{ - .expr = "[1, test_msg.single_int64_wrapper]", - .expected_result_type = AstType(ast_internal::ListType( - std::make_unique(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kInt64))))}, - CheckedExprTestCase{ - .expr = "[1, 2, test_msg.single_int64_wrapper]", - .expected_result_type = AstType(ast_internal::ListType( - std::make_unique(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kInt64))))}, - CheckedExprTestCase{ - .expr = "[test_msg.single_int64_wrapper, 1]", - .expected_result_type = AstType(ast_internal::ListType( - std::make_unique(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kInt64))))}, + CheckedExprTestCase{.expr = "[1, test_msg.single_int64_wrapper]", + .expected_result_type = AstType(ListTypeSpec( + std::make_unique(PrimitiveTypeWrapper( + PrimitiveType::kInt64))))}, + CheckedExprTestCase{.expr = "[1, 2, test_msg.single_int64_wrapper]", + .expected_result_type = AstType(ListTypeSpec( + std::make_unique(PrimitiveTypeWrapper( + PrimitiveType::kInt64))))}, + CheckedExprTestCase{.expr = "[test_msg.single_int64_wrapper, 1]", + .expected_result_type = AstType(ListTypeSpec( + std::make_unique(PrimitiveTypeWrapper( + PrimitiveType::kInt64))))}, CheckedExprTestCase{ .expr = "[1, 2, test_msg.single_int64_wrapper, dyn(1)]", - .expected_result_type = AstType(ast_internal::ListType( - std::make_unique(ast_internal::DynamicType())))}, - CheckedExprTestCase{ - .expr = "[null, test_msg][0]", - .expected_result_type = AstType(ast_internal::MessageType( - "cel.expr.conformance.proto3.TestAllTypes"))}, + .expected_result_type = AstType( + ListTypeSpec(std::make_unique(DynTypeSpec())))}, + CheckedExprTestCase{.expr = "[null, test_msg][0]", + .expected_result_type = AstType(MessageTypeSpec( + "cel.expr.conformance.proto3.TestAllTypes"))}, CheckedExprTestCase{ .expr = "[{'k': dyn(1)}, {dyn('k'): 1}][0]", // Ambiguous type resolution, but we prefer the first option. - .expected_result_type = AstType(ast_internal::MapType( - std::make_unique(ast_internal::PrimitiveType::kString), - std::make_unique(ast_internal::DynamicType())))}, + .expected_result_type = AstType( + MapTypeSpec(std::make_unique(PrimitiveType::kString), + std::make_unique(DynTypeSpec())))}, CheckedExprTestCase{ .expr = "[{'k': 1}, {dyn('k'): 1}][0]", - .expected_result_type = AstType(ast_internal::MapType( - std::make_unique(ast_internal::DynamicType()), - std::make_unique( - ast_internal::PrimitiveType::kInt64)))}, + .expected_result_type = AstType( + MapTypeSpec(std::make_unique(DynTypeSpec()), + std::make_unique(PrimitiveType::kInt64)))}, CheckedExprTestCase{ .expr = "[{dyn('k'): 1}, {'k': 1}][0]", - .expected_result_type = AstType(ast_internal::MapType( - std::make_unique(ast_internal::DynamicType()), - std::make_unique( - ast_internal::PrimitiveType::kInt64)))}, + .expected_result_type = AstType( + MapTypeSpec(std::make_unique(DynTypeSpec()), + std::make_unique(PrimitiveType::kInt64)))}, CheckedExprTestCase{ .expr = "[{'k': 1}, {'k': dyn(1)}][0]", - .expected_result_type = AstType(ast_internal::MapType( - std::make_unique(ast_internal::PrimitiveType::kString), - std::make_unique(ast_internal::DynamicType())))}, - CheckedExprTestCase{ - .expr = "[{'k': 1}, {dyn('k'): dyn(1)}][0]", - .expected_result_type = AstType(ast_internal::MapType( - std::make_unique(ast_internal::DynamicType()), - std::make_unique(ast_internal::DynamicType())))}, + .expected_result_type = AstType( + MapTypeSpec(std::make_unique(PrimitiveType::kString), + std::make_unique(DynTypeSpec())))}, + CheckedExprTestCase{.expr = "[{'k': 1}, {dyn('k'): dyn(1)}][0]", + .expected_result_type = AstType(MapTypeSpec( + std::make_unique(DynTypeSpec()), + std::make_unique(DynTypeSpec())))}, CheckedExprTestCase{ .expr = "[{'k': 1.0}, {dyn('k'): test_msg.single_int64_wrapper}][0]", - .expected_result_type = AstType(ast_internal::DynamicType())}, + .expected_result_type = AstType(DynTypeSpec())}, CheckedExprTestCase{ .expr = "test_msg.single_int64", - .expected_result_type = - AstType(ast_internal::PrimitiveType::kInt64), + .expected_result_type = AstType(PrimitiveType::kInt64), }, CheckedExprTestCase{ .expr = "[[1], {1: 2u}][0]", - .expected_result_type = AstType(ast_internal::DynamicType()), + .expected_result_type = AstType(DynTypeSpec()), }, CheckedExprTestCase{ .expr = "[{1: 2u}, [1]][0]", - .expected_result_type = AstType(ast_internal::DynamicType()), + .expected_result_type = AstType(DynTypeSpec()), }, CheckedExprTestCase{ .expr = "[test_msg.single_int64_wrapper," " test_msg.single_string_wrapper][0]", - .expected_result_type = AstType(ast_internal::DynamicType()), + .expected_result_type = AstType(DynTypeSpec()), })); class StrictNullAssignmentTest diff --git a/checker/optional_test.cc b/checker/optional_test.cc index 580cd381c..be05eccd8 100644 --- a/checker/optional_test.cc +++ b/checker/optional_test.cc @@ -28,7 +28,7 @@ #include "checker/type_checker.h" #include "checker/type_checker_builder.h" #include "checker/type_checker_builder_factory.h" -#include "common/ast/expr.h" +#include "common/ast.h" #include "internal/testing.h" #include "internal/testing_descriptor_pool.h" @@ -97,7 +97,7 @@ TEST(OptionalTest, OptSelectDoesNotAnnotateFieldType) { EXPECT_THAT(checked_ast->type_map(), Not(Contains(Key(field_id)))); EXPECT_THAT(checked_ast->GetTypeOrDyn(checked_ast->root_expr().id()), - IsOptionalType(TypeSpec(ast_internal::PrimitiveType::kInt64))); + IsOptionalType(TypeSpec(PrimitiveType::kInt64))); } struct TestCase { @@ -148,132 +148,126 @@ INSTANTIATE_TEST_SUITE_P( ::testing::Values( TestCase{ "optional.of('abc')", - IsOptionalType(TypeSpec(ast_internal::PrimitiveType::kString)), + IsOptionalType(TypeSpec(PrimitiveType::kString)), }, TestCase{ "optional.ofNonZeroValue('')", - IsOptionalType(TypeSpec(ast_internal::PrimitiveType::kString)), + IsOptionalType(TypeSpec(PrimitiveType::kString)), }, TestCase{ "optional.none()", - IsOptionalType(TypeSpec(ast_internal::DynamicType())), + IsOptionalType(TypeSpec(DynTypeSpec())), }, TestCase{ "optional.of('abc').hasValue()", - Eq(TypeSpec(ast_internal::PrimitiveType::kBool)), + Eq(TypeSpec(PrimitiveType::kBool)), }, TestCase{ "optional.of('abc').value()", - Eq(TypeSpec(ast_internal::PrimitiveType::kString)), + Eq(TypeSpec(PrimitiveType::kString)), }, TestCase{ "type(optional.of('abc')) == optional_type", - Eq(TypeSpec(ast_internal::PrimitiveType::kBool)), + Eq(TypeSpec(PrimitiveType::kBool)), }, TestCase{ "type(optional.of('abc')) == optional_type", - Eq(TypeSpec(ast_internal::PrimitiveType::kBool)), + Eq(TypeSpec(PrimitiveType::kBool)), }, TestCase{ "optional.of('abc').or(optional.of('def'))", - IsOptionalType(TypeSpec(ast_internal::PrimitiveType::kString)), + IsOptionalType(TypeSpec(PrimitiveType::kString)), }, TestCase{"optional.of('abc').or(optional.of(1))", _, "no matching overload for 'or'"}, TestCase{ "optional.of('abc').orValue('def')", - Eq(TypeSpec(ast_internal::PrimitiveType::kString)), + Eq(TypeSpec(PrimitiveType::kString)), }, TestCase{"optional.of('abc').orValue(1)", _, "no matching overload for 'orValue'"}, TestCase{ "{'k': 'v'}.?k", - IsOptionalType(TypeSpec(ast_internal::PrimitiveType::kString)), + IsOptionalType(TypeSpec(PrimitiveType::kString)), }, TestCase{"1.?k", _, "expression of type 'int' cannot be the operand of a select " "operation"}, TestCase{ "{'k': {'k': 'v'}}.?k.?k2", - IsOptionalType(TypeSpec(ast_internal::PrimitiveType::kString)), + IsOptionalType(TypeSpec(PrimitiveType::kString)), }, TestCase{ "{'k': {'k': 'v'}}.?k.k2", - IsOptionalType(TypeSpec(ast_internal::PrimitiveType::kString)), + IsOptionalType(TypeSpec(PrimitiveType::kString)), }, TestCase{"{?'k': optional.of('v')}", - Eq(TypeSpec(ast_internal::MapType( - std::unique_ptr( - new TypeSpec(ast_internal::PrimitiveType::kString)), - std::unique_ptr(new TypeSpec( - ast_internal::PrimitiveType::kString)))))}, + Eq(TypeSpec(MapTypeSpec(std::unique_ptr(new TypeSpec( + PrimitiveType::kString)), + std::unique_ptr(new TypeSpec( + PrimitiveType::kString)))))}, TestCase{"{'k': 'v', ?'k2': optional.none()}", - Eq(TypeSpec(ast_internal::MapType( - std::unique_ptr( - new TypeSpec(ast_internal::PrimitiveType::kString)), - std::unique_ptr(new TypeSpec( - ast_internal::PrimitiveType::kString)))))}, + Eq(TypeSpec(MapTypeSpec(std::unique_ptr(new TypeSpec( + PrimitiveType::kString)), + std::unique_ptr(new TypeSpec( + PrimitiveType::kString)))))}, TestCase{"{'k': 'v', ?'k2': 'v'}", _, "expected type 'optional_type(string)' but found 'string'"}, TestCase{"[?optional.of('v')]", - Eq(TypeSpec(ast_internal::ListType(std::unique_ptr( - new TypeSpec(ast_internal::PrimitiveType::kString)))))}, + Eq(TypeSpec(ListTypeSpec(std::unique_ptr( + new TypeSpec(PrimitiveType::kString)))))}, TestCase{"['v', ?optional.none()]", - Eq(TypeSpec(ast_internal::ListType(std::unique_ptr( - new TypeSpec(ast_internal::PrimitiveType::kString)))))}, + Eq(TypeSpec(ListTypeSpec(std::unique_ptr( + new TypeSpec(PrimitiveType::kString)))))}, TestCase{"['v1', ?'v2']", _, "expected type 'optional_type(string)' but found 'string'"}, TestCase{"[optional.of(dyn('1')), optional.of('2')][0]", - IsOptionalType(TypeSpec(ast_internal::DynamicType()))}, + IsOptionalType(TypeSpec(DynTypeSpec()))}, TestCase{"[optional.of('1'), optional.of(dyn('2'))][0]", - IsOptionalType(TypeSpec(ast_internal::DynamicType()))}, + IsOptionalType(TypeSpec(DynTypeSpec()))}, TestCase{"[{1: optional.of(1)}, {1: optional.of(dyn(1))}][0][1]", - IsOptionalType(TypeSpec(ast_internal::DynamicType()))}, + IsOptionalType(TypeSpec(DynTypeSpec()))}, TestCase{"[{1: optional.of(dyn(1))}, {1: optional.of(1)}][0][1]", - IsOptionalType(TypeSpec(ast_internal::DynamicType()))}, + IsOptionalType(TypeSpec(DynTypeSpec()))}, TestCase{"[optional.of('1'), optional.of(2)][0]", - Eq(TypeSpec(ast_internal::DynamicType()))}, + Eq(TypeSpec(DynTypeSpec()))}, TestCase{"['v1', ?'v2']", _, "expected type 'optional_type(string)' but found 'string'"}, TestCase{"cel.expr.conformance.proto3.TestAllTypes{?single_int64: " "optional.of(1)}", - Eq(TypeSpec(ast_internal::MessageType( + Eq(TypeSpec(MessageTypeSpec( "cel.expr.conformance.proto3.TestAllTypes")))}, - TestCase{"[0][?1]", - IsOptionalType(TypeSpec(ast_internal::PrimitiveType::kInt64))}, + TestCase{"[0][?1]", IsOptionalType(TypeSpec(PrimitiveType::kInt64))}, TestCase{"[[0]][?1][?1]", - IsOptionalType(TypeSpec(ast_internal::PrimitiveType::kInt64))}, + IsOptionalType(TypeSpec(PrimitiveType::kInt64))}, TestCase{"[[0]][?1][1]", - IsOptionalType(TypeSpec(ast_internal::PrimitiveType::kInt64))}, - TestCase{"{0: 1}[?1]", - IsOptionalType(TypeSpec(ast_internal::PrimitiveType::kInt64))}, + IsOptionalType(TypeSpec(PrimitiveType::kInt64))}, + TestCase{"{0: 1}[?1]", IsOptionalType(TypeSpec(PrimitiveType::kInt64))}, TestCase{"{0: {0: 1}}[?1][?1]", - IsOptionalType(TypeSpec(ast_internal::PrimitiveType::kInt64))}, + IsOptionalType(TypeSpec(PrimitiveType::kInt64))}, TestCase{"{0: {0: 1}}[?1][1]", - IsOptionalType(TypeSpec(ast_internal::PrimitiveType::kInt64))}, + IsOptionalType(TypeSpec(PrimitiveType::kInt64))}, TestCase{"{0: {0: 1}}[?1]['']", _, "no matching overload for '_[_]'"}, TestCase{"{0: {0: 1}}[?1][?'']", _, "no matching overload for '_[?_]'"}, - TestCase{ - "optional.of('abc').optMap(x, x + 'def')", - IsOptionalType(TypeSpec(ast_internal::PrimitiveType::kString))}, - TestCase{ - "optional.of('abc').optFlatMap(x, optional.of(x + 'def'))", - IsOptionalType(TypeSpec(ast_internal::PrimitiveType::kString))}, + TestCase{"optional.of('abc').optMap(x, x + 'def')", + IsOptionalType(TypeSpec(PrimitiveType::kString))}, + TestCase{"optional.of('abc').optFlatMap(x, optional.of(x + 'def'))", + IsOptionalType(TypeSpec(PrimitiveType::kString))}, // Legacy nullability behaviors. TestCase{"cel.expr.conformance.proto3.TestAllTypes{?null_value: " "optional.of(0)}", - Eq(TypeSpec(ast_internal::MessageType( + Eq(TypeSpec(MessageTypeSpec( "cel.expr.conformance.proto3.TestAllTypes")))}, TestCase{"cel.expr.conformance.proto3.TestAllTypes{?null_value: null}", - Eq(TypeSpec(ast_internal::MessageType( + Eq(TypeSpec(MessageTypeSpec( "cel.expr.conformance.proto3.TestAllTypes")))}, TestCase{"cel.expr.conformance.proto3.TestAllTypes{?null_value: " "optional.of(null)}", - Eq(TypeSpec(ast_internal::MessageType( + Eq(TypeSpec(MessageTypeSpec( "cel.expr.conformance.proto3.TestAllTypes")))}, TestCase{"cel.expr.conformance.proto3.TestAllTypes{}.?single_int64 " "== null", - Eq(TypeSpec(ast_internal::PrimitiveType::kBool))})); + Eq(TypeSpec(PrimitiveType::kBool))})); class OptionalStrictNullAssignmentTest : public testing::TestWithParam {}; diff --git a/checker/standard_library_test.cc b/checker/standard_library_test.cc index 2b7533027..f3330a76d 100644 --- a/checker/standard_library_test.cc +++ b/checker/standard_library_test.cc @@ -27,7 +27,6 @@ #include "checker/type_checker_builder_factory.h" #include "checker/validation_result.h" #include "common/ast.h" -#include "common/ast/expr.h" #include "common/constant.h" #include "common/decl.h" #include "common/type.h" @@ -40,13 +39,13 @@ namespace { using ::absl_testing::IsOk; using ::absl_testing::StatusIs; -using ::cel::ast_internal::Reference; +using ::cel::Reference; using ::cel::internal::GetSharedTestingDescriptorPool; using ::testing::IsEmpty; using ::testing::Pointee; using ::testing::Property; -using AstType = cel::ast_internal::Type; +using AstType = cel::TypeSpec; TEST(StandardLibraryTest, StandardLibraryAddsDecls) { ASSERT_OK_AND_ASSIGN( @@ -130,10 +129,9 @@ TEST(StandardLibraryTest, ComprehensionResultTypeIsSubstituted) { ASSERT_OK_AND_ASSIGN(auto checked_ast, result.ReleaseAst()); - ast_internal::Type type = - checked_ast->GetTypeOrDyn(checked_ast->root_expr().id()); + TypeSpec type = checked_ast->GetTypeOrDyn(checked_ast->root_expr().id()); EXPECT_TRUE(type.has_primitive() && - type.primitive() == ast_internal::PrimitiveType::kInt64); + type.primitive() == PrimitiveType::kInt64); } class StandardLibraryDefinitionsTest : public ::testing::Test { diff --git a/common/BUILD b/common/BUILD index 1985b91a9..8f4e062aa 100644 --- a/common/BUILD +++ b/common/BUILD @@ -1042,7 +1042,6 @@ cc_library( ":expr", "//base:ast", "//common/ast:constant_proto", - "//common/ast:expr", "//common/ast:expr_proto", "//common/ast:source_info_proto", "//internal:status_macros", @@ -1071,7 +1070,6 @@ cc_test( ":expr", ":source", ":type", - "//common/ast:expr", "//compiler", "//compiler:compiler_factory", "//compiler:optional", diff --git a/common/ast/BUILD b/common/ast/BUILD index c4eaea783..644ee1b36 100644 --- a/common/ast/BUILD +++ b/common/ast/BUILD @@ -88,8 +88,8 @@ cc_library( srcs = ["source_info_proto.cc"], hdrs = ["source_info_proto.h"], deps = [ - ":expr", ":expr_proto", + "//common:ast", "//internal:status_macros", "@com_google_absl//absl/base:nullability", "@com_google_absl//absl/status", diff --git a/common/ast/source_info_proto.cc b/common/ast/source_info_proto.cc index f4b253943..ae1803fbb 100644 --- a/common/ast/source_info_proto.cc +++ b/common/ast/source_info_proto.cc @@ -23,22 +23,20 @@ #include "google/protobuf/struct.pb.h" #include "google/protobuf/timestamp.pb.h" #include "absl/status/status.h" -#include "common/ast/expr.h" +#include "common/ast.h" #include "common/ast/expr_proto.h" #include "internal/status_macros.h" namespace cel::ast_internal { using ::cel::ast_internal::ExprToProto; -using ::cel::ast_internal::Extension; -using ::cel::ast_internal::SourceInfo; using ExprPb = cel::expr::Expr; using ParsedExprPb = cel::expr::ParsedExpr; using CheckedExprPb = cel::expr::CheckedExpr; using ExtensionPb = cel::expr::SourceInfo::Extension; -absl::Status SourceInfoToProto(const SourceInfo& source_info, +absl::Status SourceInfoToProto(const cel::SourceInfo& source_info, cel::expr::SourceInfo* out) { cel::expr::SourceInfo& result = *out; result.set_syntax_version(source_info.syntax_version()); @@ -68,14 +66,14 @@ absl::Status SourceInfoToProto(const SourceInfo& source_info, for (auto component : extension.affected_components()) { switch (component) { - case Extension::Component::kParser: + case cel::ExtensionSpec::Component::kParser: extension_pb->add_affected_components(ExtensionPb::COMPONENT_PARSER); break; - case Extension::Component::kTypeChecker: + case cel::ExtensionSpec::Component::kTypeChecker: extension_pb->add_affected_components( ExtensionPb::COMPONENT_TYPE_CHECKER); break; - case Extension::Component::kRuntime: + case cel::ExtensionSpec::Component::kRuntime: extension_pb->add_affected_components(ExtensionPb::COMPONENT_RUNTIME); break; default: diff --git a/common/ast/source_info_proto.h b/common/ast/source_info_proto.h index 134964fcb..c44bb2a73 100644 --- a/common/ast/source_info_proto.h +++ b/common/ast/source_info_proto.h @@ -18,13 +18,13 @@ #include "cel/expr/syntax.pb.h" #include "absl/base/nullability.h" #include "absl/status/status.h" -#include "common/ast/expr.h" +#include "common/ast.h" namespace cel::ast_internal { // Conversion utility for the CEL-C++ source info representation to the protobuf // representation. -absl::Status SourceInfoToProto(const ast_internal::SourceInfo& source_info, +absl::Status SourceInfoToProto(const SourceInfo& source_info, cel::expr::SourceInfo* absl_nonnull out); } // namespace cel::ast_internal diff --git a/common/ast_proto.cc b/common/ast_proto.cc index 3f8df26f0..ee990f0e5 100644 --- a/common/ast_proto.cc +++ b/common/ast_proto.cc @@ -32,7 +32,6 @@ #include "absl/types/variant.h" #include "common/ast.h" #include "common/ast/constant_proto.h" -#include "common/ast/expr.h" #include "common/ast/expr_proto.h" #include "common/ast/source_info_proto.h" #include "common/constant.h" @@ -42,27 +41,10 @@ namespace cel { namespace { -using ::cel::ast_internal::AbstractType; using ::cel::ast_internal::ConstantFromProto; using ::cel::ast_internal::ConstantToProto; -using ::cel::ast_internal::DynamicType; -using ::cel::ast_internal::ErrorType; using ::cel::ast_internal::ExprFromProto; using ::cel::ast_internal::ExprToProto; -using ::cel::ast_internal::Extension; -using ::cel::ast_internal::FunctionType; -using ::cel::ast_internal::ListType; -using ::cel::ast_internal::MapType; -using ::cel::ast_internal::MessageType; -using ::cel::ast_internal::NullType; -using ::cel::ast_internal::ParamType; -using ::cel::ast_internal::PrimitiveType; -using ::cel::ast_internal::PrimitiveTypeWrapper; -using ::cel::ast_internal::Reference; -using ::cel::ast_internal::SourceInfo; -using ::cel::ast_internal::Type; -using ::cel::ast_internal::UnspecifiedType; -using ::cel::ast_internal::WellKnownType; using ExprPb = cel::expr::Expr; using ParsedExprPb = cel::expr::ParsedExpr; @@ -89,32 +71,32 @@ absl::StatusOr ConvertProtoSourceInfoToNative( } macro_calls.emplace(pair.first, *(std::move(native_expr))); } - std::vector extensions; + std::vector extensions; extensions.reserve(source_info.extensions_size()); for (const auto& extension : source_info.extensions()) { - std::vector components; + std::vector components; components.reserve(extension.affected_components().size()); for (const auto& component : extension.affected_components()) { switch (component) { case ExtensionPb::COMPONENT_PARSER: - components.push_back(Extension::Component::kParser); + components.push_back(ExtensionSpec::Component::kParser); break; case ExtensionPb::COMPONENT_TYPE_CHECKER: - components.push_back(Extension::Component::kTypeChecker); + components.push_back(ExtensionSpec::Component::kTypeChecker); break; case ExtensionPb::COMPONENT_RUNTIME: - components.push_back(Extension::Component::kRuntime); + components.push_back(ExtensionSpec::Component::kRuntime); break; default: - components.push_back(Extension::Component::kUnspecified); + components.push_back(ExtensionSpec::Component::kUnspecified); break; } } - extensions.push_back( - Extension(extension.id(), - std::make_unique( - extension.version().major(), extension.version().minor()), - std::move(components))); + extensions.push_back(ExtensionSpec( + extension.id(), + std::make_unique(extension.version().major(), + extension.version().minor()), + std::move(components))); } return SourceInfo( source_info.syntax_version(), source_info.location(), @@ -125,7 +107,7 @@ absl::StatusOr ConvertProtoSourceInfoToNative( std::move(macro_calls), std::move(extensions)); } -absl::StatusOr ConvertProtoTypeToNative( +absl::StatusOr ConvertProtoTypeToNative( const cel::expr::Type& type); absl::StatusOr ToNative( @@ -152,17 +134,17 @@ absl::StatusOr ToNative( } } -absl::StatusOr ToNative( +absl::StatusOr ToNative( cel::expr::Type::WellKnownType well_known_type) { switch (well_known_type) { case cel::expr::Type::WELL_KNOWN_TYPE_UNSPECIFIED: - return WellKnownType::kWellKnownTypeUnspecified; + return WellKnownTypeSpec::kWellKnownTypeUnspecified; case cel::expr::Type::ANY: - return WellKnownType::kAny; + return WellKnownTypeSpec::kAny; case cel::expr::Type::TIMESTAMP: - return WellKnownType::kTimestamp; + return WellKnownTypeSpec::kTimestamp; case cel::expr::Type::DURATION: - return WellKnownType::kDuration; + return WellKnownTypeSpec::kDuration; default: return absl::InvalidArgumentError( "Illegal type specified for " @@ -170,16 +152,17 @@ absl::StatusOr ToNative( } } -absl::StatusOr ToNative( +absl::StatusOr ToNative( const cel::expr::Type::ListType& list_type) { auto native_elem_type = ConvertProtoTypeToNative(list_type.elem_type()); if (!native_elem_type.ok()) { return native_elem_type.status(); } - return ListType(std::make_unique(*(std::move(native_elem_type)))); + return ListTypeSpec( + std::make_unique(*(std::move(native_elem_type)))); } -absl::StatusOr ToNative( +absl::StatusOr ToNative( const cel::expr::Type::MapType& map_type) { auto native_key_type = ConvertProtoTypeToNative(map_type.key_type()); if (!native_key_type.ok()) { @@ -189,13 +172,14 @@ absl::StatusOr ToNative( if (!native_value_type.ok()) { return native_value_type.status(); } - return MapType(std::make_unique(*(std::move(native_key_type))), - std::make_unique(*(std::move(native_value_type)))); + return MapTypeSpec( + std::make_unique(*(std::move(native_key_type))), + std::make_unique(*(std::move(native_value_type)))); } -absl::StatusOr ToNative( +absl::StatusOr ToNative( const cel::expr::Type::FunctionType& function_type) { - std::vector arg_types; + std::vector arg_types; arg_types.reserve(function_type.arg_types_size()); for (const auto& arg_type : function_type.arg_types()) { auto native_arg = ConvertProtoTypeToNative(arg_type); @@ -208,13 +192,14 @@ absl::StatusOr ToNative( if (!native_result.ok()) { return native_result.status(); } - return FunctionType(std::make_unique(*(std::move(native_result))), - std::move(arg_types)); + return FunctionTypeSpec( + std::make_unique(*(std::move(native_result))), + std::move(arg_types)); } absl::StatusOr ToNative( const cel::expr::Type::AbstractType& abstract_type) { - std::vector parameter_types; + std::vector parameter_types; for (const auto& parameter_type : abstract_type.parameter_types()) { auto native_parameter_type = ConvertProtoTypeToNative(parameter_type); if (!native_parameter_type.ok()) { @@ -225,81 +210,81 @@ absl::StatusOr ToNative( return AbstractType(abstract_type.name(), std::move(parameter_types)); } -absl::StatusOr ConvertProtoTypeToNative( +absl::StatusOr ConvertProtoTypeToNative( const cel::expr::Type& type) { switch (type.type_kind_case()) { case cel::expr::Type::kDyn: - return Type(DynamicType()); + return TypeSpec(DynTypeSpec()); case cel::expr::Type::kNull: - return Type(NullType()); + return TypeSpec(NullTypeSpec()); case cel::expr::Type::kPrimitive: { auto native_primitive = ToNative(type.primitive()); if (!native_primitive.ok()) { return native_primitive.status(); } - return Type(*(std::move(native_primitive))); + return TypeSpec(*(std::move(native_primitive))); } case cel::expr::Type::kWrapper: { auto native_wrapper = ToNative(type.wrapper()); if (!native_wrapper.ok()) { return native_wrapper.status(); } - return Type(PrimitiveTypeWrapper(*(std::move(native_wrapper)))); + return TypeSpec(PrimitiveTypeWrapper(*(std::move(native_wrapper)))); } case cel::expr::Type::kWellKnown: { auto native_well_known = ToNative(type.well_known()); if (!native_well_known.ok()) { return native_well_known.status(); } - return Type(*std::move(native_well_known)); + return TypeSpec(*std::move(native_well_known)); } case cel::expr::Type::kListType: { auto native_list_type = ToNative(type.list_type()); if (!native_list_type.ok()) { return native_list_type.status(); } - return Type(*(std::move(native_list_type))); + return TypeSpec(*(std::move(native_list_type))); } case cel::expr::Type::kMapType: { auto native_map_type = ToNative(type.map_type()); if (!native_map_type.ok()) { return native_map_type.status(); } - return Type(*(std::move(native_map_type))); + return TypeSpec(*(std::move(native_map_type))); } case cel::expr::Type::kFunction: { auto native_function = ToNative(type.function()); if (!native_function.ok()) { return native_function.status(); } - return Type(*(std::move(native_function))); + return TypeSpec(*(std::move(native_function))); } case cel::expr::Type::kMessageType: - return Type(MessageType(type.message_type())); + return TypeSpec(MessageTypeSpec(type.message_type())); case cel::expr::Type::kTypeParam: - return Type(ParamType(type.type_param())); + return TypeSpec(ParamTypeSpec(type.type_param())); case cel::expr::Type::kType: { if (type.type().type_kind_case() == cel::expr::Type::TypeKindCase::TYPE_KIND_NOT_SET) { - return Type(std::unique_ptr()); + return TypeSpec(std::unique_ptr()); } auto native_type = ConvertProtoTypeToNative(type.type()); if (!native_type.ok()) { return native_type.status(); } - return Type(std::make_unique(*std::move(native_type))); + return TypeSpec(std::make_unique(*std::move(native_type))); } case cel::expr::Type::kError: - return Type(ErrorType::kValue); + return TypeSpec(ErrorTypeSpec::kValue); case cel::expr::Type::kAbstractType: { auto native_abstract = ToNative(type.abstract_type()); if (!native_abstract.ok()) { return native_abstract.status(); } - return Type(*(std::move(native_abstract))); + return TypeSpec(*(std::move(native_abstract))); } case cel::expr::Type::TYPE_KIND_NOT_SET: - return Type(UnspecifiedType()); + return TypeSpec(UnsetTypeSpec()); default: return absl::InvalidArgumentError( "Illegal type specified for cel::expr::Type."); @@ -338,7 +323,7 @@ absl::StatusOr ReferenceToProto(const Reference& reference) { return result; } -absl::Status TypeToProto(const Type& type, TypePb* result); +absl::Status TypeToProto(const TypeSpec& type, TypePb* result); struct TypeKindToProtoVisitor { absl::Status operator()(PrimitiveType primitive) { @@ -377,56 +362,56 @@ struct TypeKindToProtoVisitor { return absl::OkStatus(); } - absl::Status operator()(UnspecifiedType) { + absl::Status operator()(UnsetTypeSpec) { result->clear_type_kind(); return absl::OkStatus(); } - absl::Status operator()(DynamicType) { + absl::Status operator()(DynTypeSpec) { result->mutable_dyn(); return absl::OkStatus(); } - absl::Status operator()(ErrorType) { + absl::Status operator()(ErrorTypeSpec) { result->mutable_error(); return absl::OkStatus(); } - absl::Status operator()(NullType) { + absl::Status operator()(NullTypeSpec) { result->set_null(google::protobuf::NULL_VALUE); return absl::OkStatus(); } - absl::Status operator()(const ListType& list_type) { + absl::Status operator()(const ListTypeSpec& list_type) { return TypeToProto(list_type.elem_type(), result->mutable_list_type()->mutable_elem_type()); } - absl::Status operator()(const MapType& map_type) { + absl::Status operator()(const MapTypeSpec& map_type) { CEL_RETURN_IF_ERROR(TypeToProto( map_type.key_type(), result->mutable_map_type()->mutable_key_type())); return TypeToProto(map_type.value_type(), result->mutable_map_type()->mutable_value_type()); } - absl::Status operator()(const MessageType& message_type) { + absl::Status operator()(const MessageTypeSpec& message_type) { result->set_message_type(message_type.type()); return absl::OkStatus(); } - absl::Status operator()(const WellKnownType& well_known_type) { + absl::Status operator()(const WellKnownTypeSpec& well_known_type) { switch (well_known_type) { - case WellKnownType::kWellKnownTypeUnspecified: + case WellKnownTypeSpec::kWellKnownTypeUnspecified: result->set_well_known(TypePb::WELL_KNOWN_TYPE_UNSPECIFIED); return absl::OkStatus(); - case WellKnownType::kAny: + case WellKnownTypeSpec::kAny: result->set_well_known(TypePb::ANY); return absl::OkStatus(); - case WellKnownType::kDuration: + case WellKnownTypeSpec::kDuration: result->set_well_known(TypePb::DURATION); return absl::OkStatus(); - case WellKnownType::kTimestamp: + case WellKnownTypeSpec::kTimestamp: result->set_well_known(TypePb::TIMESTAMP); return absl::OkStatus(); default: @@ -435,12 +420,12 @@ struct TypeKindToProtoVisitor { return absl::InvalidArgumentError("Unsupported well-known type"); } - absl::Status operator()(const FunctionType& function_type) { + absl::Status operator()(const FunctionTypeSpec& function_type) { CEL_RETURN_IF_ERROR( TypeToProto(function_type.result_type(), result->mutable_function()->mutable_result_type())); - for (const Type& arg_type : function_type.arg_types()) { + for (const TypeSpec& arg_type : function_type.arg_types()) { CEL_RETURN_IF_ERROR( TypeToProto(arg_type, result->mutable_function()->add_arg_types())); } @@ -450,19 +435,19 @@ struct TypeKindToProtoVisitor { absl::Status operator()(const AbstractType& type) { auto* abstract_type_pb = result->mutable_abstract_type(); abstract_type_pb->set_name(type.name()); - for (const Type& type_param : type.parameter_types()) { + for (const TypeSpec& type_param : type.parameter_types()) { CEL_RETURN_IF_ERROR( TypeToProto(type_param, abstract_type_pb->add_parameter_types())); } return absl::OkStatus(); } - absl::Status operator()(const std::unique_ptr& type_type) { - return TypeToProto((type_type != nullptr) ? *type_type : Type(), + absl::Status operator()(const std::unique_ptr& type_type) { + return TypeToProto((type_type != nullptr) ? *type_type : TypeSpec(), result->mutable_type()); } - absl::Status operator()(const ParamType& param_type) { + absl::Status operator()(const ParamTypeSpec& param_type) { result->set_type_param(param_type.type()); return absl::OkStatus(); } @@ -470,7 +455,7 @@ struct TypeKindToProtoVisitor { TypePb* result; }; -absl::Status TypeToProto(const Type& type, TypePb* result) { +absl::Status TypeToProto(const TypeSpec& type, TypePb* result) { return absl::visit(TypeKindToProtoVisitor{result}, type.type_kind()); } @@ -480,7 +465,7 @@ absl::StatusOr> CreateAstFromParsedExpr( const cel::expr::Expr& expr, const cel::expr::SourceInfo* source_info) { CEL_ASSIGN_OR_RETURN(auto runtime_expr, ExprValueFromProto(expr)); - cel::ast_internal::SourceInfo runtime_source_info; + SourceInfo runtime_source_info; if (source_info != nullptr) { CEL_ASSIGN_OR_RETURN(runtime_source_info, ConvertProtoSourceInfoToNative(*source_info)); diff --git a/common/ast_proto_test.cc b/common/ast_proto_test.cc index 195d25edd..ddaa4191a 100644 --- a/common/ast_proto_test.cc +++ b/common/ast_proto_test.cc @@ -32,7 +32,6 @@ #include "absl/strings/string_view.h" #include "absl/types/variant.h" #include "common/ast.h" -#include "common/ast/expr.h" #include "common/decl.h" #include "common/expr.h" #include "common/source.h" @@ -53,8 +52,8 @@ namespace { using ::absl_testing::IsOk; using ::absl_testing::StatusIs; -using ::cel::ast_internal::PrimitiveType; -using ::cel::ast_internal::WellKnownType; +using ::cel::PrimitiveType; +using ::cel::WellKnownTypeSpec; using ::cel::internal::test::EqualsProto; using ::cel::expr::CheckedExpr; using ::cel::expr::ParsedExpr; @@ -62,7 +61,7 @@ using ::testing::HasSubstr; using TypePb = cel::expr::Type; -absl::StatusOr ConvertProtoTypeToNative( +absl::StatusOr ConvertProtoTypeToNative( const cel::expr::Type& type) { CheckedExpr checked_expr; checked_expr.mutable_expr()->mutable_ident_expr()->set_name("foo"); @@ -169,7 +168,7 @@ TEST(AstConvertersTest, WellKnownTypeUnspecifiedToNative) { ASSERT_TRUE(native_type->has_well_known()); EXPECT_EQ(native_type->well_known(), - WellKnownType::kWellKnownTypeUnspecified); + WellKnownTypeSpec::kWellKnownTypeUnspecified); } TEST(AstConvertersTest, WellKnownTypeAnyToNative) { @@ -179,7 +178,7 @@ TEST(AstConvertersTest, WellKnownTypeAnyToNative) { auto native_type = ConvertProtoTypeToNative(type); ASSERT_TRUE(native_type->has_well_known()); - EXPECT_EQ(native_type->well_known(), WellKnownType::kAny); + EXPECT_EQ(native_type->well_known(), WellKnownTypeSpec::kAny); } TEST(AstConvertersTest, WellKnownTypeTimestampToNative) { @@ -189,7 +188,7 @@ TEST(AstConvertersTest, WellKnownTypeTimestampToNative) { auto native_type = ConvertProtoTypeToNative(type); ASSERT_TRUE(native_type->has_well_known()); - EXPECT_EQ(native_type->well_known(), WellKnownType::kTimestamp); + EXPECT_EQ(native_type->well_known(), WellKnownTypeSpec::kTimestamp); } TEST(AstConvertersTest, WellKnownTypeDuraionToNative) { @@ -199,7 +198,7 @@ TEST(AstConvertersTest, WellKnownTypeDuraionToNative) { auto native_type = ConvertProtoTypeToNative(type); ASSERT_TRUE(native_type->has_well_known()); - EXPECT_EQ(native_type->well_known(), WellKnownType::kDuration); + EXPECT_EQ(native_type->well_known(), WellKnownTypeSpec::kDuration); } TEST(AstConvertersTest, WellKnownTypeError) { @@ -316,7 +315,7 @@ TEST(AstConvertersTest, NullTypeToNative) { auto native_type = ConvertProtoTypeToNative(type); ASSERT_TRUE(native_type->has_null()); - EXPECT_EQ(native_type->null(), ast_internal::NullType()); + EXPECT_EQ(native_type->null(), NullTypeSpec()); } TEST(AstConvertersTest, PrimitiveTypeWrapperToNative) { @@ -363,8 +362,7 @@ TEST(AstConvertersTest, TypeTypeDefault) { auto native_type = ConvertProtoTypeToNative(cel::expr::Type()); ASSERT_THAT(native_type, IsOk()); - EXPECT_TRUE(absl::holds_alternative( - native_type->type_kind())); + EXPECT_TRUE(absl::holds_alternative(native_type->type_kind())); } TEST(AstConvertersTest, ReferenceToNative) { @@ -478,14 +476,14 @@ TEST(AstConvertersTest, AstToCheckedExprBasic) { macro.mutable_ident_expr().set_name("name"); ast.mutable_source_info().mutable_macro_calls().insert({1, std::move(macro)}); - ast_internal::Reference reference; + Reference reference; reference.set_name("name"); reference.mutable_overload_id().push_back("id1"); reference.mutable_overload_id().push_back("id2"); reference.mutable_value().set_bool_value(true); - ast_internal::Type type; - type.set_type_kind(ast_internal::DynamicType()); + TypeSpec type; + type.set_type_kind(DynTypeSpec()); ast.mutable_reference_map().insert({1, std::move(reference)}); ast.mutable_type_map().insert({1, std::move(type)}); @@ -654,7 +652,7 @@ TEST(AstConvertersTest, AstToParsedExprBasic) { expr.set_id(1); expr.mutable_ident_expr().set_name("expr"); - ast_internal::SourceInfo source_info; + SourceInfo source_info; source_info.set_syntax_version("version"); source_info.set_location("location"); source_info.mutable_line_offsets().push_back(1); diff --git a/eval/compiler/BUILD b/eval/compiler/BUILD index efbe09f1b..33541f822 100644 --- a/eval/compiler/BUILD +++ b/eval/compiler/BUILD @@ -108,7 +108,6 @@ cc_library( "//common:kind", "//common:type", "//common:value", - "//common/ast:expr", "//eval/eval:comprehension_step", "//eval/eval:const_value_step", "//eval/eval:container_access_step", @@ -395,7 +394,6 @@ cc_library( "//common:ast_rewrite", "//common:expr", "//common:kind", - "//common/ast:expr", "//runtime:runtime_issue", "//runtime/internal:issue_collector", "@com_google_absl//absl/container:flat_hash_map", @@ -440,7 +438,6 @@ cc_test( "//base:builtins", "//common:ast", "//common:expr", - "//common/ast:expr", "//common/ast:expr_proto", "//eval/public:builtin_func_registrar", "//eval/public:cel_function", @@ -515,7 +512,6 @@ cc_library( "//common:expr", "//common:native_type", "//common:value", - "//common/ast:expr", "//eval/eval:compiler_constant_step", "//eval/eval:direct_expression_step", "//eval/eval:evaluator_core", diff --git a/eval/compiler/flat_expr_builder.cc b/eval/compiler/flat_expr_builder.cc index 31857fa9b..141cabdf1 100644 --- a/eval/compiler/flat_expr_builder.cc +++ b/eval/compiler/flat_expr_builder.cc @@ -52,7 +52,6 @@ #include "base/type_provider.h" #include "common/allocator.h" #include "common/ast.h" -#include "common/ast/expr.h" #include "common/ast_traverse.h" #include "common/ast_visitor.h" #include "common/constant.h" @@ -506,8 +505,7 @@ class FlatExprVisitor : public cel::AstVisitor { FlatExprVisitor( const Resolver& resolver, const cel::RuntimeOptions& options, std::vector> program_optimizers, - const absl::flat_hash_map& - reference_map, + const absl::flat_hash_map& reference_map, const cel::TypeProvider& type_provider, IssueCollector& issue_collector, ProgramBuilder& program_builder, PlannerContext& extension_context, bool enable_optional_types) diff --git a/eval/compiler/qualified_reference_resolver.cc b/eval/compiler/qualified_reference_resolver.cc index cd653da3c..09950bfe8 100644 --- a/eval/compiler/qualified_reference_resolver.cc +++ b/eval/compiler/qualified_reference_resolver.cc @@ -29,7 +29,7 @@ #include "absl/types/optional.h" #include "base/ast.h" #include "base/builtins.h" -#include "common/ast/expr.h" +#include "common/ast.h" #include "common/ast_rewrite.h" #include "common/expr.h" #include "common/kind.h" @@ -43,8 +43,8 @@ namespace google::api::expr::runtime { namespace { using ::cel::Expr; +using ::cel::Reference; using ::cel::RuntimeIssue; -using ::cel::ast_internal::Reference; using ::cel::runtime_internal::IssueCollector; // Optional types are opt-in but require special handling in the evaluator. diff --git a/eval/compiler/qualified_reference_resolver_test.cc b/eval/compiler/qualified_reference_resolver_test.cc index 329cceb0d..0d710a465 100644 --- a/eval/compiler/qualified_reference_resolver_test.cc +++ b/eval/compiler/qualified_reference_resolver_test.cc @@ -26,7 +26,6 @@ #include "base/ast.h" #include "base/builtins.h" #include "common/ast.h" -#include "common/ast/expr.h" #include "common/ast/expr_proto.h" #include "common/expr.h" #include "eval/compiler/resolver.h" @@ -51,8 +50,8 @@ using ::absl_testing::StatusIs; using ::cel::Ast; using ::cel::Expr; using ::cel::RuntimeIssue; +using ::cel::SourceInfo; using ::cel::ast_internal::ExprToProto; -using ::cel::ast_internal::SourceInfo; using ::cel::internal::test::EqualsProto; using ::cel::runtime_internal::IssueCollector; using ::testing::Contains; diff --git a/eval/compiler/regex_precompilation_optimization.cc b/eval/compiler/regex_precompilation_optimization.cc index 7f5759c09..dcc7edd2b 100644 --- a/eval/compiler/regex_precompilation_optimization.cc +++ b/eval/compiler/regex_precompilation_optimization.cc @@ -28,7 +28,6 @@ #include "absl/types/optional.h" #include "base/builtins.h" #include "common/ast.h" -#include "common/ast/expr.h" #include "common/casting.h" #include "common/expr.h" #include "common/native_type.h" @@ -51,9 +50,9 @@ using ::cel::Cast; using ::cel::Expr; using ::cel::InstanceOf; using ::cel::NativeTypeId; +using ::cel::Reference; using ::cel::StringValue; using ::cel::Value; -using ::cel::ast_internal::Reference; using ::cel::internal::down_cast; using ReferenceMap = absl::flat_hash_map; diff --git a/eval/eval/BUILD b/eval/eval/BUILD index 15b81ca01..256390459 100644 --- a/eval/eval/BUILD +++ b/eval/eval/BUILD @@ -654,8 +654,8 @@ cc_test( ":ident_step", "//base:builtins", "//base:data", + "//common:ast", "//common:expr", - "//common/ast:expr", "//eval/public:activation", "//eval/public:cel_attribute", "//eval/public:cel_expr_builder_factory", diff --git a/eval/eval/container_access_step_test.cc b/eval/eval/container_access_step_test.cc index b4a549083..ce640987d 100644 --- a/eval/eval/container_access_step_test.cc +++ b/eval/eval/container_access_step_test.cc @@ -12,7 +12,7 @@ #include "absl/status/status.h" #include "base/builtins.h" #include "base/type_provider.h" -#include "common/ast/expr.h" +#include "common/ast.h" #include "common/expr.h" #include "eval/eval/cel_expression_flat_impl.h" #include "eval/eval/direct_expression_step.h" @@ -41,8 +41,8 @@ namespace { using ::absl_testing::StatusIs; using ::cel::Expr; +using ::cel::SourceInfo; using ::cel::TypeProvider; -using ::cel::ast_internal::SourceInfo; using ::cel::runtime_internal::NewTestingRuntimeEnv; using ::cel::runtime_internal::RuntimeEnv; using ::cel::expr::ParsedExpr; diff --git a/parser/BUILD b/parser/BUILD index 63a6918c0..13caa3bf6 100644 --- a/parser/BUILD +++ b/parser/BUILD @@ -43,7 +43,6 @@ cc_library( "//common:expr_factory", "//common:operators", "//common:source", - "//common/ast:expr", "//common/ast:expr_proto", "//common/ast:source_info_proto", "//internal:lexis", diff --git a/parser/parser.cc b/parser/parser.cc index 9f2cec0d9..af0803341 100644 --- a/parser/parser.cc +++ b/parser/parser.cc @@ -54,7 +54,6 @@ #include "absl/types/variant.h" #include "antlr4-runtime.h" #include "common/ast.h" -#include "common/ast/expr.h" #include "common/ast/expr_proto.h" #include "common/ast/source_info_proto.h" #include "common/constant.h" @@ -670,7 +669,7 @@ class ParserVisitor final : public CelBaseVisitor, std::any visitNull(CelParser::NullContext* ctx) override; // Note: this is destructive and intended to be called after the parse is // finished. - cel::ast_internal::SourceInfo GetSourceInfo(); + cel::SourceInfo GetSourceInfo(); EnrichedSourceInfo enriched_source_info() const; void syntaxError(antlr4::Recognizer* recognizer, antlr4::Token* offending_symbol, size_t line, size_t col, @@ -1397,8 +1396,8 @@ std::any ParserVisitor::visitNull(CelParser::NullContext* ctx) { factory_.NextId(SourceRangeFromParserRuleContext(ctx)))); } -cel::ast_internal::SourceInfo ParserVisitor::GetSourceInfo() { - cel::ast_internal::SourceInfo source_info; +cel::SourceInfo ParserVisitor::GetSourceInfo() { + cel::SourceInfo source_info; source_info.set_location(std::string(source_.description())); for (const auto& positions : factory_.positions()) { source_info.mutable_positions().insert( @@ -1638,7 +1637,7 @@ class RecoveryLimitErrorStrategy final : public DefaultErrorStrategy { struct ParseResult { cel::Expr expr; - cel::ast_internal::SourceInfo source_info; + cel::SourceInfo source_info; EnrichedSourceInfo enriched_source_info; }; diff --git a/runtime/internal/BUILD b/runtime/internal/BUILD index b5f532410..6ee9482b5 100644 --- a/runtime/internal/BUILD +++ b/runtime/internal/BUILD @@ -88,9 +88,9 @@ cc_library( hdrs = ["convert_constant.h"], deps = [ "//common:allocator", + "//common:ast", "//common:constant", "//common:value", - "//common/ast:expr", "//eval/internal:errors", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", diff --git a/runtime/internal/convert_constant.h b/runtime/internal/convert_constant.h index 6d3349b0e..f1ac0c850 100644 --- a/runtime/internal/convert_constant.h +++ b/runtime/internal/convert_constant.h @@ -16,7 +16,7 @@ #include "absl/status/statusor.h" #include "common/allocator.h" -#include "common/ast/expr.h" +#include "common/ast.h" #include "common/value.h" namespace cel::runtime_internal { diff --git a/testutil/BUILD b/testutil/BUILD index bb31ea02e..3f1aa4fe8 100644 --- a/testutil/BUILD +++ b/testutil/BUILD @@ -70,7 +70,6 @@ cc_library( ":expr_printer", "//common:ast", "//common:expr", - "//common/ast:expr", "//extensions/protobuf:ast_converters", "@com_google_absl//absl/strings", "@com_google_cel_spec//proto/cel/expr:checked_cc_proto", @@ -83,7 +82,6 @@ cc_test( deps = [ ":baseline_tests", "//common:ast", - "//common/ast:expr", "//internal:testing", "@com_google_protobuf//:protobuf", ], diff --git a/testutil/baseline_tests.cc b/testutil/baseline_tests.cc index f5f725819..4e56ad485 100644 --- a/testutil/baseline_tests.cc +++ b/testutil/baseline_tests.cc @@ -21,7 +21,6 @@ #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" #include "common/ast.h" -#include "common/ast/expr.h" #include "common/expr.h" #include "extensions/protobuf/ast_converters.h" #include "testutil/expr_printer.h" @@ -59,11 +58,11 @@ std::string FormatType(const TypeSpec& t) { return absl::StrCat("wrapper(", FormatPrimitive(t.wrapper()), ")"); } else if (t.has_well_known()) { switch (t.well_known()) { - case ast_internal::WellKnownType::kAny: + case WellKnownTypeSpec::kAny: return "google.protobuf.Any"; - case ast_internal::WellKnownType::kDuration: + case WellKnownTypeSpec::kDuration: return "google.protobuf.Duration"; - case ast_internal::WellKnownType::kTimestamp: + case WellKnownTypeSpec::kTimestamp: return "google.protobuf.Timestamp"; default: return ""; @@ -98,7 +97,7 @@ std::string FormatType(const TypeSpec& t) { return ""; } -std::string FormatReference(const cel::ast_internal::Reference& r) { +std::string FormatReference(const cel::Reference& r) { if (r.overload_id().empty()) { return r.name(); } diff --git a/testutil/baseline_tests_test.cc b/testutil/baseline_tests_test.cc index 13fcfab1b..33050583f 100644 --- a/testutil/baseline_tests_test.cc +++ b/testutil/baseline_tests_test.cc @@ -18,7 +18,6 @@ #include #include "common/ast.h" -#include "common/ast/expr.h" #include "internal/testing.h" #include "google/protobuf/text_format.h" @@ -31,7 +30,7 @@ TEST(FormatBaselineAst, Basic) { Ast ast; ast.mutable_root_expr().mutable_ident_expr().set_name("foo"); ast.mutable_root_expr().set_id(1); - ast.mutable_type_map()[1] = TypeSpec(ast_internal::PrimitiveType::kInt64); + ast.mutable_type_map()[1] = TypeSpec(PrimitiveType::kInt64); ast.mutable_reference_map()[1].set_name("foo"); EXPECT_EQ(FormatBaselineAst(ast), "foo~int^foo"); @@ -50,7 +49,7 @@ TEST(FormatBaselineAst, NoReference) { Ast ast; ast.mutable_root_expr().mutable_ident_expr().set_name("foo"); ast.mutable_root_expr().set_id(1); - ast.mutable_type_map()[1] = TypeSpec(ast_internal::PrimitiveType::kInt64); + ast.mutable_type_map()[1] = TypeSpec(PrimitiveType::kInt64); EXPECT_EQ(FormatBaselineAst(ast), "foo~int"); } @@ -59,7 +58,7 @@ TEST(FormatBaselineAst, MutlipleReferences) { Ast ast; ast.mutable_root_expr().mutable_call_expr().set_function("_+_"); ast.mutable_root_expr().set_id(1); - ast.mutable_type_map()[1] = TypeSpec(ast_internal::DynamicType()); + ast.mutable_type_map()[1] = TypeSpec(DynTypeSpec()); ast.mutable_reference_map()[1].mutable_overload_id().push_back( "add_timestamp_duration"); ast.mutable_reference_map()[1].mutable_overload_id().push_back( @@ -68,15 +67,14 @@ TEST(FormatBaselineAst, MutlipleReferences) { auto& arg1 = ast.mutable_root_expr().mutable_call_expr().add_args(); arg1.mutable_ident_expr().set_name("a"); arg1.set_id(2); - ast.mutable_type_map()[2] = TypeSpec(ast_internal::DynamicType()); + ast.mutable_type_map()[2] = TypeSpec(DynTypeSpec()); ast.mutable_reference_map()[2].set_name("a"); } { auto& arg2 = ast.mutable_root_expr().mutable_call_expr().add_args(); arg2.mutable_ident_expr().set_name("b"); arg2.set_id(3); - ast.mutable_type_map()[3] = - TypeSpec(ast_internal::WellKnownType::kDuration); + ast.mutable_type_map()[3] = TypeSpec(WellKnownTypeSpec::kDuration); ast.mutable_reference_map()[3].set_name("b"); } @@ -161,58 +159,47 @@ TEST_P(FormatBaselineTypeSpecTest, Runner) { INSTANTIATE_TEST_SUITE_P( Types, FormatBaselineTypeSpecTest, ::testing::Values( - TestCase{TypeSpec(ast_internal::PrimitiveType::kBool), "x~bool"}, - TestCase{TypeSpec(ast_internal::PrimitiveType::kInt64), "x~int"}, - TestCase{TypeSpec(ast_internal::PrimitiveType::kUint64), "x~uint"}, - TestCase{TypeSpec(ast_internal::PrimitiveType::kDouble), "x~double"}, - TestCase{TypeSpec(ast_internal::PrimitiveType::kString), "x~string"}, - TestCase{TypeSpec(ast_internal::PrimitiveType::kBytes), "x~bytes"}, - TestCase{TypeSpec(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kBool)), + TestCase{TypeSpec(PrimitiveType::kBool), "x~bool"}, + TestCase{TypeSpec(PrimitiveType::kInt64), "x~int"}, + TestCase{TypeSpec(PrimitiveType::kUint64), "x~uint"}, + TestCase{TypeSpec(PrimitiveType::kDouble), "x~double"}, + TestCase{TypeSpec(PrimitiveType::kString), "x~string"}, + TestCase{TypeSpec(PrimitiveType::kBytes), "x~bytes"}, + TestCase{TypeSpec(PrimitiveTypeWrapper(PrimitiveType::kBool)), "x~wrapper(bool)"}, - TestCase{TypeSpec(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kInt64)), + TestCase{TypeSpec(PrimitiveTypeWrapper(PrimitiveType::kInt64)), "x~wrapper(int)"}, - TestCase{TypeSpec(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kUint64)), + TestCase{TypeSpec(PrimitiveTypeWrapper(PrimitiveType::kUint64)), "x~wrapper(uint)"}, - TestCase{TypeSpec(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kDouble)), + TestCase{TypeSpec(PrimitiveTypeWrapper(PrimitiveType::kDouble)), "x~wrapper(double)"}, - TestCase{TypeSpec(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kString)), + TestCase{TypeSpec(PrimitiveTypeWrapper(PrimitiveType::kString)), "x~wrapper(string)"}, - TestCase{TypeSpec(ast_internal::PrimitiveTypeWrapper( - ast_internal::PrimitiveType::kBytes)), + TestCase{TypeSpec(PrimitiveTypeWrapper(PrimitiveType::kBytes)), "x~wrapper(bytes)"}, - TestCase{TypeSpec(ast_internal::WellKnownType::kAny), - "x~google.protobuf.Any"}, - TestCase{TypeSpec(ast_internal::WellKnownType::kDuration), + TestCase{TypeSpec(WellKnownTypeSpec::kAny), "x~google.protobuf.Any"}, + TestCase{TypeSpec(WellKnownTypeSpec::kDuration), "x~google.protobuf.Duration"}, - TestCase{TypeSpec(ast_internal::WellKnownType::kTimestamp), + TestCase{TypeSpec(WellKnownTypeSpec::kTimestamp), "x~google.protobuf.Timestamp"}, - TestCase{TypeSpec(ast_internal::DynamicType()), "x~dyn"}, - TestCase{TypeSpec(ast_internal::NullType()), "x~null"}, - TestCase{TypeSpec(ast_internal::UnspecifiedType()), "x~"}, - TestCase{TypeSpec(ast_internal::MessageType("com.example.Type")), + TestCase{TypeSpec(DynTypeSpec()), "x~dyn"}, + TestCase{TypeSpec(NullTypeSpec()), "x~null"}, + TestCase{TypeSpec(UnsetTypeSpec()), "x~"}, + TestCase{TypeSpec(MessageTypeSpec("com.example.Type")), "x~com.example.Type"}, - TestCase{TypeSpec(ast_internal::AbstractType( - "optional_type", - {TypeSpec(ast_internal::PrimitiveType::kInt64)})), + TestCase{TypeSpec(AbstractType("optional_type", + {TypeSpec(PrimitiveType::kInt64)})), "x~optional_type(int)"}, TestCase{TypeSpec(std::make_unique()), "x~type"}, - TestCase{TypeSpec(std::make_unique( - ast_internal::PrimitiveType::kInt64)), + TestCase{TypeSpec(std::make_unique(PrimitiveType::kInt64)), "x~type(int)"}, - TestCase{TypeSpec(ast_internal::ParamType("T")), "x~T"}, - TestCase{TypeSpec(ast_internal::MapType( - std::make_unique( - ast_internal::PrimitiveType::kString), - std::make_unique( - ast_internal::PrimitiveType::kString))), + TestCase{TypeSpec(ParamTypeSpec("T")), "x~T"}, + TestCase{TypeSpec(MapTypeSpec( + std::make_unique(PrimitiveType::kString), + std::make_unique(PrimitiveType::kString))), "x~map(string, string)"}, - TestCase{TypeSpec(ast_internal::ListType(std::make_unique( - ast_internal::PrimitiveType::kString))), + TestCase{TypeSpec(ListTypeSpec( + std::make_unique(PrimitiveType::kString))), "x~list(string)"})); } // namespace diff --git a/tools/BUILD b/tools/BUILD index 0071e1018..2790b845c 100644 --- a/tools/BUILD +++ b/tools/BUILD @@ -76,11 +76,9 @@ cc_library( "//eval/public:ast_visitor", "//eval/public:ast_visitor_base", "//eval/public:source_position", - "@com_google_absl//absl/base:nullability", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/functional:any_invocable", "@com_google_absl//absl/memory", - "@com_google_absl//absl/types:span", "@com_google_cel_spec//proto/cel/expr:checked_cc_proto", "@com_google_cel_spec//proto/cel/expr:syntax_cc_proto", ],