Skip to content

Commit d76b840

Browse files
jnthntatumcopybara-github
authored andcommitted
Add ast_internal::NullType for internal AST type representation.
Remove unused type aliases in ast_internal. PiperOrigin-RevId: 792296334
1 parent ecae658 commit d76b840

9 files changed

Lines changed: 27 additions & 34 deletions

File tree

checker/internal/type_checker_impl.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ absl::StatusOr<AstType> FlattenType(const Type& type) {
180180
case TypeKind::kError:
181181
return AstType(ast_internal::ErrorType());
182182
case TypeKind::kNull:
183-
return AstType(nullptr);
183+
return AstType(ast_internal::NullType());
184184
case TypeKind::kBool:
185185
return AstType(ast_internal::PrimitiveType::kBool);
186186
case TypeKind::kInt:

checker/internal/type_checker_impl_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ INSTANTIATE_TEST_SUITE_P(
926926
::testing::Values(
927927
AstTypeConversionTestCase{
928928
.decl_type = NullType(),
929-
.expected_type = AstType(nullptr),
929+
.expected_type = AstType(ast_internal::NullType()),
930930
},
931931
AstTypeConversionTestCase{
932932
.decl_type = DynType(),

codelab/BUILD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ cc_library(
3939
name = "exercise1",
4040
srcs = ["exercise1.cc"],
4141
hdrs = ["exercise1.h"],
42+
tags = [
43+
"manual",
44+
"nobuilder",
45+
],
4246
deps = [
4347
"//eval/public:activation",
4448
"//eval/public:builtin_func_registrar",

common/ast/expr.h

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#ifndef THIRD_PARTY_CEL_CPP_BASE_AST_INTERNAL_EXPR_H_
1818
#define THIRD_PARTY_CEL_CPP_BASE_AST_INTERNAL_EXPR_H_
1919

20-
#include <cstddef>
2120
#include <cstdint>
2221
#include <memory>
2322
#include <string>
@@ -33,19 +32,6 @@
3332

3433
namespace cel::ast_internal {
3534

36-
// Temporary aliases that will be deleted in future.
37-
using NullValue = std::nullptr_t;
38-
using Bytes = cel::BytesConstant;
39-
using Constant = cel::Constant;
40-
using ConstantKind = cel::ConstantKind;
41-
using Ident = cel::IdentExpr;
42-
using Expr = cel::Expr;
43-
using ExprKind = cel::ExprKind;
44-
using Select = cel::SelectExpr;
45-
using Call = cel::CallExpr;
46-
using CreateList = cel::ListExpr;
47-
using CreateStruct = cel::StructExpr;
48-
using Comprehension = cel::ComprehensionExpr;
4935

5036
// An extension that was requested for the source expression.
5137
class Extension {
@@ -566,10 +552,17 @@ enum class ErrorType { kErrorTypeValue = 0 };
566552

567553
struct UnspecifiedType : public absl::monostate {};
568554

569-
struct DynamicType : public absl::monostate {};
555+
struct DynamicType {};
556+
557+
inline bool operator==(const DynamicType&, const DynamicType&) { return true; }
558+
inline bool operator!=(const DynamicType&, const DynamicType&) { return false; }
559+
560+
struct NullType {};
561+
inline bool operator==(const NullType&, const NullType&) { return true; }
562+
inline bool operator!=(const NullType&, const NullType&) { return false; }
570563

571564
using TypeKind =
572-
absl::variant<UnspecifiedType, DynamicType, NullValue, PrimitiveType,
565+
absl::variant<UnspecifiedType, DynamicType, NullType, PrimitiveType,
573566
PrimitiveTypeWrapper, WellKnownType, ListType, MapType,
574567
FunctionType, MessageType, ParamType,
575568
absl_nullable std::unique_ptr<Type>, ErrorType, AbstractType>;
@@ -599,7 +592,7 @@ class Type {
599592
}
600593

601594
bool has_null() const {
602-
return absl::holds_alternative<NullValue>(type_kind_);
595+
return absl::holds_alternative<NullType>(type_kind_);
603596
}
604597

605598
bool has_primitive() const {
@@ -646,12 +639,12 @@ class Type {
646639
return absl::holds_alternative<AbstractType>(type_kind_);
647640
}
648641

649-
NullValue null() const {
650-
auto* value = absl::get_if<NullValue>(&type_kind_);
642+
NullType null() const {
643+
auto* value = absl::get_if<NullType>(&type_kind_);
651644
if (value != nullptr) {
652645
return *value;
653646
}
654-
return nullptr;
647+
return {};
655648
}
656649

657650
PrimitiveType primitive() const {

common/ast/expr_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ TEST(AstTest, FunctionTypeDefaults) {
8181
}
8282

8383
TEST(AstTest, TypeDefaults) {
84-
EXPECT_EQ(Type().null(), nullptr);
84+
EXPECT_EQ(Type().null(), NullType());
8585
EXPECT_EQ(Type().primitive(), PrimitiveType::kPrimitiveTypeUnspecified);
8686
EXPECT_EQ(Type().wrapper(), PrimitiveType::kPrimitiveTypeUnspecified);
8787
EXPECT_EQ(Type().well_known(), WellKnownType::kWellKnownTypeUnspecified);

common/ast_proto.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#include "common/ast_proto.h"
1616

17-
#include <cstddef>
1817
#include <cstdint>
1918
#include <memory>
2019
#include <string>
@@ -57,7 +56,7 @@ using ::cel::ast_internal::FunctionType;
5756
using ::cel::ast_internal::ListType;
5857
using ::cel::ast_internal::MapType;
5958
using ::cel::ast_internal::MessageType;
60-
using ::cel::ast_internal::NullValue;
59+
using ::cel::ast_internal::NullType;
6160
using ::cel::ast_internal::ParamType;
6261
using ::cel::ast_internal::PrimitiveType;
6362
using ::cel::ast_internal::PrimitiveTypeWrapper;
@@ -234,7 +233,7 @@ absl::StatusOr<Type> ConvertProtoTypeToNative(
234233
case cel::expr::Type::kDyn:
235234
return Type(DynamicType());
236235
case cel::expr::Type::kNull:
237-
return Type(nullptr);
236+
return Type(NullType());
238237
case cel::expr::Type::kPrimitive: {
239238
auto native_primitive = ToNative(type.primitive());
240239
if (!native_primitive.ok()) {
@@ -395,7 +394,7 @@ struct TypeKindToProtoVisitor {
395394
return absl::OkStatus();
396395
}
397396

398-
absl::Status operator()(std::nullptr_t) {
397+
absl::Status operator()(NullType) {
399398
result->set_null(google::protobuf::NULL_VALUE);
400399
return absl::OkStatus();
401400
}

common/ast_proto_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ TEST(AstConvertersTest, NullTypeToNative) {
311311
auto native_type = ConvertProtoTypeToNative(type);
312312

313313
ASSERT_TRUE(native_type->has_null());
314-
EXPECT_EQ(native_type->null(), nullptr);
314+
EXPECT_EQ(native_type->null(), ast_internal::NullType());
315315
}
316316

317317
TEST(AstConvertersTest, PrimitiveTypeWrapperToNative) {

runtime/internal/convert_constant.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414

1515
#include "runtime/internal/convert_constant.h"
1616

17+
#include <cstddef>
1718
#include <cstdint>
1819

1920
#include "absl/status/status.h"
2021
#include "absl/status/statusor.h"
2122
#include "absl/time/time.h"
2223
#include "absl/types/variant.h"
2324
#include "common/allocator.h"
24-
#include "common/ast/expr.h"
2525
#include "common/constant.h"
2626
#include "common/value.h"
2727
#include "eval/internal/errors.h"
@@ -36,10 +36,7 @@ struct ConvertVisitor {
3636
absl::StatusOr<cel::Value> operator()(absl::monostate) {
3737
return absl::InvalidArgumentError("unspecified constant");
3838
}
39-
absl::StatusOr<cel::Value> operator()(
40-
const cel::ast_internal::NullValue& value) {
41-
return NullValue();
42-
}
39+
absl::StatusOr<cel::Value> operator()(std::nullptr_t) { return NullValue(); }
4340
absl::StatusOr<cel::Value> operator()(bool value) { return BoolValue(value); }
4441
absl::StatusOr<cel::Value> operator()(int64_t value) {
4542
return IntValue(value);

testutil/baseline_tests_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ INSTANTIATE_TEST_SUITE_P(
194194
TestCase{AstType(ast_internal::WellKnownType::kTimestamp),
195195
"x~google.protobuf.Timestamp"},
196196
TestCase{AstType(ast_internal::DynamicType()), "x~dyn"},
197-
TestCase{AstType(nullptr), "x~null"},
197+
TestCase{AstType(ast_internal::NullType()), "x~null"},
198198
TestCase{AstType(ast_internal::UnspecifiedType()), "x~<error>"},
199199
TestCase{AstType(ast_internal::MessageType("com.example.Type")),
200200
"x~com.example.Type"},

0 commit comments

Comments
 (0)