From 7602d0a348f4be222757eeb4d4ed790263e45d60 Mon Sep 17 00:00:00 2001 From: Josh L Date: Tue, 12 Nov 2024 21:57:05 +0000 Subject: [PATCH] Add `facet_types()` accessor to `Check::Context` --- toolchain/check/context.cpp | 10 ++++------ toolchain/check/context.h | 3 +++ toolchain/check/deduce.cpp | 5 ++--- toolchain/check/eval.cpp | 2 +- toolchain/check/handle_impl.cpp | 2 +- toolchain/check/handle_index.cpp | 2 +- toolchain/check/impl.cpp | 2 +- toolchain/check/impl_lookup.cpp | 2 +- toolchain/check/import_ref.cpp | 8 ++++---- toolchain/check/member_access.cpp | 4 ++-- toolchain/check/subst.cpp | 6 +++--- 11 files changed, 23 insertions(+), 23 deletions(-) diff --git a/toolchain/check/context.cpp b/toolchain/check/context.cpp index aba29e2243575..91d69d107b909 100644 --- a/toolchain/check/context.cpp +++ b/toolchain/check/context.cpp @@ -1186,8 +1186,7 @@ auto Context::TryToDefineType(SemIR::TypeId type_id, } if (auto facet_type = types().TryGetAs(type_id)) { - const auto& facet_type_info = - sem_ir().facet_types().Get(facet_type->facet_type_id); + const auto& facet_type_info = facet_types().Get(facet_type->facet_type_id); for (auto interface : facet_type_info.impls_constraints) { auto interface_id = interface.interface_id; if (!interfaces().Get(interface_id).is_defined()) { @@ -1224,10 +1223,9 @@ auto Context::GetTypeIdForTypeConstant(SemIR::ConstantId constant_id) auto Context::FacetTypeFromInterface(SemIR::InterfaceId interface_id, SemIR::SpecificId specific_id) -> SemIR::FacetType { - SemIR::FacetTypeId facet_type_id = - sem_ir().facet_types().Add(SemIR::FacetTypeInfo{ - .impls_constraints = {{interface_id, specific_id}}, - .requirement_block_id = SemIR::InstBlockId::Invalid}); + SemIR::FacetTypeId facet_type_id = facet_types().Add(SemIR::FacetTypeInfo{ + .impls_constraints = {{interface_id, specific_id}}, + .requirement_block_id = SemIR::InstBlockId::Invalid}); return {.type_id = SemIR::TypeId::TypeType, .facet_type_id = facet_type_id}; } diff --git a/toolchain/check/context.h b/toolchain/check/context.h index 170552c2d2463..78fc99e35ee52 100644 --- a/toolchain/check/context.h +++ b/toolchain/check/context.h @@ -527,6 +527,9 @@ class Context { auto interfaces() -> ValueStore& { return sem_ir().interfaces(); } + auto facet_types() -> CanonicalValueStore& { + return sem_ir().facet_types(); + } auto impls() -> SemIR::ImplStore& { return sem_ir().impls(); } auto generics() -> SemIR::GenericStore& { return sem_ir().generics(); } auto specifics() -> SemIR::SpecificStore& { return sem_ir().specifics(); } diff --git a/toolchain/check/deduce.cpp b/toolchain/check/deduce.cpp index fdd4838b184cd..92b675f24afb8 100644 --- a/toolchain/check/deduce.cpp +++ b/toolchain/check/deduce.cpp @@ -117,9 +117,8 @@ class DeductionWorklist { auto AddAll(SemIR::FacetTypeId params, SemIR::FacetTypeId args, bool needs_substitution) -> void { const auto& param_impls = - context_.sem_ir().facet_types().Get(params).impls_constraints; - const auto& arg_impls = - context_.sem_ir().facet_types().Get(args).impls_constraints; + context_.facet_types().Get(params).impls_constraints; + const auto& arg_impls = context_.facet_types().Get(args).impls_constraints; if (param_impls.size() != arg_impls.size()) { // TODO: Decide whether to error on this or just treat the parameter list // as non-deduced. For now we treat it as non-deduced. diff --git a/toolchain/check/eval.cpp b/toolchain/check/eval.cpp index 34ca410c43946..281a2ef9ab8a6 100644 --- a/toolchain/check/eval.cpp +++ b/toolchain/check/eval.cpp @@ -1158,7 +1158,7 @@ static auto MakeConstantForCall(EvalContext& eval_context, SemIRLoc loc, static auto MakeFacetTypeResult(Context& context, const SemIR::FacetTypeInfo& info, Phase phase) -> SemIR::ConstantId { - SemIR::FacetTypeId facet_type_id = context.sem_ir().facet_types().Add(info); + SemIR::FacetTypeId facet_type_id = context.facet_types().Add(info); return MakeConstantResult(context, SemIR::FacetType{.type_id = SemIR::TypeId::TypeType, .facet_type_id = facet_type_id}, diff --git a/toolchain/check/handle_impl.cpp b/toolchain/check/handle_impl.cpp index 5b62b81e8e9be..8616e7e51d885 100644 --- a/toolchain/check/handle_impl.cpp +++ b/toolchain/check/handle_impl.cpp @@ -180,7 +180,7 @@ static auto ExtendImpl(Context& context, Parse::NodeId extend_node, return; } const SemIR::FacetTypeInfo& info = - context.sem_ir().facet_types().Get(facet_type->facet_type_id); + context.facet_types().Get(facet_type->facet_type_id); for (auto interface_type : info.impls_constraints) { auto& interface = context.interfaces().Get(interface_type.interface_id); if (!interface.is_defined()) { diff --git a/toolchain/check/handle_index.cpp b/toolchain/check/handle_index.cpp index b80d61c92b587..ea68858275af6 100644 --- a/toolchain/check/handle_index.cpp +++ b/toolchain/check/handle_index.cpp @@ -65,7 +65,7 @@ static auto GetIndexWithArgs(Context& context, Parse::NodeId node_id, continue; } const auto& facet_type_info = - context.sem_ir().facet_types().Get(facet_type->facet_type_id); + context.facet_types().Get(facet_type->facet_type_id); auto interface_type = facet_type_info.TryAsSingleInterface(); if (!interface_type) { continue; diff --git a/toolchain/check/impl.cpp b/toolchain/check/impl.cpp index f067148bd8188..beede7a696dc3 100644 --- a/toolchain/check/impl.cpp +++ b/toolchain/check/impl.cpp @@ -224,7 +224,7 @@ auto BuildImplWitness(Context& context, SemIR::ImplId impl_id) return SemIR::InstId::BuiltinError; } const SemIR::FacetTypeInfo& facet_type_info = - context.sem_ir().facet_types().Get(facet_type->facet_type_id); + context.facet_types().Get(facet_type->facet_type_id); auto interface = facet_type_info.TryAsSingleInterface(); if (!interface) { diff --git a/toolchain/check/impl_lookup.cpp b/toolchain/check/impl_lookup.cpp index efe82f545546c..1320d104e3d53 100644 --- a/toolchain/check/impl_lookup.cpp +++ b/toolchain/check/impl_lookup.cpp @@ -68,7 +68,7 @@ static auto FindAssociatedImportIRs(Context& context, } case SemIR::IdKind::For: { const auto& facet_type_info = - context.sem_ir().facet_types().Get(SemIR::FacetTypeId(arg)); + context.facet_types().Get(SemIR::FacetTypeId(arg)); for (const auto& impl : facet_type_info.impls_constraints) { add_entity(context.interfaces().Get(impl.interface_id)); } diff --git a/toolchain/check/import_ref.cpp b/toolchain/check/import_ref.cpp index 6921632c36fd3..e15d0b2cbe420 100644 --- a/toolchain/check/import_ref.cpp +++ b/toolchain/check/import_ref.cpp @@ -965,7 +965,7 @@ class ImportRefResolver { } case CARBON_KIND(SemIR::FacetType inst): { const SemIR::FacetTypeInfo& facet_type_info = - context_.sem_ir().facet_types().Get(inst.facet_type_id); + context_.facet_types().Get(inst.facet_type_id); // This is specifically the facet type produced by an interface // declaration, and so should consist of a single interface. // TODO: Will also have to handle named constraints here, once those are @@ -2015,7 +2015,7 @@ class ImportRefResolver { context_.constant_values().GetInstId(interface_const_id)); if (auto facet_type = interface_const_inst.TryAs()) { const SemIR::FacetTypeInfo& facet_type_info = - context_.sem_ir().facet_types().Get(facet_type->facet_type_id); + context_.facet_types().Get(facet_type->facet_type_id); auto interface_type = facet_type_info.TryAsSingleInterface(); CARBON_CHECK(interface_type); interface_id = interface_type->interface_id; @@ -2095,7 +2095,7 @@ class ImportRefResolver { context_.constant_values().GetInstId(interface_const_id)); if (auto facet_type = interface_const_inst.TryAs()) { const SemIR::FacetTypeInfo& new_facet_type_info = - context_.sem_ir().facet_types().Get(facet_type->facet_type_id); + context_.facet_types().Get(facet_type->facet_type_id); impls_constraints.append(new_facet_type_info.impls_constraints); } else { auto generic_interface_type = @@ -2109,7 +2109,7 @@ class ImportRefResolver { } // TODO: Also process the other requirements. SemIR::FacetTypeId facet_type_id = - context_.sem_ir().facet_types().Add(SemIR::FacetTypeInfo{ + context_.facet_types().Add(SemIR::FacetTypeInfo{ .impls_constraints = impls_constraints, .requirement_block_id = SemIR::InstBlockId::Invalid}); return ResolveAs( diff --git a/toolchain/check/member_access.cpp b/toolchain/check/member_access.cpp index a9f1032d25741..4ea3362826c1f 100644 --- a/toolchain/check/member_access.cpp +++ b/toolchain/check/member_access.cpp @@ -56,7 +56,7 @@ static auto GetAsLookupScope(Context& context, SemIR::LocId loc_id, loc_id, QualifiedExprInUndefinedInterfaceScope, base_id); }); const auto& facet_type_info = - context.sem_ir().facet_types().Get(base_as_facet_type->facet_type_id); + context.facet_types().Get(base_as_facet_type->facet_type_id); auto base_as_interface = facet_type_info.TryAsSingleInterface(); if (base_as_interface) { auto& interface_info = @@ -184,7 +184,7 @@ static auto PerformImplLookup( auto facet_type = context.types().GetAs(assoc_type.interface_type_id); const auto& facet_type_info = - context.sem_ir().facet_types().Get(facet_type.facet_type_id); + context.facet_types().Get(facet_type.facet_type_id); auto interface_type = facet_type_info.TryAsSingleInterface(); if (!interface_type) { context.TODO(loc_id, diff --git a/toolchain/check/subst.cpp b/toolchain/check/subst.cpp index b179604c929c1..71f368a17faa7 100644 --- a/toolchain/check/subst.cpp +++ b/toolchain/check/subst.cpp @@ -98,7 +98,7 @@ static auto PushOperand(Context& context, Worklist& worklist, break; case SemIR::IdKind::For: { const auto& facet_type_info = - context.sem_ir().facet_types().Get(SemIR::FacetTypeId(arg)); + context.facet_types().Get(SemIR::FacetTypeId(arg)); for (auto interface : facet_type_info.impls_constraints) { PushOperand(context, worklist, SemIR::IdKind::For, interface.specific_id.index); @@ -188,7 +188,7 @@ static auto PopOperand(Context& context, Worklist& worklist, SemIR::IdKind kind, } case SemIR::IdKind::For: { const auto& old_facet_type_info = - context.sem_ir().facet_types().Get(SemIR::FacetTypeId(arg)); + context.facet_types().Get(SemIR::FacetTypeId(arg)); SemIR::FacetTypeInfo new_facet_type_info = old_facet_type_info; // Since these were added to a stack, we get them back in reverse order. for (auto i : llvm::reverse( @@ -199,7 +199,7 @@ static auto PopOperand(Context& context, Worklist& worklist, SemIR::IdKind kind, new_facet_type_info.impls_constraints[i].specific_id = SemIR::SpecificId(specific_id); } - return context.sem_ir().facet_types().Add(new_facet_type_info).index; + return context.facet_types().Add(new_facet_type_info).index; } default: return arg;