diff --git a/checker/internal/type_checker_impl.cc b/checker/internal/type_checker_impl.cc index 7b05e1cb9..0967c7326 100644 --- a/checker/internal/type_checker_impl.cc +++ b/checker/internal/type_checker_impl.cc @@ -180,7 +180,7 @@ absl::StatusOr FlattenType(const Type& type) { case TypeKind::kError: return AstType(ast_internal::ErrorType()); case TypeKind::kNull: - return AstType(nullptr); + return AstType(ast_internal::NullType()); case TypeKind::kBool: return AstType(ast_internal::PrimitiveType::kBool); case TypeKind::kInt: diff --git a/checker/internal/type_checker_impl_test.cc b/checker/internal/type_checker_impl_test.cc index 208861030..66fb7b57c 100644 --- a/checker/internal/type_checker_impl_test.cc +++ b/checker/internal/type_checker_impl_test.cc @@ -926,7 +926,7 @@ INSTANTIATE_TEST_SUITE_P( ::testing::Values( AstTypeConversionTestCase{ .decl_type = NullType(), - .expected_type = AstType(nullptr), + .expected_type = AstType(ast_internal::NullType()), }, AstTypeConversionTestCase{ .decl_type = DynType(), diff --git a/codelab/BUILD b/codelab/BUILD index 954ec25ba..7cc3e6767 100644 --- a/codelab/BUILD +++ b/codelab/BUILD @@ -39,6 +39,10 @@ cc_library( name = "exercise1", srcs = ["exercise1.cc"], hdrs = ["exercise1.h"], + tags = [ + "manual", + "nobuilder", + ], deps = [ "//eval/public:activation", "//eval/public:builtin_func_registrar", diff --git a/common/ast/expr.h b/common/ast/expr.h index f23eafdad..a3820c4a6 100644 --- a/common/ast/expr.h +++ b/common/ast/expr.h @@ -17,7 +17,6 @@ #ifndef THIRD_PARTY_CEL_CPP_BASE_AST_INTERNAL_EXPR_H_ #define THIRD_PARTY_CEL_CPP_BASE_AST_INTERNAL_EXPR_H_ -#include #include #include #include @@ -33,19 +32,6 @@ namespace cel::ast_internal { -// Temporary aliases that will be deleted in future. -using NullValue = std::nullptr_t; -using Bytes = cel::BytesConstant; -using Constant = cel::Constant; -using ConstantKind = cel::ConstantKind; -using Ident = cel::IdentExpr; -using Expr = cel::Expr; -using ExprKind = cel::ExprKind; -using Select = cel::SelectExpr; -using Call = cel::CallExpr; -using CreateList = cel::ListExpr; -using CreateStruct = cel::StructExpr; -using Comprehension = cel::ComprehensionExpr; // An extension that was requested for the source expression. class Extension { @@ -566,10 +552,17 @@ enum class ErrorType { kErrorTypeValue = 0 }; struct UnspecifiedType : public absl::monostate {}; -struct DynamicType : public absl::monostate {}; +struct DynamicType {}; + +inline bool operator==(const DynamicType&, const DynamicType&) { return true; } +inline bool operator!=(const DynamicType&, const DynamicType&) { return false; } + +struct NullType {}; +inline bool operator==(const NullType&, const NullType&) { return true; } +inline bool operator!=(const NullType&, const NullType&) { return false; } using TypeKind = - absl::variant, ErrorType, AbstractType>; @@ -599,7 +592,7 @@ class Type { } bool has_null() const { - return absl::holds_alternative(type_kind_); + return absl::holds_alternative(type_kind_); } bool has_primitive() const { @@ -646,12 +639,12 @@ class Type { return absl::holds_alternative(type_kind_); } - NullValue null() const { - auto* value = absl::get_if(&type_kind_); + NullType null() const { + auto* value = absl::get_if(&type_kind_); if (value != nullptr) { return *value; } - return nullptr; + return {}; } PrimitiveType primitive() const { diff --git a/common/ast/expr_test.cc b/common/ast/expr_test.cc index 2ef74488a..fb62cbda7 100644 --- a/common/ast/expr_test.cc +++ b/common/ast/expr_test.cc @@ -81,7 +81,7 @@ TEST(AstTest, FunctionTypeDefaults) { } TEST(AstTest, TypeDefaults) { - EXPECT_EQ(Type().null(), nullptr); + EXPECT_EQ(Type().null(), NullType()); EXPECT_EQ(Type().primitive(), PrimitiveType::kPrimitiveTypeUnspecified); EXPECT_EQ(Type().wrapper(), PrimitiveType::kPrimitiveTypeUnspecified); EXPECT_EQ(Type().well_known(), WellKnownType::kWellKnownTypeUnspecified); diff --git a/common/ast_proto.cc b/common/ast_proto.cc index 8e097a266..5fcf21f80 100644 --- a/common/ast_proto.cc +++ b/common/ast_proto.cc @@ -14,7 +14,6 @@ #include "common/ast_proto.h" -#include #include #include #include @@ -57,7 +56,7 @@ using ::cel::ast_internal::FunctionType; using ::cel::ast_internal::ListType; using ::cel::ast_internal::MapType; using ::cel::ast_internal::MessageType; -using ::cel::ast_internal::NullValue; +using ::cel::ast_internal::NullType; using ::cel::ast_internal::ParamType; using ::cel::ast_internal::PrimitiveType; using ::cel::ast_internal::PrimitiveTypeWrapper; @@ -234,7 +233,7 @@ absl::StatusOr ConvertProtoTypeToNative( case cel::expr::Type::kDyn: return Type(DynamicType()); case cel::expr::Type::kNull: - return Type(nullptr); + return Type(NullType()); case cel::expr::Type::kPrimitive: { auto native_primitive = ToNative(type.primitive()); if (!native_primitive.ok()) { @@ -395,7 +394,7 @@ struct TypeKindToProtoVisitor { return absl::OkStatus(); } - absl::Status operator()(std::nullptr_t) { + absl::Status operator()(NullType) { result->set_null(google::protobuf::NULL_VALUE); return absl::OkStatus(); } diff --git a/common/ast_proto_test.cc b/common/ast_proto_test.cc index 3d8b31af6..4837a413d 100644 --- a/common/ast_proto_test.cc +++ b/common/ast_proto_test.cc @@ -311,7 +311,7 @@ TEST(AstConvertersTest, NullTypeToNative) { auto native_type = ConvertProtoTypeToNative(type); ASSERT_TRUE(native_type->has_null()); - EXPECT_EQ(native_type->null(), nullptr); + EXPECT_EQ(native_type->null(), ast_internal::NullType()); } TEST(AstConvertersTest, PrimitiveTypeWrapperToNative) { diff --git a/runtime/internal/convert_constant.cc b/runtime/internal/convert_constant.cc index 6a33cfb0b..a9effd229 100644 --- a/runtime/internal/convert_constant.cc +++ b/runtime/internal/convert_constant.cc @@ -14,6 +14,7 @@ #include "runtime/internal/convert_constant.h" +#include #include #include "absl/status/status.h" @@ -21,7 +22,6 @@ #include "absl/time/time.h" #include "absl/types/variant.h" #include "common/allocator.h" -#include "common/ast/expr.h" #include "common/constant.h" #include "common/value.h" #include "eval/internal/errors.h" @@ -36,10 +36,7 @@ struct ConvertVisitor { absl::StatusOr operator()(absl::monostate) { return absl::InvalidArgumentError("unspecified constant"); } - absl::StatusOr operator()( - const cel::ast_internal::NullValue& value) { - return NullValue(); - } + absl::StatusOr operator()(std::nullptr_t) { return NullValue(); } absl::StatusOr operator()(bool value) { return BoolValue(value); } absl::StatusOr operator()(int64_t value) { return IntValue(value); diff --git a/testutil/baseline_tests_test.cc b/testutil/baseline_tests_test.cc index 28ca73a52..cf7027982 100644 --- a/testutil/baseline_tests_test.cc +++ b/testutil/baseline_tests_test.cc @@ -194,7 +194,7 @@ INSTANTIATE_TEST_SUITE_P( TestCase{AstType(ast_internal::WellKnownType::kTimestamp), "x~google.protobuf.Timestamp"}, TestCase{AstType(ast_internal::DynamicType()), "x~dyn"}, - TestCase{AstType(nullptr), "x~null"}, + TestCase{AstType(ast_internal::NullType()), "x~null"}, TestCase{AstType(ast_internal::UnspecifiedType()), "x~"}, TestCase{AstType(ast_internal::MessageType("com.example.Type")), "x~com.example.Type"},