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
+11 -10
View File
@@ -14,6 +14,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/function.h"
@@ -194,13 +195,13 @@ static auto PerformImplLookup(
return SemIR::ErrorInst::SingletonInstId;
}
auto self_type_id = context.GetTypeIdForTypeConstant(type_const_id);
auto self_type_id = context.types().GetTypeIdForTypeConstantId(type_const_id);
auto witness_id =
LookupImplWitness(context, loc_id, type_const_id,
assoc_type.interface_type_id.AsConstantId());
if (!witness_id.has_value()) {
auto interface_type_id = context.GetInterfaceType(
interface_type->interface_id, interface_type->specific_id);
auto interface_type_id = GetInterfaceType(
context, interface_type->interface_id, interface_type->specific_id);
if (missing_impl_diagnoser) {
// TODO: Pass in the expression whose type we are printing.
CARBON_DIAGNOSTIC(MissingImplInMemberAccessNote, Note,
@@ -286,7 +287,7 @@ static auto LookupMemberNameInScope(Context& context, SemIR::LocId loc_id,
if (lookup_in_type_of_base) {
SemIR::TypeId base_type_id = context.insts().Get(base_id).type_id();
if (base_type_id != SemIR::TypeType::SingletonTypeId &&
context.IsFacetType(base_type_id)) {
context.types().IsFacetType(base_type_id)) {
// Handles `T.F` when `T` is a non-type facet.
auto base_as_type = ExprAsType(context, loc_id, base_id);
@@ -308,8 +309,8 @@ static auto LookupMemberNameInScope(Context& context, SemIR::LocId loc_id,
// Get the witness that `T` implements `base_type_id`.
if (base_interface == *assoc_interface) {
witness_inst_id = context.GetOrAddInst<SemIR::FacetAccessWitness>(
loc_id, {.type_id = context.GetSingletonType(
SemIR::WitnessType::SingletonInstId),
loc_id, {.type_id = GetSingletonType(
context, SemIR::WitnessType::SingletonInstId),
.facet_value_inst_id = base_id});
// TODO: Result will eventually be a facet type witness instead of
// an interface witness. Will need to use the index
@@ -366,8 +367,8 @@ static auto PerformInstanceBinding(Context& context, SemIR::LocId loc_id,
}
return context.GetOrAddInst<SemIR::BoundMethod>(
loc_id, {.type_id = context.GetSingletonType(
SemIR::BoundMethodType::SingletonInstId),
loc_id, {.type_id = GetSingletonType(
context, SemIR::BoundMethodType::SingletonInstId),
.object_id = base_id,
.function_decl_id = member_id});
}
@@ -508,7 +509,7 @@ auto PerformMemberAccess(Context& context, SemIR::LocId loc_id,
// TODO: According to the design, this should be a "lookup in base" lookup,
// not a "lookup in type of base" lookup, and the facet itself should have
// member names that directly name members of the `impl`.
if (context.IsFacetType(base_type_id)) {
if (context.types().IsFacetType(base_type_id)) {
return member_id;
}
@@ -591,7 +592,7 @@ auto PerformTupleAccess(Context& context, SemIR::LocId loc_id,
auto index_node_id = context.insts().GetLocId(index_inst_id);
index_inst_id = ConvertToValueOfType(
context, index_node_id, index_inst_id,
context.GetSingletonType(SemIR::IntLiteralType::SingletonInstId));
GetSingletonType(context, SemIR::IntLiteralType::SingletonInstId));
auto index_const_id = context.constant_values().Get(index_inst_id);
if (index_const_id == SemIR::ErrorInst::SingletonConstantId) {
return SemIR::ErrorInst::SingletonInstId;