From b5bdfdd8574a7f0784f6964383205802cf775cc1 Mon Sep 17 00:00:00 2001 From: Boaz Brickner Date: Mon, 17 Nov 2025 17:06:14 +0100 Subject: [PATCH] Rename `TypeLiteralInfo` to `RecognizedTypeInfo` (#6384) Following https://github.com/carbon-language/carbon-lang/pull/6364/files/d6f19812d2350df8714e6022560e7443470c1a18#r2525516156. Part of #5263. --- toolchain/check/cpp/type_mapping.cpp | 23 ++++++++++++----------- toolchain/sem_ir/inst_namer.cpp | 6 +++--- toolchain/sem_ir/stringify.cpp | 12 ++++++------ toolchain/sem_ir/type_info.cpp | 10 +++++----- toolchain/sem_ir/type_info.h | 8 ++++---- 5 files changed, 30 insertions(+), 29 deletions(-) diff --git a/toolchain/check/cpp/type_mapping.cpp b/toolchain/check/cpp/type_mapping.cpp index 044225744beb..53490c3bb1ea 100644 --- a/toolchain/check/cpp/type_mapping.cpp +++ b/toolchain/check/cpp/type_mapping.cpp @@ -119,20 +119,21 @@ static auto TryMapClassType(Context& context, SemIR::ClassType class_type) // If the class represents a Carbon type literal, map it to the corresponding // C++ builtin type. - auto literal = SemIR::TypeLiteralInfo::ForType(context.sem_ir(), class_type); - switch (literal.kind) { - case SemIR::TypeLiteralInfo::None: { + auto type_info = + SemIR::RecognizedTypeInfo::ForType(context.sem_ir(), class_type); + switch (type_info.kind) { + case SemIR::RecognizedTypeInfo::None: { break; } - case SemIR::TypeLiteralInfo::Numeric: { + case SemIR::RecognizedTypeInfo::Numeric: { // Carbon supports large bit width beyond C++ builtins; we don't need to // translate those. - if (!literal.numeric.bit_width_id.is_embedded_value()) { + if (!type_info.numeric.bit_width_id.is_embedded_value()) { return clang::QualType(); } - int bit_width = literal.numeric.bit_width_id.AsValue(); + int bit_width = type_info.numeric.bit_width_id.AsValue(); - switch (literal.numeric.kind) { + switch (type_info.numeric.kind) { case SemIR::NumericTypeLiteralInfo::None: { CARBON_FATAL("Unexpected invalid numeric type literal"); } @@ -148,19 +149,19 @@ static auto TryMapClassType(Context& context, SemIR::ClassType class_type) } } } - case SemIR::TypeLiteralInfo::Char: { + case SemIR::RecognizedTypeInfo::Char: { return ast_context.CharTy; } - case SemIR::TypeLiteralInfo::CppLong32: { + case SemIR::RecognizedTypeInfo::CppLong32: { if (ast_context.getIntWidth(ast_context.LongTy) == 32) { return ast_context.LongTy; } break; } - case SemIR::TypeLiteralInfo::CppNullptrT: { + case SemIR::RecognizedTypeInfo::CppNullptrT: { return ast_context.NullPtrTy; } - case SemIR::TypeLiteralInfo::Str: { + case SemIR::RecognizedTypeInfo::Str: { return LookupCppType(context, {"std", "string_view"}); } } diff --git a/toolchain/sem_ir/inst_namer.cpp b/toolchain/sem_ir/inst_namer.cpp index 76df40996e2b..bc927a908ef9 100644 --- a/toolchain/sem_ir/inst_namer.cpp +++ b/toolchain/sem_ir/inst_namer.cpp @@ -869,9 +869,9 @@ auto InstNamer::NamingContext::NameInst() -> void { return; } case CARBON_KIND(ClassType inst): { - if (auto literal_info = TypeLiteralInfo::ForType(sem_ir(), inst); - literal_info.is_valid()) { - AddInstName(literal_info.GetLiteralAsString(sem_ir())); + if (auto type_info = RecognizedTypeInfo::ForType(sem_ir(), inst); + type_info.is_valid()) { + AddInstName(type_info.GetLiteralAsString(sem_ir())); } else { AddEntityNameAndMaybePush(inst.class_id); } diff --git a/toolchain/sem_ir/stringify.cpp b/toolchain/sem_ir/stringify.cpp index 700f81536223..57b93db00efd 100644 --- a/toolchain/sem_ir/stringify.cpp +++ b/toolchain/sem_ir/stringify.cpp @@ -300,9 +300,9 @@ class Stringifier { auto StringifyInst(InstId /*inst_id*/, ClassType inst) -> void { const auto& class_info = sem_ir_->classes().Get(inst.class_id); - if (auto literal_info = TypeLiteralInfo::ForType(*sem_ir_, inst); - literal_info.is_valid()) { - literal_info.PrintLiteral(*sem_ir_, *out_); + if (auto type_info = RecognizedTypeInfo::ForType(*sem_ir_, inst); + type_info.is_valid()) { + type_info.PrintLiteral(*sem_ir_, *out_); return; } step_stack_->PushEntityName(class_info, inst.specific_id); @@ -787,13 +787,13 @@ auto StringifySpecific(const File& sem_ir, SpecificId specific_id) // Print `Core.Int(N)` as `iN`. // TODO: This duplicates work done in StringifyInst for ClassType. const auto& class_info = sem_ir.classes().Get(class_decl.class_id); - if (auto literal_info = TypeLiteralInfo::ForType( + if (auto type_info = RecognizedTypeInfo::ForType( sem_ir, ClassType{.type_id = TypeType::TypeId, .class_id = class_decl.class_id, .specific_id = specific_id}); - literal_info.is_valid()) { + type_info.is_valid()) { RawStringOstream out; - literal_info.PrintLiteral(sem_ir, out); + type_info.PrintLiteral(sem_ir, out); return out.TakeStr(); } step_stack.PushEntityName(class_info, specific_id); diff --git a/toolchain/sem_ir/type_info.cpp b/toolchain/sem_ir/type_info.cpp index 9f0ddb861327..07edfefee9a0 100644 --- a/toolchain/sem_ir/type_info.cpp +++ b/toolchain/sem_ir/type_info.cpp @@ -133,8 +133,8 @@ auto NumericTypeLiteralInfo::GetLiteralAsString(const File& file) const return out.TakeStr(); } -auto TypeLiteralInfo::ForType(const File& file, ClassType class_type) - -> TypeLiteralInfo { +auto RecognizedTypeInfo::ForType(const File& file, ClassType class_type) + -> RecognizedTypeInfo { if (class_type.specific_id.has_value()) { auto numeric = NumericTypeLiteralInfo::ForType(file, class_type); if (numeric.is_valid()) { @@ -185,8 +185,8 @@ auto TypeLiteralInfo::ForType(const File& file, ClassType class_type) return {.kind = None}; } -auto TypeLiteralInfo::PrintLiteral(const File& file, - llvm::raw_ostream& out) const -> void { +auto RecognizedTypeInfo::PrintLiteral(const File& file, + llvm::raw_ostream& out) const -> void { switch (kind) { case None: CARBON_FATAL("Printing invalid type literal"); @@ -216,7 +216,7 @@ auto TypeLiteralInfo::PrintLiteral(const File& file, } } -auto TypeLiteralInfo::GetLiteralAsString(const File& file) const +auto RecognizedTypeInfo::GetLiteralAsString(const File& file) const -> std::string { RawStringOstream out; PrintLiteral(file, out); diff --git a/toolchain/sem_ir/type_info.h b/toolchain/sem_ir/type_info.h index eab380e97405..658fb24cc8be 100644 --- a/toolchain/sem_ir/type_info.h +++ b/toolchain/sem_ir/type_info.h @@ -227,9 +227,9 @@ struct NumericTypeLiteralInfo { IntId bit_width_id; }; -// Information about a literal that corresponds to a type. -// TODO: Rename to `RecognizedTypeInfo` (Cpp types are not type literals). -struct TypeLiteralInfo { +// Information about a recognized type, which is either a literal type, or a C++ +// builtin. +struct RecognizedTypeInfo { enum Kind : char { None, // A numeric type literal such as `i8`; see `numeric` field for details. @@ -247,7 +247,7 @@ struct TypeLiteralInfo { // Returns the type literal that would evaluate to this class type, if any. static auto ForType(const File& file, ClassType class_type) - -> TypeLiteralInfo; + -> RecognizedTypeInfo; // Prints the type literal that corresponds to this type. auto PrintLiteral(const File& file, llvm::raw_ostream& out) const -> void;