Browse Source

Initial rough support for deducing generic arguments in a call to a generic function. (#4184)

Richard Smith 1 year ago
parent
commit
b3fcaf9969

+ 2 - 0
toolchain/check/BUILD

@@ -18,6 +18,7 @@ cc_library(
         "context.cpp",
         "convert.cpp",
         "decl_name_stack.cpp",
+        "deduce.cpp",
         "eval.cpp",
         "function.cpp",
         "generic.cpp",
@@ -36,6 +37,7 @@ cc_library(
         "convert.h",
         "decl_introducer_state.h",
         "decl_name_stack.h",
+        "deduce.h",
         "diagnostic_helpers.h",
         "eval.h",
         "function.h",

+ 10 - 11
toolchain/check/call.cpp

@@ -7,6 +7,7 @@
 #include "toolchain/base/kind_switch.h"
 #include "toolchain/check/context.h"
 #include "toolchain/check/convert.h"
+#include "toolchain/check/deduce.h"
 #include "toolchain/check/function.h"
 #include "toolchain/check/generic.h"
 #include "toolchain/sem_ir/ids.h"
@@ -98,18 +99,16 @@ auto PerformCall(Context& context, Parse::NodeId node_id,
   }
   auto& callable = context.functions().Get(callee_function.function_id);
 
-  // TODO: Properly determine the generic argument values for the call. For now,
-  // we do so only if the function introduces no generic parameters beyond those
-  // of the enclosing context.
+  // If the callee is a generic function, determine the generic argument values
+  // for the call.
   auto specific_id = SemIR::SpecificId::Invalid;
-  if (callee_function.specific_id.is_valid()) {
-    auto enclosing_args_id =
-        context.specifics().Get(callee_function.specific_id).args_id;
-    auto fn_params_id = context.generics().Get(callable.generic_id).bindings_id;
-    if (context.inst_blocks().Get(fn_params_id).size() ==
-        context.inst_blocks().Get(enclosing_args_id).size()) {
-      specific_id =
-          MakeSpecific(context, callable.generic_id, enclosing_args_id);
+  if (callable.generic_id.is_valid()) {
+    specific_id = DeduceGenericCallArguments(
+        context, node_id, callable.generic_id, callee_function.specific_id,
+        callable.implicit_param_refs_id, callable.param_refs_id,
+        callee_function.self_id, arg_ids);
+    if (!specific_id.is_valid()) {
+      return SemIR::InstId::BuiltinError;
     }
   }
 

+ 220 - 0
toolchain/check/deduce.cpp

@@ -0,0 +1,220 @@
+// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
+// Exceptions. See /LICENSE for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+#include "toolchain/check/deduce.h"
+
+#include "toolchain/base/kind_switch.h"
+#include "toolchain/check/context.h"
+#include "toolchain/check/generic.h"
+#include "toolchain/check/subst.h"
+#include "toolchain/sem_ir/typed_insts.h"
+
+namespace Carbon::Check {
+
+namespace {
+// A list of pairs of (instruction from generic, corresponding instruction from
+// call to of generic) for which we still need to perform deduction, along with
+// methods to add and pop pending deductions from the list. Deductions are
+// popped in order from most- to least-recently pushed, with the intent that
+// they are visited in depth-first order, although the order is not expected to
+// matter except when it influences which error is diagnosed.
+class DeductionWorklist {
+ public:
+  explicit DeductionWorklist(Context& context) : context_(context) {}
+
+  struct PendingDeduction {
+    SemIR::InstId param;
+    SemIR::InstId arg;
+    bool needs_substitution;
+  };
+
+  // Adds a single (param, arg) deduction.
+  auto Add(SemIR::InstId param, SemIR::InstId arg, bool needs_substitution)
+      -> void {
+    deductions_.push_back(
+        {.param = param, .arg = arg, .needs_substitution = needs_substitution});
+  }
+
+  // Adds a list of (param, arg) deductions. These are added in reverse order so
+  // they are popped in forward order.
+  auto AddAll(llvm::ArrayRef<SemIR::InstId> params,
+              llvm::ArrayRef<SemIR::InstId> args, bool needs_substitution)
+      -> void {
+    if (params.size() != args.size()) {
+      // TODO: Decide whether to error on this or just treat the parameter list
+      // as non-deduced. For now we treat it as non-deduced.
+      return;
+    }
+    for (auto [param, arg] : llvm::reverse(llvm::zip_equal(params, args))) {
+      Add(param, arg, needs_substitution);
+    }
+  }
+
+  auto AddAll(SemIR::InstBlockId params, llvm::ArrayRef<SemIR::InstId> args,
+              bool needs_substitution) -> void {
+    AddAll(context_.inst_blocks().Get(params), args, needs_substitution);
+  }
+
+  auto AddAll(SemIR::InstBlockId params, SemIR::InstBlockId args,
+              bool needs_substitution) -> void {
+    AddAll(context_.inst_blocks().Get(params), context_.inst_blocks().Get(args),
+           needs_substitution);
+  }
+
+  // Returns whether we have completed all deductions.
+  auto Done() -> bool { return deductions_.empty(); }
+
+  // Pops the next deduction. Requires `!Done()`.
+  auto PopNext() -> PendingDeduction { return deductions_.pop_back_val(); }
+
+ private:
+  Context& context_;
+  llvm::SmallVector<PendingDeduction> deductions_;
+};
+}  // namespace
+
+static auto NoteGenericHere(Context& context, SemIR::GenericId generic_id,
+                            Context::DiagnosticBuilder& diag) -> void {
+  CARBON_DIAGNOSTIC(DeductionGenericHere, Note,
+                    "While deducing parameters of generic declared here.");
+  diag.Note(context.generics().Get(generic_id).decl_id, DeductionGenericHere);
+}
+
+auto DeduceGenericCallArguments(
+    Context& context, Parse::NodeId node_id, SemIR::GenericId generic_id,
+    SemIR::SpecificId enclosing_specific_id,
+    [[maybe_unused]] SemIR::InstBlockId implicit_params_id,
+    SemIR::InstBlockId params_id, [[maybe_unused]] SemIR::InstId self_id,
+    llvm::ArrayRef<SemIR::InstId> arg_ids) -> SemIR::SpecificId {
+  DeductionWorklist worklist(context);
+
+  llvm::SmallVector<SemIR::InstId> result_arg_ids;
+  llvm::SmallVector<Substitution> substitutions;
+
+  // Copy any outer generic arguments from the specified instance and prepare to
+  // substitute them into the function declaration.
+  if (enclosing_specific_id.is_valid()) {
+    auto args = context.inst_blocks().Get(
+        context.specifics().Get(enclosing_specific_id).args_id);
+    result_arg_ids.assign(args.begin(), args.end());
+
+    // TODO: Subst is linear in the length of the substitutions list. Change it
+    // so we can pass in an array mapping indexes to substitutions instead.
+    substitutions.reserve(args.size());
+    for (auto [i, subst_inst_id] : llvm::enumerate(args)) {
+      substitutions.push_back(
+          {.bind_id = SemIR::CompileTimeBindIndex(i),
+           .replacement_id = context.constant_values().Get(subst_inst_id)});
+    }
+  }
+  auto first_deduced_index = SemIR::CompileTimeBindIndex(result_arg_ids.size());
+
+  // Initialize the deduced arguments to Invalid.
+  result_arg_ids.resize(context.inst_blocks()
+                            .Get(context.generics().Get(generic_id).bindings_id)
+                            .size(),
+                        SemIR::InstId::Invalid);
+
+  // Prepare to perform deduction of the explicit parameters against their
+  // arguments.
+  // TODO: Also perform deduction for type of self.
+  worklist.AddAll(params_id, arg_ids, /*needs_substitution=*/true);
+
+  while (!worklist.Done()) {
+    auto [param_id, arg_id, needs_substitution] = worklist.PopNext();
+
+    // If the parameter has a symbolic type, deduce against that.
+    auto param_type_id = context.insts().Get(param_id).type_id();
+    if (param_type_id.AsConstantId().is_symbolic()) {
+      worklist.Add(
+          context.types().GetInstId(param_type_id),
+          context.types().GetInstId(context.insts().Get(arg_id).type_id()),
+          needs_substitution);
+    }
+
+    // If the parameter is a symbolic constant, deduce against it.
+    auto param_const_id = context.constant_values().Get(param_id);
+    if (!param_const_id.is_valid() || !param_const_id.is_symbolic()) {
+      continue;
+    }
+
+    // If we've not yet substituted into the parameter, do so now.
+    if (needs_substitution) {
+      param_const_id = SubstConstant(context, param_const_id, substitutions);
+      if (!param_const_id.is_valid() || !param_const_id.is_symbolic()) {
+        continue;
+      }
+      needs_substitution = false;
+    }
+
+    CARBON_KIND_SWITCH(context.insts().Get(context.constant_values().GetInstId(
+                           param_const_id))) {
+      // Deducing a symbolic binding from an argument with a constant value
+      // deduces the binding as having that constant value.
+      case CARBON_KIND(SemIR::BindSymbolicName bind): {
+        auto& entity_name = context.entity_names().Get(bind.entity_name_id);
+        auto index = entity_name.bind_index;
+        if (index.is_valid() && index >= first_deduced_index) {
+          CARBON_CHECK(static_cast<size_t>(index.index) < result_arg_ids.size())
+              << "Deduced value for unexpected index " << index
+              << "; expected to deduce " << result_arg_ids.size()
+              << " arguments.";
+          auto arg_const_inst_id =
+              context.constant_values().GetConstantInstId(arg_id);
+          if (arg_const_inst_id.is_valid()) {
+            if (result_arg_ids[index.index].is_valid() &&
+                result_arg_ids[index.index] != arg_const_inst_id) {
+              // TODO: Include the two different deduced values.
+              CARBON_DIAGNOSTIC(DeductionInconsistent, Error,
+                                "Inconsistent deductions for value of generic "
+                                "parameter `{0}`.",
+                                SemIR::NameId);
+              auto diag = context.emitter().Build(
+                  node_id, DeductionInconsistent, entity_name.name_id);
+              NoteGenericHere(context, generic_id, diag);
+              diag.Emit();
+              return SemIR::SpecificId::Invalid;
+            }
+            result_arg_ids[index.index] = arg_const_inst_id;
+          }
+        }
+        break;
+      }
+
+        // TODO: Handle more cases.
+
+      default:
+        break;
+    }
+  }
+
+  // Check we deduced an argument value for every parameter.
+  for (auto [i, deduced_arg_id] :
+       llvm::enumerate(llvm::ArrayRef(result_arg_ids)
+                           .drop_front(first_deduced_index.index))) {
+    if (!deduced_arg_id.is_valid()) {
+      auto binding_index = first_deduced_index.index + i;
+      auto binding_id = context.inst_blocks().Get(
+          context.generics().Get(generic_id).bindings_id)[binding_index];
+      auto entity_name_id =
+          context.insts().GetAs<SemIR::AnyBindName>(binding_id).entity_name_id;
+      CARBON_DIAGNOSTIC(DeductionIncomplete, Error,
+                        "Cannot deduce value for generic parameter `{0}`.",
+                        SemIR::NameId);
+      auto diag = context.emitter().Build(
+          node_id, DeductionIncomplete,
+          context.entity_names().Get(entity_name_id).name_id);
+      NoteGenericHere(context, generic_id, diag);
+      diag.Emit();
+      return SemIR::SpecificId::Invalid;
+    }
+  }
+
+  // TODO: Convert the deduced values to the types of the bindings.
+
+  return MakeSpecific(context, generic_id,
+                      context.inst_blocks().AddCanonical(result_arg_ids));
+}
+
+}  // namespace Carbon::Check

+ 25 - 0
toolchain/check/deduce.h

@@ -0,0 +1,25 @@
+// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
+// Exceptions. See /LICENSE for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+#ifndef CARBON_TOOLCHAIN_CHECK_DEDUCE_H_
+#define CARBON_TOOLCHAIN_CHECK_DEDUCE_H_
+
+#include "toolchain/check/context.h"
+#include "toolchain/sem_ir/ids.h"
+
+namespace Carbon::Check {
+
+// Deduces the generic arguments to use in a call to a generic.
+auto DeduceGenericCallArguments(Context& context, Parse::NodeId node_id,
+                                SemIR::GenericId generic_id,
+                                SemIR::SpecificId enclosing_specific_id,
+                                SemIR::InstBlockId implicit_params_id,
+                                SemIR::InstBlockId params_id,
+                                SemIR::InstId self_id,
+                                llvm::ArrayRef<SemIR::InstId> arg_ids)
+    -> SemIR::SpecificId;
+
+}  // namespace Carbon::Check
+
+#endif  // CARBON_TOOLCHAIN_CHECK_DEDUCE_H_

+ 19 - 4
toolchain/check/eval.cpp

@@ -305,8 +305,8 @@ static auto GetConstantValue(EvalContext& eval_context,
   return eval_context.inst_blocks().AddCanonical(const_insts);
 }
 
-// The constant value of a type block is that type block, but we still need to
-// extract its phase.
+// Compute the constant value of a type block. This may be different from the
+// input type block if we have known generic arguments.
 static auto GetConstantValue(EvalContext& eval_context,
                              SemIR::TypeBlockId type_block_id, Phase* phase)
     -> SemIR::TypeBlockId {
@@ -314,10 +314,25 @@ static auto GetConstantValue(EvalContext& eval_context,
     return SemIR::TypeBlockId::Invalid;
   }
   auto types = eval_context.type_blocks().Get(type_block_id);
+  llvm::SmallVector<SemIR::TypeId> new_types;
   for (auto type_id : types) {
-    GetConstantValue(eval_context, type_id, phase);
+    auto new_type_id = GetConstantValue(eval_context, type_id, phase);
+    if (!new_type_id.is_valid()) {
+      return SemIR::TypeBlockId::Invalid;
+    }
+
+    // Once we leave the small buffer, we know the first few elements are all
+    // constant, so it's likely that the entire block is constant. Resize to the
+    // target size given that we're going to allocate memory now anyway.
+    if (new_types.size() == new_types.capacity()) {
+      new_types.reserve(types.size());
+    }
+
+    new_types.push_back(new_type_id);
   }
-  return type_block_id;
+  // TODO: If the new block is identical to the original block, and we know the
+  // old ID was canonical, return the original ID.
+  return eval_context.type_blocks().AddCanonical(new_types);
 }
 
 // The constant value of a specific is the specific with the corresponding

+ 43 - 46
toolchain/check/testdata/basics/no_prelude/raw_ir.carbon

@@ -38,13 +38,13 @@ fn Foo[T:! type](n: T) -> (T, ()) {
 // CHECK:STDOUT:     typeTypeType:    {kind: copy, type: typeTypeType}
 // CHECK:STDOUT:     typeError:       {kind: copy, type: typeError}
 // CHECK:STDOUT:     'type(instNamespaceType)': {kind: copy, type: type(instNamespaceType)}
-// CHECK:STDOUT:     'type(inst+20)':   {kind: none, type: type(inst+8)}
+// CHECK:STDOUT:     'type(inst+19)':   {kind: none, type: type(inst+8)}
 // CHECK:STDOUT:     'type(inst+8)':    {kind: none, type: type(inst+8)}
 // CHECK:STDOUT:     'type(symbolicConstant0)': {kind: copy, type: type(symbolicConstant0)}
-// CHECK:STDOUT:     'type(symbolicConstant1)': {kind: pointer, type: type(symbolicConstant5)}
-// CHECK:STDOUT:     'type(symbolicConstant5)': {kind: copy, type: type(symbolicConstant5)}
+// CHECK:STDOUT:     'type(symbolicConstant1)': {kind: pointer, type: type(symbolicConstant4)}
+// CHECK:STDOUT:     'type(symbolicConstant4)': {kind: copy, type: type(symbolicConstant4)}
 // CHECK:STDOUT:     'type(symbolicConstant2)': {kind: copy, type: type(symbolicConstant2)}
-// CHECK:STDOUT:     'type(symbolicConstant3)': {kind: pointer, type: type(symbolicConstant5)}
+// CHECK:STDOUT:     'type(symbolicConstant3)': {kind: pointer, type: type(symbolicConstant4)}
 // CHECK:STDOUT:   type_blocks:
 // CHECK:STDOUT:     type_block0:     {}
 // CHECK:STDOUT:     type_block1:
@@ -73,25 +73,24 @@ fn Foo[T:! type](n: T) -> (T, ()) {
 // CHECK:STDOUT:     'inst+13':         {kind: TupleType, arg0: type_block2, type: typeTypeType}
 // CHECK:STDOUT:     'inst+14':         {kind: Converted, arg0: inst+11, arg1: inst+13, type: typeTypeType}
 // CHECK:STDOUT:     'inst+15':         {kind: VarStorage, arg0: nameReturnSlot, type: type(symbolicConstant3)}
-// CHECK:STDOUT:     'inst+16':         {kind: FunctionDecl, arg0: function0, arg1: block7, type: type(inst+20)}
+// CHECK:STDOUT:     'inst+16':         {kind: FunctionDecl, arg0: function0, arg1: block7, type: type(inst+19)}
 // CHECK:STDOUT:     'inst+17':         {kind: BindSymbolicName, arg0: entity_name0, arg1: inst<invalid>, type: typeTypeType}
 // CHECK:STDOUT:     'inst+18':         {kind: TupleType, arg0: type_block3, type: typeTypeType}
-// CHECK:STDOUT:     'inst+19':         {kind: TupleType, arg0: type_block3, type: typeTypeType}
-// CHECK:STDOUT:     'inst+20':         {kind: FunctionType, arg0: function0, arg1: specific<invalid>, type: typeTypeType}
-// CHECK:STDOUT:     'inst+21':         {kind: StructValue, arg0: empty, type: type(inst+20)}
-// CHECK:STDOUT:     'inst+22':         {kind: PointerType, arg0: type(symbolicConstant1), type: typeTypeType}
-// CHECK:STDOUT:     'inst+23':         {kind: NameRef, arg0: name2, arg1: inst+6, type: type(symbolicConstant2)}
-// CHECK:STDOUT:     'inst+24':         {kind: TupleLiteral, arg0: empty, type: type(inst+8)}
-// CHECK:STDOUT:     'inst+25':         {kind: TupleLiteral, arg0: block13, type: type(symbolicConstant3)}
-// CHECK:STDOUT:     'inst+26':         {kind: TupleAccess, arg0: inst+15, arg1: element0, type: type(symbolicConstant2)}
-// CHECK:STDOUT:     'inst+27':         {kind: InitializeFrom, arg0: inst+23, arg1: inst+26, type: type(symbolicConstant2)}
-// CHECK:STDOUT:     'inst+28':         {kind: TupleAccess, arg0: inst+15, arg1: element1, type: type(inst+8)}
-// CHECK:STDOUT:     'inst+29':         {kind: TupleInit, arg0: empty, arg1: inst+28, type: type(inst+8)}
-// CHECK:STDOUT:     'inst+30':         {kind: TupleValue, arg0: block15, type: type(inst+8)}
-// CHECK:STDOUT:     'inst+31':         {kind: Converted, arg0: inst+24, arg1: inst+29, type: type(inst+8)}
-// CHECK:STDOUT:     'inst+32':         {kind: TupleInit, arg0: block14, arg1: inst+15, type: type(symbolicConstant3)}
-// CHECK:STDOUT:     'inst+33':         {kind: Converted, arg0: inst+25, arg1: inst+32, type: type(symbolicConstant3)}
-// CHECK:STDOUT:     'inst+34':         {kind: ReturnExpr, arg0: inst+33, arg1: inst+15}
+// CHECK:STDOUT:     'inst+19':         {kind: FunctionType, arg0: function0, arg1: specific<invalid>, type: typeTypeType}
+// CHECK:STDOUT:     'inst+20':         {kind: StructValue, arg0: empty, type: type(inst+19)}
+// CHECK:STDOUT:     'inst+21':         {kind: PointerType, arg0: type(symbolicConstant1), type: typeTypeType}
+// CHECK:STDOUT:     'inst+22':         {kind: NameRef, arg0: name2, arg1: inst+6, type: type(symbolicConstant2)}
+// CHECK:STDOUT:     'inst+23':         {kind: TupleLiteral, arg0: empty, type: type(inst+8)}
+// CHECK:STDOUT:     'inst+24':         {kind: TupleLiteral, arg0: block13, type: type(symbolicConstant3)}
+// CHECK:STDOUT:     'inst+25':         {kind: TupleAccess, arg0: inst+15, arg1: element0, type: type(symbolicConstant2)}
+// CHECK:STDOUT:     'inst+26':         {kind: InitializeFrom, arg0: inst+22, arg1: inst+25, type: type(symbolicConstant2)}
+// CHECK:STDOUT:     'inst+27':         {kind: TupleAccess, arg0: inst+15, arg1: element1, type: type(inst+8)}
+// CHECK:STDOUT:     'inst+28':         {kind: TupleInit, arg0: empty, arg1: inst+27, type: type(inst+8)}
+// CHECK:STDOUT:     'inst+29':         {kind: TupleValue, arg0: block15, type: type(inst+8)}
+// CHECK:STDOUT:     'inst+30':         {kind: Converted, arg0: inst+23, arg1: inst+28, type: type(inst+8)}
+// CHECK:STDOUT:     'inst+31':         {kind: TupleInit, arg0: block14, arg1: inst+15, type: type(symbolicConstant3)}
+// CHECK:STDOUT:     'inst+32':         {kind: Converted, arg0: inst+24, arg1: inst+31, type: type(symbolicConstant3)}
+// CHECK:STDOUT:     'inst+33':         {kind: ReturnExpr, arg0: inst+32, arg1: inst+15}
 // CHECK:STDOUT:   constant_values:
 // CHECK:STDOUT:     'inst+0':          templateConstant(inst+0)
 // CHECK:STDOUT:     'inst+2':          symbolicConstant2
@@ -103,23 +102,21 @@ fn Foo[T:! type](n: T) -> (T, ()) {
 // CHECK:STDOUT:     'inst+12':         templateConstant(inst+8)
 // CHECK:STDOUT:     'inst+13':         symbolicConstant1
 // CHECK:STDOUT:     'inst+14':         symbolicConstant3
-// CHECK:STDOUT:     'inst+16':         templateConstant(inst+21)
+// CHECK:STDOUT:     'inst+16':         templateConstant(inst+20)
 // CHECK:STDOUT:     'inst+17':         symbolicConstant2
 // CHECK:STDOUT:     'inst+18':         symbolicConstant3
-// CHECK:STDOUT:     'inst+19':         symbolicConstant4
+// CHECK:STDOUT:     'inst+19':         templateConstant(inst+19)
 // CHECK:STDOUT:     'inst+20':         templateConstant(inst+20)
-// CHECK:STDOUT:     'inst+21':         templateConstant(inst+21)
-// CHECK:STDOUT:     'inst+22':         symbolicConstant5
-// CHECK:STDOUT:     'inst+29':         templateConstant(inst+30)
-// CHECK:STDOUT:     'inst+30':         templateConstant(inst+30)
-// CHECK:STDOUT:     'inst+31':         templateConstant(inst+30)
+// CHECK:STDOUT:     'inst+21':         symbolicConstant4
+// CHECK:STDOUT:     'inst+28':         templateConstant(inst+29)
+// CHECK:STDOUT:     'inst+29':         templateConstant(inst+29)
+// CHECK:STDOUT:     'inst+30':         templateConstant(inst+29)
 // CHECK:STDOUT:   symbolic_constants:
 // CHECK:STDOUT:     symbolicConstant0: {inst: inst+3, generic: generic<invalid>, index: genericInst<invalid>}
 // CHECK:STDOUT:     symbolicConstant1: {inst: inst+13, generic: generic<invalid>, index: genericInst<invalid>}
 // CHECK:STDOUT:     symbolicConstant2: {inst: inst+3, generic: generic0, index: genericInstInDecl0}
 // CHECK:STDOUT:     symbolicConstant3: {inst: inst+13, generic: generic0, index: genericInstInDecl1}
-// CHECK:STDOUT:     symbolicConstant4: {inst: inst+19, generic: generic<invalid>, index: genericInst<invalid>}
-// CHECK:STDOUT:     symbolicConstant5: {inst: inst+22, generic: generic<invalid>, index: genericInst<invalid>}
+// CHECK:STDOUT:     symbolicConstant4: {inst: inst+21, generic: generic<invalid>, index: genericInst<invalid>}
 // CHECK:STDOUT:   inst_blocks:
 // CHECK:STDOUT:     empty:           {}
 // CHECK:STDOUT:     exports:
@@ -154,25 +151,25 @@ fn Foo[T:! type](n: T) -> (T, ()) {
 // CHECK:STDOUT:       0:               inst+3
 // CHECK:STDOUT:     block11:
 // CHECK:STDOUT:       0:               inst+3
-// CHECK:STDOUT:       1:               inst+19
+// CHECK:STDOUT:       1:               inst+13
 // CHECK:STDOUT:     block12:
-// CHECK:STDOUT:       0:               inst+23
-// CHECK:STDOUT:       1:               inst+24
-// CHECK:STDOUT:       2:               inst+25
-// CHECK:STDOUT:       3:               inst+26
-// CHECK:STDOUT:       4:               inst+27
-// CHECK:STDOUT:       5:               inst+28
-// CHECK:STDOUT:       6:               inst+29
-// CHECK:STDOUT:       7:               inst+31
-// CHECK:STDOUT:       8:               inst+32
-// CHECK:STDOUT:       9:               inst+33
-// CHECK:STDOUT:       10:              inst+34
+// CHECK:STDOUT:       0:               inst+22
+// CHECK:STDOUT:       1:               inst+23
+// CHECK:STDOUT:       2:               inst+24
+// CHECK:STDOUT:       3:               inst+25
+// CHECK:STDOUT:       4:               inst+26
+// CHECK:STDOUT:       5:               inst+27
+// CHECK:STDOUT:       6:               inst+28
+// CHECK:STDOUT:       7:               inst+30
+// CHECK:STDOUT:       8:               inst+31
+// CHECK:STDOUT:       9:               inst+32
+// CHECK:STDOUT:       10:              inst+33
 // CHECK:STDOUT:     block13:
-// CHECK:STDOUT:       0:               inst+23
-// CHECK:STDOUT:       1:               inst+24
+// CHECK:STDOUT:       0:               inst+22
+// CHECK:STDOUT:       1:               inst+23
 // CHECK:STDOUT:     block14:
-// CHECK:STDOUT:       0:               inst+27
-// CHECK:STDOUT:       1:               inst+31
+// CHECK:STDOUT:       0:               inst+26
+// CHECK:STDOUT:       1:               inst+30
 // CHECK:STDOUT:     block15:         {}
 // CHECK:STDOUT:     block16:
 // CHECK:STDOUT:       0:               inst+0

+ 253 - 0
toolchain/check/testdata/class/generic/method_deduce.carbon

@@ -0,0 +1,253 @@
+// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
+// Exceptions. See /LICENSE for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// AUTOUPDATE
+// TIP: To test this file alone, run:
+// TIP:   bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/generic/method_deduce.carbon
+// TIP: To dump output, run:
+// TIP:   bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/generic/method_deduce.carbon
+
+class A {}
+class B {}
+
+class Class(T:! type) {
+  fn Get(U:! type) -> (T, U);
+  fn GetNoDeduce(x: T, U:! type) -> (T, U);
+}
+
+fn CallGenericMethod(c: Class(A)) -> (A, B) {
+  return c.Get(B);
+}
+
+fn CallGenericMethodWithNonDeducedParam(c: Class(A)) -> (A, B) {
+  return c.GetNoDeduce({}, B);
+}
+
+// CHECK:STDOUT: --- method_deduce.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:   %T: type = bind_symbolic_name T 0 [symbolic]
+// CHECK:STDOUT:   %Class.type: type = generic_class_type @Class [template]
+// CHECK:STDOUT:   %.2: type = tuple_type () [template]
+// CHECK:STDOUT:   %Class.1: %Class.type = struct_value () [template]
+// CHECK:STDOUT:   %Class.2: type = class_type @Class, @Class(%T) [symbolic]
+// CHECK:STDOUT:   %U: type = bind_symbolic_name U 1 [symbolic]
+// CHECK:STDOUT:   %.3: type = tuple_type (type, type) [template]
+// CHECK:STDOUT:   %.4: type = tuple_type (%T, %U) [symbolic]
+// CHECK:STDOUT:   %Get.type.1: type = fn_type @Get, @Class(%T) [symbolic]
+// CHECK:STDOUT:   %Get.1: %Get.type.1 = struct_value () [symbolic]
+// CHECK:STDOUT:   %GetNoDeduce.type.1: type = fn_type @GetNoDeduce, @Class(%T) [symbolic]
+// CHECK:STDOUT:   %GetNoDeduce.1: %GetNoDeduce.type.1 = struct_value () [symbolic]
+// CHECK:STDOUT:   %Class.3: type = class_type @Class, @Class(%A) [template]
+// CHECK:STDOUT:   %.5: type = tuple_type (%A, %B) [template]
+// CHECK:STDOUT:   %CallGenericMethod.type: type = fn_type @CallGenericMethod [template]
+// CHECK:STDOUT:   %CallGenericMethod: %CallGenericMethod.type = struct_value () [template]
+// CHECK:STDOUT:   %.6: type = ptr_type %.1 [template]
+// CHECK:STDOUT:   %.7: type = tuple_type (%.6, %.6) [template]
+// CHECK:STDOUT:   %.8: type = ptr_type %.7 [template]
+// CHECK:STDOUT:   %Get.type.2: type = fn_type @Get, @Class(%A) [template]
+// CHECK:STDOUT:   %Get.2: %Get.type.2 = struct_value () [template]
+// CHECK:STDOUT:   %GetNoDeduce.type.2: type = fn_type @GetNoDeduce, @Class(%A) [template]
+// CHECK:STDOUT:   %GetNoDeduce.2: %GetNoDeduce.type.2 = struct_value () [template]
+// CHECK:STDOUT:   %CallGenericMethodWithNonDeducedParam.type: type = fn_type @CallGenericMethodWithNonDeducedParam [template]
+// CHECK:STDOUT:   %CallGenericMethodWithNonDeducedParam: %CallGenericMethodWithNonDeducedParam.type = struct_value () [template]
+// CHECK:STDOUT:   %struct: %A = struct_value () [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: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: file {
+// CHECK:STDOUT:   package: <namespace> = namespace [template] {
+// CHECK:STDOUT:     .Core = imports.%Core
+// CHECK:STDOUT:     .A = %A.decl
+// CHECK:STDOUT:     .B = %B.decl
+// CHECK:STDOUT:     .Class = %Class.decl
+// CHECK:STDOUT:     .CallGenericMethod = %CallGenericMethod.decl
+// CHECK:STDOUT:     .CallGenericMethodWithNonDeducedParam = %CallGenericMethodWithNonDeducedParam.decl
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %Core.import = import Core
+// CHECK:STDOUT:   %A.decl: type = class_decl @A [template = constants.%A] {}
+// CHECK:STDOUT:   %B.decl: type = class_decl @B [template = constants.%B] {}
+// CHECK:STDOUT:   %Class.decl: %Class.type = class_decl @Class [template = constants.%Class.1] {
+// CHECK:STDOUT:     %T.loc14_13.1: type = param T
+// CHECK:STDOUT:     %T.loc14_13.2: type = bind_symbolic_name T 0, %T.loc14_13.1 [symbolic = @Class.%T (constants.%T)]
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %CallGenericMethod.decl: %CallGenericMethod.type = fn_decl @CallGenericMethod [template = constants.%CallGenericMethod] {
+// CHECK:STDOUT:     %Class.ref.loc19: %Class.type = name_ref Class, %Class.decl [template = constants.%Class.1]
+// CHECK:STDOUT:     %A.ref.loc19_31: type = name_ref A, %A.decl [template = constants.%A]
+// CHECK:STDOUT:     %.loc19_30: init type = call %Class.ref.loc19(%A.ref.loc19_31) [template = constants.%Class.3]
+// CHECK:STDOUT:     %.loc19_32.1: type = value_of_initializer %.loc19_30 [template = constants.%Class.3]
+// CHECK:STDOUT:     %.loc19_32.2: type = converted %.loc19_30, %.loc19_32.1 [template = constants.%Class.3]
+// CHECK:STDOUT:     %c.loc19_22.1: %Class.3 = param c
+// CHECK:STDOUT:     @CallGenericMethod.%c: %Class.3 = bind_name c, %c.loc19_22.1
+// CHECK:STDOUT:     %A.ref.loc19_39: type = name_ref A, %A.decl [template = constants.%A]
+// CHECK:STDOUT:     %B.ref.loc19: type = name_ref B, %B.decl [template = constants.%B]
+// CHECK:STDOUT:     %.loc19_43.1: %.3 = tuple_literal (%A.ref.loc19_39, %B.ref.loc19)
+// CHECK:STDOUT:     %.loc19_43.2: type = converted %.loc19_43.1, constants.%.5 [template = constants.%.5]
+// CHECK:STDOUT:     @CallGenericMethod.%return: ref %.5 = var <return slot>
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %CallGenericMethodWithNonDeducedParam.decl: %CallGenericMethodWithNonDeducedParam.type = fn_decl @CallGenericMethodWithNonDeducedParam [template = constants.%CallGenericMethodWithNonDeducedParam] {
+// CHECK:STDOUT:     %Class.ref.loc23: %Class.type = name_ref Class, %Class.decl [template = constants.%Class.1]
+// CHECK:STDOUT:     %A.ref.loc23_50: type = name_ref A, %A.decl [template = constants.%A]
+// CHECK:STDOUT:     %.loc23_49: init type = call %Class.ref.loc23(%A.ref.loc23_50) [template = constants.%Class.3]
+// CHECK:STDOUT:     %.loc23_51.1: type = value_of_initializer %.loc23_49 [template = constants.%Class.3]
+// CHECK:STDOUT:     %.loc23_51.2: type = converted %.loc23_49, %.loc23_51.1 [template = constants.%Class.3]
+// CHECK:STDOUT:     %c.loc23_41.1: %Class.3 = param c
+// CHECK:STDOUT:     @CallGenericMethodWithNonDeducedParam.%c: %Class.3 = bind_name c, %c.loc23_41.1
+// CHECK:STDOUT:     %A.ref.loc23_58: type = name_ref A, %A.decl [template = constants.%A]
+// CHECK:STDOUT:     %B.ref.loc23: type = name_ref B, %B.decl [template = constants.%B]
+// CHECK:STDOUT:     %.loc23_62.1: %.3 = tuple_literal (%A.ref.loc23_58, %B.ref.loc23)
+// CHECK:STDOUT:     %.loc23_62.2: type = converted %.loc23_62.1, constants.%.5 [template = constants.%.5]
+// CHECK:STDOUT:     @CallGenericMethodWithNonDeducedParam.%return: ref %.5 = var <return slot>
+// CHECK:STDOUT:   }
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: class @A {
+// CHECK:STDOUT: !members:
+// CHECK:STDOUT:   .Self = constants.%A
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: class @B {
+// CHECK:STDOUT: !members:
+// CHECK:STDOUT:   .Self = constants.%B
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: generic class @Class(file.%T.loc14_13.2: type) {
+// CHECK:STDOUT:   %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
+// CHECK:STDOUT:
+// CHECK:STDOUT: !definition:
+// CHECK:STDOUT:   %Get.type: type = fn_type @Get, @Class(%T) [symbolic = %Get.type (constants.%Get.type.1)]
+// CHECK:STDOUT:   %Get: @Class.%Get.type (%Get.type.1) = struct_value () [symbolic = %Get (constants.%Get.1)]
+// CHECK:STDOUT:   %GetNoDeduce.type: type = fn_type @GetNoDeduce, @Class(%T) [symbolic = %GetNoDeduce.type (constants.%GetNoDeduce.type.1)]
+// CHECK:STDOUT:   %GetNoDeduce: @Class.%GetNoDeduce.type (%GetNoDeduce.type.1) = struct_value () [symbolic = %GetNoDeduce (constants.%GetNoDeduce.1)]
+// CHECK:STDOUT:
+// CHECK:STDOUT:   class {
+// CHECK:STDOUT:     %Get.decl: @Class.%Get.type (%Get.type.1) = fn_decl @Get [symbolic = %Get (constants.%Get.1)] {
+// CHECK:STDOUT:       %U.loc15_10.1: type = param U
+// CHECK:STDOUT:       %U.loc15_10.2: type = bind_symbolic_name U 1, %U.loc15_10.1 [symbolic = @Get.%U.1 (constants.%U)]
+// CHECK:STDOUT:       %T.ref.loc15: type = name_ref T, file.%T.loc14_13.2 [symbolic = @Get.%T (constants.%T)]
+// CHECK:STDOUT:       %U.ref.loc15: type = name_ref U, %U.loc15_10.2 [symbolic = @Get.%U.1 (constants.%U)]
+// CHECK:STDOUT:       %.loc15_28.1: %.3 = tuple_literal (%T.ref.loc15, %U.ref.loc15)
+// CHECK:STDOUT:       %.loc15_28.2: type = converted %.loc15_28.1, constants.%.4 [symbolic = @Get.%.1 (constants.%.4)]
+// CHECK:STDOUT:       %return.var.loc15: ref @Get.%.1 (%.4) = var <return slot>
+// CHECK:STDOUT:     }
+// CHECK:STDOUT:     %GetNoDeduce.decl: @Class.%GetNoDeduce.type (%GetNoDeduce.type.1) = fn_decl @GetNoDeduce [symbolic = %GetNoDeduce (constants.%GetNoDeduce.1)] {
+// CHECK:STDOUT:       %T.ref.loc16_21: type = name_ref T, file.%T.loc14_13.2 [symbolic = @GetNoDeduce.%T (constants.%T)]
+// CHECK:STDOUT:       %x.loc16_18.1: @GetNoDeduce.%T (%T) = param x
+// CHECK:STDOUT:       %x.loc16_18.2: @GetNoDeduce.%T (%T) = bind_name x, %x.loc16_18.1
+// CHECK:STDOUT:       %U.loc16_24.1: type = param U
+// CHECK:STDOUT:       %U.loc16_24.2: type = bind_symbolic_name U 1, %U.loc16_24.1 [symbolic = @GetNoDeduce.%U.1 (constants.%U)]
+// CHECK:STDOUT:       %T.ref.loc16_38: type = name_ref T, file.%T.loc14_13.2 [symbolic = @GetNoDeduce.%T (constants.%T)]
+// CHECK:STDOUT:       %U.ref.loc16: type = name_ref U, %U.loc16_24.2 [symbolic = @GetNoDeduce.%U.1 (constants.%U)]
+// CHECK:STDOUT:       %.loc16_42.1: %.3 = tuple_literal (%T.ref.loc16_38, %U.ref.loc16)
+// CHECK:STDOUT:       %.loc16_42.2: type = converted %.loc16_42.1, constants.%.4 [symbolic = @GetNoDeduce.%.1 (constants.%.4)]
+// CHECK:STDOUT:       %return.var.loc16: ref @GetNoDeduce.%.1 (%.4) = var <return slot>
+// CHECK:STDOUT:     }
+// CHECK:STDOUT:
+// CHECK:STDOUT:   !members:
+// CHECK:STDOUT:     .Self = constants.%Class.2
+// CHECK:STDOUT:     .Get = %Get.decl
+// CHECK:STDOUT:     .GetNoDeduce = %GetNoDeduce.decl
+// CHECK:STDOUT:   }
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: generic fn @Get(file.%T.loc14_13.2: type, @Class.%U.loc15_10.2: type) {
+// CHECK:STDOUT:   %U.1: type = bind_symbolic_name U 1 [symbolic = %U.1 (constants.%U)]
+// CHECK:STDOUT:   %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
+// CHECK:STDOUT:   %.1: type = tuple_type (@Get.%T (%T), @Get.%U.1 (%U)) [symbolic = %.1 (constants.%.4)]
+// CHECK:STDOUT:
+// CHECK:STDOUT:   fn(@Class.%U.loc15_10.2: type) -> @Get.%.1 (%.4);
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: generic fn @GetNoDeduce(file.%T.loc14_13.2: type, @Class.%U.loc16_24.2: type) {
+// CHECK:STDOUT:   %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
+// CHECK:STDOUT:   %U.1: type = bind_symbolic_name U 1 [symbolic = %U.1 (constants.%U)]
+// CHECK:STDOUT:   %.1: type = tuple_type (@GetNoDeduce.%T (%T), @GetNoDeduce.%U.1 (%U)) [symbolic = %.1 (constants.%.4)]
+// CHECK:STDOUT:
+// CHECK:STDOUT:   fn(@Class.%x.loc16_18.2: @GetNoDeduce.%T (%T), @Class.%U.loc16_24.2: type) -> @GetNoDeduce.%.1 (%.4);
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @CallGenericMethod(%c: %Class.3) -> %return: %.5 {
+// CHECK:STDOUT: !entry:
+// CHECK:STDOUT:   %c.ref: %Class.3 = name_ref c, %c
+// CHECK:STDOUT:   %.loc20: %Get.type.2 = specific_constant @Class.%Get.decl, @Class(constants.%A) [template = constants.%Get.2]
+// CHECK:STDOUT:   %Get.ref: %Get.type.2 = name_ref Get, %.loc20 [template = constants.%Get.2]
+// CHECK:STDOUT:   %B.ref: type = name_ref B, file.%B.decl [template = constants.%B]
+// CHECK:STDOUT:   %.loc19: ref %.5 = splice_block %return {}
+// CHECK:STDOUT:   %Get.call: init %.5 = call %Get.ref(%B.ref) to %.loc19
+// CHECK:STDOUT:   return %Get.call to %return
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @CallGenericMethodWithNonDeducedParam(%c: %Class.3) -> %return: %.5 {
+// CHECK:STDOUT: !entry:
+// CHECK:STDOUT:   %c.ref: %Class.3 = name_ref c, %c
+// CHECK:STDOUT:   %.loc24_11: %GetNoDeduce.type.2 = specific_constant @Class.%GetNoDeduce.decl, @Class(constants.%A) [template = constants.%GetNoDeduce.2]
+// CHECK:STDOUT:   %GetNoDeduce.ref: %GetNoDeduce.type.2 = name_ref GetNoDeduce, %.loc24_11 [template = constants.%GetNoDeduce.2]
+// CHECK:STDOUT:   %.loc24_25.1: %.1 = struct_literal ()
+// CHECK:STDOUT:   %B.ref: type = name_ref B, file.%B.decl [template = constants.%B]
+// CHECK:STDOUT:   %.loc23: ref %.5 = splice_block %return {}
+// CHECK:STDOUT:   %.loc24_25.2: ref %A = temporary_storage
+// CHECK:STDOUT:   %.loc24_25.3: init %A = class_init (), %.loc24_25.2 [template = constants.%struct]
+// CHECK:STDOUT:   %.loc24_25.4: ref %A = temporary %.loc24_25.2, %.loc24_25.3
+// CHECK:STDOUT:   %.loc24_23.1: ref %A = converted %.loc24_25.1, %.loc24_25.4
+// CHECK:STDOUT:   %.loc24_23.2: %A = bind_value %.loc24_23.1
+// CHECK:STDOUT:   %GetNoDeduce.call: init %.5 = call %GetNoDeduce.ref(%.loc24_23.2, %B.ref) to %.loc23
+// CHECK:STDOUT:   return %GetNoDeduce.call to %return
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @Class(constants.%T) {
+// CHECK:STDOUT:   %T => constants.%T
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @Get(constants.%T, constants.%U) {
+// CHECK:STDOUT:   %U.1 => constants.%U
+// CHECK:STDOUT:   %T => constants.%T
+// CHECK:STDOUT:   %.1 => constants.%.4
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @GetNoDeduce(constants.%T, constants.%U) {
+// CHECK:STDOUT:   %T => constants.%T
+// CHECK:STDOUT:   %U.1 => constants.%U
+// CHECK:STDOUT:   %.1 => constants.%.4
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @Class(@Class.%T) {
+// CHECK:STDOUT:   %T => constants.%T
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @Class(constants.%A) {
+// CHECK:STDOUT:   %T => constants.%A
+// CHECK:STDOUT:
+// CHECK:STDOUT: !definition:
+// CHECK:STDOUT:   %Get.type => constants.%Get.type.2
+// CHECK:STDOUT:   %Get => constants.%Get.2
+// CHECK:STDOUT:   %GetNoDeduce.type => constants.%GetNoDeduce.type.2
+// CHECK:STDOUT:   %GetNoDeduce => constants.%GetNoDeduce.2
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @Get(constants.%A, constants.%B) {
+// CHECK:STDOUT:   %U.1 => constants.%B
+// CHECK:STDOUT:   %T => constants.%A
+// CHECK:STDOUT:   %.1 => constants.%.5
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @GetNoDeduce(constants.%A, constants.%B) {
+// CHECK:STDOUT:   %T => constants.%A
+// CHECK:STDOUT:   %U.1 => constants.%B
+// CHECK:STDOUT:   %.1 => constants.%.5
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 679 - 0
toolchain/check/testdata/function/generic/deduce.carbon

@@ -0,0 +1,679 @@
+// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
+// Exceptions. See /LICENSE for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// AUTOUPDATE
+// TIP: To test this file alone, run:
+// TIP:   bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/function/generic/deduce.carbon
+// TIP: To dump output, run:
+// TIP:   bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/generic/deduce.carbon
+
+// --- deduce_explicit.carbon
+
+library "deduce_explicit";
+
+fn ExplicitGenericParam(T:! type) -> T*;
+
+fn CallExplicitGenericParam() -> i32* {
+  return ExplicitGenericParam(i32);
+}
+
+fn CallExplicitGenericParamWithGenericArg(T:! type) -> {.a: T}* {
+  return ExplicitGenericParam({.a: T});
+}
+
+// --- fail_todo_explicit_vs_deduced.carbon
+
+library "fail_todo_explicit_vs_deduced";
+
+class A {}
+
+fn ExplicitAndAlsoDeduced(T:! type, x: T) -> T*;
+
+// TODO: This should presumably be accepted. We shouldn't deduce values for parameters with explicitly-specified values.
+fn CallExplicitAndAlsoDeduced(n: i32) -> i32* {
+  // CHECK:STDERR: fail_todo_explicit_vs_deduced.carbon:[[@LINE+7]]:10: ERROR: Inconsistent deductions for value of generic parameter `T`.
+  // CHECK:STDERR:   return ExplicitAndAlsoDeduced(A, {});
+  // CHECK:STDERR:          ^~~~~~~~~~~~~~~~~~~~~~~
+  // CHECK:STDERR: fail_todo_explicit_vs_deduced.carbon:[[@LINE-7]]:1: While deducing parameters of generic declared here.
+  // CHECK:STDERR: fn ExplicitAndAlsoDeduced(T:! type, x: T) -> T*;
+  // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+  // CHECK:STDERR:
+  return ExplicitAndAlsoDeduced(A, {});
+}
+
+// --- fail_todo_deduce_implicit.carbon
+
+library "fail_todo_deduce_implicit";
+
+fn ImplicitGenericParam[T:! type](x: T) -> T*;
+
+fn CallImplicitGenericParam(n: i32) -> i32* {
+  // CHECK:STDERR: fail_todo_deduce_implicit.carbon:[[@LINE+4]]:10: ERROR: Semantics TODO: `Call with implicit parameters`.
+  // CHECK:STDERR:   return ImplicitGenericParam(n);
+  // CHECK:STDERR:          ^~~~~~~~~~~~~~~~~~~~~
+  // CHECK:STDERR:
+  return ImplicitGenericParam(n);
+}
+
+// --- fail_todo_deduce_nested.carbon
+
+library "fail_todo_deduce_nested";
+
+fn TupleParam[T:! type](x: (T, i32));
+
+fn CallTupleParam() {
+  // CHECK:STDERR: fail_todo_deduce_nested.carbon:[[@LINE+7]]:3: ERROR: Cannot deduce value for generic parameter `T`.
+  // CHECK:STDERR:   TupleParam((1, 2));
+  // CHECK:STDERR:   ^~~~~~~~~~~
+  // CHECK:STDERR: fail_todo_deduce_nested.carbon:[[@LINE-6]]:1: While deducing parameters of generic declared here.
+  // CHECK:STDERR: fn TupleParam[T:! type](x: (T, i32));
+  // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+  // CHECK:STDERR:
+  TupleParam((1, 2));
+}
+
+fn StructParam[T:! type](x: {.a: T, .b: i32});
+
+fn CallStructParam() {
+  // CHECK:STDERR: fail_todo_deduce_nested.carbon:[[@LINE+7]]:3: ERROR: Cannot deduce value for generic parameter `T`.
+  // CHECK:STDERR:   StructParam({.a = 1, .b = 2});
+  // CHECK:STDERR:   ^~~~~~~~~~~~
+  // CHECK:STDERR: fail_todo_deduce_nested.carbon:[[@LINE-6]]:1: While deducing parameters of generic declared here.
+  // CHECK:STDERR: fn StructParam[T:! type](x: {.a: T, .b: i32});
+  // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+  // CHECK:STDERR:
+  StructParam({.a = 1, .b = 2});
+}
+
+// --- fail_deduce_incomplete.carbon
+
+library "fail_deduce_incomplete";
+
+// TODO: It would be nice to diagnose this at its point of declaration, because
+// U is not deducible.
+fn ImplicitNotDeducible[T:! type, U:! type](x: T) -> U;
+
+fn CallImplicitNotDeducible() {
+  // CHECK:STDERR: fail_deduce_incomplete.carbon:[[@LINE+7]]:3: ERROR: Cannot deduce value for generic parameter `U`.
+  // CHECK:STDERR:   ImplicitNotDeducible(42);
+  // CHECK:STDERR:   ^~~~~~~~~~~~~~~~~~~~~
+  // CHECK:STDERR: fail_deduce_incomplete.carbon:[[@LINE-6]]:1: While deducing parameters of generic declared here.
+  // CHECK:STDERR: fn ImplicitNotDeducible[T:! type, U:! type](x: T) -> U;
+  // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+  // CHECK:STDERR:
+  ImplicitNotDeducible(42);
+}
+
+// --- fail_deduce_inconsistent.carbon
+
+library "fail_deduce_inconsistent";
+
+fn ImplicitNotDeducible[T:! type](x: T, y: T) -> T;
+
+fn CallImplicitNotDeducible() {
+  // CHECK:STDERR: fail_deduce_inconsistent.carbon:[[@LINE+6]]:3: ERROR: Inconsistent deductions for value of generic parameter `T`.
+  // CHECK:STDERR:   ImplicitNotDeducible(42, {.x = 12});
+  // CHECK:STDERR:   ^~~~~~~~~~~~~~~~~~~~~
+  // CHECK:STDERR: fail_deduce_inconsistent.carbon:[[@LINE-6]]:1: While deducing parameters of generic declared here.
+  // CHECK:STDERR: fn ImplicitNotDeducible[T:! type](x: T, y: T) -> T;
+  // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+  ImplicitNotDeducible(42, {.x = 12});
+}
+
+// CHECK:STDOUT: --- deduce_explicit.carbon
+// CHECK:STDOUT:
+// CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %T: type = bind_symbolic_name T 0 [symbolic]
+// CHECK:STDOUT:   %.1: type = ptr_type %T [symbolic]
+// CHECK:STDOUT:   %ExplicitGenericParam.type: type = fn_type @ExplicitGenericParam [template]
+// CHECK:STDOUT:   %.2: type = tuple_type () [template]
+// CHECK:STDOUT:   %ExplicitGenericParam: %ExplicitGenericParam.type = struct_value () [template]
+// CHECK:STDOUT:   %Int32.type: type = fn_type @Int32 [template]
+// CHECK:STDOUT:   %Int32: %Int32.type = struct_value () [template]
+// CHECK:STDOUT:   %.3: type = ptr_type i32 [template]
+// CHECK:STDOUT:   %CallExplicitGenericParam.type: type = fn_type @CallExplicitGenericParam [template]
+// CHECK:STDOUT:   %CallExplicitGenericParam: %CallExplicitGenericParam.type = struct_value () [template]
+// CHECK:STDOUT:   %.4: type = struct_type {.a: %T} [symbolic]
+// CHECK:STDOUT:   %.5: type = ptr_type %.4 [symbolic]
+// CHECK:STDOUT:   %CallExplicitGenericParamWithGenericArg.type: type = fn_type @CallExplicitGenericParamWithGenericArg [template]
+// CHECK:STDOUT:   %CallExplicitGenericParamWithGenericArg: %CallExplicitGenericParamWithGenericArg.type = struct_value () [template]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: imports {
+// CHECK:STDOUT:   %Core: <namespace> = namespace file.%Core.import, [template] {
+// CHECK:STDOUT:     .Int32 = %import_ref
+// 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:   %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: file {
+// CHECK:STDOUT:   package: <namespace> = namespace [template] {
+// CHECK:STDOUT:     .Core = imports.%Core
+// CHECK:STDOUT:     .ExplicitGenericParam = %ExplicitGenericParam.decl
+// CHECK:STDOUT:     .CallExplicitGenericParam = %CallExplicitGenericParam.decl
+// CHECK:STDOUT:     .CallExplicitGenericParamWithGenericArg = %CallExplicitGenericParamWithGenericArg.decl
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %Core.import = import Core
+// CHECK:STDOUT:   %ExplicitGenericParam.decl: %ExplicitGenericParam.type = fn_decl @ExplicitGenericParam [template = constants.%ExplicitGenericParam] {
+// CHECK:STDOUT:     %T.loc4_25.1: type = param T
+// CHECK:STDOUT:     @ExplicitGenericParam.%T.loc4: type = bind_symbolic_name T 0, %T.loc4_25.1 [symbolic = @ExplicitGenericParam.%T.1 (constants.%T)]
+// CHECK:STDOUT:     %T.ref.loc4: type = name_ref T, @ExplicitGenericParam.%T.loc4 [symbolic = @ExplicitGenericParam.%T.1 (constants.%T)]
+// CHECK:STDOUT:     %.loc4: type = ptr_type %T [symbolic = @ExplicitGenericParam.%.1 (constants.%.1)]
+// CHECK:STDOUT:     @ExplicitGenericParam.%return: ref @ExplicitGenericParam.%.1 (%.1) = var <return slot>
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %CallExplicitGenericParam.decl: %CallExplicitGenericParam.type = fn_decl @CallExplicitGenericParam [template = constants.%CallExplicitGenericParam] {
+// CHECK:STDOUT:     %int.make_type_32: init type = call constants.%Int32() [template = i32]
+// CHECK:STDOUT:     %.loc6_37.1: type = value_of_initializer %int.make_type_32 [template = i32]
+// CHECK:STDOUT:     %.loc6_37.2: type = converted %int.make_type_32, %.loc6_37.1 [template = i32]
+// CHECK:STDOUT:     %.loc6_37.3: type = ptr_type i32 [template = constants.%.3]
+// CHECK:STDOUT:     @CallExplicitGenericParam.%return: ref %.3 = var <return slot>
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %CallExplicitGenericParamWithGenericArg.decl: %CallExplicitGenericParamWithGenericArg.type = fn_decl @CallExplicitGenericParamWithGenericArg [template = constants.%CallExplicitGenericParamWithGenericArg] {
+// CHECK:STDOUT:     %T.loc10_43.1: type = param T
+// CHECK:STDOUT:     @CallExplicitGenericParamWithGenericArg.%T.loc10: type = bind_symbolic_name T 0, %T.loc10_43.1 [symbolic = @CallExplicitGenericParamWithGenericArg.%T.1 (constants.%T)]
+// CHECK:STDOUT:     %T.ref.loc10: type = name_ref T, @CallExplicitGenericParamWithGenericArg.%T.loc10 [symbolic = @CallExplicitGenericParamWithGenericArg.%T.1 (constants.%T)]
+// CHECK:STDOUT:     %.loc10_62: type = struct_type {.a: %T} [symbolic = @CallExplicitGenericParamWithGenericArg.%.1 (constants.%.4)]
+// CHECK:STDOUT:     %.loc10_63: type = ptr_type %.4 [symbolic = @CallExplicitGenericParamWithGenericArg.%.2 (constants.%.5)]
+// CHECK:STDOUT:     @CallExplicitGenericParamWithGenericArg.%return: ref @CallExplicitGenericParamWithGenericArg.%.2 (%.5) = var <return slot>
+// CHECK:STDOUT:   }
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: generic fn @ExplicitGenericParam(%T.loc4: type) {
+// CHECK:STDOUT:   %T.1: type = bind_symbolic_name T 0 [symbolic = %T.1 (constants.%T)]
+// CHECK:STDOUT:   %.1: type = ptr_type @ExplicitGenericParam.%T.1 (%T) [symbolic = %.1 (constants.%.1)]
+// CHECK:STDOUT:
+// CHECK:STDOUT:   fn(%T.loc4: type) -> @ExplicitGenericParam.%.1 (%.1);
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @CallExplicitGenericParam() -> %.3 {
+// CHECK:STDOUT: !entry:
+// CHECK:STDOUT:   %ExplicitGenericParam.ref: %ExplicitGenericParam.type = name_ref ExplicitGenericParam, file.%ExplicitGenericParam.decl [template = constants.%ExplicitGenericParam]
+// CHECK:STDOUT:   %int.make_type_32: init type = call constants.%Int32() [template = i32]
+// CHECK:STDOUT:   %.loc7_30.1: type = value_of_initializer %int.make_type_32 [template = i32]
+// CHECK:STDOUT:   %.loc7_30.2: type = converted %int.make_type_32, %.loc7_30.1 [template = i32]
+// CHECK:STDOUT:   %ExplicitGenericParam.call: init %.3 = call %ExplicitGenericParam.ref(%.loc7_30.2)
+// CHECK:STDOUT:   %.loc7_35.1: %.3 = value_of_initializer %ExplicitGenericParam.call
+// CHECK:STDOUT:   %.loc7_35.2: %.3 = converted %ExplicitGenericParam.call, %.loc7_35.1
+// CHECK:STDOUT:   return %.loc7_35.2
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: generic fn @CallExplicitGenericParamWithGenericArg(%T.loc10: type) {
+// CHECK:STDOUT:   %T.1: type = bind_symbolic_name T 0 [symbolic = %T.1 (constants.%T)]
+// CHECK:STDOUT:   %.1: type = struct_type {.a: @CallExplicitGenericParamWithGenericArg.%T.1 (%T)} [symbolic = %.1 (constants.%.4)]
+// CHECK:STDOUT:   %.2: type = ptr_type @CallExplicitGenericParamWithGenericArg.%.1 (%.4) [symbolic = %.2 (constants.%.5)]
+// CHECK:STDOUT:
+// CHECK:STDOUT: !definition:
+// CHECK:STDOUT:
+// CHECK:STDOUT:   fn(%T.loc10: type) -> @CallExplicitGenericParamWithGenericArg.%.2 (%.5) {
+// CHECK:STDOUT:   !entry:
+// CHECK:STDOUT:     %ExplicitGenericParam.ref: %ExplicitGenericParam.type = name_ref ExplicitGenericParam, file.%ExplicitGenericParam.decl [template = constants.%ExplicitGenericParam]
+// CHECK:STDOUT:     %T.ref: type = name_ref T, %T.loc10 [symbolic = %T.1 (constants.%T)]
+// CHECK:STDOUT:     %.loc11_37: type = struct_type {.a: %T} [symbolic = %.1 (constants.%.4)]
+// CHECK:STDOUT:     %ExplicitGenericParam.call: init @CallExplicitGenericParamWithGenericArg.%.2 (%.5) = call %ExplicitGenericParam.ref(%.loc11_37)
+// CHECK:STDOUT:     %.loc11_39.1: @CallExplicitGenericParamWithGenericArg.%.2 (%.5) = value_of_initializer %ExplicitGenericParam.call
+// CHECK:STDOUT:     %.loc11_39.2: @CallExplicitGenericParamWithGenericArg.%.2 (%.5) = converted %ExplicitGenericParam.call, %.loc11_39.1
+// CHECK:STDOUT:     return %.loc11_39.2
+// CHECK:STDOUT:   }
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @ExplicitGenericParam(constants.%T) {
+// CHECK:STDOUT:   %T.1 => constants.%T
+// CHECK:STDOUT:   %.1 => constants.%.1
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @ExplicitGenericParam(i32) {
+// CHECK:STDOUT:   %T.1 => i32
+// CHECK:STDOUT:   %.1 => constants.%.3
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @CallExplicitGenericParamWithGenericArg(constants.%T) {
+// CHECK:STDOUT:   %T.1 => constants.%T
+// CHECK:STDOUT:   %.1 => constants.%.4
+// CHECK:STDOUT:   %.2 => constants.%.5
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @ExplicitGenericParam(constants.%.4) {
+// CHECK:STDOUT:   %T.1 => constants.%.4
+// CHECK:STDOUT:   %.1 => constants.%.5
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: --- fail_todo_explicit_vs_deduced.carbon
+// CHECK:STDOUT:
+// CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %A: type = class_type @A [template]
+// CHECK:STDOUT:   %.1: type = struct_type {} [template]
+// CHECK:STDOUT:   %T: type = bind_symbolic_name T 0 [symbolic]
+// CHECK:STDOUT:   %.2: type = ptr_type %T [symbolic]
+// CHECK:STDOUT:   %ExplicitAndAlsoDeduced.type: type = fn_type @ExplicitAndAlsoDeduced [template]
+// CHECK:STDOUT:   %.3: type = tuple_type () [template]
+// CHECK:STDOUT:   %ExplicitAndAlsoDeduced: %ExplicitAndAlsoDeduced.type = struct_value () [template]
+// 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:   %CallExplicitAndAlsoDeduced.type: type = fn_type @CallExplicitAndAlsoDeduced [template]
+// CHECK:STDOUT:   %CallExplicitAndAlsoDeduced: %CallExplicitAndAlsoDeduced.type = struct_value () [template]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: imports {
+// CHECK:STDOUT:   %Core: <namespace> = namespace file.%Core.import, [template] {
+// CHECK:STDOUT:     .Int32 = %import_ref
+// 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:   %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: file {
+// CHECK:STDOUT:   package: <namespace> = namespace [template] {
+// CHECK:STDOUT:     .Core = imports.%Core
+// CHECK:STDOUT:     .A = %A.decl
+// CHECK:STDOUT:     .ExplicitAndAlsoDeduced = %ExplicitAndAlsoDeduced.decl
+// CHECK:STDOUT:     .CallExplicitAndAlsoDeduced = %CallExplicitAndAlsoDeduced.decl
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %Core.import = import Core
+// CHECK:STDOUT:   %A.decl: type = class_decl @A [template = constants.%A] {}
+// CHECK:STDOUT:   %ExplicitAndAlsoDeduced.decl: %ExplicitAndAlsoDeduced.type = fn_decl @ExplicitAndAlsoDeduced [template = constants.%ExplicitAndAlsoDeduced] {
+// CHECK:STDOUT:     %T.loc6_27.1: type = param T
+// CHECK:STDOUT:     @ExplicitAndAlsoDeduced.%T.loc6: type = bind_symbolic_name T 0, %T.loc6_27.1 [symbolic = @ExplicitAndAlsoDeduced.%T.1 (constants.%T)]
+// CHECK:STDOUT:     %T.ref.loc6_40: type = name_ref T, @ExplicitAndAlsoDeduced.%T.loc6 [symbolic = @ExplicitAndAlsoDeduced.%T.1 (constants.%T)]
+// CHECK:STDOUT:     %x.loc6_37.1: @ExplicitAndAlsoDeduced.%T.1 (%T) = param x
+// CHECK:STDOUT:     @ExplicitAndAlsoDeduced.%x: @ExplicitAndAlsoDeduced.%T.1 (%T) = bind_name x, %x.loc6_37.1
+// CHECK:STDOUT:     %T.ref.loc6_46: type = name_ref T, @ExplicitAndAlsoDeduced.%T.loc6 [symbolic = @ExplicitAndAlsoDeduced.%T.1 (constants.%T)]
+// CHECK:STDOUT:     %.loc6: type = ptr_type %T [symbolic = @ExplicitAndAlsoDeduced.%.1 (constants.%.2)]
+// CHECK:STDOUT:     @ExplicitAndAlsoDeduced.%return: ref @ExplicitAndAlsoDeduced.%.1 (%.2) = var <return slot>
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %CallExplicitAndAlsoDeduced.decl: %CallExplicitAndAlsoDeduced.type = fn_decl @CallExplicitAndAlsoDeduced [template = constants.%CallExplicitAndAlsoDeduced] {
+// CHECK:STDOUT:     %int.make_type_32.loc9_34: init type = call constants.%Int32() [template = i32]
+// CHECK:STDOUT:     %.loc9_34.1: type = value_of_initializer %int.make_type_32.loc9_34 [template = i32]
+// CHECK:STDOUT:     %.loc9_34.2: type = converted %int.make_type_32.loc9_34, %.loc9_34.1 [template = i32]
+// CHECK:STDOUT:     %n.loc9_31.1: i32 = param n
+// CHECK:STDOUT:     @CallExplicitAndAlsoDeduced.%n: i32 = bind_name n, %n.loc9_31.1
+// CHECK:STDOUT:     %int.make_type_32.loc9_42: init type = call constants.%Int32() [template = i32]
+// CHECK:STDOUT:     %.loc9_45.1: type = value_of_initializer %int.make_type_32.loc9_42 [template = i32]
+// CHECK:STDOUT:     %.loc9_45.2: type = converted %int.make_type_32.loc9_42, %.loc9_45.1 [template = i32]
+// CHECK:STDOUT:     %.loc9_45.3: type = ptr_type i32 [template = constants.%.4]
+// CHECK:STDOUT:     @CallExplicitAndAlsoDeduced.%return: ref %.4 = var <return slot>
+// CHECK:STDOUT:   }
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: class @A {
+// CHECK:STDOUT: !members:
+// CHECK:STDOUT:   .Self = constants.%A
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: generic fn @ExplicitAndAlsoDeduced(%T.loc6: type) {
+// CHECK:STDOUT:   %T.1: type = bind_symbolic_name T 0 [symbolic = %T.1 (constants.%T)]
+// CHECK:STDOUT:   %.1: type = ptr_type @ExplicitAndAlsoDeduced.%T.1 (%T) [symbolic = %.1 (constants.%.2)]
+// CHECK:STDOUT:
+// CHECK:STDOUT:   fn(%T.loc6: type, %x: @ExplicitAndAlsoDeduced.%T.1 (%T)) -> @ExplicitAndAlsoDeduced.%.1 (%.2);
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @CallExplicitAndAlsoDeduced(%n: i32) -> %.4 {
+// CHECK:STDOUT: !entry:
+// CHECK:STDOUT:   %ExplicitAndAlsoDeduced.ref: %ExplicitAndAlsoDeduced.type = name_ref ExplicitAndAlsoDeduced, file.%ExplicitAndAlsoDeduced.decl [template = constants.%ExplicitAndAlsoDeduced]
+// CHECK:STDOUT:   %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
+// CHECK:STDOUT:   %.loc17: %.1 = struct_literal ()
+// CHECK:STDOUT:   return <error>
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @ExplicitAndAlsoDeduced(constants.%T) {
+// CHECK:STDOUT:   %T.1 => constants.%T
+// CHECK:STDOUT:   %.1 => constants.%.2
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: --- fail_todo_deduce_implicit.carbon
+// CHECK:STDOUT:
+// CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %T: type = bind_symbolic_name T 0 [symbolic]
+// CHECK:STDOUT:   %.1: type = ptr_type %T [symbolic]
+// CHECK:STDOUT:   %ImplicitGenericParam.type: type = fn_type @ImplicitGenericParam [template]
+// CHECK:STDOUT:   %.2: type = tuple_type () [template]
+// CHECK:STDOUT:   %ImplicitGenericParam: %ImplicitGenericParam.type = struct_value () [template]
+// CHECK:STDOUT:   %Int32.type: type = fn_type @Int32 [template]
+// CHECK:STDOUT:   %Int32: %Int32.type = struct_value () [template]
+// CHECK:STDOUT:   %.3: type = ptr_type i32 [template]
+// CHECK:STDOUT:   %CallImplicitGenericParam.type: type = fn_type @CallImplicitGenericParam [template]
+// CHECK:STDOUT:   %CallImplicitGenericParam: %CallImplicitGenericParam.type = struct_value () [template]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: imports {
+// CHECK:STDOUT:   %Core: <namespace> = namespace file.%Core.import, [template] {
+// CHECK:STDOUT:     .Int32 = %import_ref
+// 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:   %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: file {
+// CHECK:STDOUT:   package: <namespace> = namespace [template] {
+// CHECK:STDOUT:     .Core = imports.%Core
+// CHECK:STDOUT:     .ImplicitGenericParam = %ImplicitGenericParam.decl
+// CHECK:STDOUT:     .CallImplicitGenericParam = %CallImplicitGenericParam.decl
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %Core.import = import Core
+// CHECK:STDOUT:   %ImplicitGenericParam.decl: %ImplicitGenericParam.type = fn_decl @ImplicitGenericParam [template = constants.%ImplicitGenericParam] {
+// CHECK:STDOUT:     %T.loc4_25.1: type = param T
+// CHECK:STDOUT:     @ImplicitGenericParam.%T.loc4: type = bind_symbolic_name T 0, %T.loc4_25.1 [symbolic = @ImplicitGenericParam.%T.1 (constants.%T)]
+// CHECK:STDOUT:     %T.ref.loc4_38: type = name_ref T, @ImplicitGenericParam.%T.loc4 [symbolic = @ImplicitGenericParam.%T.1 (constants.%T)]
+// CHECK:STDOUT:     %x.loc4_35.1: @ImplicitGenericParam.%T.1 (%T) = param x
+// CHECK:STDOUT:     @ImplicitGenericParam.%x: @ImplicitGenericParam.%T.1 (%T) = bind_name x, %x.loc4_35.1
+// CHECK:STDOUT:     %T.ref.loc4_44: type = name_ref T, @ImplicitGenericParam.%T.loc4 [symbolic = @ImplicitGenericParam.%T.1 (constants.%T)]
+// CHECK:STDOUT:     %.loc4: type = ptr_type %T [symbolic = @ImplicitGenericParam.%.1 (constants.%.1)]
+// CHECK:STDOUT:     @ImplicitGenericParam.%return: ref @ImplicitGenericParam.%.1 (%.1) = var <return slot>
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %CallImplicitGenericParam.decl: %CallImplicitGenericParam.type = fn_decl @CallImplicitGenericParam [template = constants.%CallImplicitGenericParam] {
+// CHECK:STDOUT:     %int.make_type_32.loc6_32: init type = call constants.%Int32() [template = i32]
+// CHECK:STDOUT:     %.loc6_32.1: type = value_of_initializer %int.make_type_32.loc6_32 [template = i32]
+// CHECK:STDOUT:     %.loc6_32.2: type = converted %int.make_type_32.loc6_32, %.loc6_32.1 [template = i32]
+// CHECK:STDOUT:     %n.loc6_29.1: i32 = param n
+// CHECK:STDOUT:     @CallImplicitGenericParam.%n: i32 = bind_name n, %n.loc6_29.1
+// CHECK:STDOUT:     %int.make_type_32.loc6_40: init type = call constants.%Int32() [template = i32]
+// CHECK:STDOUT:     %.loc6_43.1: type = value_of_initializer %int.make_type_32.loc6_40 [template = i32]
+// CHECK:STDOUT:     %.loc6_43.2: type = converted %int.make_type_32.loc6_40, %.loc6_43.1 [template = i32]
+// CHECK:STDOUT:     %.loc6_43.3: type = ptr_type i32 [template = constants.%.3]
+// CHECK:STDOUT:     @CallImplicitGenericParam.%return: ref %.3 = var <return slot>
+// CHECK:STDOUT:   }
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: generic fn @ImplicitGenericParam(%T.loc4: type) {
+// CHECK:STDOUT:   %T.1: type = bind_symbolic_name T 0 [symbolic = %T.1 (constants.%T)]
+// CHECK:STDOUT:   %.1: type = ptr_type @ImplicitGenericParam.%T.1 (%T) [symbolic = %.1 (constants.%.1)]
+// CHECK:STDOUT:
+// CHECK:STDOUT:   fn[%T.loc4: type](%x: @ImplicitGenericParam.%T.1 (%T)) -> @ImplicitGenericParam.%.1 (%.1);
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @CallImplicitGenericParam(%n: i32) -> %.3 {
+// CHECK:STDOUT: !entry:
+// CHECK:STDOUT:   %ImplicitGenericParam.ref: %ImplicitGenericParam.type = name_ref ImplicitGenericParam, file.%ImplicitGenericParam.decl [template = constants.%ImplicitGenericParam]
+// CHECK:STDOUT:   %n.ref: i32 = name_ref n, %n
+// CHECK:STDOUT:   %ImplicitGenericParam.call: init %.3 = call %ImplicitGenericParam.ref(<invalid>) [template = <error>]
+// CHECK:STDOUT:   %.loc11_33.1: %.3 = value_of_initializer %ImplicitGenericParam.call [template = <error>]
+// CHECK:STDOUT:   %.loc11_33.2: %.3 = converted %ImplicitGenericParam.call, %.loc11_33.1 [template = <error>]
+// CHECK:STDOUT:   return %.loc11_33.2
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @ImplicitGenericParam(constants.%T) {
+// CHECK:STDOUT:   %T.1 => constants.%T
+// CHECK:STDOUT:   %.1 => constants.%.1
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @ImplicitGenericParam(i32) {
+// CHECK:STDOUT:   %T.1 => i32
+// CHECK:STDOUT:   %.1 => constants.%.3
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: --- fail_todo_deduce_nested.carbon
+// CHECK:STDOUT:
+// CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %T: type = bind_symbolic_name T 0 [symbolic]
+// CHECK:STDOUT:   %Int32.type: type = fn_type @Int32 [template]
+// CHECK:STDOUT:   %.1: type = tuple_type () [template]
+// CHECK:STDOUT:   %Int32: %Int32.type = struct_value () [template]
+// CHECK:STDOUT:   %.2: type = tuple_type (type, type) [template]
+// CHECK:STDOUT:   %.3: type = tuple_type (%T, i32) [symbolic]
+// CHECK:STDOUT:   %TupleParam.type: type = fn_type @TupleParam [template]
+// CHECK:STDOUT:   %TupleParam: %TupleParam.type = struct_value () [template]
+// CHECK:STDOUT:   %CallTupleParam.type: type = fn_type @CallTupleParam [template]
+// CHECK:STDOUT:   %CallTupleParam: %CallTupleParam.type = struct_value () [template]
+// CHECK:STDOUT:   %.4: i32 = int_literal 1 [template]
+// CHECK:STDOUT:   %.5: i32 = int_literal 2 [template]
+// CHECK:STDOUT:   %.6: type = tuple_type (i32, i32) [template]
+// CHECK:STDOUT:   %.7: type = struct_type {.a: %T, .b: i32} [symbolic]
+// CHECK:STDOUT:   %StructParam.type: type = fn_type @StructParam [template]
+// CHECK:STDOUT:   %StructParam: %StructParam.type = struct_value () [template]
+// CHECK:STDOUT:   %CallStructParam.type: type = fn_type @CallStructParam [template]
+// CHECK:STDOUT:   %CallStructParam: %CallStructParam.type = struct_value () [template]
+// CHECK:STDOUT:   %.8: type = struct_type {.a: i32, .b: i32} [template]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: imports {
+// CHECK:STDOUT:   %Core: <namespace> = namespace file.%Core.import, [template] {
+// CHECK:STDOUT:     .Int32 = %import_ref
+// 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:   %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: file {
+// CHECK:STDOUT:   package: <namespace> = namespace [template] {
+// CHECK:STDOUT:     .Core = imports.%Core
+// CHECK:STDOUT:     .TupleParam = %TupleParam.decl
+// CHECK:STDOUT:     .CallTupleParam = %CallTupleParam.decl
+// CHECK:STDOUT:     .StructParam = %StructParam.decl
+// CHECK:STDOUT:     .CallStructParam = %CallStructParam.decl
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %Core.import = import Core
+// CHECK:STDOUT:   %TupleParam.decl: %TupleParam.type = fn_decl @TupleParam [template = constants.%TupleParam] {
+// CHECK:STDOUT:     %T.loc4_15.1: type = param T
+// CHECK:STDOUT:     @TupleParam.%T.loc4: type = bind_symbolic_name T 0, %T.loc4_15.1 [symbolic = @TupleParam.%T.1 (constants.%T)]
+// CHECK:STDOUT:     %T.ref.loc4: type = name_ref T, @TupleParam.%T.loc4 [symbolic = @TupleParam.%T.1 (constants.%T)]
+// CHECK:STDOUT:     %int.make_type_32.loc4: init type = call constants.%Int32() [template = i32]
+// CHECK:STDOUT:     %.loc4_35.1: %.2 = tuple_literal (%T.ref.loc4, %int.make_type_32.loc4)
+// CHECK:STDOUT:     %.loc4_35.2: type = value_of_initializer %int.make_type_32.loc4 [template = i32]
+// CHECK:STDOUT:     %.loc4_35.3: type = converted %int.make_type_32.loc4, %.loc4_35.2 [template = i32]
+// CHECK:STDOUT:     %.loc4_35.4: type = converted %.loc4_35.1, constants.%.3 [symbolic = @TupleParam.%.1 (constants.%.3)]
+// CHECK:STDOUT:     %x.loc4_25.1: @TupleParam.%.1 (%.3) = param x
+// CHECK:STDOUT:     @TupleParam.%x: @TupleParam.%.1 (%.3) = bind_name x, %x.loc4_25.1
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %CallTupleParam.decl: %CallTupleParam.type = fn_decl @CallTupleParam [template = constants.%CallTupleParam] {}
+// CHECK:STDOUT:   %StructParam.decl: %StructParam.type = fn_decl @StructParam [template = constants.%StructParam] {
+// CHECK:STDOUT:     %T.loc17_16.1: type = param T
+// CHECK:STDOUT:     @StructParam.%T.loc17: type = bind_symbolic_name T 0, %T.loc17_16.1 [symbolic = @StructParam.%T.1 (constants.%T)]
+// CHECK:STDOUT:     %T.ref.loc17: type = name_ref T, @StructParam.%T.loc17 [symbolic = @StructParam.%T.1 (constants.%T)]
+// CHECK:STDOUT:     %int.make_type_32.loc17: init type = call constants.%Int32() [template = i32]
+// CHECK:STDOUT:     %.loc17_41.1: type = value_of_initializer %int.make_type_32.loc17 [template = i32]
+// CHECK:STDOUT:     %.loc17_41.2: type = converted %int.make_type_32.loc17, %.loc17_41.1 [template = i32]
+// CHECK:STDOUT:     %.loc17_44: type = struct_type {.a: %T, .b: i32} [symbolic = @StructParam.%.1 (constants.%.7)]
+// CHECK:STDOUT:     %x.loc17_26.1: @StructParam.%.1 (%.7) = param x
+// CHECK:STDOUT:     @StructParam.%x: @StructParam.%.1 (%.7) = bind_name x, %x.loc17_26.1
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %CallStructParam.decl: %CallStructParam.type = fn_decl @CallStructParam [template = constants.%CallStructParam] {}
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
+// CHECK:STDOUT:
+// CHECK:STDOUT: generic fn @TupleParam(%T.loc4: type) {
+// CHECK:STDOUT:   %T.1: type = bind_symbolic_name T 0 [symbolic = %T.1 (constants.%T)]
+// CHECK:STDOUT:   %.1: type = tuple_type (@TupleParam.%T.1 (%T), i32) [symbolic = %.1 (constants.%.3)]
+// CHECK:STDOUT:
+// CHECK:STDOUT:   fn[%T.loc4: type](%x: @TupleParam.%.1 (%.3));
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @CallTupleParam() {
+// CHECK:STDOUT: !entry:
+// CHECK:STDOUT:   %TupleParam.ref: %TupleParam.type = name_ref TupleParam, file.%TupleParam.decl [template = constants.%TupleParam]
+// CHECK:STDOUT:   %.loc14_15: i32 = int_literal 1 [template = constants.%.4]
+// CHECK:STDOUT:   %.loc14_18: i32 = int_literal 2 [template = constants.%.5]
+// CHECK:STDOUT:   %.loc14_19: %.6 = tuple_literal (%.loc14_15, %.loc14_18)
+// CHECK:STDOUT:   return
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: generic fn @StructParam(%T.loc17: type) {
+// CHECK:STDOUT:   %T.1: type = bind_symbolic_name T 0 [symbolic = %T.1 (constants.%T)]
+// CHECK:STDOUT:   %.1: type = struct_type {.a: @StructParam.%T.1 (%T), .b: i32} [symbolic = %.1 (constants.%.7)]
+// CHECK:STDOUT:
+// CHECK:STDOUT:   fn[%T.loc17: type](%x: @StructParam.%.1 (%.7));
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @CallStructParam() {
+// CHECK:STDOUT: !entry:
+// CHECK:STDOUT:   %StructParam.ref: %StructParam.type = name_ref StructParam, file.%StructParam.decl [template = constants.%StructParam]
+// CHECK:STDOUT:   %.loc27_21: i32 = int_literal 1 [template = constants.%.4]
+// CHECK:STDOUT:   %.loc27_29: i32 = int_literal 2 [template = constants.%.5]
+// CHECK:STDOUT:   %.loc27_30: %.8 = struct_literal (%.loc27_21, %.loc27_29)
+// CHECK:STDOUT:   return
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @TupleParam(constants.%T) {
+// CHECK:STDOUT:   %T.1 => constants.%T
+// CHECK:STDOUT:   %.1 => constants.%.3
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @StructParam(constants.%T) {
+// CHECK:STDOUT:   %T.1 => constants.%T
+// CHECK:STDOUT:   %.1 => constants.%.7
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: --- fail_deduce_incomplete.carbon
+// CHECK:STDOUT:
+// CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %T: type = bind_symbolic_name T 0 [symbolic]
+// CHECK:STDOUT:   %U: type = bind_symbolic_name U 1 [symbolic]
+// CHECK:STDOUT:   %ImplicitNotDeducible.type: type = fn_type @ImplicitNotDeducible [template]
+// CHECK:STDOUT:   %.1: type = tuple_type () [template]
+// CHECK:STDOUT:   %ImplicitNotDeducible: %ImplicitNotDeducible.type = struct_value () [template]
+// CHECK:STDOUT:   %CallImplicitNotDeducible.type: type = fn_type @CallImplicitNotDeducible [template]
+// CHECK:STDOUT:   %CallImplicitNotDeducible: %CallImplicitNotDeducible.type = struct_value () [template]
+// CHECK:STDOUT:   %.2: i32 = int_literal 42 [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: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: file {
+// CHECK:STDOUT:   package: <namespace> = namespace [template] {
+// CHECK:STDOUT:     .Core = imports.%Core
+// CHECK:STDOUT:     .ImplicitNotDeducible = %ImplicitNotDeducible.decl
+// CHECK:STDOUT:     .CallImplicitNotDeducible = %CallImplicitNotDeducible.decl
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %Core.import = import Core
+// CHECK:STDOUT:   %ImplicitNotDeducible.decl: %ImplicitNotDeducible.type = fn_decl @ImplicitNotDeducible [template = constants.%ImplicitNotDeducible] {
+// CHECK:STDOUT:     %T.loc6_25.1: type = param T
+// CHECK:STDOUT:     @ImplicitNotDeducible.%T.loc6: type = bind_symbolic_name T 0, %T.loc6_25.1 [symbolic = @ImplicitNotDeducible.%T.1 (constants.%T)]
+// CHECK:STDOUT:     %U.loc6_35.1: type = param U
+// CHECK:STDOUT:     @ImplicitNotDeducible.%U.loc6: type = bind_symbolic_name U 1, %U.loc6_35.1 [symbolic = @ImplicitNotDeducible.%U.1 (constants.%U)]
+// CHECK:STDOUT:     %T.ref: type = name_ref T, @ImplicitNotDeducible.%T.loc6 [symbolic = @ImplicitNotDeducible.%T.1 (constants.%T)]
+// CHECK:STDOUT:     %x.loc6_45.1: @ImplicitNotDeducible.%T.1 (%T) = param x
+// CHECK:STDOUT:     @ImplicitNotDeducible.%x: @ImplicitNotDeducible.%T.1 (%T) = bind_name x, %x.loc6_45.1
+// CHECK:STDOUT:     %U.ref: type = name_ref U, @ImplicitNotDeducible.%U.loc6 [symbolic = @ImplicitNotDeducible.%U.1 (constants.%U)]
+// CHECK:STDOUT:     @ImplicitNotDeducible.%return: ref @ImplicitNotDeducible.%U.1 (%U) = var <return slot>
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %CallImplicitNotDeducible.decl: %CallImplicitNotDeducible.type = fn_decl @CallImplicitNotDeducible [template = constants.%CallImplicitNotDeducible] {}
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: generic fn @ImplicitNotDeducible(%T.loc6: type, %U.loc6: type) {
+// CHECK:STDOUT:   %T.1: type = bind_symbolic_name T 0 [symbolic = %T.1 (constants.%T)]
+// CHECK:STDOUT:   %U.1: type = bind_symbolic_name U 1 [symbolic = %U.1 (constants.%U)]
+// CHECK:STDOUT:
+// CHECK:STDOUT:   fn[%T.loc6: type, %U.loc6: type](%x: @ImplicitNotDeducible.%T.1 (%T)) -> @ImplicitNotDeducible.%U.1 (%U);
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @CallImplicitNotDeducible() {
+// CHECK:STDOUT: !entry:
+// CHECK:STDOUT:   %ImplicitNotDeducible.ref: %ImplicitNotDeducible.type = name_ref ImplicitNotDeducible, file.%ImplicitNotDeducible.decl [template = constants.%ImplicitNotDeducible]
+// CHECK:STDOUT:   %.loc16: i32 = int_literal 42 [template = constants.%.2]
+// CHECK:STDOUT:   return
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @ImplicitNotDeducible(constants.%T, constants.%U) {
+// CHECK:STDOUT:   %T.1 => constants.%T
+// CHECK:STDOUT:   %U.1 => constants.%U
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: --- fail_deduce_inconsistent.carbon
+// CHECK:STDOUT:
+// CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %T: type = bind_symbolic_name T 0 [symbolic]
+// CHECK:STDOUT:   %ImplicitNotDeducible.type: type = fn_type @ImplicitNotDeducible [template]
+// CHECK:STDOUT:   %.1: type = tuple_type () [template]
+// CHECK:STDOUT:   %ImplicitNotDeducible: %ImplicitNotDeducible.type = struct_value () [template]
+// CHECK:STDOUT:   %CallImplicitNotDeducible.type: type = fn_type @CallImplicitNotDeducible [template]
+// CHECK:STDOUT:   %CallImplicitNotDeducible: %CallImplicitNotDeducible.type = struct_value () [template]
+// CHECK:STDOUT:   %.2: i32 = int_literal 42 [template]
+// CHECK:STDOUT:   %.3: i32 = int_literal 12 [template]
+// CHECK:STDOUT:   %.4: type = struct_type {.x: i32} [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: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: file {
+// CHECK:STDOUT:   package: <namespace> = namespace [template] {
+// CHECK:STDOUT:     .Core = imports.%Core
+// CHECK:STDOUT:     .ImplicitNotDeducible = %ImplicitNotDeducible.decl
+// CHECK:STDOUT:     .CallImplicitNotDeducible = %CallImplicitNotDeducible.decl
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %Core.import = import Core
+// CHECK:STDOUT:   %ImplicitNotDeducible.decl: %ImplicitNotDeducible.type = fn_decl @ImplicitNotDeducible [template = constants.%ImplicitNotDeducible] {
+// CHECK:STDOUT:     %T.loc4_25.1: type = param T
+// CHECK:STDOUT:     @ImplicitNotDeducible.%T.loc4: type = bind_symbolic_name T 0, %T.loc4_25.1 [symbolic = @ImplicitNotDeducible.%T.1 (constants.%T)]
+// CHECK:STDOUT:     %T.ref.loc4_38: type = name_ref T, @ImplicitNotDeducible.%T.loc4 [symbolic = @ImplicitNotDeducible.%T.1 (constants.%T)]
+// CHECK:STDOUT:     %x.loc4_35.1: @ImplicitNotDeducible.%T.1 (%T) = param x
+// CHECK:STDOUT:     @ImplicitNotDeducible.%x: @ImplicitNotDeducible.%T.1 (%T) = bind_name x, %x.loc4_35.1
+// CHECK:STDOUT:     %T.ref.loc4_44: type = name_ref T, @ImplicitNotDeducible.%T.loc4 [symbolic = @ImplicitNotDeducible.%T.1 (constants.%T)]
+// CHECK:STDOUT:     %y.loc4_41.1: @ImplicitNotDeducible.%T.1 (%T) = param y
+// CHECK:STDOUT:     @ImplicitNotDeducible.%y: @ImplicitNotDeducible.%T.1 (%T) = bind_name y, %y.loc4_41.1
+// CHECK:STDOUT:     %T.ref.loc4_50: type = name_ref T, @ImplicitNotDeducible.%T.loc4 [symbolic = @ImplicitNotDeducible.%T.1 (constants.%T)]
+// CHECK:STDOUT:     @ImplicitNotDeducible.%return: ref @ImplicitNotDeducible.%T.1 (%T) = var <return slot>
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %CallImplicitNotDeducible.decl: %CallImplicitNotDeducible.type = fn_decl @CallImplicitNotDeducible [template = constants.%CallImplicitNotDeducible] {}
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: generic fn @ImplicitNotDeducible(%T.loc4: type) {
+// CHECK:STDOUT:   %T.1: type = bind_symbolic_name T 0 [symbolic = %T.1 (constants.%T)]
+// CHECK:STDOUT:
+// CHECK:STDOUT:   fn[%T.loc4: type](%x: @ImplicitNotDeducible.%T.1 (%T), %y: @ImplicitNotDeducible.%T.1 (%T)) -> @ImplicitNotDeducible.%T.1 (%T);
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @CallImplicitNotDeducible() {
+// CHECK:STDOUT: !entry:
+// CHECK:STDOUT:   %ImplicitNotDeducible.ref: %ImplicitNotDeducible.type = name_ref ImplicitNotDeducible, file.%ImplicitNotDeducible.decl [template = constants.%ImplicitNotDeducible]
+// CHECK:STDOUT:   %.loc13_24: i32 = int_literal 42 [template = constants.%.2]
+// CHECK:STDOUT:   %.loc13_34: i32 = int_literal 12 [template = constants.%.3]
+// CHECK:STDOUT:   %.loc13_36: %.4 = struct_literal (%.loc13_34)
+// CHECK:STDOUT:   return
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: specific @ImplicitNotDeducible(constants.%T) {
+// CHECK:STDOUT:   %T.1 => constants.%T
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 8 - 26
toolchain/check/testdata/function/generic/redeclare.carbon

@@ -32,14 +32,12 @@ fn F(T:! type, U:! type) -> T*;
 // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 // CHECK:STDERR:
 fn F(T:! type, U:! type) -> U* {
-  // CHECK:STDERR: fail_different_return_type.carbon:[[@LINE+11]]:3: ERROR: Cannot implicitly convert from `T*` to `U*`.
-  // CHECK:STDERR:   return F(T);
-  // CHECK:STDERR:   ^~~~~~~~~~~~
-  // CHECK:STDERR:
-  // CHECK:STDERR: fail_different_return_type.carbon:[[@LINE+7]]:10: ERROR: 1 argument(s) passed to function expecting 2 argument(s).
+  // TODO: This diagnostic is not very good. We should check the arity in a
+  // function call before, or as part of, deduction.
+  // CHECK:STDERR: fail_different_return_type.carbon:[[@LINE+7]]:10: ERROR: Cannot deduce value for generic parameter `T`.
   // CHECK:STDERR:   return F(T);
   // CHECK:STDERR:          ^~
-  // CHECK:STDERR: fail_different_return_type.carbon:[[@LINE-17]]:1: Calling function declared here.
+  // CHECK:STDERR: fail_different_return_type.carbon:[[@LINE-15]]:1: While deducing parameters of generic declared here.
   // CHECK:STDERR: fn F(T:! type, U:! type) -> T*;
   // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   // CHECK:STDERR:
@@ -60,14 +58,10 @@ fn F(T:! type, U:! type) -> T*;
 // CHECK:STDERR:      ^
 // CHECK:STDERR:
 fn F(U:! type, T:! type) -> T* {
-  // CHECK:STDERR: fail_reorder.carbon:[[@LINE+11]]:3: ERROR: Cannot implicitly convert from `T*` to `T*`.
-  // CHECK:STDERR:   return F(T);
-  // CHECK:STDERR:   ^~~~~~~~~~~~
-  // CHECK:STDERR:
-  // CHECK:STDERR: fail_reorder.carbon:[[@LINE+7]]:10: ERROR: 1 argument(s) passed to function expecting 2 argument(s).
+  // CHECK:STDERR: fail_reorder.carbon:[[@LINE+7]]:10: ERROR: Cannot deduce value for generic parameter `T`.
   // CHECK:STDERR:   return F(T);
   // CHECK:STDERR:          ^~
-  // CHECK:STDERR: fail_reorder.carbon:[[@LINE-17]]:1: Calling function declared here.
+  // CHECK:STDERR: fail_reorder.carbon:[[@LINE-13]]:1: While deducing parameters of generic declared here.
   // CHECK:STDERR: fn F(T:! type, U:! type) -> T*;
   // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   // CHECK:STDERR:
@@ -88,14 +82,10 @@ fn F(T:! type, U:! type) -> T*;
 // CHECK:STDERR:      ^
 // CHECK:STDERR:
 fn F(U:! type, T:! type) -> U* {
-  // CHECK:STDERR: fail_rename.carbon:[[@LINE+10]]:3: ERROR: Cannot implicitly convert from `T*` to `U*`.
-  // CHECK:STDERR:   return F(T);
-  // CHECK:STDERR:   ^~~~~~~~~~~~
-  // CHECK:STDERR:
-  // CHECK:STDERR: fail_rename.carbon:[[@LINE+6]]:10: ERROR: 1 argument(s) passed to function expecting 2 argument(s).
+  // CHECK:STDERR: fail_rename.carbon:[[@LINE+6]]:10: ERROR: Cannot deduce value for generic parameter `T`.
   // CHECK:STDERR:   return F(T);
   // CHECK:STDERR:          ^~
-  // CHECK:STDERR: fail_rename.carbon:[[@LINE-17]]:1: Calling function declared here.
+  // CHECK:STDERR: fail_rename.carbon:[[@LINE-13]]:1: While deducing parameters of generic declared here.
   // CHECK:STDERR: fn F(T:! type, U:! type) -> T*;
   // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   return F(T);
@@ -233,13 +223,11 @@ fn F(U:! type, T:! type) -> U* {
 // CHECK:STDOUT:   %.1: type = ptr_type @.1.%U.1 (%U) [symbolic = %.1 (constants.%.3)]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !definition:
-// CHECK:STDOUT:   %.2: type = ptr_type @.1.%T.1 (%T) [symbolic = %.2 (constants.%.1)]
 // CHECK:STDOUT:
 // CHECK:STDOUT:   fn(%T.loc13: type, %U.loc13: type) -> @.1.%.1 (%.3) {
 // CHECK:STDOUT:   !entry:
 // CHECK:STDOUT:     %F.ref: %F.type = name_ref F, file.%F.decl [template = constants.%F]
 // CHECK:STDOUT:     %T.ref: type = name_ref T, %T.loc13 [symbolic = %T.1 (constants.%T)]
-// CHECK:STDOUT:     %F.call: init @.1.%.2 (%.1) = call %F.ref(<invalid>) [template = <error>]
 // CHECK:STDOUT:     return <error>
 // CHECK:STDOUT:   }
 // CHECK:STDOUT: }
@@ -324,14 +312,11 @@ fn F(U:! type, T:! type) -> U* {
 // CHECK:STDOUT:   %.1: type = ptr_type @.1.%T.1 (%T.2) [symbolic = %.1 (constants.%.3)]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !definition:
-// CHECK:STDOUT:   %T.2: type = bind_symbolic_name T 0 [symbolic = %T.2 (constants.%T.1)]
-// CHECK:STDOUT:   %.2: type = ptr_type @.1.%T.2 (%T.1) [symbolic = %.2 (constants.%.1)]
 // CHECK:STDOUT:
 // CHECK:STDOUT:   fn(%U.loc13: type, %T.loc13: type) -> @.1.%.1 (%.3) {
 // CHECK:STDOUT:   !entry:
 // CHECK:STDOUT:     %F.ref: %F.type = name_ref F, file.%F.decl [template = constants.%F]
 // CHECK:STDOUT:     %T.ref: type = name_ref T, %T.loc13 [symbolic = %T.1 (constants.%T.2)]
-// CHECK:STDOUT:     %F.call: init @.1.%.2 (%.1) = call %F.ref(<invalid>) [template = <error>]
 // CHECK:STDOUT:     return <error>
 // CHECK:STDOUT:   }
 // CHECK:STDOUT: }
@@ -416,14 +401,11 @@ fn F(U:! type, T:! type) -> U* {
 // CHECK:STDOUT:   %.1: type = ptr_type @.1.%U.1 (%U.2) [symbolic = %.1 (constants.%.3)]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !definition:
-// CHECK:STDOUT:   %T.2: type = bind_symbolic_name T 0 [symbolic = %T.2 (constants.%T.1)]
-// CHECK:STDOUT:   %.2: type = ptr_type @.1.%T.2 (%T.1) [symbolic = %.2 (constants.%.1)]
 // CHECK:STDOUT:
 // CHECK:STDOUT:   fn(%U.loc13: type, %T.loc13: type) -> @.1.%.1 (%.3) {
 // CHECK:STDOUT:   !entry:
 // CHECK:STDOUT:     %F.ref: %F.type = name_ref F, file.%F.decl [template = constants.%F]
 // CHECK:STDOUT:     %T.ref: type = name_ref T, %T.loc13 [symbolic = %T.1 (constants.%T.2)]
-// CHECK:STDOUT:     %F.call: init @.1.%.2 (%.1) = call %F.ref(<invalid>) [template = <error>]
 // CHECK:STDOUT:     return <error>
 // CHECK:STDOUT:   }
 // CHECK:STDOUT: }

+ 30 - 31
toolchain/check/testdata/impl/fail_impl_bad_assoc_fn.carbon

@@ -278,27 +278,26 @@ class SelfNestedBadReturnType {
 // CHECK:STDOUT:   %.13: type = tuple_type (%.10, %.11) [symbolic]
 // CHECK:STDOUT:   %.14: i32 = int_literal 4 [template]
 // CHECK:STDOUT:   %.15: type = array_type %.14, %Self.3 [symbolic]
-// CHECK:STDOUT:   %.16: type = tuple_type (@F.13.%.1 (%.10), @F.13.%.2 (%.11)) [symbolic]
 // CHECK:STDOUT:   %F.type.13: type = fn_type @F.13 [template]
 // CHECK:STDOUT:   %F.14: %F.type.13 = struct_value () [template]
-// CHECK:STDOUT:   %.17: type = assoc_entity_type @SelfNested, %F.type.13 [template]
-// CHECK:STDOUT:   %.18: %.17 = assoc_entity element0, @SelfNested.%F.decl [template]
+// CHECK:STDOUT:   %.16: type = assoc_entity_type @SelfNested, %F.type.13 [template]
+// CHECK:STDOUT:   %.17: %.16 = assoc_entity element0, @SelfNested.%F.decl [template]
 // CHECK:STDOUT:   %SelfNestedBadParam: type = class_type @SelfNestedBadParam [template]
-// CHECK:STDOUT:   %.19: type = ptr_type %SelfNestedBadParam [template]
-// CHECK:STDOUT:   %.20: type = struct_type {.x: i32, .y: i32} [template]
-// CHECK:STDOUT:   %.21: type = tuple_type (%.19, %.20) [template]
-// CHECK:STDOUT:   %.22: type = array_type %.14, %SelfNestedBadParam [template]
+// CHECK:STDOUT:   %.18: type = ptr_type %SelfNestedBadParam [template]
+// CHECK:STDOUT:   %.19: type = struct_type {.x: i32, .y: i32} [template]
+// CHECK:STDOUT:   %.20: type = tuple_type (%.18, %.19) [template]
+// CHECK:STDOUT:   %.21: type = array_type %.14, %SelfNestedBadParam [template]
 // CHECK:STDOUT:   %F.type.14: type = fn_type @F.14 [template]
 // CHECK:STDOUT:   %F.15: %F.type.14 = struct_value () [template]
-// CHECK:STDOUT:   %.23: type = struct_type {.x: %SelfNestedBadParam, .y: i32} [template]
-// CHECK:STDOUT:   %.24: type = tuple_type (%.19, %.23) [template]
+// CHECK:STDOUT:   %.22: type = struct_type {.x: %SelfNestedBadParam, .y: i32} [template]
+// CHECK:STDOUT:   %.23: type = tuple_type (%.18, %.22) [template]
 // CHECK:STDOUT:   %SelfNestedBadReturnType: type = class_type @SelfNestedBadReturnType [template]
-// CHECK:STDOUT:   %.25: type = ptr_type %SelfNestedBadReturnType [template]
-// CHECK:STDOUT:   %.26: type = struct_type {.x: %SelfNestedBadReturnType, .y: i32} [template]
-// CHECK:STDOUT:   %.27: type = tuple_type (%.25, %.26) [template]
+// CHECK:STDOUT:   %.24: type = ptr_type %SelfNestedBadReturnType [template]
+// CHECK:STDOUT:   %.25: type = struct_type {.x: %SelfNestedBadReturnType, .y: i32} [template]
+// CHECK:STDOUT:   %.26: type = tuple_type (%.24, %.25) [template]
 // CHECK:STDOUT:   %F.type.15: type = fn_type @F.15 [template]
 // CHECK:STDOUT:   %F.16: %F.type.15 = struct_value () [template]
-// CHECK:STDOUT:   %.28: type = array_type %.14, %SelfNestedBadReturnType [template]
+// CHECK:STDOUT:   %.27: type = array_type %.14, %SelfNestedBadReturnType [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: imports {
@@ -424,7 +423,7 @@ class SelfNestedBadReturnType {
 // CHECK:STDOUT:     %.loc188_52: type = array_type %.loc188_51, %Self.3 [symbolic = @F.13.%.4 (constants.%.15)]
 // CHECK:STDOUT:     %return.var: ref @F.13.%.4 (%.15) = var <return slot>
 // CHECK:STDOUT:   }
-// CHECK:STDOUT:   %.loc188_53: %.17 = assoc_entity element0, %F.decl [template = constants.%.18]
+// CHECK:STDOUT:   %.loc188_53: %.16 = assoc_entity element0, %F.decl [template = constants.%.17]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:
 // CHECK:STDOUT:   .Self = %Self
@@ -651,22 +650,22 @@ class SelfNestedBadReturnType {
 // CHECK:STDOUT: impl @impl.14: %SelfNestedBadParam as %.9 {
 // CHECK:STDOUT:   %F.decl: %F.type.14 = fn_decl @F.14 [template = constants.%F.15] {
 // CHECK:STDOUT:     %SelfNestedBadParam.ref.loc200_14: type = name_ref SelfNestedBadParam, file.%SelfNestedBadParam.decl [template = constants.%SelfNestedBadParam]
-// CHECK:STDOUT:     %.loc200_32: type = ptr_type %SelfNestedBadParam [template = constants.%.19]
+// CHECK:STDOUT:     %.loc200_32: type = ptr_type %SelfNestedBadParam [template = constants.%.18]
 // CHECK:STDOUT:     %int.make_type_32.loc200_40: init type = call constants.%Int32() [template = i32]
 // CHECK:STDOUT:     %.loc200_40.1: type = value_of_initializer %int.make_type_32.loc200_40 [template = i32]
 // CHECK:STDOUT:     %.loc200_40.2: type = converted %int.make_type_32.loc200_40, %.loc200_40.1 [template = i32]
 // CHECK:STDOUT:     %int.make_type_32.loc200_49: init type = call constants.%Int32() [template = i32]
 // CHECK:STDOUT:     %.loc200_49.1: type = value_of_initializer %int.make_type_32.loc200_49 [template = i32]
 // CHECK:STDOUT:     %.loc200_49.2: type = converted %int.make_type_32.loc200_49, %.loc200_49.1 [template = i32]
-// CHECK:STDOUT:     %.loc200_52: type = struct_type {.x: i32, .y: i32} [template = constants.%.20]
+// CHECK:STDOUT:     %.loc200_52: type = struct_type {.x: i32, .y: i32} [template = constants.%.19]
 // CHECK:STDOUT:     %.loc200_53.1: %.12 = tuple_literal (%.loc200_32, %.loc200_52)
-// CHECK:STDOUT:     %.loc200_53.2: type = converted %.loc200_53.1, constants.%.21 [template = constants.%.21]
-// CHECK:STDOUT:     %x.loc200_10.1: %.21 = param x
-// CHECK:STDOUT:     %x.loc200_10.2: %.21 = bind_name x, %x.loc200_10.1
+// CHECK:STDOUT:     %.loc200_53.2: type = converted %.loc200_53.1, constants.%.20 [template = constants.%.20]
+// CHECK:STDOUT:     %x.loc200_10.1: %.20 = param x
+// CHECK:STDOUT:     %x.loc200_10.2: %.20 = bind_name x, %x.loc200_10.1
 // CHECK:STDOUT:     %SelfNestedBadParam.ref.loc200_60: type = name_ref SelfNestedBadParam, file.%SelfNestedBadParam.decl [template = constants.%SelfNestedBadParam]
 // CHECK:STDOUT:     %.loc200_80: i32 = int_literal 4 [template = constants.%.14]
-// CHECK:STDOUT:     %.loc200_81: type = array_type %.loc200_80, %SelfNestedBadParam [template = constants.%.22]
-// CHECK:STDOUT:     %return.var: ref %.22 = var <return slot>
+// CHECK:STDOUT:     %.loc200_81: type = array_type %.loc200_80, %SelfNestedBadParam [template = constants.%.21]
+// CHECK:STDOUT:     %return.var: ref %.21 = var <return slot>
 // CHECK:STDOUT:   }
 // CHECK:STDOUT:   %.1: <witness> = interface_witness (<error>) [template = <error>]
 // CHECK:STDOUT:
@@ -678,20 +677,20 @@ class SelfNestedBadReturnType {
 // CHECK:STDOUT: impl @impl.15: %SelfNestedBadReturnType as %.9 {
 // CHECK:STDOUT:   %F.decl: %F.type.15 = fn_decl @F.15 [template = constants.%F.16] {
 // CHECK:STDOUT:     %SelfNestedBadReturnType.ref.loc212_14: type = name_ref SelfNestedBadReturnType, file.%SelfNestedBadReturnType.decl [template = constants.%SelfNestedBadReturnType]
-// CHECK:STDOUT:     %.loc212_37: type = ptr_type %SelfNestedBadReturnType [template = constants.%.25]
+// CHECK:STDOUT:     %.loc212_37: type = ptr_type %SelfNestedBadReturnType [template = constants.%.24]
 // CHECK:STDOUT:     %SelfNestedBadReturnType.ref.loc212_45: type = name_ref SelfNestedBadReturnType, file.%SelfNestedBadReturnType.decl [template = constants.%SelfNestedBadReturnType]
 // CHECK:STDOUT:     %int.make_type_32: init type = call constants.%Int32() [template = i32]
 // CHECK:STDOUT:     %.loc212_74.1: type = value_of_initializer %int.make_type_32 [template = i32]
 // CHECK:STDOUT:     %.loc212_74.2: type = converted %int.make_type_32, %.loc212_74.1 [template = i32]
-// CHECK:STDOUT:     %.loc212_77: type = struct_type {.x: %SelfNestedBadReturnType, .y: i32} [template = constants.%.26]
+// CHECK:STDOUT:     %.loc212_77: type = struct_type {.x: %SelfNestedBadReturnType, .y: i32} [template = constants.%.25]
 // CHECK:STDOUT:     %.loc212_78.1: %.12 = tuple_literal (%.loc212_37, %.loc212_77)
-// CHECK:STDOUT:     %.loc212_78.2: type = converted %.loc212_78.1, constants.%.27 [template = constants.%.27]
-// CHECK:STDOUT:     %x.loc212_10.1: %.27 = param x
-// CHECK:STDOUT:     %x.loc212_10.2: %.27 = bind_name x, %x.loc212_10.1
+// CHECK:STDOUT:     %.loc212_78.2: type = converted %.loc212_78.1, constants.%.26 [template = constants.%.26]
+// CHECK:STDOUT:     %x.loc212_10.1: %.26 = param x
+// CHECK:STDOUT:     %x.loc212_10.2: %.26 = bind_name x, %x.loc212_10.1
 // CHECK:STDOUT:     %SelfNestedBadParam.ref: type = name_ref SelfNestedBadParam, file.%SelfNestedBadParam.decl [template = constants.%SelfNestedBadParam]
 // CHECK:STDOUT:     %.loc212_105: i32 = int_literal 4 [template = constants.%.14]
-// CHECK:STDOUT:     %.loc212_106: type = array_type %.loc212_105, %SelfNestedBadParam [template = constants.%.22]
-// CHECK:STDOUT:     %return.var: ref %.22 = var <return slot>
+// CHECK:STDOUT:     %.loc212_106: type = array_type %.loc212_105, %SelfNestedBadParam [template = constants.%.21]
+// CHECK:STDOUT:     %return.var: ref %.21 = var <return slot>
 // CHECK:STDOUT:   }
 // CHECK:STDOUT:   %.1: <witness> = interface_witness (<error>) [template = <error>]
 // CHECK:STDOUT:
@@ -883,9 +882,9 @@ class SelfNestedBadReturnType {
 // CHECK:STDOUT:   fn(@SelfNested.%x.loc188_8.2: @F.13.%.3 (%.13)) -> @F.13.%.4 (%.15);
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: fn @F.14(@impl.14.%x.loc200_10.2: %.21) -> %.22;
+// CHECK:STDOUT: fn @F.14(@impl.14.%x.loc200_10.2: %.20) -> %.21;
 // CHECK:STDOUT:
-// CHECK:STDOUT: fn @F.15(@impl.15.%x.loc212_10.2: %.27) -> %.22;
+// CHECK:STDOUT: fn @F.15(@impl.15.%x.loc212_10.2: %.26) -> %.21;
 // CHECK:STDOUT:
 // CHECK:STDOUT: specific @F.1(constants.%Self.1) {}
 // CHECK:STDOUT:
@@ -895,7 +894,7 @@ class SelfNestedBadReturnType {
 // CHECK:STDOUT:   %Self => constants.%Self.3
 // CHECK:STDOUT:   %.1 => constants.%.10
 // CHECK:STDOUT:   %.2 => constants.%.11
-// CHECK:STDOUT:   %.3 => constants.%.16
+// CHECK:STDOUT:   %.3 => constants.%.13
 // CHECK:STDOUT:   %.4 => constants.%.15
 // CHECK:STDOUT: }
 // CHECK:STDOUT:

+ 26 - 27
toolchain/check/testdata/impl/no_prelude/self_in_signature.carbon

@@ -64,23 +64,22 @@ impl D as SelfNested {
 // CHECK:STDOUT:   %.11: type = struct_type {.x: %Self.2, .y: %.2} [symbolic]
 // CHECK:STDOUT:   %.12: type = tuple_type (type, type) [template]
 // CHECK:STDOUT:   %.13: type = tuple_type (%.10, %.11) [symbolic]
-// CHECK:STDOUT:   %.14: type = tuple_type (@F.4.%.1 (%.10), @F.4.%.2 (%.11)) [symbolic]
 // CHECK:STDOUT:   %F.type.4: type = fn_type @F.4 [template]
 // CHECK:STDOUT:   %F.4: %F.type.4 = struct_value () [template]
-// CHECK:STDOUT:   %.15: type = assoc_entity_type @SelfNested, %F.type.4 [template]
-// CHECK:STDOUT:   %.16: %.15 = assoc_entity element0, @SelfNested.%F.decl [template]
-// CHECK:STDOUT:   %.17: type = ptr_type %C [template]
-// CHECK:STDOUT:   %.18: type = struct_type {.x: %C, .y: %.2} [template]
-// CHECK:STDOUT:   %.19: type = tuple_type (%.17, %.18) [template]
+// CHECK:STDOUT:   %.14: type = assoc_entity_type @SelfNested, %F.type.4 [template]
+// CHECK:STDOUT:   %.15: %.14 = assoc_entity element0, @SelfNested.%F.decl [template]
+// CHECK:STDOUT:   %.16: type = ptr_type %C [template]
+// CHECK:STDOUT:   %.17: type = struct_type {.x: %C, .y: %.2} [template]
+// CHECK:STDOUT:   %.18: type = tuple_type (%.16, %.17) [template]
 // CHECK:STDOUT:   %F.type.5: type = fn_type @F.5 [template]
 // CHECK:STDOUT:   %F.5: %F.type.5 = struct_value () [template]
-// CHECK:STDOUT:   %.20: <witness> = interface_witness (%F.5) [template]
-// CHECK:STDOUT:   %.21: type = ptr_type %D [template]
-// CHECK:STDOUT:   %.22: type = struct_type {.x: %D, .y: %.2} [template]
-// CHECK:STDOUT:   %.23: type = tuple_type (%.21, %.22) [template]
+// CHECK:STDOUT:   %.19: <witness> = interface_witness (%F.5) [template]
+// CHECK:STDOUT:   %.20: type = ptr_type %D [template]
+// CHECK:STDOUT:   %.21: type = struct_type {.x: %D, .y: %.2} [template]
+// CHECK:STDOUT:   %.22: type = tuple_type (%.20, %.21) [template]
 // CHECK:STDOUT:   %F.type.6: type = fn_type @F.6 [template]
 // CHECK:STDOUT:   %F.6: %F.type.6 = struct_value () [template]
-// CHECK:STDOUT:   %.24: <witness> = interface_witness (%F.6) [template]
+// CHECK:STDOUT:   %.23: <witness> = interface_witness (%F.6) [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -156,7 +155,7 @@ impl D as SelfNested {
 // CHECK:STDOUT:     %x.loc28_8.1: @F.4.%.3 (%.13) = param x
 // CHECK:STDOUT:     %x.loc28_8.2: @F.4.%.3 (%.13) = bind_name x, %x.loc28_8.1
 // CHECK:STDOUT:   }
-// CHECK:STDOUT:   %.loc28_39: %.15 = assoc_entity element0, %F.decl [template = constants.%.16]
+// CHECK:STDOUT:   %.loc28_39: %.14 = assoc_entity element0, %F.decl [template = constants.%.15]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:
 // CHECK:STDOUT:   .Self = %Self
@@ -203,17 +202,17 @@ impl D as SelfNested {
 // CHECK:STDOUT: impl @impl.3: %C as %.9 {
 // CHECK:STDOUT:   %F.decl: %F.type.5 = fn_decl @F.5 [template = constants.%F.5] {
 // CHECK:STDOUT:     %C.ref.loc32_12: type = name_ref C, file.%C.decl [template = constants.%C]
-// CHECK:STDOUT:     %.loc32_13: type = ptr_type %C [template = constants.%.17]
+// CHECK:STDOUT:     %.loc32_13: type = ptr_type %C [template = constants.%.16]
 // CHECK:STDOUT:     %C.ref.loc32_21: type = name_ref C, file.%C.decl [template = constants.%C]
 // CHECK:STDOUT:     %.loc32_29.1: %.2 = tuple_literal ()
 // CHECK:STDOUT:     %.loc32_29.2: type = converted %.loc32_29.1, constants.%.2 [template = constants.%.2]
-// CHECK:STDOUT:     %.loc32_30: type = struct_type {.x: %C, .y: %.2} [template = constants.%.18]
+// CHECK:STDOUT:     %.loc32_30: type = struct_type {.x: %C, .y: %.2} [template = constants.%.17]
 // CHECK:STDOUT:     %.loc32_31.1: %.12 = tuple_literal (%.loc32_13, %.loc32_30)
-// CHECK:STDOUT:     %.loc32_31.2: type = converted %.loc32_31.1, constants.%.19 [template = constants.%.19]
-// CHECK:STDOUT:     %x.loc32_8.1: %.19 = param x
-// CHECK:STDOUT:     %x.loc32_8.2: %.19 = bind_name x, %x.loc32_8.1
+// CHECK:STDOUT:     %.loc32_31.2: type = converted %.loc32_31.1, constants.%.18 [template = constants.%.18]
+// CHECK:STDOUT:     %x.loc32_8.1: %.18 = param x
+// CHECK:STDOUT:     %x.loc32_8.2: %.18 = bind_name x, %x.loc32_8.1
 // CHECK:STDOUT:   }
-// CHECK:STDOUT:   %.1: <witness> = interface_witness (%F.decl) [template = constants.%.20]
+// CHECK:STDOUT:   %.1: <witness> = interface_witness (%F.decl) [template = constants.%.19]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:
 // CHECK:STDOUT:   .F = %F.decl
@@ -223,17 +222,17 @@ impl D as SelfNested {
 // CHECK:STDOUT: impl @impl.4: %D as %.9 {
 // CHECK:STDOUT:   %F.decl: %F.type.6 = fn_decl @F.6 [template = constants.%F.6] {
 // CHECK:STDOUT:     %Self.ref.loc36_12: type = name_ref Self, constants.%D [template = constants.%D]
-// CHECK:STDOUT:     %.loc36_16: type = ptr_type %D [template = constants.%.21]
+// CHECK:STDOUT:     %.loc36_16: type = ptr_type %D [template = constants.%.20]
 // CHECK:STDOUT:     %Self.ref.loc36_24: type = name_ref Self, constants.%D [template = constants.%D]
 // CHECK:STDOUT:     %.loc36_35.1: %.2 = tuple_literal ()
 // CHECK:STDOUT:     %.loc36_35.2: type = converted %.loc36_35.1, constants.%.2 [template = constants.%.2]
-// CHECK:STDOUT:     %.loc36_36: type = struct_type {.x: %D, .y: %.2} [template = constants.%.22]
+// CHECK:STDOUT:     %.loc36_36: type = struct_type {.x: %D, .y: %.2} [template = constants.%.21]
 // CHECK:STDOUT:     %.loc36_37.1: %.12 = tuple_literal (%.loc36_16, %.loc36_36)
-// CHECK:STDOUT:     %.loc36_37.2: type = converted %.loc36_37.1, constants.%.23 [template = constants.%.23]
-// CHECK:STDOUT:     %x.loc36_8.1: %.23 = param x
-// CHECK:STDOUT:     %x.loc36_8.2: %.23 = bind_name x, %x.loc36_8.1
+// CHECK:STDOUT:     %.loc36_37.2: type = converted %.loc36_37.1, constants.%.22 [template = constants.%.22]
+// CHECK:STDOUT:     %x.loc36_8.1: %.22 = param x
+// CHECK:STDOUT:     %x.loc36_8.2: %.22 = bind_name x, %x.loc36_8.1
 // CHECK:STDOUT:   }
-// CHECK:STDOUT:   %.1: <witness> = interface_witness (%F.decl) [template = constants.%.24]
+// CHECK:STDOUT:   %.1: <witness> = interface_witness (%F.decl) [template = constants.%.23]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:
 // CHECK:STDOUT:   .F = %F.decl
@@ -281,9 +280,9 @@ impl D as SelfNested {
 // CHECK:STDOUT:   fn(@SelfNested.%x.loc28_8.2: @F.4.%.3 (%.13));
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: fn @F.5(@impl.3.%x.loc32_8.2: %.19);
+// CHECK:STDOUT: fn @F.5(@impl.3.%x.loc32_8.2: %.18);
 // CHECK:STDOUT:
-// CHECK:STDOUT: fn @F.6(@impl.4.%x.loc36_8.2: %.23);
+// CHECK:STDOUT: fn @F.6(@impl.4.%x.loc36_8.2: %.22);
 // CHECK:STDOUT:
 // CHECK:STDOUT: specific @F.1(constants.%Self.1) {
 // CHECK:STDOUT:   %Self => constants.%Self.1
@@ -293,6 +292,6 @@ impl D as SelfNested {
 // CHECK:STDOUT:   %Self => constants.%Self.2
 // CHECK:STDOUT:   %.1 => constants.%.10
 // CHECK:STDOUT:   %.2 => constants.%.11
-// CHECK:STDOUT:   %.3 => constants.%.14
+// CHECK:STDOUT:   %.3 => constants.%.13
 // CHECK:STDOUT: }
 // CHECK:STDOUT:

+ 4 - 0
toolchain/check/testdata/interface/no_prelude/generic.carbon

@@ -434,3 +434,7 @@ fn G(T:! Generic(B)) {
 // CHECK:STDOUT:   %T.1 => constants.%T.3
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: specific @F(constants.%T.3) {
+// CHECK:STDOUT:   %T.1 => constants.%T.3
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 5 - 0
toolchain/diagnostics/diagnostic_kind.def

@@ -204,6 +204,11 @@ CARBON_DIAGNOSTIC_KIND(ClassSpecificDeclRepeated)
 CARBON_DIAGNOSTIC_KIND(ClassIncompleteWithinDefinition)
 CARBON_DIAGNOSTIC_KIND(ConstructionOfAbstractClass)
 
+// Deduction.
+CARBON_DIAGNOSTIC_KIND(DeductionIncomplete)
+CARBON_DIAGNOSTIC_KIND(DeductionInconsistent)
+CARBON_DIAGNOSTIC_KIND(DeductionGenericHere)
+
 // Export checking.
 CARBON_DIAGNOSTIC_KIND(ExportNotImportedEntity)
 CARBON_DIAGNOSTIC_KIND(ExportNotImportedEntitySource)