Просмотр исходного кода

Basic support for implementing and using a parameterized interface. (#4203)

The main change here is to form a specific when checking an interface
function against an impl function, instead of just substituting the
`Self` type.
Richard Smith 1 год назад
Родитель
Сommit
4a21b6af9b
54 измененных файлов с 998 добавлено и 266 удалено
  1. 5 10
      toolchain/check/function.cpp
  2. 7 7
      toolchain/check/function.h
  3. 1 2
      toolchain/check/handle_function.cpp
  4. 84 29
      toolchain/check/impl.cpp
  5. 11 4
      toolchain/check/import_ref.cpp
  6. 6 12
      toolchain/check/member_access.cpp
  7. 9 10
      toolchain/check/merge.cpp
  8. 5 4
      toolchain/check/merge.h
  9. 0 6
      toolchain/check/subst.cpp
  10. 0 5
      toolchain/check/subst.h
  11. 44 50
      toolchain/check/testdata/class/generic/import.carbon
  12. 4 0
      toolchain/check/testdata/function/builtin/method.carbon
  13. 4 0
      toolchain/check/testdata/function/builtin/no_prelude/call_from_operator.carbon
  14. 6 0
      toolchain/check/testdata/impl/compound.carbon
  15. 2 0
      toolchain/check/testdata/impl/extend_impl.carbon
  16. 4 0
      toolchain/check/testdata/impl/fail_call_invalid.carbon
  17. 12 0
      toolchain/check/testdata/impl/fail_extend_impl_forall.carbon
  18. 2 0
      toolchain/check/testdata/impl/fail_impl_as_scope.carbon
  19. 36 0
      toolchain/check/testdata/impl/fail_impl_bad_assoc_fn.carbon
  20. 2 0
      toolchain/check/testdata/impl/impl_as.carbon
  21. 2 0
      toolchain/check/testdata/impl/impl_forall.carbon
  22. 2 0
      toolchain/check/testdata/impl/lookup/alias.carbon
  23. 2 0
      toolchain/check/testdata/impl/lookup/fail_todo_undefined_impl.carbon
  24. 2 0
      toolchain/check/testdata/impl/lookup/import.carbon
  25. 4 0
      toolchain/check/testdata/impl/lookup/instance_method.carbon
  26. 2 0
      toolchain/check/testdata/impl/lookup/no_prelude/import.carbon
  27. 2 0
      toolchain/check/testdata/impl/no_prelude/basic.carbon
  28. 5 18
      toolchain/check/testdata/impl/no_prelude/fail_impl_bad_type.carbon
  29. 4 0
      toolchain/check/testdata/impl/no_prelude/import_self.carbon
  30. 482 93
      toolchain/check/testdata/impl/no_prelude/interface_args.carbon
  31. 4 0
      toolchain/check/testdata/impl/no_prelude/self_in_class.carbon
  32. 22 0
      toolchain/check/testdata/impl/no_prelude/self_in_signature.carbon
  33. 2 0
      toolchain/check/testdata/interface/no_prelude/default_fn.carbon
  34. 21 3
      toolchain/check/testdata/interface/no_prelude/generic.carbon
  35. 25 13
      toolchain/check/testdata/interface/no_prelude/generic_import.carbon
  36. 14 0
      toolchain/check/testdata/interface/no_prelude/generic_vs_params.carbon
  37. 9 0
      toolchain/check/testdata/operators/overloaded/add.carbon
  38. 9 0
      toolchain/check/testdata/operators/overloaded/bit_and.carbon
  39. 4 0
      toolchain/check/testdata/operators/overloaded/bit_complement.carbon
  40. 9 0
      toolchain/check/testdata/operators/overloaded/bit_or.carbon
  41. 9 0
      toolchain/check/testdata/operators/overloaded/bit_xor.carbon
  42. 5 0
      toolchain/check/testdata/operators/overloaded/dec.carbon
  43. 9 0
      toolchain/check/testdata/operators/overloaded/div.carbon
  44. 16 0
      toolchain/check/testdata/operators/overloaded/eq.carbon
  45. 10 0
      toolchain/check/testdata/operators/overloaded/fail_assign_non_ref.carbon
  46. 9 0
      toolchain/check/testdata/operators/overloaded/fail_no_impl_for_arg.carbon
  47. 5 0
      toolchain/check/testdata/operators/overloaded/inc.carbon
  48. 9 0
      toolchain/check/testdata/operators/overloaded/left_shift.carbon
  49. 9 0
      toolchain/check/testdata/operators/overloaded/mod.carbon
  50. 9 0
      toolchain/check/testdata/operators/overloaded/mul.carbon
  51. 4 0
      toolchain/check/testdata/operators/overloaded/negate.carbon
  52. 16 0
      toolchain/check/testdata/operators/overloaded/ordered.carbon
  53. 9 0
      toolchain/check/testdata/operators/overloaded/right_shift.carbon
  54. 9 0
      toolchain/check/testdata/operators/overloaded/sub.carbon

+ 5 - 10
toolchain/check/function.cpp

@@ -5,7 +5,6 @@
 #include "toolchain/check/function.h"
 
 #include "toolchain/check/merge.h"
-#include "toolchain/check/subst.h"
 #include "toolchain/sem_ir/ids.h"
 
 namespace Carbon::Check {
@@ -13,10 +12,10 @@ namespace Carbon::Check {
 auto CheckFunctionTypeMatches(Context& context,
                               const SemIR::Function& new_function,
                               const SemIR::Function& prev_function,
-                              Substitutions substitutions, bool check_syntax)
-    -> bool {
+                              SemIR::SpecificId prev_specific_id,
+                              bool check_syntax) -> bool {
   if (!CheckRedeclParamsMatch(context, DeclParams(new_function),
-                              DeclParams(prev_function), substitutions,
+                              DeclParams(prev_function), prev_specific_id,
                               check_syntax)) {
     return false;
   }
@@ -25,16 +24,12 @@ auto CheckFunctionTypeMatches(Context& context,
   // use it here.
   auto new_return_type_id =
       new_function.GetDeclaredReturnType(context.sem_ir());
-  auto prev_return_type_id = prev_function.GetDeclaredReturnType(
-      context.sem_ir(), SemIR::SpecificId::Invalid);
+  auto prev_return_type_id =
+      prev_function.GetDeclaredReturnType(context.sem_ir(), prev_specific_id);
   if (new_return_type_id == SemIR::TypeId::Error ||
       prev_return_type_id == SemIR::TypeId::Error) {
     return false;
   }
-  if (prev_return_type_id.is_valid()) {
-    prev_return_type_id =
-        SubstType(context, prev_return_type_id, substitutions);
-  }
   if (!context.types().AreEqualAcrossDeclarations(new_return_type_id,
                                                   prev_return_type_id)) {
     CARBON_DIAGNOSTIC(

+ 7 - 7
toolchain/check/function.h

@@ -27,13 +27,13 @@ struct SuspendedFunction {
 };
 
 // Checks that `new_function` has the same parameter types and return type as
-// `prev_function`, applying the specified set of substitutions to the
-// previous function. Prints a suitable diagnostic and returns false if not.
-auto CheckFunctionTypeMatches(Context& context,
-                              const SemIR::Function& new_function,
-                              const SemIR::Function& prev_function,
-                              Substitutions substitutions, bool check_syntax)
-    -> bool;
+// `prev_function`, or if `prev_function_id` is specified, a specific version of
+// `prev_function`. Prints a suitable diagnostic and returns false if not.
+auto CheckFunctionTypeMatches(
+    Context& context, const SemIR::Function& new_function,
+    const SemIR::Function& prev_function,
+    SemIR::SpecificId prev_specific_id = SemIR::SpecificId::Invalid,
+    bool check_syntax = true) -> bool;
 
 // Checks that the return type of the specified function is complete, issuing an
 // error if not. This computes the return slot usage for the function if

+ 1 - 2
toolchain/check/handle_function.cpp

@@ -77,8 +77,7 @@ static auto MergeFunctionRedecl(Context& context, SemIRLoc new_loc,
                                 SemIR::ImportIRId prev_import_ir_id) -> bool {
   auto& prev_function = context.functions().Get(prev_function_id);
 
-  if (!CheckFunctionTypeMatches(context, new_function, prev_function, {},
-                                /*check_syntax=*/true)) {
+  if (!CheckFunctionTypeMatches(context, new_function, prev_function)) {
     return false;
   }
 

+ 84 - 29
toolchain/check/impl.cpp

@@ -7,9 +7,10 @@
 #include "toolchain/base/kind_switch.h"
 #include "toolchain/check/context.h"
 #include "toolchain/check/function.h"
+#include "toolchain/check/generic.h"
 #include "toolchain/check/import_ref.h"
-#include "toolchain/check/subst.h"
 #include "toolchain/diagnostics/diagnostic_emitter.h"
+#include "toolchain/sem_ir/generic.h"
 #include "toolchain/sem_ir/ids.h"
 #include "toolchain/sem_ir/impl.h"
 #include "toolchain/sem_ir/inst.h"
@@ -27,13 +28,59 @@ static auto NoteAssociatedFunction(Context& context,
   builder.Note(function.decl_id, ImplAssociatedFunctionHere, function.name_id);
 }
 
+// Gets the self specific of a generic declaration that is an interface member,
+// given a specific for an enclosing generic, plus a type to use as `Self`.
+static auto GetSelfSpecificForInterfaceMemberWithSelfType(
+    Context& context, SemIR::SpecificId enclosing_specific_id,
+    SemIR::GenericId generic_id, SemIR::TypeId self_type_id)
+    -> SemIR::SpecificId {
+  const auto& generic = context.generics().Get(generic_id);
+  auto bindings = context.inst_blocks().Get(generic.bindings_id);
+
+  llvm::SmallVector<SemIR::InstId> arg_ids;
+  arg_ids.reserve(bindings.size());
+
+  // Start with the enclosing arguments.
+  if (enclosing_specific_id.is_valid()) {
+    auto enclosing_specific_args_id =
+        context.specifics().Get(enclosing_specific_id).args_id;
+    auto enclosing_specific_args =
+        context.inst_blocks().Get(enclosing_specific_args_id);
+    arg_ids.assign(enclosing_specific_args.begin(),
+                   enclosing_specific_args.end());
+  }
+
+  // Add the `Self` argument.
+  CARBON_CHECK(
+      context.entity_names()
+          .Get(context.insts()
+                   .GetAs<SemIR::BindSymbolicName>(bindings[arg_ids.size()])
+                   .entity_name_id)
+          .name_id == SemIR::NameId::SelfType)
+      << "Expected a Self binding, found "
+      << context.insts().Get(bindings[arg_ids.size()]);
+  arg_ids.push_back(context.types().GetInstId(self_type_id));
+
+  // Take any trailing argument values from the self specific.
+  // TODO: If these refer to outer arguments, for example in their types, we may
+  // need to perform extra substitutions here.
+  auto self_specific_args = context.inst_blocks().Get(
+      context.specifics().Get(generic.self_specific_id).args_id);
+  for (auto arg_id : self_specific_args.drop_front(arg_ids.size())) {
+    arg_ids.push_back(context.constant_values().GetConstantInstId(arg_id));
+  }
+
+  auto args_id = context.inst_blocks().AddCanonical(arg_ids);
+  return MakeSpecific(context, generic_id, args_id);
+}
+
 // Checks that `impl_function_id` is a valid implementation of the function
 // described in the interface as `interface_function_id`. Returns the value to
 // put into the corresponding slot in the witness table, which can be
 // `BuiltinError` if the function is not usable.
 static auto CheckAssociatedFunctionImplementation(
-    Context& context, SemIR::FunctionId interface_function_id,
-    SemIR::InstId impl_decl_id, Substitutions substitutions) -> SemIR::InstId {
+    Context& context, SemIR::FunctionType interface_function_type,
+    SemIR::InstId impl_decl_id, SemIR::TypeId self_type_id) -> SemIR::InstId {
   auto impl_function_decl =
       context.insts().TryGetAs<SemIR::FunctionDecl>(impl_decl_id);
   if (!impl_function_decl) {
@@ -42,19 +89,32 @@ static auto CheckAssociatedFunctionImplementation(
                       SemIR::NameId);
     auto builder = context.emitter().Build(
         impl_decl_id, ImplFunctionWithNonFunction,
-        context.functions().Get(interface_function_id).name_id);
-    NoteAssociatedFunction(context, builder, interface_function_id);
+        context.functions().Get(interface_function_type.function_id).name_id);
+    NoteAssociatedFunction(context, builder,
+                           interface_function_type.function_id);
     builder.Emit();
 
     return SemIR::InstId::BuiltinError;
   }
 
+  // Map from the specific for the function type to the specific for the
+  // function signature. The function signature may have additional generic
+  // parameters.
+  auto interface_function_specific_id =
+      GetSelfSpecificForInterfaceMemberWithSelfType(
+          context, interface_function_type.specific_id,
+          context.functions()
+              .Get(interface_function_type.function_id)
+              .generic_id,
+          self_type_id);
+
   // TODO: This should be a semantic check rather than a syntactic one. The
   // functions should be allowed to have different signatures as long as we can
   // synthesize a suitable thunk.
   if (!CheckFunctionTypeMatches(
           context, context.functions().Get(impl_function_decl->function_id),
-          context.functions().Get(interface_function_id), substitutions,
+          context.functions().Get(interface_function_type.function_id),
+          interface_function_specific_id,
           /*check_syntax=*/false)) {
     return SemIR::InstId::BuiltinError;
   }
@@ -63,18 +123,17 @@ static auto CheckAssociatedFunctionImplementation(
 
 // Builds a witness that the specified impl implements the given interface.
 static auto BuildInterfaceWitness(
-    Context& context, const SemIR::Impl& impl,
+    Context& context, const SemIR::Impl& impl, SemIR::TypeId interface_type_id,
     SemIR::InterfaceType interface_type,
     llvm::SmallVectorImpl<SemIR::InstId>& used_decl_ids) -> SemIR::InstId {
   const auto& interface = context.interfaces().Get(interface_type.interface_id);
-  if (!interface.is_defined()) {
-    CARBON_DIAGNOSTIC(ImplOfUndefinedInterface, Error,
-                      "Implementation of undefined interface {0}.",
-                      SemIR::NameId);
-    auto builder = context.emitter().Build(
-        impl.definition_id, ImplOfUndefinedInterface, interface.name_id);
-    context.NoteUndefinedInterface(interface_type.interface_id, builder);
-    builder.Emit();
+  if (!context.TryToDefineType(interface_type_id, [&] {
+        CARBON_DIAGNOSTIC(ImplOfUndefinedInterface, Error,
+                          "Implementation of undefined interface {0}.",
+                          SemIR::NameId);
+        return context.emitter().Build(
+            impl.definition_id, ImplOfUndefinedInterface, interface.name_id);
+      })) {
     return SemIR::InstId::BuiltinError;
   }
 
@@ -85,18 +144,11 @@ static auto BuildInterfaceWitness(
       context.inst_blocks().Get(interface.associated_entities_id);
   table.reserve(assoc_entities.size());
 
-  // Substitute `Self` with the impl's self type when associated functions.
-  // TODO: Also substitute the arguments from interface_type.specific_id.
-  auto self_bind =
-      context.insts().GetAs<SemIR::BindSymbolicName>(interface.self_param_id);
-  Substitution substitutions[1] = {
-      {.bind_id =
-           context.entity_names().Get(self_bind.entity_name_id).bind_index,
-       .replacement_id = context.types().GetConstantId(impl.self_id)}};
-
   for (auto decl_id : assoc_entities) {
     LoadImportRef(context, decl_id);
-    decl_id = context.constant_values().GetConstantInstId(decl_id);
+    decl_id =
+        context.constant_values().GetInstId(SemIR::GetConstantValueInSpecific(
+            context.sem_ir(), interface_type.specific_id, decl_id));
     CARBON_CHECK(decl_id.is_valid()) << "Non-constant associated entity";
     auto decl = context.insts().Get(decl_id);
     CARBON_KIND_SWITCH(decl) {
@@ -115,7 +167,7 @@ static auto BuildInterfaceWitness(
         if (impl_decl_id.is_valid()) {
           used_decl_ids.push_back(impl_decl_id);
           table.push_back(CheckAssociatedFunctionImplementation(
-              context, fn_type->function_id, impl_decl_id, substitutions));
+              context, *fn_type, impl_decl_id, impl.self_id));
         } else {
           CARBON_DIAGNOSTIC(
               ImplMissingFunction, Error,
@@ -137,7 +189,10 @@ static auto BuildInterfaceWitness(
                      "impl of interface with associated constant");
         return SemIR::InstId::BuiltinError;
       default:
-        CARBON_FATAL() << "Unexpected kind of associated entity " << decl;
+        CARBON_CHECK(decl_id == SemIR::InstId::BuiltinError)
+            << "Unexpected kind of associated entity " << decl;
+        table.push_back(SemIR::InstId::BuiltinError);
+        break;
     }
   }
 
@@ -162,8 +217,8 @@ auto BuildImplWitness(Context& context, SemIR::ImplId impl_id)
 
   llvm::SmallVector<SemIR::InstId> used_decl_ids;
 
-  auto witness_id =
-      BuildInterfaceWitness(context, impl, *interface_type, used_decl_ids);
+  auto witness_id = BuildInterfaceWitness(context, impl, impl.constraint_id,
+                                          *interface_type, used_decl_ids);
 
   // TODO: Diagnose if any declarations in the impl are not in used_decl_ids.
 

+ 11 - 4
toolchain/check/import_ref.cpp

@@ -1358,7 +1358,8 @@ class ImportRefResolver {
 
   // Make a declaration of a function. This is done as a separate step from
   // importing the function declaration in order to resolve cycles.
-  auto MakeFunctionDecl(const SemIR::Function& import_function)
+  auto MakeFunctionDecl(const SemIR::Function& import_function,
+                        SemIR::SpecificId specific_id)
       -> std::pair<SemIR::FunctionId, SemIR::ConstantId> {
     SemIR::FunctionDecl function_decl = {
         .type_id = SemIR::TypeId::Invalid,
@@ -1375,8 +1376,6 @@ class ImportRefResolver {
           .is_extern = import_function.is_extern,
           .builtin_function_kind = import_function.builtin_function_kind}});
 
-    // TODO: Import this or recompute it.
-    auto specific_id = SemIR::SpecificId::Invalid;
     function_decl.type_id =
         context_.GetFunctionType(function_decl.function_id, specific_id);
 
@@ -1393,14 +1392,22 @@ class ImportRefResolver {
 
     SemIR::FunctionId function_id = SemIR::FunctionId::Invalid;
     if (!function_const_id.is_valid()) {
+      auto import_specific_id = import_ir_.types()
+                                    .GetAs<SemIR::FunctionType>(inst.type_id)
+                                    .specific_id;
+      auto specific_data = GetLocalSpecificData(import_specific_id);
       if (HasNewWork()) {
         // This is the end of the first phase. Don't make a new function yet if
         // we already have new work.
         return Retry();
       }
+
+      auto specific_id =
+          GetOrAddLocalSpecific(import_specific_id, specific_data);
+
       // On the second phase, create a forward declaration of the interface.
       std::tie(function_id, function_const_id) =
-          MakeFunctionDecl(import_function);
+          MakeFunctionDecl(import_function, specific_id);
     } else {
       // On the third phase, compute the function ID from the constant value of
       // the declaration.

+ 6 - 12
toolchain/check/member_access.cpp

@@ -8,10 +8,9 @@
 #include "toolchain/base/kind_switch.h"
 #include "toolchain/check/context.h"
 #include "toolchain/check/convert.h"
-#include "toolchain/check/generic.h"
 #include "toolchain/check/import_ref.h"
-#include "toolchain/check/subst.h"
 #include "toolchain/diagnostics/diagnostic_emitter.h"
+#include "toolchain/sem_ir/generic.h"
 #include "toolchain/sem_ir/ids.h"
 #include "toolchain/sem_ir/inst.h"
 #include "toolchain/sem_ir/typed_insts.h"
@@ -191,16 +190,11 @@ static auto PerformImplLookup(Context& context, Parse::NodeId node_id,
     return SemIR::InstId::BuiltinError;
   }
 
-  // Substitute into the type declared in the interface.
-  // TODO: Also substitute the arguments from interface_type.specific_id.
-  auto self_param =
-      context.insts().GetAs<SemIR::BindSymbolicName>(interface.self_param_id);
-  Substitution substitutions[1] = {
-      {.bind_id =
-           context.entity_names().Get(self_param.entity_name_id).bind_index,
-       .replacement_id = type_const_id}};
-  auto subst_type_id =
-      SubstType(context, assoc_type.entity_type_id, substitutions);
+  // TODO: This produces the type of the associated entity with no value for
+  // `Self`. The type `Self` might appear in the type of an associated constant,
+  // and if so, we'll need to substitute it here somehow.
+  auto subst_type_id = SemIR::GetTypeInSpecific(
+      context.sem_ir(), interface_type.specific_id, assoc_type.entity_type_id);
 
   return context.AddInst(
       SemIR::LocIdAndInst::NoLoc<SemIR::InterfaceWitnessAccess>(

+ 9 - 10
toolchain/check/merge.cpp

@@ -153,7 +153,7 @@ static auto CheckRedeclParam(Context& context,
                              int32_t param_index,
                              SemIR::InstId new_param_ref_id,
                              SemIR::InstId prev_param_ref_id,
-                             Substitutions substitutions) -> bool {
+                             SemIR::SpecificId prev_specific_id) -> bool {
   // TODO: Consider differentiating between type and name mistakes. For now,
   // taking the simpler approach because I also think we may want to refactor
   // params.
@@ -171,14 +171,13 @@ static auto CheckRedeclParam(Context& context,
         .Emit();
   };
 
-  // TODO: Pass in a specific ID for the previous declaration instead of
-  // substitutions.
   auto new_param_ref = context.insts().Get(new_param_ref_id);
   auto prev_param_ref = context.insts().Get(prev_param_ref_id);
   if (new_param_ref.kind() != prev_param_ref.kind() ||
       !context.types().AreEqualAcrossDeclarations(
           new_param_ref.type_id(),
-          SubstType(context, prev_param_ref.type_id(), substitutions))) {
+          SemIR::GetTypeInSpecific(context.sem_ir(), prev_specific_id,
+                                   prev_param_ref.type_id()))) {
     diagnose();
     return false;
   }
@@ -217,7 +216,7 @@ static auto CheckRedeclParams(Context& context, SemIRLoc new_decl_loc,
                               SemIRLoc prev_decl_loc,
                               SemIR::InstBlockId prev_param_refs_id,
                               llvm::StringLiteral param_diag_label,
-                              Substitutions substitutions) -> bool {
+                              SemIR::SpecificId prev_specific_id) -> bool {
   // This will often occur for empty params.
   if (new_param_refs_id == prev_param_refs_id) {
     return true;
@@ -263,7 +262,7 @@ static auto CheckRedeclParams(Context& context, SemIRLoc new_decl_loc,
   for (auto [index, new_param_ref_id, prev_param_ref_id] :
        llvm::enumerate(new_param_ref_ids, prev_param_ref_ids)) {
     if (!CheckRedeclParam(context, param_diag_label, index, new_param_ref_id,
-                          prev_param_ref_id, substitutions)) {
+                          prev_param_ref_id, prev_specific_id)) {
       return false;
     }
   }
@@ -341,8 +340,8 @@ static auto CheckRedeclParamSyntax(Context& context,
 
 auto CheckRedeclParamsMatch(Context& context, const DeclParams& new_entity,
                             const DeclParams& prev_entity,
-                            Substitutions substitutions, bool check_syntax)
-    -> bool {
+                            SemIR::SpecificId prev_specific_id,
+                            bool check_syntax) -> bool {
   if (EntityHasParamError(context, new_entity) ||
       EntityHasParamError(context, prev_entity)) {
     return false;
@@ -350,12 +349,12 @@ auto CheckRedeclParamsMatch(Context& context, const DeclParams& new_entity,
   if (!CheckRedeclParams(context, new_entity.loc,
                          new_entity.implicit_param_refs_id, prev_entity.loc,
                          prev_entity.implicit_param_refs_id, "implicit ",
-                         substitutions)) {
+                         prev_specific_id)) {
     return false;
   }
   if (!CheckRedeclParams(context, new_entity.loc, new_entity.param_refs_id,
                          prev_entity.loc, prev_entity.param_refs_id, "",
-                         substitutions)) {
+                         prev_specific_id)) {
     return false;
   }
   if (check_syntax &&

+ 5 - 4
toolchain/check/merge.h

@@ -81,10 +81,11 @@ struct DeclParams {
 // Checks that the parameters in a redeclaration of an entity match the
 // parameters in the prior declaration. If not, produces a diagnostic and
 // returns false.
-auto CheckRedeclParamsMatch(Context& context, const DeclParams& new_entity,
-                            const DeclParams& prev_entity,
-                            Substitutions substitutions = Substitutions(),
-                            bool check_syntax = true) -> bool;
+auto CheckRedeclParamsMatch(
+    Context& context, const DeclParams& new_entity,
+    const DeclParams& prev_entity,
+    SemIR::SpecificId prev_specific_id = SemIR::SpecificId::Invalid,
+    bool check_syntax = true) -> bool;
 
 }  // namespace Carbon::Check
 

+ 0 - 6
toolchain/check/subst.cpp

@@ -319,10 +319,4 @@ auto SubstConstant(Context& context, SemIR::ConstantId const_id,
   return context.constant_values().Get(subst_inst_id);
 }
 
-auto SubstType(Context& context, SemIR::TypeId type_id,
-               Substitutions substitutions) -> SemIR::TypeId {
-  return context.GetTypeIdForTypeConstant(SubstConstant(
-      context, context.types().GetConstantId(type_id), substitutions));
-}
-
 }  // namespace Carbon::Check

+ 0 - 5
toolchain/check/subst.h

@@ -53,11 +53,6 @@ using Substitutions = llvm::ArrayRef<Substitution>;
 auto SubstConstant(Context& context, SemIR::ConstantId const_id,
                    Substitutions substitutions) -> SemIR::ConstantId;
 
-// Replaces the `BindSymbolicName` instruction `bind_id` with `replacement_id`
-// throughout the type `type_id`, and returns the substituted value.
-auto SubstType(Context& context, SemIR::TypeId type_id,
-               Substitutions substitutions) -> SemIR::TypeId;
-
 }  // namespace Carbon::Check
 
 #endif  // CARBON_TOOLCHAIN_CHECK_SUBST_H_

+ 44 - 50
toolchain/check/testdata/class/generic/import.carbon

@@ -229,18 +229,16 @@ class Class(U:! type) {
 // CHECK:STDOUT:   %.4: type = struct_type {.n: i32} [template]
 // CHECK:STDOUT:   %CompleteClass.2: type = class_type @CompleteClass, @CompleteClass(%T) [symbolic]
 // CHECK:STDOUT:   %.5: type = unbound_element_type %CompleteClass.2, i32 [symbolic]
-// CHECK:STDOUT:   %F.type.1: type = fn_type @F.1 [template]
-// CHECK:STDOUT:   %F.1: %F.type.1 = struct_value () [template]
-// CHECK:STDOUT:   %F.type.2: type = fn_type @F.1, @CompleteClass(%T) [symbolic]
-// CHECK:STDOUT:   %F.2: %F.type.2 = struct_value () [symbolic]
+// CHECK:STDOUT:   %F.type.1: type = fn_type @F.1, @CompleteClass(%T) [symbolic]
+// CHECK:STDOUT:   %F.1: %F.type.1 = struct_value () [symbolic]
 // CHECK:STDOUT:   %Int32.type: type = fn_type @Int32 [template]
 // CHECK:STDOUT:   %Int32: %Int32.type = struct_value () [template]
 // CHECK:STDOUT:   %CompleteClass.3: type = class_type @CompleteClass, @CompleteClass(i32) [template]
-// CHECK:STDOUT:   %F.type.3: type = fn_type @F.2 [template]
-// CHECK:STDOUT:   %F.3: %F.type.3 = struct_value () [template]
+// CHECK:STDOUT:   %F.type.2: type = fn_type @F.2 [template]
+// CHECK:STDOUT:   %F.2: %F.type.2 = struct_value () [template]
 // CHECK:STDOUT:   %.6: type = unbound_element_type %CompleteClass.3, i32 [template]
-// CHECK:STDOUT:   %F.type.4: type = fn_type @F.1, @CompleteClass(i32) [template]
-// CHECK:STDOUT:   %F.4: %F.type.4 = struct_value () [template]
+// CHECK:STDOUT:   %F.type.3: type = fn_type @F.1, @CompleteClass(i32) [template]
+// CHECK:STDOUT:   %F.3: %F.type.3 = struct_value () [template]
 // CHECK:STDOUT:   %.7: type = ptr_type %.4 [template]
 // CHECK:STDOUT:   %.8: i32 = int_literal 1 [template]
 // CHECK:STDOUT:   %struct: %CompleteClass.3 = struct_value (%.8) [template]
@@ -249,7 +247,7 @@ class Class(U:! type) {
 // CHECK:STDOUT: imports {
 // CHECK:STDOUT:   %import_ref.1: %Class.type = import_ref Main//foo, inst+6, loaded [template = constants.%Class.1]
 // CHECK:STDOUT:   %import_ref.2: %CompleteClass.type = import_ref Main//foo, inst+14, loaded [template = constants.%CompleteClass.1]
-// CHECK:STDOUT:   %import_ref.3: %F.type.3 = import_ref Main//foo, inst+55, loaded [template = constants.%F.3]
+// CHECK:STDOUT:   %import_ref.3: %F.type.2 = import_ref Main//foo, inst+55, loaded [template = constants.%F.2]
 // CHECK:STDOUT:   %Core: <namespace> = namespace file.%Core.import, [template] {
 // CHECK:STDOUT:     .Int32 = %import_ref.7
 // CHECK:STDOUT:     import Core//prelude
@@ -280,7 +278,7 @@ class Class(U:! type) {
 // CHECK:STDOUT:     %T.loc4_13.1: type = param T
 // CHECK:STDOUT:     %T.loc4_13.2: type = bind_symbolic_name T 0, %T.loc4_13.1 [symbolic = constants.%T]
 // CHECK:STDOUT:   }
-// CHECK:STDOUT:   %F.decl: %F.type.3 = fn_decl @F.2 [template = constants.%F.3] {
+// CHECK:STDOUT:   %F.decl: %F.type.2 = fn_decl @F.2 [template = constants.%F.2] {
 // CHECK:STDOUT:     %CompleteClass.ref: %CompleteClass.type = name_ref CompleteClass, imports.%import_ref.2 [template = constants.%CompleteClass.1]
 // CHECK:STDOUT:     %int.make_type_32: init type = call constants.%Int32() [template = i32]
 // CHECK:STDOUT:     %.loc8_24.1: type = value_of_initializer %int.make_type_32 [template = i32]
@@ -315,8 +313,8 @@ class Class(U:! type) {
 // CHECK:STDOUT: !definition:
 // CHECK:STDOUT:   %CompleteClass: type = class_type @CompleteClass, @CompleteClass(%T) [symbolic = %CompleteClass (constants.%CompleteClass.2)]
 // CHECK:STDOUT:   %.1: type = unbound_element_type @CompleteClass.%CompleteClass (%CompleteClass.2), i32 [symbolic = %.1 (constants.%.5)]
-// CHECK:STDOUT:   %F.type: type = fn_type @F.1, @CompleteClass(%T) [symbolic = %F.type (constants.%F.type.2)]
-// CHECK:STDOUT:   %F: @CompleteClass.%F.type (%F.type.2) = struct_value () [symbolic = %F (constants.%F.2)]
+// CHECK:STDOUT:   %F.type: type = fn_type @F.1, @CompleteClass(%T) [symbolic = %F.type (constants.%F.type.1)]
+// CHECK:STDOUT:   %F: @CompleteClass.%F.type (%F.type.1) = struct_value () [symbolic = %F (constants.%F.1)]
 // CHECK:STDOUT:
 // CHECK:STDOUT:   class {
 // CHECK:STDOUT:   !members:
@@ -369,8 +367,8 @@ class Class(U:! type) {
 // CHECK:STDOUT: !definition:
 // CHECK:STDOUT:   %CompleteClass => constants.%CompleteClass.3
 // CHECK:STDOUT:   %.1 => constants.%.6
-// CHECK:STDOUT:   %F.type => constants.%F.type.4
-// CHECK:STDOUT:   %F => constants.%F.4
+// CHECK:STDOUT:   %F.type => constants.%F.type.3
+// CHECK:STDOUT:   %F => constants.%F.3
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: --- use_foo.carbon
@@ -387,17 +385,15 @@ class Class(U:! type) {
 // CHECK:STDOUT:   %T: type = bind_symbolic_name T 0 [symbolic]
 // CHECK:STDOUT:   %CompleteClass.2: type = class_type @CompleteClass, @CompleteClass(%T) [symbolic]
 // CHECK:STDOUT:   %.3: type = unbound_element_type %CompleteClass.2, i32 [symbolic]
-// CHECK:STDOUT:   %F.type.1: type = fn_type @F.1 [template]
-// CHECK:STDOUT:   %F.1: %F.type.1 = struct_value () [template]
-// CHECK:STDOUT:   %F.type.2: type = fn_type @F.1, @CompleteClass(%T) [symbolic]
-// CHECK:STDOUT:   %F.2: %F.type.2 = struct_value () [symbolic]
+// CHECK:STDOUT:   %F.type.1: type = fn_type @F.1, @CompleteClass(%T) [symbolic]
+// CHECK:STDOUT:   %F.1: %F.type.1 = struct_value () [symbolic]
 // CHECK:STDOUT:   %CompleteClass.3: type = class_type @CompleteClass, @CompleteClass(i32) [template]
 // CHECK:STDOUT:   %.4: type = unbound_element_type %CompleteClass.3, i32 [template]
-// CHECK:STDOUT:   %F.type.3: type = fn_type @F.1, @CompleteClass(i32) [template]
-// CHECK:STDOUT:   %F.3: %F.type.3 = struct_value () [template]
+// CHECK:STDOUT:   %F.type.2: type = fn_type @F.1, @CompleteClass(i32) [template]
+// CHECK:STDOUT:   %F.2: %F.type.2 = struct_value () [template]
 // CHECK:STDOUT:   %.5: type = ptr_type %.2 [template]
-// CHECK:STDOUT:   %F.type.4: type = fn_type @F.2 [template]
-// CHECK:STDOUT:   %F.4: %F.type.4 = struct_value () [template]
+// CHECK:STDOUT:   %F.type.3: type = fn_type @F.2 [template]
+// CHECK:STDOUT:   %F.3: %F.type.3 = struct_value () [template]
 // CHECK:STDOUT:   %UseField.type: type = fn_type @UseField [template]
 // CHECK:STDOUT:   %UseField: %UseField.type = struct_value () [template]
 // CHECK:STDOUT: }
@@ -405,7 +401,7 @@ class Class(U:! type) {
 // CHECK:STDOUT: imports {
 // CHECK:STDOUT:   %import_ref.1 = import_ref Main//foo, inst+6, unloaded
 // CHECK:STDOUT:   %import_ref.2: %CompleteClass.type = import_ref Main//foo, inst+14, loaded [template = constants.%CompleteClass.1]
-// CHECK:STDOUT:   %import_ref.3: %F.type.4 = import_ref Main//foo, inst+55, loaded [template = constants.%F.4]
+// CHECK:STDOUT:   %import_ref.3: %F.type.3 = import_ref Main//foo, inst+55, loaded [template = constants.%F.3]
 // CHECK:STDOUT:   %Core: <namespace> = namespace file.%Core.import, [template] {
 // CHECK:STDOUT:     .Int32 = %import_ref.4
 // CHECK:STDOUT:     import Core//prelude
@@ -419,7 +415,7 @@ class Class(U:! type) {
 // CHECK:STDOUT:   %import_ref.4: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
 // CHECK:STDOUT:   %import_ref.5 = import_ref Main//foo, inst+18, unloaded
 // CHECK:STDOUT:   %import_ref.6: @CompleteClass.%.1 (%.3) = import_ref Main//foo, inst+28, loaded [template = %.1]
-// CHECK:STDOUT:   %import_ref.7: @CompleteClass.%F.type (%F.type.2) = import_ref Main//foo, inst+35, loaded [symbolic = @CompleteClass.%F (constants.%F.1)]
+// CHECK:STDOUT:   %import_ref.7: @CompleteClass.%F.type (%F.type.1) = import_ref Main//foo, inst+35, loaded [symbolic = @CompleteClass.%F (constants.%F.1)]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -453,8 +449,8 @@ class Class(U:! type) {
 // CHECK:STDOUT: !definition:
 // CHECK:STDOUT:   %CompleteClass: type = class_type @CompleteClass, @CompleteClass(%T) [symbolic = %CompleteClass (constants.%CompleteClass.2)]
 // CHECK:STDOUT:   %.1: type = unbound_element_type @CompleteClass.%CompleteClass (%CompleteClass.2), i32 [symbolic = %.1 (constants.%.3)]
-// CHECK:STDOUT:   %F.type: type = fn_type @F.1, @CompleteClass(%T) [symbolic = %F.type (constants.%F.type.2)]
-// CHECK:STDOUT:   %F: @CompleteClass.%F.type (%F.type.2) = struct_value () [symbolic = %F (constants.%F.2)]
+// CHECK:STDOUT:   %F.type: type = fn_type @F.1, @CompleteClass(%T) [symbolic = %F.type (constants.%F.type.1)]
+// CHECK:STDOUT:   %F: @CompleteClass.%F.type (%F.type.1) = struct_value () [symbolic = %F (constants.%F.1)]
 // CHECK:STDOUT:
 // CHECK:STDOUT:   class {
 // CHECK:STDOUT:   !members:
@@ -477,13 +473,13 @@ class Class(U:! type) {
 // CHECK:STDOUT:   %.loc6_27.2: type = converted %.loc6_23.3, %.loc6_27.1 [template = constants.%CompleteClass.3]
 // CHECK:STDOUT:   %v.var: ref %CompleteClass.3 = var v
 // CHECK:STDOUT:   %v: ref %CompleteClass.3 = bind_name v, %v.var
-// CHECK:STDOUT:   %F.ref.loc6: %F.type.4 = name_ref F, imports.%import_ref.3 [template = constants.%F.4]
+// CHECK:STDOUT:   %F.ref.loc6: %F.type.3 = name_ref F, imports.%import_ref.3 [template = constants.%F.3]
 // CHECK:STDOUT:   %.loc6_7: ref %CompleteClass.3 = splice_block %v.var {}
 // CHECK:STDOUT:   %F.call.loc6: init %CompleteClass.3 = call %F.ref.loc6() to %.loc6_7
 // CHECK:STDOUT:   assign %v.var, %F.call.loc6
 // CHECK:STDOUT:   %v.ref: ref %CompleteClass.3 = name_ref v, %v
-// CHECK:STDOUT:   %.loc7_11: %F.type.3 = specific_constant imports.%import_ref.7, @CompleteClass(i32) [template = constants.%F.3]
-// CHECK:STDOUT:   %F.ref.loc7: %F.type.3 = name_ref F, %.loc7_11 [template = constants.%F.3]
+// CHECK:STDOUT:   %.loc7_11: %F.type.2 = specific_constant imports.%import_ref.7, @CompleteClass(i32) [template = constants.%F.2]
+// CHECK:STDOUT:   %F.ref.loc7: %F.type.2 = name_ref F, %.loc7_11 [template = constants.%F.2]
 // CHECK:STDOUT:   %F.call.loc7: init i32 = call %F.ref.loc7()
 // CHECK:STDOUT:   %.loc7_15.1: i32 = value_of_initializer %F.call.loc7
 // CHECK:STDOUT:   %.loc7_15.2: i32 = converted %F.call.loc7, %.loc7_15.1
@@ -509,7 +505,7 @@ class Class(U:! type) {
 // CHECK:STDOUT:   %.loc11_27.2: type = converted %.loc11_23.3, %.loc11_27.1 [template = constants.%CompleteClass.3]
 // CHECK:STDOUT:   %v.var: ref %CompleteClass.3 = var v
 // CHECK:STDOUT:   %v: ref %CompleteClass.3 = bind_name v, %v.var
-// CHECK:STDOUT:   %F.ref: %F.type.4 = name_ref F, imports.%import_ref.3 [template = constants.%F.4]
+// CHECK:STDOUT:   %F.ref: %F.type.3 = name_ref F, imports.%import_ref.3 [template = constants.%F.3]
 // CHECK:STDOUT:   %.loc11_7: ref %CompleteClass.3 = splice_block %v.var {}
 // CHECK:STDOUT:   %F.call: init %CompleteClass.3 = call %F.ref() to %.loc11_7
 // CHECK:STDOUT:   assign %v.var, %F.call
@@ -536,8 +532,8 @@ class Class(U:! type) {
 // CHECK:STDOUT: !definition:
 // CHECK:STDOUT:   %CompleteClass => constants.%CompleteClass.3
 // CHECK:STDOUT:   %.1 => constants.%.4
-// CHECK:STDOUT:   %F.type => constants.%F.type.3
-// CHECK:STDOUT:   %F => constants.%F.3
+// CHECK:STDOUT:   %F.type => constants.%F.type.2
+// CHECK:STDOUT:   %F => constants.%F.2
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: specific @F.1(i32) {}
@@ -554,30 +550,28 @@ class Class(U:! type) {
 // CHECK:STDOUT:   %T: type = bind_symbolic_name T 0 [symbolic]
 // CHECK:STDOUT:   %CompleteClass.2: type = class_type @CompleteClass, @CompleteClass(%T) [symbolic]
 // CHECK:STDOUT:   %.3: type = unbound_element_type %CompleteClass.2, i32 [symbolic]
-// CHECK:STDOUT:   %F.type.1: type = fn_type @F.1 [template]
-// CHECK:STDOUT:   %F.1: %F.type.1 = struct_value () [template]
-// CHECK:STDOUT:   %F.type.2: type = fn_type @F.1, @CompleteClass(%T) [symbolic]
-// CHECK:STDOUT:   %F.2: %F.type.2 = struct_value () [symbolic]
+// CHECK:STDOUT:   %F.type.1: type = fn_type @F.1, @CompleteClass(%T) [symbolic]
+// CHECK:STDOUT:   %F.1: %F.type.1 = struct_value () [symbolic]
 // CHECK:STDOUT:   %Int32.type: type = fn_type @Int32 [template]
 // CHECK:STDOUT:   %Int32: %Int32.type = struct_value () [template]
 // CHECK:STDOUT:   %.4: type = ptr_type i32 [template]
 // CHECK:STDOUT:   %CompleteClass.3: type = class_type @CompleteClass, @CompleteClass(%.4) [template]
 // CHECK:STDOUT:   %.5: type = unbound_element_type %CompleteClass.3, i32 [template]
-// CHECK:STDOUT:   %F.type.3: type = fn_type @F.1, @CompleteClass(%.4) [template]
-// CHECK:STDOUT:   %F.3: %F.type.3 = struct_value () [template]
+// CHECK:STDOUT:   %F.type.2: type = fn_type @F.1, @CompleteClass(%.4) [template]
+// CHECK:STDOUT:   %F.2: %F.type.2 = struct_value () [template]
 // CHECK:STDOUT:   %.6: type = ptr_type %.2 [template]
-// CHECK:STDOUT:   %F.type.4: type = fn_type @F.2 [template]
-// CHECK:STDOUT:   %F.4: %F.type.4 = struct_value () [template]
+// CHECK:STDOUT:   %F.type.3: type = fn_type @F.2 [template]
+// CHECK:STDOUT:   %F.3: %F.type.3 = struct_value () [template]
 // CHECK:STDOUT:   %CompleteClass.4: type = class_type @CompleteClass, @CompleteClass(i32) [template]
 // CHECK:STDOUT:   %.7: type = unbound_element_type %CompleteClass.4, i32 [template]
-// CHECK:STDOUT:   %F.type.5: type = fn_type @F.1, @CompleteClass(i32) [template]
-// CHECK:STDOUT:   %F.5: %F.type.5 = struct_value () [template]
+// CHECK:STDOUT:   %F.type.4: type = fn_type @F.1, @CompleteClass(i32) [template]
+// CHECK:STDOUT:   %F.4: %F.type.4 = struct_value () [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: imports {
 // CHECK:STDOUT:   %import_ref.1 = import_ref Main//foo, inst+6, unloaded
 // CHECK:STDOUT:   %import_ref.2: %CompleteClass.type = import_ref Main//foo, inst+14, loaded [template = constants.%CompleteClass.1]
-// CHECK:STDOUT:   %import_ref.3: %F.type.4 = import_ref Main//foo, inst+55, loaded [template = constants.%F.4]
+// CHECK:STDOUT:   %import_ref.3: %F.type.3 = import_ref Main//foo, inst+55, loaded [template = constants.%F.3]
 // CHECK:STDOUT:   %Core: <namespace> = namespace file.%Core.import, [template] {
 // CHECK:STDOUT:     .Int32 = %import_ref.7
 // CHECK:STDOUT:     import Core//prelude
@@ -613,8 +607,8 @@ class Class(U:! type) {
 // CHECK:STDOUT: !definition:
 // CHECK:STDOUT:   %CompleteClass: type = class_type @CompleteClass, @CompleteClass(%T) [symbolic = %CompleteClass (constants.%CompleteClass.2)]
 // CHECK:STDOUT:   %.1: type = unbound_element_type @CompleteClass.%CompleteClass (%CompleteClass.2), i32 [symbolic = %.1 (constants.%.3)]
-// CHECK:STDOUT:   %F.type: type = fn_type @F.1, @CompleteClass(%T) [symbolic = %F.type (constants.%F.type.2)]
-// CHECK:STDOUT:   %F: @CompleteClass.%F.type (%F.type.2) = struct_value () [symbolic = %F (constants.%F.2)]
+// CHECK:STDOUT:   %F.type: type = fn_type @F.1, @CompleteClass(%T) [symbolic = %F.type (constants.%F.type.1)]
+// CHECK:STDOUT:   %F: @CompleteClass.%F.type (%F.type.1) = struct_value () [symbolic = %F (constants.%F.1)]
 // CHECK:STDOUT:
 // CHECK:STDOUT:   class {
 // CHECK:STDOUT:   !members:
@@ -636,7 +630,7 @@ class Class(U:! type) {
 // CHECK:STDOUT:   %.loc11_28.2: type = converted %.loc11_23, %.loc11_28.1 [template = constants.%CompleteClass.3]
 // CHECK:STDOUT:   %v.var: ref %CompleteClass.3 = var v
 // CHECK:STDOUT:   %v: ref %CompleteClass.3 = bind_name v, %v.var
-// CHECK:STDOUT:   %F.ref: %F.type.4 = name_ref F, imports.%import_ref.3 [template = constants.%F.4]
+// CHECK:STDOUT:   %F.ref: %F.type.3 = name_ref F, imports.%import_ref.3 [template = constants.%F.3]
 // CHECK:STDOUT:   %.loc11_33: ref %CompleteClass.4 = temporary_storage
 // CHECK:STDOUT:   %F.call: init %CompleteClass.4 = call %F.ref() to %.loc11_33
 // CHECK:STDOUT:   assign %v.var, <error>
@@ -669,8 +663,8 @@ class Class(U:! type) {
 // CHECK:STDOUT: !definition:
 // CHECK:STDOUT:   %CompleteClass => constants.%CompleteClass.3
 // CHECK:STDOUT:   %.1 => constants.%.5
-// CHECK:STDOUT:   %F.type => constants.%F.type.3
-// CHECK:STDOUT:   %F => constants.%F.3
+// CHECK:STDOUT:   %F.type => constants.%F.type.2
+// CHECK:STDOUT:   %F => constants.%F.2
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: specific @CompleteClass(i32) {
@@ -679,8 +673,8 @@ class Class(U:! type) {
 // CHECK:STDOUT: !definition:
 // CHECK:STDOUT:   %CompleteClass => constants.%CompleteClass.4
 // CHECK:STDOUT:   %.1 => constants.%.7
-// CHECK:STDOUT:   %F.type => constants.%F.type.5
-// CHECK:STDOUT:   %F => constants.%F.5
+// CHECK:STDOUT:   %F.type => constants.%F.type.4
+// CHECK:STDOUT:   %F => constants.%F.4
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: --- fail_bad_foo.impl.carbon

+ 4 - 0
toolchain/check/testdata/function/builtin/method.carbon

@@ -148,3 +148,7 @@ var arr: [i32; 1.(I.F)(2)];
 // CHECK:STDOUT:   %Self => constants.%Self
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.1(i32) {
+// CHECK:STDOUT:   %Self => i32
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 4 - 0
toolchain/check/testdata/function/builtin/no_prelude/call_from_operator.carbon

@@ -226,3 +226,7 @@ var arr: [i32; 1 + 2] = (3, 4, 3 + 4);
 // CHECK:STDOUT:   %Self => constants.%Self
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.2(i32) {
+// CHECK:STDOUT:   %Self => i32
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 6 - 0
toolchain/check/testdata/impl/compound.carbon

@@ -234,3 +234,9 @@ fn InstanceCallIndirect(p: i32*) {
 // CHECK:STDOUT:   %Self => constants.%Self
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.1(i32) {}
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @G.1(i32) {
+// CHECK:STDOUT:   %Self => i32
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 2 - 0
toolchain/check/testdata/impl/extend_impl.carbon

@@ -127,3 +127,5 @@ fn G(c: C) {
 // CHECK:STDOUT:
 // CHECK:STDOUT: specific @F.1(constants.%Self) {}
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.1(constants.%C) {}
+// CHECK:STDOUT:

+ 4 - 0
toolchain/check/testdata/impl/fail_call_invalid.carbon

@@ -132,3 +132,7 @@ fn InstanceCall(n: i32) {
 // CHECK:STDOUT:   %Self => constants.%Self
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @G.1(i32) {
+// CHECK:STDOUT:   %Self => i32
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 12 - 0
toolchain/check/testdata/impl/fail_extend_impl_forall.carbon

@@ -142,6 +142,14 @@ class C {
 // CHECK:STDOUT:
 // CHECK:STDOUT: specific @GenericInterface(constants.%T) {
 // CHECK:STDOUT:   %T => constants.%T
+// CHECK:STDOUT:
+// CHECK:STDOUT: !definition:
+// CHECK:STDOUT:   %.1 => constants.%.2
+// CHECK:STDOUT:   %Self.2 => constants.%Self
+// CHECK:STDOUT:   %F.type => constants.%F.type.1
+// CHECK:STDOUT:   %F => constants.%F.1
+// CHECK:STDOUT:   %.2 => constants.%.3
+// CHECK:STDOUT:   %.3 => constants.%.4
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: specific @F.1(constants.%T, constants.%Self) {
@@ -156,3 +164,7 @@ class C {
 // CHECK:STDOUT:   %T => constants.%T
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.1(constants.%T, constants.%C) {
+// CHECK:STDOUT:   %T => constants.%T
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 2 - 0
toolchain/check/testdata/impl/fail_impl_as_scope.carbon

@@ -90,3 +90,5 @@ impl as Simple {
 // CHECK:STDOUT:
 // CHECK:STDOUT: specific @F.1(constants.%Self) {}
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.1(<error>) {}
+// CHECK:STDOUT:

+ 36 - 0
toolchain/check/testdata/impl/fail_impl_bad_assoc_fn.carbon

@@ -888,8 +888,28 @@ class SelfNestedBadReturnType {
 // CHECK:STDOUT:
 // CHECK:STDOUT: specific @F.1(constants.%Self.1) {}
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.1(constants.%FExtraParam) {}
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.1(constants.%FExtraImplicitParam) {}
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.1(constants.%FExtraReturnType) {}
+// CHECK:STDOUT:
 // CHECK:STDOUT: specific @F.5(constants.%Self.2) {}
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.5(constants.%FMissingParam) {}
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.5(constants.%FMissingImplicitParam) {}
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.5(constants.%FMissingReturnType) {}
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.5(constants.%FDifferentParamType) {}
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.5(constants.%FDifferentImplicitParamType) {}
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.5(constants.%FDifferentReturnType) {}
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.5(constants.%FDifferentParamName) {}
+// CHECK:STDOUT:
 // CHECK:STDOUT: specific @F.13(constants.%Self.3) {
 // CHECK:STDOUT:   %Self => constants.%Self.3
 // CHECK:STDOUT:   %.1 => constants.%.10
@@ -898,3 +918,19 @@ class SelfNestedBadReturnType {
 // CHECK:STDOUT:   %.4 => constants.%.15
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.13(constants.%SelfNestedBadParam) {
+// CHECK:STDOUT:   %Self => constants.%SelfNestedBadParam
+// CHECK:STDOUT:   %.1 => constants.%.18
+// CHECK:STDOUT:   %.2 => constants.%.22
+// CHECK:STDOUT:   %.3 => constants.%.23
+// CHECK:STDOUT:   %.4 => constants.%.21
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.13(constants.%SelfNestedBadReturnType) {
+// CHECK:STDOUT:   %Self => constants.%SelfNestedBadReturnType
+// CHECK:STDOUT:   %.1 => constants.%.24
+// CHECK:STDOUT:   %.2 => constants.%.25
+// CHECK:STDOUT:   %.3 => constants.%.26
+// CHECK:STDOUT:   %.4 => constants.%.27
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 2 - 0
toolchain/check/testdata/impl/impl_as.carbon

@@ -111,3 +111,5 @@ class C {
 // CHECK:STDOUT:
 // CHECK:STDOUT: specific @F.1(constants.%Self) {}
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.1(constants.%C) {}
+// CHECK:STDOUT:

+ 2 - 0
toolchain/check/testdata/impl/impl_forall.carbon

@@ -97,3 +97,5 @@ impl forall [T:! type] T as Simple {
 // CHECK:STDOUT:
 // CHECK:STDOUT: specific @F.2(constants.%T) {}
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.1(constants.%T) {}
+// CHECK:STDOUT:

+ 2 - 0
toolchain/check/testdata/impl/lookup/alias.carbon

@@ -133,3 +133,5 @@ fn G(c: C) {
 // CHECK:STDOUT:
 // CHECK:STDOUT: specific @F.1(constants.%Self) {}
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.1(constants.%C) {}
+// CHECK:STDOUT:

+ 2 - 0
toolchain/check/testdata/impl/lookup/fail_todo_undefined_impl.carbon

@@ -137,3 +137,5 @@ impl C as I {
 // CHECK:STDOUT:
 // CHECK:STDOUT: specific @F.1(constants.%Self) {}
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.1(constants.%C) {}
+// CHECK:STDOUT:

+ 2 - 0
toolchain/check/testdata/impl/lookup/import.carbon

@@ -111,6 +111,8 @@ fn G(c: Impl.C) {
 // CHECK:STDOUT:
 // CHECK:STDOUT: specific @F.1(constants.%Self) {}
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.1(constants.%C) {}
+// CHECK:STDOUT:
 // CHECK:STDOUT: --- use.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {

+ 4 - 0
toolchain/check/testdata/impl/lookup/instance_method.carbon

@@ -156,3 +156,7 @@ fn F(c: C) -> i32 {
 // CHECK:STDOUT:   %Self => constants.%Self
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.1(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 2 - 0
toolchain/check/testdata/impl/lookup/no_prelude/import.carbon

@@ -97,6 +97,8 @@ fn G(c: Impl.C) {
 // CHECK:STDOUT:
 // CHECK:STDOUT: specific @F.1(constants.%Self) {}
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.1(constants.%C) {}
+// CHECK:STDOUT:
 // CHECK:STDOUT: --- use.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {

+ 2 - 0
toolchain/check/testdata/impl/no_prelude/basic.carbon

@@ -85,3 +85,5 @@ impl C as Simple {
 // CHECK:STDOUT:
 // CHECK:STDOUT: specific @F.1(constants.%Self) {}
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.1(constants.%C) {}
+// CHECK:STDOUT:

+ 5 - 18
toolchain/check/testdata/impl/fail_impl_bad_type.carbon → toolchain/check/testdata/impl/no_prelude/fail_impl_bad_type.carbon

@@ -4,9 +4,9 @@
 //
 // AUTOUPDATE
 // TIP: To test this file alone, run:
-// TIP:   bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/impl/fail_impl_bad_type.carbon
+// TIP:   bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/impl/no_prelude/fail_impl_bad_type.carbon
 // TIP: To dump output, run:
-// TIP:   bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/fail_impl_bad_type.carbon
+// TIP:   bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/no_prelude/fail_impl_bad_type.carbon
 
 interface I {}
 
@@ -21,27 +21,14 @@ impl true as I {}
 // CHECK:STDOUT:   %.1: type = interface_type @I [template]
 // CHECK:STDOUT:   %Self: %.1 = bind_symbolic_name Self 0 [symbolic]
 // CHECK:STDOUT:   %.2: bool = bool_literal true [template]
-// CHECK:STDOUT:   %.3: <witness> = interface_witness () [template]
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: imports {
-// CHECK:STDOUT:   %Core: <namespace> = namespace file.%Core.import, [template] {
-// CHECK:STDOUT:     import Core//prelude
-// CHECK:STDOUT:     import Core//prelude/operators
-// CHECK:STDOUT:     import Core//prelude/types
-// CHECK:STDOUT:     import Core//prelude/operators/arithmetic
-// CHECK:STDOUT:     import Core//prelude/operators/bitwise
-// CHECK:STDOUT:     import Core//prelude/operators/comparison
-// CHECK:STDOUT:     import Core//prelude/types/bool
-// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %.3: type = tuple_type () [template]
+// CHECK:STDOUT:   %.4: <witness> = interface_witness () [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace [template] {
-// CHECK:STDOUT:     .Core = imports.%Core
 // CHECK:STDOUT:     .I = %I.decl
 // CHECK:STDOUT:   }
-// CHECK:STDOUT:   %Core.import = import Core
 // CHECK:STDOUT:   %I.decl: type = interface_decl @I [template = constants.%.1] {}
 // CHECK:STDOUT:   impl_decl @impl {
 // CHECK:STDOUT:     %.loc16: bool = bool_literal true [template = constants.%.2]
@@ -58,7 +45,7 @@ impl true as I {}
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: impl @impl: <error> as %.1 {
-// CHECK:STDOUT:   %.1: <witness> = interface_witness () [template = constants.%.3]
+// CHECK:STDOUT:   %.1: <witness> = interface_witness () [template = constants.%.4]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:
 // CHECK:STDOUT:   witness = %.1

+ 4 - 0
toolchain/check/testdata/impl/no_prelude/import_self.carbon

@@ -196,3 +196,7 @@ fn F(x: (), y: ()) -> () {
 // CHECK:STDOUT:   %Self => constants.%Self
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.2(constants.%.1) {
+// CHECK:STDOUT:   %Self => constants.%.1
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 482 - 93
toolchain/check/testdata/impl/no_prelude/interface_args.carbon

@@ -24,11 +24,13 @@ impl A as Action(B) {
   fn Op() {}
 }
 
+fn F(a: A) { a.(Action(B).Op)(); }
+
 // --- action.impl.carbon
 
 impl library "action";
 
-fn F(a: A) { a.(Action(B).Op)(); }
+fn G(a: A) { a.(Action(B).Op)(); }
 
 // --- fail_action.impl.carbon
 
@@ -40,9 +42,9 @@ impl library "action";
 // CHECK:STDERR:
 fn G(a: A) { a.(Action(C).Op)(); }
 
-// --- fail_todo_factory.carbon
+// --- factory.carbon
 
-library "fail_todo_factory";
+library "factory";
 
 interface Factory(T:! type) {
   fn Make() -> T;
@@ -52,15 +54,30 @@ class A {}
 class B {}
 
 impl A as Factory(B) {
-  // CHECK:STDERR: fail_todo_factory.carbon:[[@LINE+6]]:3: ERROR: Function redeclaration differs because return type is `B`.
-  // CHECK:STDERR:   fn Make() -> B;
-  // CHECK:STDERR:   ^~~~~~~~~~~~~~~
-  // CHECK:STDERR: fail_todo_factory.carbon:[[@LINE-10]]:3: Previously declared with return type `T`.
-  // CHECK:STDERR:   fn Make() -> T;
-  // CHECK:STDERR:   ^~~~~~~~~~~~~~~
   fn Make() -> B;
 }
 
+// --- factory.impl.carbon
+
+impl library "factory";
+
+fn MakeB(a: A) -> B {
+  return a.(Factory(B).Make)();
+}
+
+// --- fail_factory.impl.carbon
+
+impl library "factory";
+
+class C {}
+
+fn MakeC(a: A) -> C {
+  // CHECK:STDERR: fail_factory.impl.carbon:[[@LINE+3]]:10: ERROR: Cannot access member of interface Factory in type A that does not implement that interface.
+  // CHECK:STDERR:   return a.(Factory(C).Make)();
+  // CHECK:STDERR:          ^~~~~~~~~~~~~~~~~~~
+  return a.(Factory(C).Make)();
+}
+
 // CHECK:STDOUT: --- action.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
@@ -81,7 +98,14 @@ impl A as Factory(B) {
 // CHECK:STDOUT:   %.6: type = interface_type @Action, @Action(%B) [template]
 // CHECK:STDOUT:   %Op.type.2: type = fn_type @Op.2 [template]
 // CHECK:STDOUT:   %Op.2: %Op.type.2 = struct_value () [template]
-// CHECK:STDOUT:   %.7: <witness> = interface_witness (%Op.2) [template]
+// CHECK:STDOUT:   %Op.type.3: type = fn_type @Op.1, @Action(%B) [template]
+// CHECK:STDOUT:   %Op.3: %Op.type.3 = struct_value () [template]
+// CHECK:STDOUT:   %.7: type = assoc_entity_type %.6, %Op.type.3 [template]
+// CHECK:STDOUT:   %.8: %.7 = assoc_entity element0, @Action.%Op.decl [template]
+// CHECK:STDOUT:   %.9: <witness> = interface_witness (%Op.2) [template]
+// CHECK:STDOUT:   %F.type: type = fn_type @F [template]
+// CHECK:STDOUT:   %F: %F.type = struct_value () [template]
+// CHECK:STDOUT:   %.10: type = ptr_type %.5 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -90,6 +114,7 @@ impl A as Factory(B) {
 // CHECK:STDOUT:     .A = %A.decl
 // CHECK:STDOUT:     .B = %B.decl
 // CHECK:STDOUT:     .C = %C.decl
+// CHECK:STDOUT:     .F = %F.decl
 // CHECK:STDOUT:   }
 // CHECK:STDOUT:   %Action.decl: %Action.type = interface_decl @Action [template = constants.%Action] {
 // CHECK:STDOUT:     %T.loc4_18.1: type = param T
@@ -101,11 +126,16 @@ impl A as Factory(B) {
 // CHECK:STDOUT:   %.loc12_19.1: type = value_of_initializer %.loc12_17 [template = constants.%.6]
 // CHECK:STDOUT:   %.loc12_19.2: type = converted %.loc12_17, %.loc12_19.1 [template = constants.%.6]
 // CHECK:STDOUT:   impl_decl @impl {
-// CHECK:STDOUT:     %A.ref: type = name_ref A, %A.decl [template = constants.%A]
+// CHECK:STDOUT:     %A.ref.loc12: type = name_ref A, %A.decl [template = constants.%A]
 // CHECK:STDOUT:     %Action.ref: %Action.type = name_ref Action, %Action.decl [template = constants.%Action]
 // CHECK:STDOUT:     %B.ref: type = name_ref B, %B.decl [template = constants.%B]
 // CHECK:STDOUT:     %.loc12_17: init type = call %Action.ref(%B.ref) [template = constants.%.6]
 // CHECK:STDOUT:   }
+// CHECK:STDOUT:   %F.decl: %F.type = fn_decl @F [template = constants.%F] {
+// CHECK:STDOUT:     %A.ref.loc16: type = name_ref A, %A.decl [template = constants.%A]
+// CHECK:STDOUT:     %a.loc16_6.1: %A = param a
+// CHECK:STDOUT:     @F.%a: %A = bind_name a, %a.loc16_6.1
+// CHECK:STDOUT:   }
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: generic interface @Action(file.%T.loc4_18.2: type) {
@@ -133,7 +163,7 @@ impl A as Factory(B) {
 // CHECK:STDOUT:
 // CHECK:STDOUT: impl @impl: %A as %.6 {
 // CHECK:STDOUT:   %Op.decl: %Op.type.2 = fn_decl @Op.2 [template = constants.%Op.2] {}
-// CHECK:STDOUT:   %.1: <witness> = interface_witness (%Op.decl) [template = constants.%.7]
+// CHECK:STDOUT:   %.1: <witness> = interface_witness (%Op.decl) [template = constants.%.9]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:
 // CHECK:STDOUT:   .Op = %Op.decl
@@ -165,6 +195,19 @@ impl A as Factory(B) {
 // CHECK:STDOUT:   return
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: fn @F(%a: %A) {
+// CHECK:STDOUT: !entry:
+// CHECK:STDOUT:   %a.ref: %A = name_ref a, %a
+// CHECK:STDOUT:   %Action.ref: %Action.type = name_ref Action, file.%Action.decl [template = constants.%Action]
+// CHECK:STDOUT:   %B.ref: type = name_ref B, file.%B.decl [template = constants.%B]
+// CHECK:STDOUT:   %.loc16_23: init type = call %Action.ref(%B.ref) [template = constants.%.6]
+// CHECK:STDOUT:   %.loc16_26: %.7 = specific_constant @Action.%.loc5, @Action(constants.%B) [template = constants.%.8]
+// CHECK:STDOUT:   %Op.ref: %.7 = name_ref Op, %.loc16_26 [template = constants.%.8]
+// CHECK:STDOUT:   %.1: %Op.type.3 = interface_witness_access @impl.%.1, element0 [template = constants.%Op.2]
+// CHECK:STDOUT:   %Op.call: init %.1 = call %.1()
+// CHECK:STDOUT:   return
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
 // CHECK:STDOUT: specific @Action(constants.%T) {
 // CHECK:STDOUT:   %T => constants.%T
 // CHECK:STDOUT: }
@@ -177,8 +220,18 @@ impl A as Factory(B) {
 // CHECK:STDOUT:
 // CHECK:STDOUT: specific @Action(constants.%B) {
 // CHECK:STDOUT:   %T => constants.%B
+// CHECK:STDOUT:
+// CHECK:STDOUT: !definition:
+// CHECK:STDOUT:   %.1 => constants.%.6
+// CHECK:STDOUT:   %Self.2 => constants.%Self
+// CHECK:STDOUT:   %Op.type => constants.%Op.type.3
+// CHECK:STDOUT:   %Op => constants.%Op.3
+// CHECK:STDOUT:   %.2 => constants.%.7
+// CHECK:STDOUT:   %.3 => constants.%.8
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.1(constants.%B, constants.%A) {}
+// CHECK:STDOUT:
 // CHECK:STDOUT: --- action.impl.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
@@ -193,23 +246,21 @@ impl A as Factory(B) {
 // CHECK:STDOUT:   %Self.1: @Action.%.1 (%.3) = bind_symbolic_name Self 1 [symbolic]
 // CHECK:STDOUT:   %.4: type = interface_type @Action, @Action(%B) [template]
 // CHECK:STDOUT:   %Self.2: %.3 = bind_symbolic_name Self 1 [symbolic]
-// CHECK:STDOUT:   %Op.type.1: type = fn_type @Op.1 [template]
-// CHECK:STDOUT:   %Op.1: %Op.type.1 = struct_value () [template]
-// CHECK:STDOUT:   %Op.type.2: type = fn_type @Op.1, @Action(%T) [symbolic]
-// CHECK:STDOUT:   %Op.2: %Op.type.2 = struct_value () [symbolic]
-// CHECK:STDOUT:   %.5: type = assoc_entity_type %.3, %Op.type.2 [symbolic]
-// CHECK:STDOUT:   %.6: %.5 = assoc_entity element0, imports.%import_ref.10 [symbolic]
-// CHECK:STDOUT:   %F.type: type = fn_type @F [template]
-// CHECK:STDOUT:   %F: %F.type = struct_value () [template]
-// CHECK:STDOUT:   %.7: type = ptr_type %.1 [template]
-// CHECK:STDOUT:   %Op.type.3: type = fn_type @Op.1, @Action(%B) [template]
+// CHECK:STDOUT:   %Op.type.1: type = fn_type @Op.1, @Action(%T) [symbolic]
+// CHECK:STDOUT:   %Op.1: %Op.type.1 = struct_value () [symbolic]
+// CHECK:STDOUT:   %.5: type = assoc_entity_type %.3, %Op.type.1 [symbolic]
+// CHECK:STDOUT:   %.6: %.5 = assoc_entity element0, imports.%import_ref.11 [symbolic]
+// CHECK:STDOUT:   %Op.type.2: type = fn_type @Op.1, @Action(%B) [template]
+// CHECK:STDOUT:   %Op.2: %Op.type.2 = struct_value () [template]
+// CHECK:STDOUT:   %.7: type = assoc_entity_type %.4, %Op.type.2 [template]
+// CHECK:STDOUT:   %.8: %.7 = assoc_entity element0, imports.%import_ref.12 [template]
+// CHECK:STDOUT:   %G.type: type = fn_type @G [template]
+// CHECK:STDOUT:   %G: %G.type = struct_value () [template]
+// CHECK:STDOUT:   %.9: type = ptr_type %.1 [template]
+// CHECK:STDOUT:   %.10: %.5 = assoc_entity element0, imports.%import_ref.14 [symbolic]
+// CHECK:STDOUT:   %Op.type.3: type = fn_type @Op.2 [template]
 // CHECK:STDOUT:   %Op.3: %Op.type.3 = struct_value () [template]
-// CHECK:STDOUT:   %.8: type = assoc_entity_type %.4, %Op.type.3 [template]
-// CHECK:STDOUT:   %.9: %.8 = assoc_entity element0, imports.%import_ref.10 [template]
-// CHECK:STDOUT:   %.10: %.5 = assoc_entity element0, imports.%import_ref.12 [symbolic]
-// CHECK:STDOUT:   %Op.type.4: type = fn_type @Op.2 [template]
-// CHECK:STDOUT:   %Op.4: %Op.type.4 = struct_value () [template]
-// CHECK:STDOUT:   %.11: <witness> = interface_witness (%Op.4) [template]
+// CHECK:STDOUT:   %.11: <witness> = interface_witness (%Op.3) [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: imports {
@@ -217,14 +268,16 @@ impl A as Factory(B) {
 // CHECK:STDOUT:   %import_ref.2: type = import_ref Main//action, inst+24, loaded [template = constants.%A]
 // CHECK:STDOUT:   %import_ref.3: type = import_ref Main//action, inst+27, loaded [template = constants.%B]
 // CHECK:STDOUT:   %import_ref.4 = import_ref Main//action, inst+29, unloaded
-// CHECK:STDOUT:   %import_ref.5 = import_ref Main//action, inst+25, unloaded
-// CHECK:STDOUT:   %import_ref.6 = import_ref Main//action, inst+28, unloaded
-// CHECK:STDOUT:   %import_ref.7 = import_ref Main//action, inst+10, unloaded
-// CHECK:STDOUT:   %import_ref.8: @Action.%.2 (%.5) = import_ref Main//action, inst+16, loaded [symbolic = @Action.%.3 (constants.%.10)]
-// CHECK:STDOUT:   %import_ref.9 = import_ref Main//action, inst+12, unloaded
+// CHECK:STDOUT:   %import_ref.5 = import_ref Main//action, inst+52, unloaded
+// CHECK:STDOUT:   %import_ref.6 = import_ref Main//action, inst+25, unloaded
+// CHECK:STDOUT:   %import_ref.7 = import_ref Main//action, inst+28, unloaded
+// CHECK:STDOUT:   %import_ref.8 = import_ref Main//action, inst+10, unloaded
+// CHECK:STDOUT:   %import_ref.9: @Action.%.2 (%.5) = import_ref Main//action, inst+16, loaded [symbolic = @Action.%.3 (constants.%.10)]
 // CHECK:STDOUT:   %import_ref.10 = import_ref Main//action, inst+12, unloaded
-// CHECK:STDOUT:   %import_ref.11: <witness> = import_ref Main//action, inst+42, loaded [template = constants.%.11]
+// CHECK:STDOUT:   %import_ref.11 = import_ref Main//action, inst+12, unloaded
 // CHECK:STDOUT:   %import_ref.12 = import_ref Main//action, inst+12, unloaded
+// CHECK:STDOUT:   %import_ref.13: <witness> = import_ref Main//action, inst+46, loaded [template = constants.%.11]
+// CHECK:STDOUT:   %import_ref.14 = import_ref Main//action, inst+12, unloaded
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -233,14 +286,15 @@ impl A as Factory(B) {
 // CHECK:STDOUT:     .A = imports.%import_ref.2
 // CHECK:STDOUT:     .B = imports.%import_ref.3
 // CHECK:STDOUT:     .C = imports.%import_ref.4
-// CHECK:STDOUT:     .F = %F.decl
+// CHECK:STDOUT:     .F = imports.%import_ref.5
+// CHECK:STDOUT:     .G = %G.decl
 // CHECK:STDOUT:   }
 // CHECK:STDOUT:   %default.import.loc2_6.1 = import <invalid>
 // CHECK:STDOUT:   %default.import.loc2_6.2 = import <invalid>
-// CHECK:STDOUT:   %F.decl: %F.type = fn_decl @F [template = constants.%F] {
+// CHECK:STDOUT:   %G.decl: %G.type = fn_decl @G [template = constants.%G] {
 // CHECK:STDOUT:     %A.ref: type = name_ref A, imports.%import_ref.2 [template = constants.%A]
 // CHECK:STDOUT:     %a.loc4_6.1: %A = param a
-// CHECK:STDOUT:     @F.%a: %A = bind_name a, %a.loc4_6.1
+// CHECK:STDOUT:     @G.%a: %A = bind_name a, %a.loc4_6.1
 // CHECK:STDOUT:   }
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
@@ -250,32 +304,32 @@ impl A as Factory(B) {
 // CHECK:STDOUT: !definition:
 // CHECK:STDOUT:   %.1: type = interface_type @Action, @Action(%T) [symbolic = %.1 (constants.%.3)]
 // CHECK:STDOUT:   %Self: %.3 = bind_symbolic_name Self 1 [symbolic = %Self (constants.%Self.2)]
-// CHECK:STDOUT:   %Op.type: type = fn_type @Op.1, @Action(%T) [symbolic = %Op.type (constants.%Op.type.2)]
-// CHECK:STDOUT:   %Op: @Action.%Op.type (%Op.type.2) = struct_value () [symbolic = %Op (constants.%Op.2)]
-// CHECK:STDOUT:   %.2: type = assoc_entity_type @Action.%.1 (%.3), @Action.%Op.type (%Op.type.2) [symbolic = %.2 (constants.%.5)]
-// CHECK:STDOUT:   %.3: @Action.%.2 (%.5) = assoc_entity element0, imports.%import_ref.10 [symbolic = %.3 (constants.%.6)]
+// CHECK:STDOUT:   %Op.type: type = fn_type @Op.1, @Action(%T) [symbolic = %Op.type (constants.%Op.type.1)]
+// CHECK:STDOUT:   %Op: @Action.%Op.type (%Op.type.1) = struct_value () [symbolic = %Op (constants.%Op.1)]
+// CHECK:STDOUT:   %.2: type = assoc_entity_type @Action.%.1 (%.3), @Action.%Op.type (%Op.type.1) [symbolic = %.2 (constants.%.5)]
+// CHECK:STDOUT:   %.3: @Action.%.2 (%.5) = assoc_entity element0, imports.%import_ref.11 [symbolic = %.3 (constants.%.6)]
 // CHECK:STDOUT:
 // CHECK:STDOUT:   interface {
 // CHECK:STDOUT:   !members:
-// CHECK:STDOUT:     .Self = imports.%import_ref.7
-// CHECK:STDOUT:     .Op = imports.%import_ref.8
-// CHECK:STDOUT:     witness = (imports.%import_ref.9)
+// CHECK:STDOUT:     .Self = imports.%import_ref.8
+// CHECK:STDOUT:     .Op = imports.%import_ref.9
+// CHECK:STDOUT:     witness = (imports.%import_ref.10)
 // CHECK:STDOUT:   }
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: impl @impl: %A as %.4 {
 // CHECK:STDOUT: !members:
-// CHECK:STDOUT:   witness = imports.%import_ref.11
+// CHECK:STDOUT:   witness = imports.%import_ref.13
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @A {
 // CHECK:STDOUT: !members:
-// CHECK:STDOUT:   .Self = imports.%import_ref.5
+// CHECK:STDOUT:   .Self = imports.%import_ref.6
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @B {
 // CHECK:STDOUT: !members:
-// CHECK:STDOUT:   .Self = imports.%import_ref.6
+// CHECK:STDOUT:   .Self = imports.%import_ref.7
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: generic fn @Op.1(constants.%T: type, constants.%Self.1: @Action.%.1 (%.3)) {
@@ -283,15 +337,15 @@ impl A as Factory(B) {
 // CHECK:STDOUT:   fn();
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: fn @F(%a: %A) {
+// CHECK:STDOUT: fn @G(%a: %A) {
 // CHECK:STDOUT: !entry:
 // CHECK:STDOUT:   %a.ref: %A = name_ref a, %a
 // CHECK:STDOUT:   %Action.ref: %Action.type = name_ref Action, imports.%import_ref.1 [template = constants.%Action]
 // CHECK:STDOUT:   %B.ref: type = name_ref B, imports.%import_ref.3 [template = constants.%B]
 // CHECK:STDOUT:   %.loc4_23: init type = call %Action.ref(%B.ref) [template = constants.%.4]
-// CHECK:STDOUT:   %.loc4_26: %.8 = specific_constant imports.%import_ref.8, @Action(constants.%B) [template = constants.%.9]
-// CHECK:STDOUT:   %Op.ref: %.8 = name_ref Op, %.loc4_26 [template = constants.%.9]
-// CHECK:STDOUT:   %.1: %Op.type.3 = interface_witness_access imports.%import_ref.11, element0 [template = constants.%Op.4]
+// CHECK:STDOUT:   %.loc4_26: %.7 = specific_constant imports.%import_ref.9, @Action(constants.%B) [template = constants.%.8]
+// CHECK:STDOUT:   %Op.ref: %.7 = name_ref Op, %.loc4_26 [template = constants.%.8]
+// CHECK:STDOUT:   %.1: %Op.type.2 = interface_witness_access imports.%import_ref.13, element0 [template = constants.%Op.3]
 // CHECK:STDOUT:   %Op.call: init %.2 = call %.1()
 // CHECK:STDOUT:   return
 // CHECK:STDOUT: }
@@ -308,10 +362,10 @@ impl A as Factory(B) {
 // CHECK:STDOUT: !definition:
 // CHECK:STDOUT:   %.1 => constants.%.4
 // CHECK:STDOUT:   %Self => constants.%Self.2
-// CHECK:STDOUT:   %Op.type => constants.%Op.type.3
-// CHECK:STDOUT:   %Op => constants.%Op.3
-// CHECK:STDOUT:   %.2 => constants.%.8
-// CHECK:STDOUT:   %.3 => constants.%.9
+// CHECK:STDOUT:   %Op.type => constants.%Op.type.2
+// CHECK:STDOUT:   %Op => constants.%Op.2
+// CHECK:STDOUT:   %.2 => constants.%.7
+// CHECK:STDOUT:   %.3 => constants.%.8
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: specific @Action(@Action.%T) {
@@ -334,22 +388,24 @@ impl A as Factory(B) {
 // CHECK:STDOUT:   %Self.1: @Action.%.1 (%.3) = bind_symbolic_name Self 1 [symbolic]
 // CHECK:STDOUT:   %.4: type = interface_type @Action, @Action(%B) [template]
 // CHECK:STDOUT:   %Self.2: %.3 = bind_symbolic_name Self 1 [symbolic]
-// CHECK:STDOUT:   %Op.type.1: type = fn_type @Op [template]
-// CHECK:STDOUT:   %Op.1: %Op.type.1 = struct_value () [template]
-// CHECK:STDOUT:   %Op.type.2: type = fn_type @Op, @Action(%T) [symbolic]
-// CHECK:STDOUT:   %Op.2: %Op.type.2 = struct_value () [symbolic]
-// CHECK:STDOUT:   %.5: type = assoc_entity_type %.3, %Op.type.2 [symbolic]
-// CHECK:STDOUT:   %.6: %.5 = assoc_entity element0, imports.%import_ref.10 [symbolic]
+// CHECK:STDOUT:   %Op.type.1: type = fn_type @Op, @Action(%T) [symbolic]
+// CHECK:STDOUT:   %Op.1: %Op.type.1 = struct_value () [symbolic]
+// CHECK:STDOUT:   %.5: type = assoc_entity_type %.3, %Op.type.1 [symbolic]
+// CHECK:STDOUT:   %.6: %.5 = assoc_entity element0, imports.%import_ref.11 [symbolic]
+// CHECK:STDOUT:   %Op.type.2: type = fn_type @Op, @Action(%B) [template]
+// CHECK:STDOUT:   %Op.2: %Op.type.2 = struct_value () [template]
+// CHECK:STDOUT:   %.7: type = assoc_entity_type %.4, %Op.type.2 [template]
+// CHECK:STDOUT:   %.8: %.7 = assoc_entity element0, imports.%import_ref.12 [template]
 // CHECK:STDOUT:   %G.type: type = fn_type @G [template]
 // CHECK:STDOUT:   %G: %G.type = struct_value () [template]
-// CHECK:STDOUT:   %.7: type = ptr_type %.1 [template]
+// CHECK:STDOUT:   %.9: type = ptr_type %.1 [template]
 // CHECK:STDOUT:   %C: type = class_type @C [template]
-// CHECK:STDOUT:   %.8: type = interface_type @Action, @Action(%C) [template]
+// CHECK:STDOUT:   %.10: type = interface_type @Action, @Action(%C) [template]
 // CHECK:STDOUT:   %Op.type.3: type = fn_type @Op, @Action(%C) [template]
 // CHECK:STDOUT:   %Op.3: %Op.type.3 = struct_value () [template]
-// CHECK:STDOUT:   %.9: type = assoc_entity_type %.8, %Op.type.3 [template]
-// CHECK:STDOUT:   %.10: %.9 = assoc_entity element0, imports.%import_ref.10 [template]
-// CHECK:STDOUT:   %.11: %.5 = assoc_entity element0, imports.%import_ref.13 [symbolic]
+// CHECK:STDOUT:   %.11: type = assoc_entity_type %.10, %Op.type.3 [template]
+// CHECK:STDOUT:   %.12: %.11 = assoc_entity element0, imports.%import_ref.11 [template]
+// CHECK:STDOUT:   %.13: %.5 = assoc_entity element0, imports.%import_ref.15 [symbolic]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: imports {
@@ -357,15 +413,17 @@ impl A as Factory(B) {
 // CHECK:STDOUT:   %import_ref.2: type = import_ref Main//action, inst+24, loaded [template = constants.%A]
 // CHECK:STDOUT:   %import_ref.3 = import_ref Main//action, inst+27, unloaded
 // CHECK:STDOUT:   %import_ref.4: type = import_ref Main//action, inst+29, loaded [template = constants.%C]
-// CHECK:STDOUT:   %import_ref.5 = import_ref Main//action, inst+25, unloaded
-// CHECK:STDOUT:   %import_ref.6 = import_ref Main//action, inst+28, unloaded
-// CHECK:STDOUT:   %import_ref.7 = import_ref Main//action, inst+10, unloaded
-// CHECK:STDOUT:   %import_ref.8: @Action.%.2 (%.5) = import_ref Main//action, inst+16, loaded [symbolic = @Action.%.3 (constants.%.11)]
-// CHECK:STDOUT:   %import_ref.9 = import_ref Main//action, inst+12, unloaded
+// CHECK:STDOUT:   %import_ref.5 = import_ref Main//action, inst+52, unloaded
+// CHECK:STDOUT:   %import_ref.6 = import_ref Main//action, inst+25, unloaded
+// CHECK:STDOUT:   %import_ref.7 = import_ref Main//action, inst+28, unloaded
+// CHECK:STDOUT:   %import_ref.8 = import_ref Main//action, inst+10, unloaded
+// CHECK:STDOUT:   %import_ref.9: @Action.%.2 (%.5) = import_ref Main//action, inst+16, loaded [symbolic = @Action.%.3 (constants.%.13)]
 // CHECK:STDOUT:   %import_ref.10 = import_ref Main//action, inst+12, unloaded
-// CHECK:STDOUT:   %import_ref.11 = import_ref Main//action, inst+42, unloaded
-// CHECK:STDOUT:   %import_ref.12 = import_ref Main//action, inst+30, unloaded
-// CHECK:STDOUT:   %import_ref.13 = import_ref Main//action, inst+12, unloaded
+// CHECK:STDOUT:   %import_ref.11 = import_ref Main//action, inst+12, unloaded
+// CHECK:STDOUT:   %import_ref.12 = import_ref Main//action, inst+12, unloaded
+// CHECK:STDOUT:   %import_ref.13 = import_ref Main//action, inst+46, unloaded
+// CHECK:STDOUT:   %import_ref.14 = import_ref Main//action, inst+30, unloaded
+// CHECK:STDOUT:   %import_ref.15 = import_ref Main//action, inst+12, unloaded
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -374,6 +432,7 @@ impl A as Factory(B) {
 // CHECK:STDOUT:     .A = imports.%import_ref.2
 // CHECK:STDOUT:     .B = imports.%import_ref.3
 // CHECK:STDOUT:     .C = imports.%import_ref.4
+// CHECK:STDOUT:     .F = imports.%import_ref.5
 // CHECK:STDOUT:     .G = %G.decl
 // CHECK:STDOUT:   }
 // CHECK:STDOUT:   %default.import.loc2_6.1 = import <invalid>
@@ -391,37 +450,37 @@ impl A as Factory(B) {
 // CHECK:STDOUT: !definition:
 // CHECK:STDOUT:   %.1: type = interface_type @Action, @Action(%T) [symbolic = %.1 (constants.%.3)]
 // CHECK:STDOUT:   %Self: %.3 = bind_symbolic_name Self 1 [symbolic = %Self (constants.%Self.2)]
-// CHECK:STDOUT:   %Op.type: type = fn_type @Op, @Action(%T) [symbolic = %Op.type (constants.%Op.type.2)]
-// CHECK:STDOUT:   %Op: @Action.%Op.type (%Op.type.2) = struct_value () [symbolic = %Op (constants.%Op.2)]
-// CHECK:STDOUT:   %.2: type = assoc_entity_type @Action.%.1 (%.3), @Action.%Op.type (%Op.type.2) [symbolic = %.2 (constants.%.5)]
-// CHECK:STDOUT:   %.3: @Action.%.2 (%.5) = assoc_entity element0, imports.%import_ref.10 [symbolic = %.3 (constants.%.6)]
+// CHECK:STDOUT:   %Op.type: type = fn_type @Op, @Action(%T) [symbolic = %Op.type (constants.%Op.type.1)]
+// CHECK:STDOUT:   %Op: @Action.%Op.type (%Op.type.1) = struct_value () [symbolic = %Op (constants.%Op.1)]
+// CHECK:STDOUT:   %.2: type = assoc_entity_type @Action.%.1 (%.3), @Action.%Op.type (%Op.type.1) [symbolic = %.2 (constants.%.5)]
+// CHECK:STDOUT:   %.3: @Action.%.2 (%.5) = assoc_entity element0, imports.%import_ref.11 [symbolic = %.3 (constants.%.6)]
 // CHECK:STDOUT:
 // CHECK:STDOUT:   interface {
 // CHECK:STDOUT:   !members:
-// CHECK:STDOUT:     .Self = imports.%import_ref.7
-// CHECK:STDOUT:     .Op = imports.%import_ref.8
-// CHECK:STDOUT:     witness = (imports.%import_ref.9)
+// CHECK:STDOUT:     .Self = imports.%import_ref.8
+// CHECK:STDOUT:     .Op = imports.%import_ref.9
+// CHECK:STDOUT:     witness = (imports.%import_ref.10)
 // CHECK:STDOUT:   }
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: impl @impl: %A as %.4 {
 // CHECK:STDOUT: !members:
-// CHECK:STDOUT:   witness = imports.%import_ref.11
+// CHECK:STDOUT:   witness = imports.%import_ref.13
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @A {
 // CHECK:STDOUT: !members:
-// CHECK:STDOUT:   .Self = imports.%import_ref.5
+// CHECK:STDOUT:   .Self = imports.%import_ref.6
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @B {
 // CHECK:STDOUT: !members:
-// CHECK:STDOUT:   .Self = imports.%import_ref.6
+// CHECK:STDOUT:   .Self = imports.%import_ref.7
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @C {
 // CHECK:STDOUT: !members:
-// CHECK:STDOUT:   .Self = imports.%import_ref.12
+// CHECK:STDOUT:   .Self = imports.%import_ref.14
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: generic fn @Op(constants.%T: type, constants.%Self.1: @Action.%.1 (%.3)) {
@@ -434,9 +493,9 @@ impl A as Factory(B) {
 // CHECK:STDOUT:   %a.ref: %A = name_ref a, %a
 // CHECK:STDOUT:   %Action.ref: %Action.type = name_ref Action, imports.%import_ref.1 [template = constants.%Action]
 // CHECK:STDOUT:   %C.ref: type = name_ref C, imports.%import_ref.4 [template = constants.%C]
-// CHECK:STDOUT:   %.loc8_23: init type = call %Action.ref(%C.ref) [template = constants.%.8]
-// CHECK:STDOUT:   %.loc8_26: %.9 = specific_constant imports.%import_ref.8, @Action(constants.%C) [template = constants.%.10]
-// CHECK:STDOUT:   %Op.ref: %.9 = name_ref Op, %.loc8_26 [template = constants.%.10]
+// CHECK:STDOUT:   %.loc8_23: init type = call %Action.ref(%C.ref) [template = constants.%.10]
+// CHECK:STDOUT:   %.loc8_26: %.11 = specific_constant imports.%import_ref.9, @Action(constants.%C) [template = constants.%.12]
+// CHECK:STDOUT:   %Op.ref: %.11 = name_ref Op, %.loc8_26 [template = constants.%.12]
 // CHECK:STDOUT:   return
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
@@ -446,6 +505,14 @@ impl A as Factory(B) {
 // CHECK:STDOUT:
 // CHECK:STDOUT: specific @Action(constants.%B) {
 // CHECK:STDOUT:   %T => constants.%B
+// CHECK:STDOUT:
+// CHECK:STDOUT: !definition:
+// CHECK:STDOUT:   %.1 => constants.%.4
+// CHECK:STDOUT:   %Self => constants.%Self.2
+// CHECK:STDOUT:   %Op.type => constants.%Op.type.2
+// CHECK:STDOUT:   %Op => constants.%Op.2
+// CHECK:STDOUT:   %.2 => constants.%.7
+// CHECK:STDOUT:   %.3 => constants.%.8
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: specific @Action(@Action.%T) {
@@ -458,15 +525,15 @@ impl A as Factory(B) {
 // CHECK:STDOUT:   %T => constants.%C
 // CHECK:STDOUT:
 // CHECK:STDOUT: !definition:
-// CHECK:STDOUT:   %.1 => constants.%.8
+// CHECK:STDOUT:   %.1 => constants.%.10
 // CHECK:STDOUT:   %Self => constants.%Self.2
 // CHECK:STDOUT:   %Op.type => constants.%Op.type.3
 // CHECK:STDOUT:   %Op => constants.%Op.3
-// CHECK:STDOUT:   %.2 => constants.%.9
-// CHECK:STDOUT:   %.3 => constants.%.10
+// CHECK:STDOUT:   %.2 => constants.%.11
+// CHECK:STDOUT:   %.3 => constants.%.12
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: --- fail_todo_factory.carbon
+// CHECK:STDOUT: --- factory.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
 // CHECK:STDOUT:   %T: type = bind_symbolic_name T 0 [symbolic]
@@ -485,6 +552,11 @@ impl A as Factory(B) {
 // CHECK:STDOUT:   %.6: type = interface_type @Factory, @Factory(%B) [template]
 // CHECK:STDOUT:   %Make.type.2: type = fn_type @Make.2 [template]
 // CHECK:STDOUT:   %Make.2: %Make.type.2 = struct_value () [template]
+// CHECK:STDOUT:   %Make.type.3: type = fn_type @Make.1, @Factory(%B) [template]
+// CHECK:STDOUT:   %Make.3: %Make.type.3 = struct_value () [template]
+// CHECK:STDOUT:   %.7: type = assoc_entity_type %.6, %Make.type.3 [template]
+// CHECK:STDOUT:   %.8: %.7 = assoc_entity element0, @Factory.%Make.decl [template]
+// CHECK:STDOUT:   %.9: <witness> = interface_witness (%Make.2) [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -540,7 +612,7 @@ impl A as Factory(B) {
 // CHECK:STDOUT:     %B.ref: type = name_ref B, file.%B.decl [template = constants.%B]
 // CHECK:STDOUT:     %return.var: ref %B = var <return slot>
 // CHECK:STDOUT:   }
-// CHECK:STDOUT:   %.1: <witness> = interface_witness (<error>) [template = <error>]
+// CHECK:STDOUT:   %.1: <witness> = interface_witness (%Make.decl) [template = constants.%.9]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:
 // CHECK:STDOUT:   .Make = %Make.decl
@@ -579,5 +651,322 @@ impl A as Factory(B) {
 // CHECK:STDOUT:
 // CHECK:STDOUT: specific @Factory(constants.%B) {
 // CHECK:STDOUT:   %T => constants.%B
+// CHECK:STDOUT:
+// CHECK:STDOUT: !definition:
+// CHECK:STDOUT:   %.1 => constants.%.6
+// CHECK:STDOUT:   %Self.2 => constants.%Self
+// CHECK:STDOUT:   %Make.type => constants.%Make.type.3
+// CHECK:STDOUT:   %Make => constants.%Make.3
+// CHECK:STDOUT:   %.2 => constants.%.7
+// CHECK:STDOUT:   %.3 => constants.%.8
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @Make.1(constants.%B, constants.%A) {
+// CHECK:STDOUT:   %T => constants.%B
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: --- factory.impl.carbon
+// CHECK:STDOUT:
+// CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %A: type = class_type @A [template]
+// CHECK:STDOUT:   %.1: type = struct_type {} [template]
+// CHECK:STDOUT:   %B: type = class_type @B [template]
+// CHECK:STDOUT:   %Factory.type: type = generic_interface_type @Factory [template]
+// CHECK:STDOUT:   %.2: type = tuple_type () [template]
+// CHECK:STDOUT:   %Factory: %Factory.type = struct_value () [template]
+// CHECK:STDOUT:   %T: type = bind_symbolic_name T 0 [symbolic]
+// CHECK:STDOUT:   %.3: type = interface_type @Factory, @Factory(%T) [symbolic]
+// CHECK:STDOUT:   %Self.1: @Factory.%.1 (%.3) = bind_symbolic_name Self 1 [symbolic]
+// CHECK:STDOUT:   %.4: type = interface_type @Factory, @Factory(%B) [template]
+// CHECK:STDOUT:   %Self.2: %.3 = bind_symbolic_name Self 1 [symbolic]
+// CHECK:STDOUT:   %Make.type.1: type = fn_type @Make.1, @Factory(%T) [symbolic]
+// CHECK:STDOUT:   %Make.1: %Make.type.1 = struct_value () [symbolic]
+// CHECK:STDOUT:   %.5: type = assoc_entity_type %.3, %Make.type.1 [symbolic]
+// CHECK:STDOUT:   %.6: %.5 = assoc_entity element0, imports.%import_ref.9 [symbolic]
+// CHECK:STDOUT:   %Make.type.2: type = fn_type @Make.1, @Factory(%B) [template]
+// CHECK:STDOUT:   %Make.2: %Make.type.2 = struct_value () [template]
+// CHECK:STDOUT:   %.7: type = assoc_entity_type %.4, %Make.type.2 [template]
+// CHECK:STDOUT:   %.8: %.7 = assoc_entity element0, imports.%import_ref.10 [template]
+// CHECK:STDOUT:   %MakeB.type: type = fn_type @MakeB [template]
+// CHECK:STDOUT:   %MakeB: %MakeB.type = struct_value () [template]
+// CHECK:STDOUT:   %.9: type = ptr_type %.1 [template]
+// CHECK:STDOUT:   %.10: %.5 = assoc_entity element0, imports.%import_ref.12 [symbolic]
+// CHECK:STDOUT:   %Make.type.3: type = fn_type @Make.2 [template]
+// CHECK:STDOUT:   %Make.3: %Make.type.3 = struct_value () [template]
+// CHECK:STDOUT:   %.11: <witness> = interface_witness (%Make.3) [template]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: imports {
+// CHECK:STDOUT:   %import_ref.1: %Factory.type = import_ref Main//factory, inst+4, loaded [template = constants.%Factory]
+// CHECK:STDOUT:   %import_ref.2: type = import_ref Main//factory, inst+27, loaded [template = constants.%A]
+// CHECK:STDOUT:   %import_ref.3: type = import_ref Main//factory, inst+30, loaded [template = constants.%B]
+// CHECK:STDOUT:   %import_ref.4 = import_ref Main//factory, inst+28, unloaded
+// CHECK:STDOUT:   %import_ref.5 = import_ref Main//factory, inst+31, unloaded
+// CHECK:STDOUT:   %import_ref.6 = import_ref Main//factory, inst+10, unloaded
+// CHECK:STDOUT:   %import_ref.7: @Factory.%.2 (%.5) = import_ref Main//factory, inst+19, loaded [symbolic = @Factory.%.3 (constants.%.10)]
+// CHECK:STDOUT:   %import_ref.8 = import_ref Main//factory, inst+14, unloaded
+// CHECK:STDOUT:   %import_ref.9 = import_ref Main//factory, inst+14, unloaded
+// CHECK:STDOUT:   %import_ref.10 = import_ref Main//factory, inst+14, unloaded
+// CHECK:STDOUT:   %import_ref.11: <witness> = import_ref Main//factory, inst+49, loaded [template = constants.%.11]
+// CHECK:STDOUT:   %import_ref.12 = import_ref Main//factory, inst+14, unloaded
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: file {
+// CHECK:STDOUT:   package: <namespace> = namespace [template] {
+// CHECK:STDOUT:     .Factory = imports.%import_ref.1
+// CHECK:STDOUT:     .A = imports.%import_ref.2
+// CHECK:STDOUT:     .B = imports.%import_ref.3
+// CHECK:STDOUT:     .MakeB = %MakeB.decl
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %default.import.loc2_6.1 = import <invalid>
+// CHECK:STDOUT:   %default.import.loc2_6.2 = import <invalid>
+// CHECK:STDOUT:   %MakeB.decl: %MakeB.type = fn_decl @MakeB [template = constants.%MakeB] {
+// CHECK:STDOUT:     %A.ref: type = name_ref A, imports.%import_ref.2 [template = constants.%A]
+// CHECK:STDOUT:     %a.loc4_10.1: %A = param a
+// CHECK:STDOUT:     @MakeB.%a: %A = bind_name a, %a.loc4_10.1
+// CHECK:STDOUT:     %B.ref: type = name_ref B, imports.%import_ref.3 [template = constants.%B]
+// CHECK:STDOUT:     @MakeB.%return: ref %B = var <return slot>
+// CHECK:STDOUT:   }
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: generic interface @Factory(constants.%T: type) {
+// CHECK:STDOUT:   %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
+// CHECK:STDOUT:
+// CHECK:STDOUT: !definition:
+// CHECK:STDOUT:   %.1: type = interface_type @Factory, @Factory(%T) [symbolic = %.1 (constants.%.3)]
+// CHECK:STDOUT:   %Self: %.3 = bind_symbolic_name Self 1 [symbolic = %Self (constants.%Self.2)]
+// CHECK:STDOUT:   %Make.type: type = fn_type @Make.1, @Factory(%T) [symbolic = %Make.type (constants.%Make.type.1)]
+// CHECK:STDOUT:   %Make: @Factory.%Make.type (%Make.type.1) = struct_value () [symbolic = %Make (constants.%Make.1)]
+// CHECK:STDOUT:   %.2: type = assoc_entity_type @Factory.%.1 (%.3), @Factory.%Make.type (%Make.type.1) [symbolic = %.2 (constants.%.5)]
+// CHECK:STDOUT:   %.3: @Factory.%.2 (%.5) = assoc_entity element0, imports.%import_ref.9 [symbolic = %.3 (constants.%.6)]
+// CHECK:STDOUT:
+// CHECK:STDOUT:   interface {
+// CHECK:STDOUT:   !members:
+// CHECK:STDOUT:     .Self = imports.%import_ref.6
+// CHECK:STDOUT:     .Make = imports.%import_ref.7
+// CHECK:STDOUT:     witness = (imports.%import_ref.8)
+// CHECK:STDOUT:   }
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: impl @impl: %A as %.4 {
+// CHECK:STDOUT: !members:
+// CHECK:STDOUT:   witness = imports.%import_ref.11
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: class @A {
+// CHECK:STDOUT: !members:
+// CHECK:STDOUT:   .Self = imports.%import_ref.4
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: class @B {
+// CHECK:STDOUT: !members:
+// CHECK:STDOUT:   .Self = imports.%import_ref.5
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: generic fn @Make.1(constants.%T: type, constants.%Self.1: @Factory.%.1 (%.3)) {
+// CHECK:STDOUT:   %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
+// CHECK:STDOUT:
+// CHECK:STDOUT:   fn() -> @Make.1.%T (%T);
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @MakeB(%a: %A) -> %return: %B {
+// CHECK:STDOUT: !entry:
+// CHECK:STDOUT:   %a.ref: %A = name_ref a, %a
+// CHECK:STDOUT:   %Factory.ref: %Factory.type = name_ref Factory, imports.%import_ref.1 [template = constants.%Factory]
+// CHECK:STDOUT:   %B.ref: type = name_ref B, imports.%import_ref.3 [template = constants.%B]
+// CHECK:STDOUT:   %.loc5_20: init type = call %Factory.ref(%B.ref) [template = constants.%.4]
+// CHECK:STDOUT:   %.loc5_23: %.7 = specific_constant imports.%import_ref.7, @Factory(constants.%B) [template = constants.%.8]
+// CHECK:STDOUT:   %Make.ref: %.7 = name_ref Make, %.loc5_23 [template = constants.%.8]
+// CHECK:STDOUT:   %.1: %Make.type.2 = interface_witness_access imports.%import_ref.11, element0 [template = constants.%Make.3]
+// CHECK:STDOUT:   %.loc4: ref %B = splice_block %return {}
+// CHECK:STDOUT:   %Make.call: init %B = call %.1() to %.loc4
+// CHECK:STDOUT:   return %Make.call to %return
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @Make.2() -> %B;
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @Factory(constants.%T) {
+// CHECK:STDOUT:   %T => constants.%T
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @Factory(constants.%B) {
+// CHECK:STDOUT:   %T => constants.%B
+// CHECK:STDOUT:
+// CHECK:STDOUT: !definition:
+// CHECK:STDOUT:   %.1 => constants.%.4
+// CHECK:STDOUT:   %Self => constants.%Self.2
+// CHECK:STDOUT:   %Make.type => constants.%Make.type.2
+// CHECK:STDOUT:   %Make => constants.%Make.2
+// CHECK:STDOUT:   %.2 => constants.%.7
+// CHECK:STDOUT:   %.3 => constants.%.8
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @Factory(@Factory.%T) {
+// CHECK:STDOUT:   %T => constants.%T
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @Make.1(constants.%T, constants.%Self.1) {
+// CHECK:STDOUT:   %T => constants.%T
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: --- fail_factory.impl.carbon
+// CHECK:STDOUT:
+// CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %A: type = class_type @A [template]
+// CHECK:STDOUT:   %.1: type = struct_type {} [template]
+// CHECK:STDOUT:   %B: type = class_type @B [template]
+// CHECK:STDOUT:   %Factory.type: type = generic_interface_type @Factory [template]
+// CHECK:STDOUT:   %.2: type = tuple_type () [template]
+// CHECK:STDOUT:   %Factory: %Factory.type = struct_value () [template]
+// CHECK:STDOUT:   %T: type = bind_symbolic_name T 0 [symbolic]
+// CHECK:STDOUT:   %.3: type = interface_type @Factory, @Factory(%T) [symbolic]
+// CHECK:STDOUT:   %Self.1: @Factory.%.1 (%.3) = bind_symbolic_name Self 1 [symbolic]
+// CHECK:STDOUT:   %.4: type = interface_type @Factory, @Factory(%B) [template]
+// CHECK:STDOUT:   %Self.2: %.3 = bind_symbolic_name Self 1 [symbolic]
+// CHECK:STDOUT:   %Make.type.1: type = fn_type @Make, @Factory(%T) [symbolic]
+// CHECK:STDOUT:   %Make.1: %Make.type.1 = struct_value () [symbolic]
+// CHECK:STDOUT:   %.5: type = assoc_entity_type %.3, %Make.type.1 [symbolic]
+// CHECK:STDOUT:   %.6: %.5 = assoc_entity element0, imports.%import_ref.9 [symbolic]
+// CHECK:STDOUT:   %Make.type.2: type = fn_type @Make, @Factory(%B) [template]
+// CHECK:STDOUT:   %Make.2: %Make.type.2 = struct_value () [template]
+// CHECK:STDOUT:   %.7: type = assoc_entity_type %.4, %Make.type.2 [template]
+// CHECK:STDOUT:   %.8: %.7 = assoc_entity element0, imports.%import_ref.10 [template]
+// CHECK:STDOUT:   %C: type = class_type @C [template]
+// CHECK:STDOUT:   %MakeC.type: type = fn_type @MakeC [template]
+// CHECK:STDOUT:   %MakeC: %MakeC.type = struct_value () [template]
+// CHECK:STDOUT:   %.9: type = ptr_type %.1 [template]
+// CHECK:STDOUT:   %.10: type = interface_type @Factory, @Factory(%C) [template]
+// CHECK:STDOUT:   %Make.type.3: type = fn_type @Make, @Factory(%C) [template]
+// CHECK:STDOUT:   %Make.3: %Make.type.3 = struct_value () [template]
+// CHECK:STDOUT:   %.11: type = assoc_entity_type %.10, %Make.type.3 [template]
+// CHECK:STDOUT:   %.12: %.11 = assoc_entity element0, imports.%import_ref.9 [template]
+// CHECK:STDOUT:   %.13: %.5 = assoc_entity element0, imports.%import_ref.12 [symbolic]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: imports {
+// CHECK:STDOUT:   %import_ref.1: %Factory.type = import_ref Main//factory, inst+4, loaded [template = constants.%Factory]
+// CHECK:STDOUT:   %import_ref.2: type = import_ref Main//factory, inst+27, loaded [template = constants.%A]
+// CHECK:STDOUT:   %import_ref.3 = import_ref Main//factory, inst+30, unloaded
+// CHECK:STDOUT:   %import_ref.4 = import_ref Main//factory, inst+28, unloaded
+// CHECK:STDOUT:   %import_ref.5 = import_ref Main//factory, inst+31, unloaded
+// CHECK:STDOUT:   %import_ref.6 = import_ref Main//factory, inst+10, unloaded
+// CHECK:STDOUT:   %import_ref.7: @Factory.%.2 (%.5) = import_ref Main//factory, inst+19, loaded [symbolic = @Factory.%.3 (constants.%.13)]
+// CHECK:STDOUT:   %import_ref.8 = import_ref Main//factory, inst+14, unloaded
+// CHECK:STDOUT:   %import_ref.9 = import_ref Main//factory, inst+14, unloaded
+// CHECK:STDOUT:   %import_ref.10 = import_ref Main//factory, inst+14, unloaded
+// CHECK:STDOUT:   %import_ref.11 = import_ref Main//factory, inst+49, unloaded
+// CHECK:STDOUT:   %import_ref.12 = import_ref Main//factory, inst+14, unloaded
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: file {
+// CHECK:STDOUT:   package: <namespace> = namespace [template] {
+// CHECK:STDOUT:     .Factory = imports.%import_ref.1
+// CHECK:STDOUT:     .A = imports.%import_ref.2
+// CHECK:STDOUT:     .B = imports.%import_ref.3
+// CHECK:STDOUT:     .C = %C.decl
+// CHECK:STDOUT:     .MakeC = %MakeC.decl
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %default.import.loc2_6.1 = import <invalid>
+// CHECK:STDOUT:   %default.import.loc2_6.2 = import <invalid>
+// CHECK:STDOUT:   %C.decl: type = class_decl @C [template = constants.%C] {}
+// CHECK:STDOUT:   %MakeC.decl: %MakeC.type = fn_decl @MakeC [template = constants.%MakeC] {
+// CHECK:STDOUT:     %A.ref: type = name_ref A, imports.%import_ref.2 [template = constants.%A]
+// CHECK:STDOUT:     %a.loc6_10.1: %A = param a
+// CHECK:STDOUT:     @MakeC.%a: %A = bind_name a, %a.loc6_10.1
+// CHECK:STDOUT:     %C.ref: type = name_ref C, %C.decl [template = constants.%C]
+// CHECK:STDOUT:     @MakeC.%return: ref %C = var <return slot>
+// CHECK:STDOUT:   }
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: generic interface @Factory(constants.%T: type) {
+// CHECK:STDOUT:   %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
+// CHECK:STDOUT:
+// CHECK:STDOUT: !definition:
+// CHECK:STDOUT:   %.1: type = interface_type @Factory, @Factory(%T) [symbolic = %.1 (constants.%.3)]
+// CHECK:STDOUT:   %Self: %.3 = bind_symbolic_name Self 1 [symbolic = %Self (constants.%Self.2)]
+// CHECK:STDOUT:   %Make.type: type = fn_type @Make, @Factory(%T) [symbolic = %Make.type (constants.%Make.type.1)]
+// CHECK:STDOUT:   %Make: @Factory.%Make.type (%Make.type.1) = struct_value () [symbolic = %Make (constants.%Make.1)]
+// CHECK:STDOUT:   %.2: type = assoc_entity_type @Factory.%.1 (%.3), @Factory.%Make.type (%Make.type.1) [symbolic = %.2 (constants.%.5)]
+// CHECK:STDOUT:   %.3: @Factory.%.2 (%.5) = assoc_entity element0, imports.%import_ref.9 [symbolic = %.3 (constants.%.6)]
+// CHECK:STDOUT:
+// CHECK:STDOUT:   interface {
+// CHECK:STDOUT:   !members:
+// CHECK:STDOUT:     .Self = imports.%import_ref.6
+// CHECK:STDOUT:     .Make = imports.%import_ref.7
+// CHECK:STDOUT:     witness = (imports.%import_ref.8)
+// CHECK:STDOUT:   }
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: impl @impl: %A as %.4 {
+// CHECK:STDOUT: !members:
+// CHECK:STDOUT:   witness = imports.%import_ref.11
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: class @A {
+// CHECK:STDOUT: !members:
+// CHECK:STDOUT:   .Self = imports.%import_ref.4
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: class @B {
+// CHECK:STDOUT: !members:
+// CHECK:STDOUT:   .Self = imports.%import_ref.5
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: class @C {
+// CHECK:STDOUT: !members:
+// CHECK:STDOUT:   .Self = constants.%C
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: generic fn @Make(constants.%T: type, constants.%Self.1: @Factory.%.1 (%.3)) {
+// CHECK:STDOUT:   %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
+// CHECK:STDOUT:
+// CHECK:STDOUT:   fn() -> @Make.%T (%T);
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @MakeC(%a: %A) -> %return: %C {
+// CHECK:STDOUT: !entry:
+// CHECK:STDOUT:   %a.ref: %A = name_ref a, %a
+// CHECK:STDOUT:   %Factory.ref: %Factory.type = name_ref Factory, imports.%import_ref.1 [template = constants.%Factory]
+// CHECK:STDOUT:   %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
+// CHECK:STDOUT:   %.loc10_20: init type = call %Factory.ref(%C.ref) [template = constants.%.10]
+// CHECK:STDOUT:   %.loc10_23: %.11 = specific_constant imports.%import_ref.7, @Factory(constants.%C) [template = constants.%.12]
+// CHECK:STDOUT:   %Make.ref: %.11 = name_ref Make, %.loc10_23 [template = constants.%.12]
+// CHECK:STDOUT:   return <error> to %return
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @Factory(constants.%T) {
+// CHECK:STDOUT:   %T => constants.%T
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @Factory(constants.%B) {
+// CHECK:STDOUT:   %T => constants.%B
+// CHECK:STDOUT:
+// CHECK:STDOUT: !definition:
+// CHECK:STDOUT:   %.1 => constants.%.4
+// CHECK:STDOUT:   %Self => constants.%Self.2
+// CHECK:STDOUT:   %Make.type => constants.%Make.type.2
+// CHECK:STDOUT:   %Make => constants.%Make.2
+// CHECK:STDOUT:   %.2 => constants.%.7
+// CHECK:STDOUT:   %.3 => constants.%.8
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @Factory(@Factory.%T) {
+// CHECK:STDOUT:   %T => constants.%T
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @Make(constants.%T, constants.%Self.1) {
+// CHECK:STDOUT:   %T => constants.%T
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @Factory(constants.%C) {
+// CHECK:STDOUT:   %T => constants.%C
+// CHECK:STDOUT:
+// CHECK:STDOUT: !definition:
+// CHECK:STDOUT:   %.1 => constants.%.10
+// CHECK:STDOUT:   %Self => constants.%Self.2
+// CHECK:STDOUT:   %Make.type => constants.%Make.type.3
+// CHECK:STDOUT:   %Make => constants.%Make.3
+// CHECK:STDOUT:   %.2 => constants.%.11
+// CHECK:STDOUT:   %.3 => constants.%.12
 // CHECK:STDOUT: }
 // CHECK:STDOUT:

+ 4 - 0
toolchain/check/testdata/impl/no_prelude/self_in_class.carbon

@@ -114,3 +114,7 @@ class A {
 // CHECK:STDOUT:   %Self => constants.%Self
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Make.1(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 22 - 0
toolchain/check/testdata/impl/no_prelude/self_in_signature.carbon

@@ -288,6 +288,14 @@ impl D as SelfNested {
 // CHECK:STDOUT:   %Self => constants.%Self.1
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.1(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.1(constants.%D) {
+// CHECK:STDOUT:   %Self => constants.%D
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
 // CHECK:STDOUT: specific @F.4(constants.%Self.2) {
 // CHECK:STDOUT:   %Self => constants.%Self.2
 // CHECK:STDOUT:   %.1 => constants.%.10
@@ -295,3 +303,17 @@ impl D as SelfNested {
 // CHECK:STDOUT:   %.3 => constants.%.13
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.4(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT:   %.1 => constants.%.16
+// CHECK:STDOUT:   %.2 => constants.%.17
+// CHECK:STDOUT:   %.3 => constants.%.18
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.4(constants.%D) {
+// CHECK:STDOUT:   %Self => constants.%D
+// CHECK:STDOUT:   %.1 => constants.%.20
+// CHECK:STDOUT:   %.2 => constants.%.21
+// CHECK:STDOUT:   %.3 => constants.%.22
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 2 - 0
toolchain/check/testdata/interface/no_prelude/default_fn.carbon

@@ -109,3 +109,5 @@ class C {
 // CHECK:STDOUT:
 // CHECK:STDOUT: specific @F.1(constants.%Self) {}
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.1(constants.%C) {}
+// CHECK:STDOUT:

+ 21 - 3
toolchain/check/testdata/interface/no_prelude/generic.carbon

@@ -83,8 +83,12 @@ fn G(T:! Generic(B)) {
 // CHECK:STDOUT:   %.9: type = interface_type @WithAssocFn, @WithAssocFn(%C) [template]
 // CHECK:STDOUT:   %F.type.2: type = fn_type @F.2 [template]
 // CHECK:STDOUT:   %F.2: %F.type.2 = struct_value () [template]
-// CHECK:STDOUT:   %.10: <witness> = interface_witness (%F.2) [template]
-// CHECK:STDOUT:   %.11: type = ptr_type %.3 [template]
+// CHECK:STDOUT:   %F.type.3: type = fn_type @F.1, @WithAssocFn(%C) [template]
+// CHECK:STDOUT:   %F.3: %F.type.3 = struct_value () [template]
+// CHECK:STDOUT:   %.10: type = assoc_entity_type %.9, %F.type.3 [template]
+// CHECK:STDOUT:   %.11: %.10 = assoc_entity element0, @WithAssocFn.%F.decl [template]
+// CHECK:STDOUT:   %.12: <witness> = interface_witness (%F.2) [template]
+// CHECK:STDOUT:   %.13: type = ptr_type %.3 [template]
 // CHECK:STDOUT:   %struct: %X = struct_value () [template]
 // CHECK:STDOUT:   %N: %T.1 = bind_symbolic_name N 1 [symbolic]
 // CHECK:STDOUT:   %WithImplicitArgs.type: type = generic_interface_type @WithImplicitArgs [template]
@@ -204,7 +208,7 @@ fn G(T:! Generic(B)) {
 // CHECK:STDOUT:     %X.ref: type = name_ref X, file.%X.decl [template = constants.%X]
 // CHECK:STDOUT:     %return.var: ref %X = var <return slot>
 // CHECK:STDOUT:   }
-// CHECK:STDOUT:   %.1: <witness> = interface_witness (%F.decl) [template = constants.%.10]
+// CHECK:STDOUT:   %.1: <witness> = interface_witness (%F.decl) [template = constants.%.12]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:
 // CHECK:STDOUT:   .F = %F.decl
@@ -289,12 +293,26 @@ fn G(T:! Generic(B)) {
 // CHECK:STDOUT:
 // CHECK:STDOUT: specific @Simple(constants.%C) {
 // CHECK:STDOUT:   %T => constants.%C
+// CHECK:STDOUT:
+// CHECK:STDOUT: !definition:
+// CHECK:STDOUT:   %.1 => constants.%.7
+// CHECK:STDOUT:   %Self.2 => constants.%Self.1
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: specific @WithAssocFn(constants.%C) {
 // CHECK:STDOUT:   %T => constants.%C
+// CHECK:STDOUT:
+// CHECK:STDOUT: !definition:
+// CHECK:STDOUT:   %.1 => constants.%.9
+// CHECK:STDOUT:   %Self.2 => constants.%Self.2
+// CHECK:STDOUT:   %F.type => constants.%F.type.3
+// CHECK:STDOUT:   %F => constants.%F.3
+// CHECK:STDOUT:   %.2 => constants.%.10
+// CHECK:STDOUT:   %.3 => constants.%.11
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.1(constants.%C, constants.%C) {}
+// CHECK:STDOUT:
 // CHECK:STDOUT: specific @WithImplicitArgs(constants.%T.1, constants.%N) {
 // CHECK:STDOUT:   %T => constants.%T.1
 // CHECK:STDOUT:   %N => constants.%N

+ 25 - 13
toolchain/check/testdata/interface/no_prelude/generic_import.carbon

@@ -102,23 +102,25 @@ impl C as AddWith(C) {
 // CHECK:STDOUT:   %.3: type = interface_type @AddWith, @AddWith(%T) [symbolic]
 // CHECK:STDOUT:   %Self.1: @AddWith.%.1 (%.3) = bind_symbolic_name Self 1 [symbolic]
 // CHECK:STDOUT:   %Self.2: %.3 = bind_symbolic_name Self 1 [symbolic]
-// CHECK:STDOUT:   %F.type.1: type = fn_type @F.1 [template]
-// CHECK:STDOUT:   %F.1: %F.type.1 = struct_value () [template]
-// CHECK:STDOUT:   %F.type.2: type = fn_type @F.1, @AddWith(%T) [symbolic]
-// CHECK:STDOUT:   %F.2: %F.type.2 = struct_value () [symbolic]
-// CHECK:STDOUT:   %.4: type = assoc_entity_type %.3, %F.type.2 [symbolic]
+// CHECK:STDOUT:   %F.type.1: type = fn_type @F.1, @AddWith(%T) [symbolic]
+// CHECK:STDOUT:   %F.1: %F.type.1 = struct_value () [symbolic]
+// CHECK:STDOUT:   %.4: type = assoc_entity_type %.3, %F.type.1 [symbolic]
 // CHECK:STDOUT:   %.5: %.4 = assoc_entity element0, imports.%import_ref.5 [symbolic]
 // CHECK:STDOUT:   %.6: type = interface_type @AddWith, @AddWith(%C) [template]
-// CHECK:STDOUT:   %F.type.3: type = fn_type @F.2 [template]
+// CHECK:STDOUT:   %F.type.2: type = fn_type @F.2 [template]
+// CHECK:STDOUT:   %F.2: %F.type.2 = struct_value () [template]
+// CHECK:STDOUT:   %F.type.3: type = fn_type @F.1, @AddWith(%C) [template]
 // CHECK:STDOUT:   %F.3: %F.type.3 = struct_value () [template]
-// CHECK:STDOUT:   %.7: <witness> = interface_witness (%F.3) [template]
+// CHECK:STDOUT:   %.7: type = assoc_entity_type %.6, %F.type.3 [template]
+// CHECK:STDOUT:   %.8: %.7 = assoc_entity element0, imports.%import_ref.5 [template]
+// CHECK:STDOUT:   %.9: <witness> = interface_witness (%F.2) [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: imports {
 // CHECK:STDOUT:   %import_ref.1: %AddWith.type = import_ref Main//a, inst+4, loaded [template = constants.%AddWith]
 // CHECK:STDOUT:   %import_ref.2 = import_ref Main//a, inst+10, unloaded
 // CHECK:STDOUT:   %import_ref.3 = import_ref Main//a, inst+16, unloaded
-// CHECK:STDOUT:   %import_ref.4: @AddWith.%F.type (%F.type.2) = import_ref Main//a, inst+12, loaded [symbolic = @AddWith.%F (constants.%F.1)]
+// CHECK:STDOUT:   %import_ref.4: @AddWith.%F.type (%F.type.1) = import_ref Main//a, inst+12, loaded [symbolic = @AddWith.%F (constants.%F.1)]
 // CHECK:STDOUT:   %import_ref.5 = import_ref Main//a, inst+12, unloaded
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
@@ -145,9 +147,9 @@ impl C as AddWith(C) {
 // CHECK:STDOUT: !definition:
 // CHECK:STDOUT:   %.1: type = interface_type @AddWith, @AddWith(%T) [symbolic = %.1 (constants.%.3)]
 // CHECK:STDOUT:   %Self: %.3 = bind_symbolic_name Self 1 [symbolic = %Self (constants.%Self.2)]
-// CHECK:STDOUT:   %F.type: type = fn_type @F.1, @AddWith(%T) [symbolic = %F.type (constants.%F.type.2)]
-// CHECK:STDOUT:   %F: @AddWith.%F.type (%F.type.2) = struct_value () [symbolic = %F (constants.%F.2)]
-// CHECK:STDOUT:   %.2: type = assoc_entity_type @AddWith.%.1 (%.3), @AddWith.%F.type (%F.type.2) [symbolic = %.2 (constants.%.4)]
+// CHECK:STDOUT:   %F.type: type = fn_type @F.1, @AddWith(%T) [symbolic = %F.type (constants.%F.type.1)]
+// CHECK:STDOUT:   %F: @AddWith.%F.type (%F.type.1) = struct_value () [symbolic = %F (constants.%F.1)]
+// CHECK:STDOUT:   %.2: type = assoc_entity_type @AddWith.%.1 (%.3), @AddWith.%F.type (%F.type.1) [symbolic = %.2 (constants.%.4)]
 // CHECK:STDOUT:   %.3: @AddWith.%.2 (%.4) = assoc_entity element0, imports.%import_ref.5 [symbolic = %.3 (constants.%.5)]
 // CHECK:STDOUT:
 // CHECK:STDOUT:   interface {
@@ -159,8 +161,8 @@ impl C as AddWith(C) {
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: impl @impl: %C as %.6 {
-// CHECK:STDOUT:   %F.decl: %F.type.3 = fn_decl @F.2 [template = constants.%F.3] {}
-// CHECK:STDOUT:   %.1: <witness> = interface_witness (%F.decl) [template = constants.%.7]
+// CHECK:STDOUT:   %F.decl: %F.type.2 = fn_decl @F.2 [template = constants.%F.2] {}
+// CHECK:STDOUT:   %.1: <witness> = interface_witness (%F.decl) [template = constants.%.9]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:
 // CHECK:STDOUT:   .F = %F.decl
@@ -194,5 +196,15 @@ impl C as AddWith(C) {
 // CHECK:STDOUT:
 // CHECK:STDOUT: specific @AddWith(constants.%C) {
 // CHECK:STDOUT:   %T => constants.%C
+// CHECK:STDOUT:
+// CHECK:STDOUT: !definition:
+// CHECK:STDOUT:   %.1 => constants.%.6
+// CHECK:STDOUT:   %Self => constants.%Self.2
+// CHECK:STDOUT:   %F.type => constants.%F.type.3
+// CHECK:STDOUT:   %F => constants.%F.3
+// CHECK:STDOUT:   %.2 => constants.%.7
+// CHECK:STDOUT:   %.3 => constants.%.8
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @F.1(constants.%C, constants.%C) {}
+// CHECK:STDOUT:

+ 14 - 0
toolchain/check/testdata/interface/no_prelude/generic_vs_params.carbon

@@ -57,6 +57,7 @@ impl X as C(X).GenericAndParams(X) {}
 // CHECK:STDOUT:   %C.3: type = class_type @C, @C(%X) [template]
 // CHECK:STDOUT:   %.11: type = ptr_type %.8 [template]
 // CHECK:STDOUT:   %.12: type = interface_type @GenericAndParams.2, @GenericAndParams.2(%X) [template]
+// CHECK:STDOUT:   %.13: type = interface_type @GenericAndParams.2, @GenericAndParams.2(%X, %U) [symbolic]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -266,6 +267,10 @@ impl X as C(X).GenericAndParams(X) {}
 // CHECK:STDOUT:
 // CHECK:STDOUT: specific @GenericAndParams.1(constants.%X) {
 // CHECK:STDOUT:   %T => constants.%X
+// CHECK:STDOUT:
+// CHECK:STDOUT: !definition:
+// CHECK:STDOUT:   %.1 => constants.%.10
+// CHECK:STDOUT:   %Self.2 => constants.%Self.3
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: specific @C(constants.%X) {
@@ -276,5 +281,14 @@ impl X as C(X).GenericAndParams(X) {}
 // CHECK:STDOUT:
 // CHECK:STDOUT: specific @GenericAndParams.2(constants.%X) {
 // CHECK:STDOUT:   %U => constants.%U
+// CHECK:STDOUT:
+// CHECK:STDOUT: !definition:
+// CHECK:STDOUT:   %T => constants.%X
+// CHECK:STDOUT:   %.1 => constants.%.13
+// CHECK:STDOUT:   %Self.2 => constants.%Self.5
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @GenericAndParams.2(constants.%X, constants.%U) {
+// CHECK:STDOUT:   %U => constants.%U
 // CHECK:STDOUT: }
 // CHECK:STDOUT:

+ 9 - 0
toolchain/check/testdata/operators/overloaded/add.carbon

@@ -237,8 +237,17 @@ fn TestAssign(a: C*, b: C) {
 // CHECK:STDOUT:   %Self => constants.%Self.1
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.2(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
 // CHECK:STDOUT: specific @Op.4(constants.%Self.2) {
 // CHECK:STDOUT:   %Self => constants.%Self.2
 // CHECK:STDOUT:   %.2 => constants.%.8
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.4(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT:   %.2 => constants.%.7
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 9 - 0
toolchain/check/testdata/operators/overloaded/bit_and.carbon

@@ -237,8 +237,17 @@ fn TestAssign(a: C*, b: C) {
 // CHECK:STDOUT:   %Self => constants.%Self.1
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.2(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
 // CHECK:STDOUT: specific @Op.4(constants.%Self.2) {
 // CHECK:STDOUT:   %Self => constants.%Self.2
 // CHECK:STDOUT:   %.2 => constants.%.8
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.4(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT:   %.2 => constants.%.7
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 4 - 0
toolchain/check/testdata/operators/overloaded/bit_complement.carbon

@@ -140,3 +140,7 @@ fn TestOp(a: C) -> C {
 // CHECK:STDOUT:   %Self => constants.%Self
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.2(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 9 - 0
toolchain/check/testdata/operators/overloaded/bit_or.carbon

@@ -237,8 +237,17 @@ fn TestAssign(a: C*, b: C) {
 // CHECK:STDOUT:   %Self => constants.%Self.1
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.2(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
 // CHECK:STDOUT: specific @Op.4(constants.%Self.2) {
 // CHECK:STDOUT:   %Self => constants.%Self.2
 // CHECK:STDOUT:   %.2 => constants.%.8
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.4(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT:   %.2 => constants.%.7
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 9 - 0
toolchain/check/testdata/operators/overloaded/bit_xor.carbon

@@ -237,8 +237,17 @@ fn TestAssign(a: C*, b: C) {
 // CHECK:STDOUT:   %Self => constants.%Self.1
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.2(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
 // CHECK:STDOUT: specific @Op.4(constants.%Self.2) {
 // CHECK:STDOUT:   %Self => constants.%Self.2
 // CHECK:STDOUT:   %.2 => constants.%.8
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.4(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT:   %.2 => constants.%.7
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 5 - 0
toolchain/check/testdata/operators/overloaded/dec.carbon

@@ -138,3 +138,8 @@ fn TestOp() {
 // CHECK:STDOUT:   %.2 => constants.%.5
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.2(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT:   %.2 => constants.%.3
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 9 - 0
toolchain/check/testdata/operators/overloaded/div.carbon

@@ -237,8 +237,17 @@ fn TestAssign(a: C*, b: C) {
 // CHECK:STDOUT:   %Self => constants.%Self.1
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.2(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
 // CHECK:STDOUT: specific @Op.4(constants.%Self.2) {
 // CHECK:STDOUT:   %Self => constants.%Self.2
 // CHECK:STDOUT:   %.2 => constants.%.8
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.4(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT:   %.2 => constants.%.7
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 16 - 0
toolchain/check/testdata/operators/overloaded/eq.carbon

@@ -264,10 +264,18 @@ fn TestLhsBad(a: D, b: C) -> bool {
 // CHECK:STDOUT:   %Self => constants.%Self
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Equal.2(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
 // CHECK:STDOUT: specific @NotEqual.2(constants.%Self) {
 // CHECK:STDOUT:   %Self => constants.%Self
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @NotEqual.2(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
 // CHECK:STDOUT: --- fail_no_impl.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
@@ -588,7 +596,15 @@ fn TestLhsBad(a: D, b: C) -> bool {
 // CHECK:STDOUT:   %Self => constants.%Self
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Equal.2(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
 // CHECK:STDOUT: specific @NotEqual.2(constants.%Self) {
 // CHECK:STDOUT:   %Self => constants.%Self
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @NotEqual.2(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 10 - 0
toolchain/check/testdata/operators/overloaded/fail_assign_non_ref.carbon

@@ -226,8 +226,18 @@ fn TestAddAssignNonRef(a: C, b: C) {
 // CHECK:STDOUT:   %.2 => constants.%.5
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.2(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT:   %.2 => constants.%.3
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
 // CHECK:STDOUT: specific @Op.4(constants.%Self.2) {
 // CHECK:STDOUT:   %Self => constants.%Self.2
 // CHECK:STDOUT:   %.2 => constants.%.8
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.4(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT:   %.2 => constants.%.3
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 9 - 0
toolchain/check/testdata/operators/overloaded/fail_no_impl_for_arg.carbon

@@ -249,8 +249,17 @@ fn TestAssign(b: D) {
 // CHECK:STDOUT:   %Self => constants.%Self.1
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.2(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
 // CHECK:STDOUT: specific @Op.4(constants.%Self.2) {
 // CHECK:STDOUT:   %Self => constants.%Self.2
 // CHECK:STDOUT:   %.2 => constants.%.7
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.4(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT:   %.2 => constants.%.6
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 5 - 0
toolchain/check/testdata/operators/overloaded/inc.carbon

@@ -138,3 +138,8 @@ fn TestOp() {
 // CHECK:STDOUT:   %.2 => constants.%.5
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.2(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT:   %.2 => constants.%.3
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 9 - 0
toolchain/check/testdata/operators/overloaded/left_shift.carbon

@@ -237,8 +237,17 @@ fn TestAssign(a: C*, b: C) {
 // CHECK:STDOUT:   %Self => constants.%Self.1
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.2(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
 // CHECK:STDOUT: specific @Op.4(constants.%Self.2) {
 // CHECK:STDOUT:   %Self => constants.%Self.2
 // CHECK:STDOUT:   %.2 => constants.%.8
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.4(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT:   %.2 => constants.%.7
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 9 - 0
toolchain/check/testdata/operators/overloaded/mod.carbon

@@ -237,8 +237,17 @@ fn TestAssign(a: C*, b: C) {
 // CHECK:STDOUT:   %Self => constants.%Self.1
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.2(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
 // CHECK:STDOUT: specific @Op.4(constants.%Self.2) {
 // CHECK:STDOUT:   %Self => constants.%Self.2
 // CHECK:STDOUT:   %.2 => constants.%.8
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.4(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT:   %.2 => constants.%.7
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 9 - 0
toolchain/check/testdata/operators/overloaded/mul.carbon

@@ -237,8 +237,17 @@ fn TestAssign(a: C*, b: C) {
 // CHECK:STDOUT:   %Self => constants.%Self.1
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.2(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
 // CHECK:STDOUT: specific @Op.4(constants.%Self.2) {
 // CHECK:STDOUT:   %Self => constants.%Self.2
 // CHECK:STDOUT:   %.2 => constants.%.8
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.4(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT:   %.2 => constants.%.7
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 4 - 0
toolchain/check/testdata/operators/overloaded/negate.carbon

@@ -140,3 +140,7 @@ fn TestOp(a: C) -> C {
 // CHECK:STDOUT:   %Self => constants.%Self
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.2(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 16 - 0
toolchain/check/testdata/operators/overloaded/ordered.carbon

@@ -375,18 +375,34 @@ fn TestGreaterEqual(a: D, b: D) -> bool {
 // CHECK:STDOUT:   %Self => constants.%Self
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Less.2(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
 // CHECK:STDOUT: specific @LessOrEquivalent.2(constants.%Self) {
 // CHECK:STDOUT:   %Self => constants.%Self
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @LessOrEquivalent.2(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
 // CHECK:STDOUT: specific @Greater.2(constants.%Self) {
 // CHECK:STDOUT:   %Self => constants.%Self
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Greater.2(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
 // CHECK:STDOUT: specific @GreaterOrEquivalent.2(constants.%Self) {
 // CHECK:STDOUT:   %Self => constants.%Self
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @GreaterOrEquivalent.2(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
 // CHECK:STDOUT: --- fail_no_impl.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {

+ 9 - 0
toolchain/check/testdata/operators/overloaded/right_shift.carbon

@@ -237,8 +237,17 @@ fn TestAssign(a: C*, b: C) {
 // CHECK:STDOUT:   %Self => constants.%Self.1
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.2(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
 // CHECK:STDOUT: specific @Op.4(constants.%Self.2) {
 // CHECK:STDOUT:   %Self => constants.%Self.2
 // CHECK:STDOUT:   %.2 => constants.%.8
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.4(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT:   %.2 => constants.%.7
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 9 - 0
toolchain/check/testdata/operators/overloaded/sub.carbon

@@ -237,8 +237,17 @@ fn TestAssign(a: C*, b: C) {
 // CHECK:STDOUT:   %Self => constants.%Self.1
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.2(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
 // CHECK:STDOUT: specific @Op.4(constants.%Self.2) {
 // CHECK:STDOUT:   %Self => constants.%Self.2
 // CHECK:STDOUT:   %.2 => constants.%.8
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @Op.4(constants.%C) {
+// CHECK:STDOUT:   %Self => constants.%C
+// CHECK:STDOUT:   %.2 => constants.%.7
+// CHECK:STDOUT: }
+// CHECK:STDOUT: