From 493eb75e7f5d9706f74fcee4f052cc99aba674c7 Mon Sep 17 00:00:00 2001 From: Geoff Romer Date: Tue, 13 Dec 2022 13:08:08 -0800 Subject: [PATCH] Rename PointerType::type to pointee_type. (#2468) This avoids the confusion that can arise from the natural assumption that `foo->type()` returns the type of the value `foo`. --- explorer/interpreter/type_checker.cpp | 10 +++++----- explorer/interpreter/value.cpp | 6 +++--- explorer/interpreter/value.h | 11 ++++++----- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/explorer/interpreter/type_checker.cpp b/explorer/interpreter/type_checker.cpp index b0a18904b5e5..ffa0318e46ba 100644 --- a/explorer/interpreter/type_checker.cpp +++ b/explorer/interpreter/type_checker.cpp @@ -366,7 +366,7 @@ static auto TypeContainsAuto(Nonnull type) -> bool { case Value::Kind::TupleType: return llvm::any_of(cast(type)->elements(), TypeContainsAuto); case Value::Kind::PointerType: - return TypeContainsAuto(&cast(type)->type()); + return TypeContainsAuto(&cast(type)->pointee_type()); case Value::Kind::StaticArrayType: return TypeContainsAuto(&cast(type)->element_type()); } @@ -987,8 +987,8 @@ auto TypeChecker::ArgumentDeduction::Deduce(Nonnull param, if (arg->kind() != Value::Kind::PointerType) { return handle_non_deduced_type(); } - return Deduce(&cast(*param).type(), - &cast(*arg).type(), + return Deduce(&cast(*param).pointee_type(), + &cast(*arg).pointee_type(), /*allow_implicit_conversion=*/false); } // Nothing to do in the case for `auto`. @@ -3077,7 +3077,7 @@ auto TypeChecker::TypeCheckExp(Nonnull e, case Operator::Deref: CARBON_RETURN_IF_ERROR( ExpectPointerType(e->source_loc(), "*", ts[0])); - op.set_static_type(&cast(*ts[0]).type()); + op.set_static_type(&cast(*ts[0]).pointee_type()); op.set_value_category(ValueCategory::Var); return Success(); case Operator::Ptr: @@ -3889,7 +3889,7 @@ auto TypeChecker::TypeCheckPattern( if (const auto* inner_binding_type = dyn_cast(&addr_pattern.binding().static_type())) { - addr_pattern.set_static_type(&inner_binding_type->type()); + addr_pattern.set_static_type(&inner_binding_type->pointee_type()); } else { return ProgramError(addr_pattern.source_loc()) << "Type associated with addr must be a pointer type."; diff --git a/explorer/interpreter/value.cpp b/explorer/interpreter/value.cpp index 1773a625f7e5..479004f95657 100644 --- a/explorer/interpreter/value.cpp +++ b/explorer/interpreter/value.cpp @@ -450,7 +450,7 @@ void Value::Print(llvm::raw_ostream& out) const { out << "Continuation"; break; case Value::Kind::PointerType: - out << cast(*this).type() << "*"; + out << cast(*this).pointee_type() << "*"; break; case Value::Kind::FunctionType: { const auto& fn_type = cast(*this); @@ -722,8 +722,8 @@ auto TypeEqual(Nonnull t1, Nonnull t2, } switch (t1->kind()) { case Value::Kind::PointerType: - return TypeEqual(&cast(*t1).type(), - &cast(*t2).type(), equality_ctx); + return TypeEqual(&cast(*t1).pointee_type(), + &cast(*t2).pointee_type(), equality_ctx); case Value::Kind::FunctionType: { const auto& fn1 = cast(*t1); const auto& fn2 = cast(*t2); diff --git a/explorer/interpreter/value.h b/explorer/interpreter/value.h index d43a821560f4..ea4a503eee27 100644 --- a/explorer/interpreter/value.h +++ b/explorer/interpreter/value.h @@ -670,8 +670,9 @@ class FunctionType : public Value { // A pointer type. class PointerType : public Value { public: - explicit PointerType(Nonnull type) - : Value(Kind::PointerType), type_(type) {} + // Constructs a pointer type with the given pointee type. + explicit PointerType(Nonnull pointee_type) + : Value(Kind::PointerType), pointee_type_(pointee_type) {} static auto classof(const Value* value) -> bool { return value->kind() == Kind::PointerType; @@ -679,13 +680,13 @@ class PointerType : public Value { template auto Decompose(F f) const { - return f(type_); + return f(pointee_type_); } - auto type() const -> const Value& { return *type_; } + auto pointee_type() const -> const Value& { return *pointee_type_; } private: - Nonnull type_; + Nonnull pointee_type_; }; // The `auto` type.