Răsfoiți Sursa

Add `facet_types()` accessor to `Check::Context` (#4518)

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
josh11b 1 an în urmă
părinte
comite
39ed62dad7

+ 4 - 6
toolchain/check/context.cpp

@@ -1186,8 +1186,7 @@ auto Context::TryToDefineType(SemIR::TypeId type_id,
   }
 
   if (auto facet_type = types().TryGetAs<SemIR::FacetType>(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};
 }
 

+ 3 - 0
toolchain/check/context.h

@@ -527,6 +527,9 @@ class Context {
   auto interfaces() -> ValueStore<SemIR::InterfaceId>& {
     return sem_ir().interfaces();
   }
+  auto facet_types() -> CanonicalValueStore<SemIR::FacetTypeId>& {
+    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(); }

+ 2 - 3
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.

+ 1 - 1
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},

+ 1 - 1
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()) {

+ 1 - 1
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;

+ 1 - 1
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) {

+ 1 - 1
toolchain/check/impl_lookup.cpp

@@ -68,7 +68,7 @@ static auto FindAssociatedImportIRs(Context& context,
         }
         case SemIR::IdKind::For<SemIR::FacetTypeId>: {
           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));
           }

+ 4 - 4
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<SemIR::FacetType>()) {
         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<SemIR::FacetType>()) {
         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<SemIR::FacetType>(

+ 2 - 2
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<SemIR::FacetType>(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,

+ 3 - 3
toolchain/check/subst.cpp

@@ -98,7 +98,7 @@ static auto PushOperand(Context& context, Worklist& worklist,
       break;
     case SemIR::IdKind::For<SemIR::FacetTypeId>: {
       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<SemIR::SpecificId>,
                     interface.specific_id.index);
@@ -188,7 +188,7 @@ static auto PopOperand(Context& context, Worklist& worklist, SemIR::IdKind kind,
     }
     case SemIR::IdKind::For<SemIR::FacetTypeId>: {
       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;