Move type functions off Context (#4951)

This creates a new check/type.h for most logic, and also moves some
functions to TypeStore in sem_ir/type.h. My approach for TypeStore is to
focus on moving the read-only functions there.
This commit is contained in:
Jon Ross-Perkins
2025-02-13 23:02:38 +00:00
committed by GitHub
parent 23e5677c8e
commit dc8f47e6ad
39 changed files with 506 additions and 393 deletions
+13 -7
View File
@@ -13,6 +13,7 @@
#include "toolchain/check/import_ref.h"
#include "toolchain/check/interface.h"
#include "toolchain/check/name_lookup.h"
#include "toolchain/check/type.h"
#include "toolchain/check/type_completion.h"
#include "toolchain/diagnostics/diagnostic_emitter.h"
#include "toolchain/sem_ir/generic.h"
@@ -85,7 +86,8 @@ auto ImplWitnessForDeclaration(Context& context, const SemIR::Impl& impl)
-> SemIR::InstId {
CARBON_CHECK(!impl.has_definition_started());
auto facet_type_id = context.GetTypeIdForTypeInst(impl.constraint_id);
auto facet_type_id =
context.types().GetTypeIdForTypeInstId(impl.constraint_id);
if (facet_type_id == SemIR::ErrorInst::SingletonTypeId) {
return SemIR::ErrorInst::SingletonInstId;
}
@@ -133,7 +135,8 @@ auto ImplWitnessForDeclaration(Context& context, const SemIR::Impl& impl)
auto table_id = context.inst_blocks().Add(table);
return context.AddInst<SemIR::ImplWitness>(
context.insts().GetLocId(impl.latest_decl_id()),
{.type_id = context.GetSingletonType(SemIR::WitnessType::SingletonInstId),
{.type_id =
GetSingletonType(context, SemIR::WitnessType::SingletonInstId),
.elements_id = table_id,
.specific_id = context.generics().GetSelfSpecific(impl.generic_id)});
}
@@ -162,7 +165,8 @@ auto AddConstantsToImplWitnessFromConstraint(Context& context,
if (witness_id == SemIR::ErrorInst::SingletonInstId) {
return;
}
auto facet_type_id = context.GetTypeIdForTypeInst(impl.constraint_id);
auto facet_type_id =
context.types().GetTypeIdForTypeInstId(impl.constraint_id);
CARBON_CHECK(facet_type_id != SemIR::ErrorInst::SingletonTypeId);
auto facet_type = context.types().GetAs<SemIR::FacetType>(facet_type_id);
const SemIR::FacetTypeInfo& facet_type_info =
@@ -239,7 +243,7 @@ auto AddConstantsToImplWitnessFromConstraint(Context& context,
// value for `Self`.
assoc_const_type_id = GetTypeForSpecificAssociatedEntity(
context, impl.constraint_id, interface_type->specific_id, decl_id,
context.GetTypeIdForTypeInst(impl.self_id), witness_id);
context.types().GetTypeIdForTypeInstId(impl.self_id), witness_id);
// Perform the conversion of the value to the type. We skipped this when
// forming the facet type because the type of the associated constant
@@ -283,7 +287,8 @@ auto ImplWitnessStartDefinition(Context& context, SemIR::Impl& impl) -> void {
return;
}
auto facet_type_id = context.GetTypeIdForTypeInst(impl.constraint_id);
auto facet_type_id =
context.types().GetTypeIdForTypeInstId(impl.constraint_id);
CARBON_CHECK(facet_type_id != SemIR::ErrorInst::SingletonTypeId);
auto facet_type = context.types().GetAs<SemIR::FacetType>(facet_type_id);
const SemIR::FacetTypeInfo& facet_type_info =
@@ -340,7 +345,8 @@ auto FinishImplWitness(Context& context, SemIR::Impl& impl) -> void {
return;
}
auto facet_type_id = context.GetTypeIdForTypeInst(impl.constraint_id);
auto facet_type_id =
context.types().GetTypeIdForTypeInstId(impl.constraint_id);
CARBON_CHECK(facet_type_id != SemIR::ErrorInst::SingletonTypeId);
auto facet_type = context.types().GetAs<SemIR::FacetType>(facet_type_id);
const SemIR::FacetTypeInfo& facet_type_info =
@@ -354,7 +360,7 @@ auto FinishImplWitness(Context& context, SemIR::Impl& impl) -> void {
auto witness = context.insts().GetAs<SemIR::ImplWitness>(impl.witness_id);
auto witness_block = context.inst_blocks().GetMutable(witness.elements_id);
auto& impl_scope = context.name_scopes().Get(impl.scope_id);
auto self_type_id = context.GetTypeIdForTypeInst(impl.self_id);
auto self_type_id = context.types().GetTypeIdForTypeInstId(impl.self_id);
auto assoc_entities =
context.inst_blocks().Get(interface.associated_entities_id);
llvm::SmallVector<SemIR::InstId> used_decl_ids;