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

Deduplicate and canonicalize all constants. (#3611)

Rather than producing multiple constants with the same value, fold all
instances of a given constant to the same constant instruction.

A future PR will use this to replace the current type canonicalization
system.
Richard Smith 2 лет назад
Родитель
Сommit
29c294880d
100 измененных файлов с 1119 добавлено и 933 удалено
  1. 0 3
      toolchain/check/BUILD
  2. 5 6
      toolchain/check/context.cpp
  3. 12 4
      toolchain/check/eval.cpp
  4. 1 0
      toolchain/check/handle_class.cpp
  5. 10 11
      toolchain/check/testdata/array/assign_var.carbon
  6. 33 37
      toolchain/check/testdata/array/base.carbon
  7. 9 7
      toolchain/check/testdata/array/fail_incomplete_element.carbon
  8. 4 5
      toolchain/check/testdata/array/fail_invalid_type.carbon
  9. 6 7
      toolchain/check/testdata/array/fail_out_of_bound.carbon
  10. 14 23
      toolchain/check/testdata/array/fail_type_mismatch.carbon
  11. 8 10
      toolchain/check/testdata/array/function_param.carbon
  12. 20 21
      toolchain/check/testdata/array/nine_elements.carbon
  13. 10 8
      toolchain/check/testdata/as/identity.carbon
  14. 10 9
      toolchain/check/testdata/as/tuple.carbon
  15. 44 51
      toolchain/check/testdata/basics/numeric_literals.carbon
  16. 25 20
      toolchain/check/testdata/class/base.carbon
  17. 22 15
      toolchain/check/testdata/class/base_field.carbon
  18. 8 5
      toolchain/check/testdata/class/base_function_unqualified.carbon
  19. 19 13
      toolchain/check/testdata/class/base_method.carbon
  20. 30 19
      toolchain/check/testdata/class/base_method_shadow.carbon
  21. 8 6
      toolchain/check/testdata/class/basic.carbon
  22. 43 32
      toolchain/check/testdata/class/derived_to_base.carbon
  23. 25 20
      toolchain/check/testdata/class/fail_abstract.carbon
  24. 4 2
      toolchain/check/testdata/class/fail_addr_not_self.carbon
  25. 6 4
      toolchain/check/testdata/class/fail_addr_self.carbon
  26. 68 38
      toolchain/check/testdata/class/fail_base_bad_type.carbon
  27. 10 6
      toolchain/check/testdata/class/fail_base_method_define.carbon
  28. 1 0
      toolchain/check/testdata/class/fail_base_misplaced.carbon
  29. 23 14
      toolchain/check/testdata/class/fail_base_modifiers.carbon
  30. 8 5
      toolchain/check/testdata/class/fail_base_no_extend.carbon
  31. 17 11
      toolchain/check/testdata/class/fail_base_repeated.carbon
  32. 10 7
      toolchain/check/testdata/class/fail_base_unbound.carbon
  33. 27 15
      toolchain/check/testdata/class/fail_derived_to_base.carbon
  34. 12 10
      toolchain/check/testdata/class/fail_field_modifiers.carbon
  35. 7 5
      toolchain/check/testdata/class/fail_incomplete.carbon
  36. 19 20
      toolchain/check/testdata/class/fail_init.carbon
  37. 15 12
      toolchain/check/testdata/class/fail_init_as_inplace.carbon
  38. 15 10
      toolchain/check/testdata/class/fail_memaccess_category.carbon
  39. 4 3
      toolchain/check/testdata/class/fail_member_of_let.carbon
  40. 5 4
      toolchain/check/testdata/class/fail_method.carbon
  41. 6 3
      toolchain/check/testdata/class/fail_method_modifiers.carbon
  42. 12 6
      toolchain/check/testdata/class/fail_modifiers.carbon
  43. 2 1
      toolchain/check/testdata/class/fail_out_of_line_decl.carbon
  44. 14 7
      toolchain/check/testdata/class/fail_redeclaration_introducer.carbon
  45. 14 7
      toolchain/check/testdata/class/fail_redeclaration_scope.carbon
  46. 4 3
      toolchain/check/testdata/class/fail_redefinition.carbon
  47. 3 2
      toolchain/check/testdata/class/fail_reorder.carbon
  48. 2 1
      toolchain/check/testdata/class/fail_scope.carbon
  49. 5 3
      toolchain/check/testdata/class/fail_self.carbon
  50. 5 1
      toolchain/check/testdata/class/fail_todo_generic.carbon
  51. 11 7
      toolchain/check/testdata/class/fail_todo_modifiers.carbon
  52. 6 4
      toolchain/check/testdata/class/fail_unbound_field.carbon
  53. 6 4
      toolchain/check/testdata/class/fail_unknown_member.carbon
  54. 12 10
      toolchain/check/testdata/class/field_access.carbon
  55. 13 11
      toolchain/check/testdata/class/field_access_in_value.carbon
  56. 6 1
      toolchain/check/testdata/class/forward_declared.carbon
  57. 12 8
      toolchain/check/testdata/class/init.carbon
  58. 12 10
      toolchain/check/testdata/class/init_as.carbon
  59. 18 14
      toolchain/check/testdata/class/init_nested.carbon
  60. 11 8
      toolchain/check/testdata/class/method.carbon
  61. 32 24
      toolchain/check/testdata/class/nested.carbon
  62. 12 9
      toolchain/check/testdata/class/nested_name.carbon
  63. 10 7
      toolchain/check/testdata/class/raw_self.carbon
  64. 8 6
      toolchain/check/testdata/class/raw_self_type.carbon
  65. 2 1
      toolchain/check/testdata/class/redeclaration.carbon
  66. 6 3
      toolchain/check/testdata/class/redeclaration_introducer.carbon
  67. 2 1
      toolchain/check/testdata/class/reenter_scope.carbon
  68. 3 2
      toolchain/check/testdata/class/scope.carbon
  69. 7 4
      toolchain/check/testdata/class/self.carbon
  70. 19 13
      toolchain/check/testdata/class/self_conversion.carbon
  71. 9 6
      toolchain/check/testdata/class/self_type.carbon
  72. 3 2
      toolchain/check/testdata/class/static_method.carbon
  73. 7 0
      toolchain/check/testdata/const/collapse.carbon
  74. 9 0
      toolchain/check/testdata/const/fail_collapse.carbon
  75. 4 8
      toolchain/check/testdata/function/call/fail_param_count.carbon
  76. 1 2
      toolchain/check/testdata/function/call/params_one_comma.carbon
  77. 2 4
      toolchain/check/testdata/function/call/params_two_comma.carbon
  78. 5 1
      toolchain/check/testdata/function/generic/fail_type_param_mismatch.carbon
  79. 5 1
      toolchain/check/testdata/function/generic/type_param.carbon
  80. 1 2
      toolchain/check/testdata/if/fail_reachable_fallthrough.carbon
  81. 5 4
      toolchain/check/testdata/if_expr/fail_not_in_function.carbon
  82. 8 7
      toolchain/check/testdata/if_expr/struct.carbon
  83. 30 48
      toolchain/check/testdata/index/expr_category.carbon
  84. 11 16
      toolchain/check/testdata/index/fail_expr_category.carbon
  85. 12 14
      toolchain/check/testdata/index/fail_invalid_base.carbon
  86. 1 2
      toolchain/check/testdata/index/tuple_return_value_access.carbon
  87. 5 1
      toolchain/check/testdata/interface/fail_duplicate.carbon
  88. 3 4
      toolchain/check/testdata/ir/duplicate_name_same_line.carbon
  89. 1 2
      toolchain/check/testdata/let/convert.carbon
  90. 14 21
      toolchain/check/testdata/let/fail_modifiers.carbon
  91. 5 1
      toolchain/check/testdata/let/generic.carbon
  92. 1 2
      toolchain/check/testdata/namespace/shadow.carbon
  93. 3 4
      toolchain/check/testdata/operators/and.carbon
  94. 17 20
      toolchain/check/testdata/operators/assignment.carbon
  95. 1 2
      toolchain/check/testdata/operators/fail_assignment_to_error.carbon
  96. 35 47
      toolchain/check/testdata/operators/fail_assignment_to_non_assignable.carbon
  97. 2 4
      toolchain/check/testdata/operators/or.carbon
  98. 3 5
      toolchain/check/testdata/operators/unary_op.carbon
  99. 3 2
      toolchain/check/testdata/package_expr/syntax.carbon
  100. 21 22
      toolchain/check/testdata/pointer/address_of_lvalue.carbon

+ 0 - 3
toolchain/check/BUILD

@@ -65,7 +65,6 @@ cc_library(
         "//toolchain/sem_ir:ids",
         "//toolchain/sem_ir:inst",
         "//toolchain/sem_ir:inst_kind",
-        "//toolchain/sem_ir:value_stores",
         "@llvm-project//llvm:Support",
     ],
 )
@@ -96,7 +95,6 @@ cc_library(
         "//toolchain/sem_ir:ids",
         "//toolchain/sem_ir:inst",
         "//toolchain/sem_ir:inst_kind",
-        "//toolchain/sem_ir:value_stores",
         "@llvm-project//llvm:Support",
     ],
 )
@@ -124,7 +122,6 @@ cc_library(
         "//toolchain/sem_ir:ids",
         "//toolchain/sem_ir:inst",
         "//toolchain/sem_ir:inst_kind",
-        "//toolchain/sem_ir:value_stores",
     ],
 )
 

+ 5 - 6
toolchain/check/context.cpp

@@ -100,14 +100,13 @@ auto Context::AddPlaceholderInst(SemIR::ParseNodeAndInst parse_node_and_inst)
 
 auto Context::AddConstant(SemIR::Inst inst, bool is_symbolic)
     -> SemIR::ConstantId {
-  // TODO: Deduplicate constants.
-  auto inst_id = sem_ir().insts().AddInNoBlock(
-      SemIR::ParseNodeAndInst::Untyped(Parse::NodeId::Invalid, inst));
-  constants().Add(inst_id);
-
+  auto [inst_id, added] = constants().GetOrAdd(inst);
   auto const_id = is_symbolic ? SemIR::ConstantId::ForSymbolicConstant(inst_id)
                               : SemIR::ConstantId::ForTemplateConstant(inst_id);
-  constant_values().Set(inst_id, const_id);
+  if (added) {
+    // TODO: Should `ConstantStore` do this for us?
+    constant_values().Set(inst_id, const_id);
+  }
 
   CARBON_VLOG() << "AddConstantInst: " << inst << "\n";
   return const_id;

+ 12 - 4
toolchain/check/eval.cpp

@@ -100,6 +100,9 @@ auto TryEvalInst(Context& context, SemIR::InstId inst_id, SemIR::Inst inst)
       return RebuildIfFieldsAreConstant(context, inst,
                                         &SemIR::BoundMethod::object_id,
                                         &SemIR::BoundMethod::function_id);
+    case SemIR::StructType::Kind:
+      return RebuildIfFieldsAreConstant(context, inst,
+                                        &SemIR::StructType::fields_id);
     case SemIR::StructValue::Kind:
       return RebuildIfFieldsAreConstant(context, inst,
                                         &SemIR::StructValue::elements_id);
@@ -110,23 +113,25 @@ auto TryEvalInst(Context& context, SemIR::InstId inst_id, SemIR::Inst inst)
       return RebuildIfFieldsAreConstant(context, inst,
                                         &SemIR::TupleValue::elements_id);
 
-    // These cases are constants already.
+    // These cases are always constants.
     case SemIR::Builtin::Kind:
     case SemIR::ClassType::Kind:
     case SemIR::ConstType::Kind:
     case SemIR::PointerType::Kind:
-    case SemIR::StructType::Kind:
     case SemIR::StructTypeField::Kind:
     case SemIR::TupleType::Kind:
     case SemIR::UnboundElementType::Kind:
       // TODO: Propagate symbolic / template nature from operands.
-      return SemIR::ConstantId::ForTemplateConstant(inst_id);
+      return context.AddConstant(inst, /*is_symbolic=*/false);
 
+    // These cases are treated as being the unique canonical definition of the
+    // corresponding constant value.
+    // TODO: This doesn't properly handle redeclarations. Consider adding a
+    // corresponding `Value` inst for each of these cases.
     case SemIR::BaseDecl::Kind:
     case SemIR::FieldDecl::Kind:
     case SemIR::FunctionDecl::Kind:
     case SemIR::Namespace::Kind:
-      // TODO: Consider adding a corresponding `Value` inst.
       return SemIR::ConstantId::ForTemplateConstant(inst_id);
 
     case SemIR::BoolLiteral::Kind:
@@ -134,6 +139,9 @@ auto TryEvalInst(Context& context, SemIR::InstId inst_id, SemIR::Inst inst)
     case SemIR::RealLiteral::Kind:
     case SemIR::StringLiteral::Kind:
       // Promote literals to the constant block.
+      // TODO: Convert literals into a canonical form. Currently we can form two
+      // different `i32` constants with the same value if they are represented
+      // by `APInt`s with different bit widths.
       return context.AddConstant(inst, /*is_symbolic=*/false);
 
     // TODO: These need special handling.

+ 1 - 0
toolchain/check/handle_class.cpp

@@ -5,6 +5,7 @@
 #include "toolchain/check/context.h"
 #include "toolchain/check/convert.h"
 #include "toolchain/check/modifiers.h"
+#include "toolchain/sem_ir/typed_insts.h"
 
 namespace Carbon::Check {
 

+ 10 - 11
toolchain/check/testdata/array/assign_var.carbon

@@ -16,12 +16,11 @@ var b: [i32; 3] = a;
 // CHECK:STDOUT:   %.4: i32 = int_literal 1 [template]
 // CHECK:STDOUT:   %.5: i32 = int_literal 2 [template]
 // CHECK:STDOUT:   %.6: i32 = int_literal 3 [template]
-// CHECK:STDOUT:   %.7: i32 = int_literal 3 [template]
-// CHECK:STDOUT:   %.8: type = array_type %.7, i32 [template]
-// CHECK:STDOUT:   %.9: type = ptr_type [i32; 3] [template]
-// CHECK:STDOUT:   %.10: i32 = int_literal 0 [template]
-// CHECK:STDOUT:   %.11: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.12: i32 = int_literal 2 [template]
+// CHECK:STDOUT:   %.7: type = array_type %.6, i32 [template]
+// CHECK:STDOUT:   %.8: type = ptr_type [i32; 3] [template]
+// CHECK:STDOUT:   %.9: i32 = int_literal 0 [template]
+// CHECK:STDOUT:   %.10: i32 = int_literal 1 [template]
+// CHECK:STDOUT:   %.11: i32 = int_literal 2 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -43,24 +42,24 @@ var b: [i32; 3] = a;
 // CHECK:STDOUT:   %.loc7_34.8: init (i32, i32, i32) = tuple_init (%.loc7_34.3, %.loc7_34.5, %.loc7_34.7) to %a.var
 // CHECK:STDOUT:   %.loc7_34.9: init (i32, i32, i32) = converted %.loc7_34.1, %.loc7_34.8
 // CHECK:STDOUT:   assign %a.var, %.loc7_34.9
-// CHECK:STDOUT:   %.loc8_14: i32 = int_literal 3 [template = constants.%.7]
-// CHECK:STDOUT:   %.loc8_15: type = array_type %.loc8_14, i32 [template = constants.%.8]
+// CHECK:STDOUT:   %.loc8_14: i32 = int_literal 3 [template = constants.%.6]
+// CHECK:STDOUT:   %.loc8_15: type = array_type %.loc8_14, i32 [template = constants.%.7]
 // CHECK:STDOUT:   %b.var: ref [i32; 3] = var b
 // CHECK:STDOUT:   %b: ref [i32; 3] = bind_name b, %b.var
 // CHECK:STDOUT:   %a.ref: ref (i32, i32, i32) = name_ref a, %a
 // CHECK:STDOUT:   %.loc8_19.1: ref i32 = tuple_access %a.ref, element0
 // CHECK:STDOUT:   %.loc8_19.2: i32 = bind_value %.loc8_19.1
-// CHECK:STDOUT:   %.loc8_19.3: i32 = int_literal 0 [template = constants.%.10]
+// CHECK:STDOUT:   %.loc8_19.3: i32 = int_literal 0 [template = constants.%.9]
 // CHECK:STDOUT:   %.loc8_19.4: ref i32 = array_index %b.var, %.loc8_19.3
 // CHECK:STDOUT:   %.loc8_19.5: init i32 = initialize_from %.loc8_19.2 to %.loc8_19.4
 // CHECK:STDOUT:   %.loc8_19.6: ref i32 = tuple_access %a.ref, element1
 // CHECK:STDOUT:   %.loc8_19.7: i32 = bind_value %.loc8_19.6
-// CHECK:STDOUT:   %.loc8_19.8: i32 = int_literal 1 [template = constants.%.11]
+// CHECK:STDOUT:   %.loc8_19.8: i32 = int_literal 1 [template = constants.%.10]
 // CHECK:STDOUT:   %.loc8_19.9: ref i32 = array_index %b.var, %.loc8_19.8
 // CHECK:STDOUT:   %.loc8_19.10: init i32 = initialize_from %.loc8_19.7 to %.loc8_19.9
 // CHECK:STDOUT:   %.loc8_19.11: ref i32 = tuple_access %a.ref, element2
 // CHECK:STDOUT:   %.loc8_19.12: i32 = bind_value %.loc8_19.11
-// CHECK:STDOUT:   %.loc8_19.13: i32 = int_literal 2 [template = constants.%.12]
+// CHECK:STDOUT:   %.loc8_19.13: i32 = int_literal 2 [template = constants.%.11]
 // CHECK:STDOUT:   %.loc8_19.14: ref i32 = array_index %b.var, %.loc8_19.13
 // CHECK:STDOUT:   %.loc8_19.15: init i32 = initialize_from %.loc8_19.12 to %.loc8_19.14
 // CHECK:STDOUT:   %.loc8_19.16: init [i32; 3] = array_init (%.loc8_19.5, %.loc8_19.10, %.loc8_19.15) to %b.var

+ 33 - 37
toolchain/check/testdata/array/base.carbon

@@ -14,27 +14,23 @@ var c: [(); 5] = ((), (), (), (), (),);
 // CHECK:STDOUT:   %.1: i32 = int_literal 1 [template]
 // CHECK:STDOUT:   %.2: type = array_type %.1, i32 [template]
 // CHECK:STDOUT:   %.3: type = ptr_type [i32; 1] [template]
-// CHECK:STDOUT:   %.4: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.5: type = tuple_type (i32) [template]
-// CHECK:STDOUT:   %.6: i32 = int_literal 0 [template]
-// CHECK:STDOUT:   %.7: i32 = int_literal 2 [template]
-// CHECK:STDOUT:   %.8: type = array_type %.7, f64 [template]
-// CHECK:STDOUT:   %.9: type = ptr_type [f64; 2] [template]
-// CHECK:STDOUT:   %.10: f64 = real_literal 111e-1 [template]
-// CHECK:STDOUT:   %.11: f64 = real_literal 22e-1 [template]
-// CHECK:STDOUT:   %.12: type = tuple_type (f64, f64) [template]
-// CHECK:STDOUT:   %.13: i32 = int_literal 0 [template]
-// CHECK:STDOUT:   %.14: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.15: type = tuple_type () [template]
-// CHECK:STDOUT:   %.16: i32 = int_literal 5 [template]
-// CHECK:STDOUT:   %.17: type = array_type %.16, () [template]
-// CHECK:STDOUT:   %.18: type = ptr_type [(); 5] [template]
-// CHECK:STDOUT:   %.19: type = tuple_type ((), (), (), (), ()) [template]
-// CHECK:STDOUT:   %.20: i32 = int_literal 0 [template]
-// CHECK:STDOUT:   %.21: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.22: i32 = int_literal 2 [template]
-// CHECK:STDOUT:   %.23: i32 = int_literal 3 [template]
-// CHECK:STDOUT:   %.24: i32 = int_literal 4 [template]
+// CHECK:STDOUT:   %.4: type = tuple_type (i32) [template]
+// CHECK:STDOUT:   %.5: i32 = int_literal 0 [template]
+// CHECK:STDOUT:   %.6: i32 = int_literal 2 [template]
+// CHECK:STDOUT:   %.7: type = array_type %.6, f64 [template]
+// CHECK:STDOUT:   %.8: type = ptr_type [f64; 2] [template]
+// CHECK:STDOUT:   %.9: f64 = real_literal 111e-1 [template]
+// CHECK:STDOUT:   %.10: f64 = real_literal 22e-1 [template]
+// CHECK:STDOUT:   %.11: type = tuple_type (f64, f64) [template]
+// CHECK:STDOUT:   %.12: i32 = int_literal 1 [template]
+// CHECK:STDOUT:   %.13: type = tuple_type () [template]
+// CHECK:STDOUT:   %.14: i32 = int_literal 5 [template]
+// CHECK:STDOUT:   %.15: type = array_type %.14, () [template]
+// CHECK:STDOUT:   %.16: type = ptr_type [(); 5] [template]
+// CHECK:STDOUT:   %.17: type = tuple_type ((), (), (), (), ()) [template]
+// CHECK:STDOUT:   %.18: i32 = int_literal 2 [template]
+// CHECK:STDOUT:   %.19: i32 = int_literal 3 [template]
+// CHECK:STDOUT:   %.20: i32 = int_literal 4 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -43,34 +39,34 @@ var c: [(); 5] = ((), (), (), (), (),);
 // CHECK:STDOUT:   %.loc7_15: type = array_type %.loc7_14, i32 [template = constants.%.2]
 // CHECK:STDOUT:   %a.var: ref [i32; 1] = var a
 // CHECK:STDOUT:   %a: ref [i32; 1] = bind_name a, %a.var
-// CHECK:STDOUT:   %.loc7_20: i32 = int_literal 1 [template = constants.%.4]
+// CHECK:STDOUT:   %.loc7_20: i32 = int_literal 1 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc7_22.1: (i32,) = tuple_literal (%.loc7_20)
-// CHECK:STDOUT:   %.loc7_22.2: i32 = int_literal 0 [template = constants.%.6]
+// CHECK:STDOUT:   %.loc7_22.2: i32 = int_literal 0 [template = constants.%.5]
 // CHECK:STDOUT:   %.loc7_22.3: ref i32 = array_index %a.var, %.loc7_22.2
 // CHECK:STDOUT:   %.loc7_22.4: init i32 = initialize_from %.loc7_20 to %.loc7_22.3
 // CHECK:STDOUT:   %.loc7_22.5: init [i32; 1] = array_init (%.loc7_22.4) to %a.var
 // CHECK:STDOUT:   %.loc7_22.6: init [i32; 1] = converted %.loc7_22.1, %.loc7_22.5
 // CHECK:STDOUT:   assign %a.var, %.loc7_22.6
-// CHECK:STDOUT:   %.loc8_14: i32 = int_literal 2 [template = constants.%.7]
-// CHECK:STDOUT:   %.loc8_15: type = array_type %.loc8_14, f64 [template = constants.%.8]
+// CHECK:STDOUT:   %.loc8_14: i32 = int_literal 2 [template = constants.%.6]
+// CHECK:STDOUT:   %.loc8_15: type = array_type %.loc8_14, f64 [template = constants.%.7]
 // CHECK:STDOUT:   %b.var: ref [f64; 2] = var b
 // CHECK:STDOUT:   %b: ref [f64; 2] = bind_name b, %b.var
-// CHECK:STDOUT:   %.loc8_20: f64 = real_literal 111e-1 [template = constants.%.10]
-// CHECK:STDOUT:   %.loc8_26: f64 = real_literal 22e-1 [template = constants.%.11]
+// CHECK:STDOUT:   %.loc8_20: f64 = real_literal 111e-1 [template = constants.%.9]
+// CHECK:STDOUT:   %.loc8_26: f64 = real_literal 22e-1 [template = constants.%.10]
 // CHECK:STDOUT:   %.loc8_30.1: (f64, f64) = tuple_literal (%.loc8_20, %.loc8_26)
-// CHECK:STDOUT:   %.loc8_30.2: i32 = int_literal 0 [template = constants.%.13]
+// CHECK:STDOUT:   %.loc8_30.2: i32 = int_literal 0 [template = constants.%.5]
 // CHECK:STDOUT:   %.loc8_30.3: ref f64 = array_index %b.var, %.loc8_30.2
 // CHECK:STDOUT:   %.loc8_30.4: init f64 = initialize_from %.loc8_20 to %.loc8_30.3
-// CHECK:STDOUT:   %.loc8_30.5: i32 = int_literal 1 [template = constants.%.14]
+// CHECK:STDOUT:   %.loc8_30.5: i32 = int_literal 1 [template = constants.%.12]
 // CHECK:STDOUT:   %.loc8_30.6: ref f64 = array_index %b.var, %.loc8_30.5
 // CHECK:STDOUT:   %.loc8_30.7: init f64 = initialize_from %.loc8_26 to %.loc8_30.6
 // CHECK:STDOUT:   %.loc8_30.8: init [f64; 2] = array_init (%.loc8_30.4, %.loc8_30.7) to %b.var
 // CHECK:STDOUT:   %.loc8_30.9: init [f64; 2] = converted %.loc8_30.1, %.loc8_30.8
 // CHECK:STDOUT:   assign %b.var, %.loc8_30.9
 // CHECK:STDOUT:   %.loc9_10.1: () = tuple_literal ()
-// CHECK:STDOUT:   %.loc9_13: i32 = int_literal 5 [template = constants.%.16]
-// CHECK:STDOUT:   %.loc9_10.2: type = converted %.loc9_10.1, constants.%.15 [template = constants.%.15]
-// CHECK:STDOUT:   %.loc9_14: type = array_type %.loc9_13, () [template = constants.%.17]
+// CHECK:STDOUT:   %.loc9_13: i32 = int_literal 5 [template = constants.%.14]
+// CHECK:STDOUT:   %.loc9_10.2: type = converted %.loc9_10.1, constants.%.13 [template = constants.%.13]
+// CHECK:STDOUT:   %.loc9_14: type = array_type %.loc9_13, () [template = constants.%.15]
 // CHECK:STDOUT:   %c.var: ref [(); 5] = var c
 // CHECK:STDOUT:   %c: ref [(); 5] = bind_name c, %c.var
 // CHECK:STDOUT:   %.loc9_20.1: () = tuple_literal ()
@@ -79,23 +75,23 @@ var c: [(); 5] = ((), (), (), (), (),);
 // CHECK:STDOUT:   %.loc9_32.1: () = tuple_literal ()
 // CHECK:STDOUT:   %.loc9_36.1: () = tuple_literal ()
 // CHECK:STDOUT:   %.loc9_38.1: ((), (), (), (), ()) = tuple_literal (%.loc9_20.1, %.loc9_24.1, %.loc9_28.1, %.loc9_32.1, %.loc9_36.1)
-// CHECK:STDOUT:   %.loc9_38.2: i32 = int_literal 0 [template = constants.%.20]
+// CHECK:STDOUT:   %.loc9_38.2: i32 = int_literal 0 [template = constants.%.5]
 // CHECK:STDOUT:   %.loc9_38.3: ref () = array_index %c.var, %.loc9_38.2
 // CHECK:STDOUT:   %.loc9_20.2: init () = tuple_init () to %.loc9_38.3
 // CHECK:STDOUT:   %.loc9_20.3: init () = converted %.loc9_20.1, %.loc9_20.2
-// CHECK:STDOUT:   %.loc9_38.4: i32 = int_literal 1 [template = constants.%.21]
+// CHECK:STDOUT:   %.loc9_38.4: i32 = int_literal 1 [template = constants.%.12]
 // CHECK:STDOUT:   %.loc9_38.5: ref () = array_index %c.var, %.loc9_38.4
 // CHECK:STDOUT:   %.loc9_24.2: init () = tuple_init () to %.loc9_38.5
 // CHECK:STDOUT:   %.loc9_24.3: init () = converted %.loc9_24.1, %.loc9_24.2
-// CHECK:STDOUT:   %.loc9_38.6: i32 = int_literal 2 [template = constants.%.22]
+// CHECK:STDOUT:   %.loc9_38.6: i32 = int_literal 2 [template = constants.%.18]
 // CHECK:STDOUT:   %.loc9_38.7: ref () = array_index %c.var, %.loc9_38.6
 // CHECK:STDOUT:   %.loc9_28.2: init () = tuple_init () to %.loc9_38.7
 // CHECK:STDOUT:   %.loc9_28.3: init () = converted %.loc9_28.1, %.loc9_28.2
-// CHECK:STDOUT:   %.loc9_38.8: i32 = int_literal 3 [template = constants.%.23]
+// CHECK:STDOUT:   %.loc9_38.8: i32 = int_literal 3 [template = constants.%.19]
 // CHECK:STDOUT:   %.loc9_38.9: ref () = array_index %c.var, %.loc9_38.8
 // CHECK:STDOUT:   %.loc9_32.2: init () = tuple_init () to %.loc9_38.9
 // CHECK:STDOUT:   %.loc9_32.3: init () = converted %.loc9_32.1, %.loc9_32.2
-// CHECK:STDOUT:   %.loc9_38.10: i32 = int_literal 4 [template = constants.%.24]
+// CHECK:STDOUT:   %.loc9_38.10: i32 = int_literal 4 [template = constants.%.20]
 // CHECK:STDOUT:   %.loc9_38.11: ref () = array_index %c.var, %.loc9_38.10
 // CHECK:STDOUT:   %.loc9_36.2: init () = tuple_init () to %.loc9_38.11
 // CHECK:STDOUT:   %.loc9_36.3: init () = converted %.loc9_36.1, %.loc9_36.2

+ 9 - 7
toolchain/check/testdata/array/fail_incomplete_element.carbon

@@ -22,27 +22,29 @@ var p: Incomplete* = &a[0];
 // CHECK:STDOUT: --- fail_incomplete_element.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %Incomplete: type = class_type @Incomplete [template]
 // CHECK:STDOUT:   %.1: i32 = int_literal 1 [template]
 // CHECK:STDOUT:   %.2: type = array_type %.1, Incomplete [template]
-// CHECK:STDOUT:   %.3: i32 = int_literal 0 [template]
-// CHECK:STDOUT:   %.4: type = ptr_type <error> [template]
+// CHECK:STDOUT:   %.3: type = ptr_type Incomplete [template]
+// CHECK:STDOUT:   %.4: i32 = int_literal 0 [template]
+// CHECK:STDOUT:   %.5: type = ptr_type <error> [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Incomplete = %Incomplete.decl, .a = %a, .p = %p} [template]
 // CHECK:STDOUT:   %Incomplete.decl = class_decl @Incomplete, ()
-// CHECK:STDOUT:   %Incomplete: type = class_type @Incomplete [template]
-// CHECK:STDOUT:   %Incomplete.ref.loc15: type = name_ref Incomplete, %Incomplete [template = %Incomplete]
+// CHECK:STDOUT:   %Incomplete: type = class_type @Incomplete [template = constants.%Incomplete]
+// CHECK:STDOUT:   %Incomplete.ref.loc15: type = name_ref Incomplete, %Incomplete [template = constants.%Incomplete]
 // CHECK:STDOUT:   %.loc15_21: i32 = int_literal 1 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc15_22: type = array_type %.loc15_21, Incomplete [template = constants.%.2]
 // CHECK:STDOUT:   %a.var: ref <error> = var a
 // CHECK:STDOUT:   %a: ref <error> = bind_name a, %a.var
-// CHECK:STDOUT:   %Incomplete.ref.loc20: type = name_ref Incomplete, %Incomplete [template = %Incomplete]
-// CHECK:STDOUT:   %.loc20_18: type = ptr_type Incomplete [template]
+// CHECK:STDOUT:   %Incomplete.ref.loc20: type = name_ref Incomplete, %Incomplete [template = constants.%Incomplete]
+// CHECK:STDOUT:   %.loc20_18: type = ptr_type Incomplete [template = constants.%.3]
 // CHECK:STDOUT:   %p.var: ref Incomplete* = var p
 // CHECK:STDOUT:   %p: ref Incomplete* = bind_name p, %p.var
 // CHECK:STDOUT:   %a.ref: ref <error> = name_ref a, %a
-// CHECK:STDOUT:   %.loc20_25: i32 = int_literal 0 [template = constants.%.3]
+// CHECK:STDOUT:   %.loc20_25: i32 = int_literal 0 [template = constants.%.4]
 // CHECK:STDOUT:   %.loc20_22: <error>* = addr_of <error>
 // CHECK:STDOUT:   assign %p.var, <error>
 // CHECK:STDOUT: }

+ 4 - 5
toolchain/check/testdata/array/fail_invalid_type.carbon

@@ -13,16 +13,15 @@ var a: [1; 1];
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
 // CHECK:STDOUT:   %.1: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.2: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.3: type = array_type %.2, <error> [template]
-// CHECK:STDOUT:   %.4: type = ptr_type [<error>; 1] [template]
+// CHECK:STDOUT:   %.2: type = array_type %.1, <error> [template]
+// CHECK:STDOUT:   %.3: type = ptr_type [<error>; 1] [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.a = %a} [template]
 // CHECK:STDOUT:   %.loc10_9: i32 = int_literal 1 [template = constants.%.1]
-// CHECK:STDOUT:   %.loc10_12: i32 = int_literal 1 [template = constants.%.2]
-// CHECK:STDOUT:   %.loc10_13: type = array_type %.loc10_12, <error> [template = constants.%.3]
+// CHECK:STDOUT:   %.loc10_12: i32 = int_literal 1 [template = constants.%.1]
+// CHECK:STDOUT:   %.loc10_13: type = array_type %.loc10_12, <error> [template = constants.%.2]
 // CHECK:STDOUT:   %a.var: ref [<error>; 1] = var a
 // CHECK:STDOUT:   %a: ref [<error>; 1] = bind_name a, %a.var
 // CHECK:STDOUT: }

+ 6 - 7
toolchain/check/testdata/array/fail_out_of_bound.carbon

@@ -15,10 +15,9 @@ var a: [i32; 1] = (1, 2, 3);
 // CHECK:STDOUT:   %.1: i32 = int_literal 1 [template]
 // CHECK:STDOUT:   %.2: type = array_type %.1, i32 [template]
 // CHECK:STDOUT:   %.3: type = ptr_type [i32; 1] [template]
-// CHECK:STDOUT:   %.4: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.5: i32 = int_literal 2 [template]
-// CHECK:STDOUT:   %.6: i32 = int_literal 3 [template]
-// CHECK:STDOUT:   %.7: type = tuple_type (i32, i32, i32) [template]
+// CHECK:STDOUT:   %.4: i32 = int_literal 2 [template]
+// CHECK:STDOUT:   %.5: i32 = int_literal 3 [template]
+// CHECK:STDOUT:   %.6: type = tuple_type (i32, i32, i32) [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -27,9 +26,9 @@ var a: [i32; 1] = (1, 2, 3);
 // CHECK:STDOUT:   %.loc10_15: type = array_type %.loc10_14, i32 [template = constants.%.2]
 // CHECK:STDOUT:   %a.var: ref [i32; 1] = var a
 // CHECK:STDOUT:   %a: ref [i32; 1] = bind_name a, %a.var
-// CHECK:STDOUT:   %.loc10_20: i32 = int_literal 1 [template = constants.%.4]
-// CHECK:STDOUT:   %.loc10_23: i32 = int_literal 2 [template = constants.%.5]
-// CHECK:STDOUT:   %.loc10_26: i32 = int_literal 3 [template = constants.%.6]
+// CHECK:STDOUT:   %.loc10_20: i32 = int_literal 1 [template = constants.%.1]
+// CHECK:STDOUT:   %.loc10_23: i32 = int_literal 2 [template = constants.%.4]
+// CHECK:STDOUT:   %.loc10_26: i32 = int_literal 3 [template = constants.%.5]
 // CHECK:STDOUT:   %.loc10_27: (i32, i32, i32) = tuple_literal (%.loc10_20, %.loc10_23, %.loc10_26)
 // CHECK:STDOUT:   assign %a.var, <error>
 // CHECK:STDOUT: }

+ 14 - 23
toolchain/check/testdata/array/fail_type_mismatch.carbon

@@ -42,19 +42,10 @@ var d: [i32; 3] = t2;
 // CHECK:STDOUT:   %.11: type = tuple_type (type, type, type) [template]
 // CHECK:STDOUT:   %.12: type = tuple_type (i32, String*, String*) [template]
 // CHECK:STDOUT:   %.13: type = ptr_type (i32, String*, String*) [template]
-// CHECK:STDOUT:   %.14: i32 = int_literal 3 [template]
-// CHECK:STDOUT:   %.15: type = array_type %.14, i32 [template]
-// CHECK:STDOUT:   %.16: i32 = int_literal 0 [template]
-// CHECK:STDOUT:   %.17: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.18: i32 = int_literal 3 [template]
-// CHECK:STDOUT:   %.19: type = array_type %.18, i32 [template]
-// CHECK:STDOUT:   %.20: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.21: i32 = int_literal 2 [template]
-// CHECK:STDOUT:   %.22: type = tuple_type (i32, i32) [template]
-// CHECK:STDOUT:   %.23: type = tuple_type (type, type) [template]
-// CHECK:STDOUT:   %.24: type = ptr_type (i32, i32) [template]
-// CHECK:STDOUT:   %.25: i32 = int_literal 3 [template]
-// CHECK:STDOUT:   %.26: type = array_type %.25, i32 [template]
+// CHECK:STDOUT:   %.14: i32 = int_literal 2 [template]
+// CHECK:STDOUT:   %.15: type = tuple_type (i32, i32) [template]
+// CHECK:STDOUT:   %.16: type = tuple_type (type, type) [template]
+// CHECK:STDOUT:   %.17: type = ptr_type (i32, i32) [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -75,32 +66,32 @@ var d: [i32; 3] = t2;
 // CHECK:STDOUT:   %.loc12_29.2: type = converted %.loc12_29.1, constants.%.8 [template = constants.%.8]
 // CHECK:STDOUT:   %t1.var: ref (i32, String, String) = var t1
 // CHECK:STDOUT:   %t1: ref (i32, String, String) = bind_name t1, %t1.var
-// CHECK:STDOUT:   %.loc16_14: i32 = int_literal 3 [template = constants.%.14]
-// CHECK:STDOUT:   %.loc16_15: type = array_type %.loc16_14, i32 [template = constants.%.15]
+// CHECK:STDOUT:   %.loc16_14: i32 = int_literal 3 [template = constants.%.1]
+// CHECK:STDOUT:   %.loc16_15: type = array_type %.loc16_14, i32 [template = constants.%.2]
 // CHECK:STDOUT:   %b.var: ref [i32; 3] = var b
 // CHECK:STDOUT:   %b: ref [i32; 3] = bind_name b, %b.var
 // CHECK:STDOUT:   %t1.ref: ref (i32, String, String) = name_ref t1, %t1
 // CHECK:STDOUT:   %.loc16_19.1: ref i32 = tuple_access %t1.ref, element0
 // CHECK:STDOUT:   %.loc16_19.2: i32 = bind_value %.loc16_19.1
-// CHECK:STDOUT:   %.loc16_19.3: i32 = int_literal 0 [template = constants.%.16]
+// CHECK:STDOUT:   %.loc16_19.3: i32 = int_literal 0 [template = constants.%.9]
 // CHECK:STDOUT:   %.loc16_19.4: ref i32 = array_index %b.var, %.loc16_19.3
 // CHECK:STDOUT:   %.loc16_19.5: init i32 = initialize_from %.loc16_19.2 to %.loc16_19.4
 // CHECK:STDOUT:   %.loc16_19.6: ref String = tuple_access %t1.ref, element1
 // CHECK:STDOUT:   assign %b.var, <error>
-// CHECK:STDOUT:   %.loc21_14: i32 = int_literal 3 [template = constants.%.18]
-// CHECK:STDOUT:   %.loc21_15: type = array_type %.loc21_14, i32 [template = constants.%.19]
+// CHECK:STDOUT:   %.loc21_14: i32 = int_literal 3 [template = constants.%.1]
+// CHECK:STDOUT:   %.loc21_15: type = array_type %.loc21_14, i32 [template = constants.%.2]
 // CHECK:STDOUT:   %c.var: ref [i32; 3] = var c
 // CHECK:STDOUT:   %c: ref [i32; 3] = bind_name c, %c.var
-// CHECK:STDOUT:   %.loc21_20: i32 = int_literal 1 [template = constants.%.20]
-// CHECK:STDOUT:   %.loc21_23: i32 = int_literal 2 [template = constants.%.21]
+// CHECK:STDOUT:   %.loc21_20: i32 = int_literal 1 [template = constants.%.4]
+// CHECK:STDOUT:   %.loc21_23: i32 = int_literal 2 [template = constants.%.14]
 // CHECK:STDOUT:   %.loc21_24: (i32, i32) = tuple_literal (%.loc21_20, %.loc21_23)
 // CHECK:STDOUT:   assign %c.var, <error>
 // CHECK:STDOUT:   %.loc23_18.1: (type, type) = tuple_literal (i32, i32)
-// CHECK:STDOUT:   %.loc23_18.2: type = converted %.loc23_18.1, constants.%.22 [template = constants.%.22]
+// CHECK:STDOUT:   %.loc23_18.2: type = converted %.loc23_18.1, constants.%.15 [template = constants.%.15]
 // CHECK:STDOUT:   %t2.var: ref (i32, i32) = var t2
 // CHECK:STDOUT:   %t2: ref (i32, i32) = bind_name t2, %t2.var
-// CHECK:STDOUT:   %.loc27_14: i32 = int_literal 3 [template = constants.%.25]
-// CHECK:STDOUT:   %.loc27_15: type = array_type %.loc27_14, i32 [template = constants.%.26]
+// CHECK:STDOUT:   %.loc27_14: i32 = int_literal 3 [template = constants.%.1]
+// CHECK:STDOUT:   %.loc27_15: type = array_type %.loc27_14, i32 [template = constants.%.2]
 // CHECK:STDOUT:   %d.var: ref [i32; 3] = var d
 // CHECK:STDOUT:   %d: ref [i32; 3] = bind_name d, %d.var
 // CHECK:STDOUT:   %t2.ref: ref (i32, i32) = name_ref t2, %t2

+ 8 - 10
toolchain/check/testdata/array/function_param.carbon

@@ -20,12 +20,10 @@ fn G() -> i32 {
 // CHECK:STDOUT:   %.3: type = ptr_type [i32; 3] [template]
 // CHECK:STDOUT:   %.4: i32 = int_literal 1 [template]
 // CHECK:STDOUT:   %.5: i32 = int_literal 2 [template]
-// CHECK:STDOUT:   %.6: i32 = int_literal 3 [template]
-// CHECK:STDOUT:   %.7: type = tuple_type (i32, i32, i32) [template]
+// CHECK:STDOUT:   %.6: type = tuple_type (i32, i32, i32) [template]
+// CHECK:STDOUT:   %.7: i32 = int_literal 0 [template]
 // CHECK:STDOUT:   %.8: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.9: i32 = int_literal 0 [template]
-// CHECK:STDOUT:   %.10: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.11: i32 = int_literal 2 [template]
+// CHECK:STDOUT:   %.9: i32 = int_literal 2 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -49,17 +47,17 @@ fn G() -> i32 {
 // CHECK:STDOUT:   %F.ref: <function> = name_ref F, file.%F [template = file.%F]
 // CHECK:STDOUT:   %.loc12_13: i32 = int_literal 1 [template = constants.%.4]
 // CHECK:STDOUT:   %.loc12_16: i32 = int_literal 2 [template = constants.%.5]
-// CHECK:STDOUT:   %.loc12_19: i32 = int_literal 3 [template = constants.%.6]
+// CHECK:STDOUT:   %.loc12_19: i32 = int_literal 3 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc12_20.1: (i32, i32, i32) = tuple_literal (%.loc12_13, %.loc12_16, %.loc12_19)
-// CHECK:STDOUT:   %.loc12_23: i32 = int_literal 1 [template = constants.%.8]
+// CHECK:STDOUT:   %.loc12_23: i32 = int_literal 1 [template = constants.%.4]
 // CHECK:STDOUT:   %.loc12_20.2: ref [i32; 3] = temporary_storage
-// CHECK:STDOUT:   %.loc12_20.3: i32 = int_literal 0 [template = constants.%.9]
+// CHECK:STDOUT:   %.loc12_20.3: i32 = int_literal 0 [template = constants.%.7]
 // CHECK:STDOUT:   %.loc12_20.4: ref i32 = array_index %.loc12_20.2, %.loc12_20.3
 // CHECK:STDOUT:   %.loc12_20.5: init i32 = initialize_from %.loc12_13 to %.loc12_20.4
-// CHECK:STDOUT:   %.loc12_20.6: i32 = int_literal 1 [template = constants.%.10]
+// CHECK:STDOUT:   %.loc12_20.6: i32 = int_literal 1 [template = constants.%.8]
 // CHECK:STDOUT:   %.loc12_20.7: ref i32 = array_index %.loc12_20.2, %.loc12_20.6
 // CHECK:STDOUT:   %.loc12_20.8: init i32 = initialize_from %.loc12_16 to %.loc12_20.7
-// CHECK:STDOUT:   %.loc12_20.9: i32 = int_literal 2 [template = constants.%.11]
+// CHECK:STDOUT:   %.loc12_20.9: i32 = int_literal 2 [template = constants.%.9]
 // CHECK:STDOUT:   %.loc12_20.10: ref i32 = array_index %.loc12_20.2, %.loc12_20.9
 // CHECK:STDOUT:   %.loc12_20.11: init i32 = initialize_from %.loc12_19 to %.loc12_20.10
 // CHECK:STDOUT:   %.loc12_20.12: init [i32; 3] = array_init (%.loc12_20.5, %.loc12_20.8, %.loc12_20.11) to %.loc12_20.2

+ 20 - 21
toolchain/check/testdata/array/nine_elements.carbon

@@ -20,17 +20,16 @@ var a: [i32; 9] = (1, 2, 3, 4, 5, 6, 7, 8, 9);
 // CHECK:STDOUT:   %.9: i32 = int_literal 6 [template]
 // CHECK:STDOUT:   %.10: i32 = int_literal 7 [template]
 // CHECK:STDOUT:   %.11: i32 = int_literal 8 [template]
-// CHECK:STDOUT:   %.12: i32 = int_literal 9 [template]
-// CHECK:STDOUT:   %.13: type = tuple_type (i32, i32, i32, i32, i32, i32, i32, i32, i32) [template]
-// CHECK:STDOUT:   %.14: i32 = int_literal 0 [template]
-// CHECK:STDOUT:   %.15: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.16: i32 = int_literal 2 [template]
-// CHECK:STDOUT:   %.17: i32 = int_literal 3 [template]
-// CHECK:STDOUT:   %.18: i32 = int_literal 4 [template]
-// CHECK:STDOUT:   %.19: i32 = int_literal 5 [template]
-// CHECK:STDOUT:   %.20: i32 = int_literal 6 [template]
-// CHECK:STDOUT:   %.21: i32 = int_literal 7 [template]
-// CHECK:STDOUT:   %.22: i32 = int_literal 8 [template]
+// CHECK:STDOUT:   %.12: type = tuple_type (i32, i32, i32, i32, i32, i32, i32, i32, i32) [template]
+// CHECK:STDOUT:   %.13: i32 = int_literal 0 [template]
+// CHECK:STDOUT:   %.14: i32 = int_literal 1 [template]
+// CHECK:STDOUT:   %.15: i32 = int_literal 2 [template]
+// CHECK:STDOUT:   %.16: i32 = int_literal 3 [template]
+// CHECK:STDOUT:   %.17: i32 = int_literal 4 [template]
+// CHECK:STDOUT:   %.18: i32 = int_literal 5 [template]
+// CHECK:STDOUT:   %.19: i32 = int_literal 6 [template]
+// CHECK:STDOUT:   %.20: i32 = int_literal 7 [template]
+// CHECK:STDOUT:   %.21: i32 = int_literal 8 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -47,33 +46,33 @@ var a: [i32; 9] = (1, 2, 3, 4, 5, 6, 7, 8, 9);
 // CHECK:STDOUT:   %.loc7_35: i32 = int_literal 6 [template = constants.%.9]
 // CHECK:STDOUT:   %.loc7_38: i32 = int_literal 7 [template = constants.%.10]
 // CHECK:STDOUT:   %.loc7_41: i32 = int_literal 8 [template = constants.%.11]
-// CHECK:STDOUT:   %.loc7_44: i32 = int_literal 9 [template = constants.%.12]
+// CHECK:STDOUT:   %.loc7_44: i32 = int_literal 9 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc7_45.1: (i32, i32, i32, i32, i32, i32, i32, i32, i32) = tuple_literal (%.loc7_20, %.loc7_23, %.loc7_26, %.loc7_29, %.loc7_32, %.loc7_35, %.loc7_38, %.loc7_41, %.loc7_44)
-// CHECK:STDOUT:   %.loc7_45.2: i32 = int_literal 0 [template = constants.%.14]
+// CHECK:STDOUT:   %.loc7_45.2: i32 = int_literal 0 [template = constants.%.13]
 // CHECK:STDOUT:   %.loc7_45.3: ref i32 = array_index %a.var, %.loc7_45.2
 // CHECK:STDOUT:   %.loc7_45.4: init i32 = initialize_from %.loc7_20 to %.loc7_45.3
-// CHECK:STDOUT:   %.loc7_45.5: i32 = int_literal 1 [template = constants.%.15]
+// CHECK:STDOUT:   %.loc7_45.5: i32 = int_literal 1 [template = constants.%.14]
 // CHECK:STDOUT:   %.loc7_45.6: ref i32 = array_index %a.var, %.loc7_45.5
 // CHECK:STDOUT:   %.loc7_45.7: init i32 = initialize_from %.loc7_23 to %.loc7_45.6
-// CHECK:STDOUT:   %.loc7_45.8: i32 = int_literal 2 [template = constants.%.16]
+// CHECK:STDOUT:   %.loc7_45.8: i32 = int_literal 2 [template = constants.%.15]
 // CHECK:STDOUT:   %.loc7_45.9: ref i32 = array_index %a.var, %.loc7_45.8
 // CHECK:STDOUT:   %.loc7_45.10: init i32 = initialize_from %.loc7_26 to %.loc7_45.9
-// CHECK:STDOUT:   %.loc7_45.11: i32 = int_literal 3 [template = constants.%.17]
+// CHECK:STDOUT:   %.loc7_45.11: i32 = int_literal 3 [template = constants.%.16]
 // CHECK:STDOUT:   %.loc7_45.12: ref i32 = array_index %a.var, %.loc7_45.11
 // CHECK:STDOUT:   %.loc7_45.13: init i32 = initialize_from %.loc7_29 to %.loc7_45.12
-// CHECK:STDOUT:   %.loc7_45.14: i32 = int_literal 4 [template = constants.%.18]
+// CHECK:STDOUT:   %.loc7_45.14: i32 = int_literal 4 [template = constants.%.17]
 // CHECK:STDOUT:   %.loc7_45.15: ref i32 = array_index %a.var, %.loc7_45.14
 // CHECK:STDOUT:   %.loc7_45.16: init i32 = initialize_from %.loc7_32 to %.loc7_45.15
-// CHECK:STDOUT:   %.loc7_45.17: i32 = int_literal 5 [template = constants.%.19]
+// CHECK:STDOUT:   %.loc7_45.17: i32 = int_literal 5 [template = constants.%.18]
 // CHECK:STDOUT:   %.loc7_45.18: ref i32 = array_index %a.var, %.loc7_45.17
 // CHECK:STDOUT:   %.loc7_45.19: init i32 = initialize_from %.loc7_35 to %.loc7_45.18
-// CHECK:STDOUT:   %.loc7_45.20: i32 = int_literal 6 [template = constants.%.20]
+// CHECK:STDOUT:   %.loc7_45.20: i32 = int_literal 6 [template = constants.%.19]
 // CHECK:STDOUT:   %.loc7_45.21: ref i32 = array_index %a.var, %.loc7_45.20
 // CHECK:STDOUT:   %.loc7_45.22: init i32 = initialize_from %.loc7_38 to %.loc7_45.21
-// CHECK:STDOUT:   %.loc7_45.23: i32 = int_literal 7 [template = constants.%.21]
+// CHECK:STDOUT:   %.loc7_45.23: i32 = int_literal 7 [template = constants.%.20]
 // CHECK:STDOUT:   %.loc7_45.24: ref i32 = array_index %a.var, %.loc7_45.23
 // CHECK:STDOUT:   %.loc7_45.25: init i32 = initialize_from %.loc7_41 to %.loc7_45.24
-// CHECK:STDOUT:   %.loc7_45.26: i32 = int_literal 8 [template = constants.%.22]
+// CHECK:STDOUT:   %.loc7_45.26: i32 = int_literal 8 [template = constants.%.21]
 // CHECK:STDOUT:   %.loc7_45.27: ref i32 = array_index %a.var, %.loc7_45.26
 // CHECK:STDOUT:   %.loc7_45.28: init i32 = initialize_from %.loc7_44 to %.loc7_45.27
 // CHECK:STDOUT:   %.loc7_45.29: init [i32; 9] = array_init (%.loc7_45.4, %.loc7_45.7, %.loc7_45.10, %.loc7_45.13, %.loc7_45.16, %.loc7_45.19, %.loc7_45.22, %.loc7_45.25, %.loc7_45.28) to %a.var

+ 10 - 8
toolchain/check/testdata/as/identity.carbon

@@ -27,15 +27,17 @@ fn Initializing() {
 // CHECK:STDOUT: --- identity.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %X: type = class_type @X [template]
 // CHECK:STDOUT:   %.1: type = struct_type {} [template]
 // CHECK:STDOUT:   %.2: type = tuple_type () [template]
 // CHECK:STDOUT:   %.3: type = ptr_type {} [template]
+// CHECK:STDOUT:   %.4: type = ptr_type X [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.X = %X.decl, .Value = %Value, .Reference = %Reference, .Make = %Make, .Initializing = %Initializing} [template]
 // CHECK:STDOUT:   %X.decl = class_decl @X, ()
-// CHECK:STDOUT:   %X: type = class_type @X [template]
+// CHECK:STDOUT:   %X: type = class_type @X [template = constants.%X]
 // CHECK:STDOUT:   %Value: <function> = fn_decl @Value [template]
 // CHECK:STDOUT:   %Reference: <function> = fn_decl @Reference [template]
 // CHECK:STDOUT:   %Make: <function> = fn_decl @Make [template]
@@ -49,20 +51,20 @@ fn Initializing() {
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @Value(%n: X) {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %X.ref.loc14_10: type = name_ref X, file.%X [template = file.%X]
+// CHECK:STDOUT:   %X.ref.loc14_10: type = name_ref X, file.%X [template = constants.%X]
 // CHECK:STDOUT:   %n.ref: X = name_ref n, %n
-// CHECK:STDOUT:   %X.ref.loc14_19: type = name_ref X, file.%X [template = file.%X]
+// CHECK:STDOUT:   %X.ref.loc14_19: type = name_ref X, file.%X [template = constants.%X]
 // CHECK:STDOUT:   %m: X = bind_name m, %n.ref
 // CHECK:STDOUT:   return
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @Reference(%p: X*) {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %X.ref.loc18_10: type = name_ref X, file.%X [template = file.%X]
-// CHECK:STDOUT:   %.loc18_11: type = ptr_type X [template]
+// CHECK:STDOUT:   %X.ref.loc18_10: type = name_ref X, file.%X [template = constants.%X]
+// CHECK:STDOUT:   %.loc18_11: type = ptr_type X [template = constants.%.4]
 // CHECK:STDOUT:   %p.ref: X* = name_ref p, %p
 // CHECK:STDOUT:   %.loc18_17: ref X = deref %p.ref
-// CHECK:STDOUT:   %X.ref.loc18_23: type = name_ref X, file.%X [template = file.%X]
+// CHECK:STDOUT:   %X.ref.loc18_23: type = name_ref X, file.%X [template = constants.%X]
 // CHECK:STDOUT:   %.loc18_15: X* = addr_of %.loc18_17
 // CHECK:STDOUT:   %q: X* = bind_name q, %.loc18_15
 // CHECK:STDOUT:   return
@@ -72,13 +74,13 @@ fn Initializing() {
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @Initializing() {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %X.ref.loc24_10: type = name_ref X, file.%X [template = file.%X]
+// CHECK:STDOUT:   %X.ref.loc24_10: type = name_ref X, file.%X [template = constants.%X]
 // CHECK:STDOUT:   %x.var: ref X = var x
 // CHECK:STDOUT:   %x: ref X = bind_name x, %x.var
 // CHECK:STDOUT:   %Make.ref: <function> = name_ref Make, file.%Make [template = file.%Make]
 // CHECK:STDOUT:   %.loc24_7: ref X = splice_block %x.var {}
 // CHECK:STDOUT:   %.loc24_19: init X = call %Make.ref() to %.loc24_7
-// CHECK:STDOUT:   %X.ref.loc24_25: type = name_ref X, file.%X [template = file.%X]
+// CHECK:STDOUT:   %X.ref.loc24_25: type = name_ref X, file.%X [template = constants.%X]
 // CHECK:STDOUT:   assign %x.var, %.loc24_19
 // CHECK:STDOUT:   return
 // CHECK:STDOUT: }

+ 10 - 9
toolchain/check/testdata/as/tuple.carbon

@@ -23,6 +23,7 @@ fn Var() {
 // CHECK:STDOUT: --- tuple.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %X: type = class_type @X [template]
 // CHECK:STDOUT:   %.1: type = struct_type {} [template]
 // CHECK:STDOUT:   %.2: type = tuple_type () [template]
 // CHECK:STDOUT:   %.3: type = ptr_type {} [template]
@@ -35,7 +36,7 @@ fn Var() {
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.X = %X.decl, .Make = %Make, .Let = %Let, .Var = %Var} [template]
 // CHECK:STDOUT:   %X.decl = class_decl @X, ()
-// CHECK:STDOUT:   %X: type = class_type @X [template]
+// CHECK:STDOUT:   %X: type = class_type @X [template = constants.%X]
 // CHECK:STDOUT:   %Make: <function> = fn_decl @Make [template]
 // CHECK:STDOUT:   %Let: <function> = fn_decl @Let [template]
 // CHECK:STDOUT:   %Var: <function> = fn_decl @Var [template]
@@ -50,8 +51,8 @@ fn Var() {
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @Let() {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %X.ref.loc15_11: type = name_ref X, file.%X [template = file.%X]
-// CHECK:STDOUT:   %X.ref.loc15_14: type = name_ref X, file.%X [template = file.%X]
+// CHECK:STDOUT:   %X.ref.loc15_11: type = name_ref X, file.%X [template = constants.%X]
+// CHECK:STDOUT:   %X.ref.loc15_14: type = name_ref X, file.%X [template = constants.%X]
 // CHECK:STDOUT:   %.loc15_15.1: (type, type) = tuple_literal (%X.ref.loc15_11, %X.ref.loc15_14)
 // CHECK:STDOUT:   %.loc15_15.2: type = converted %.loc15_15.1, constants.%.5 [template = constants.%.5]
 // CHECK:STDOUT:   %Make.ref.loc15_20: <function> = name_ref Make, file.%Make [template = file.%Make]
@@ -61,8 +62,8 @@ fn Var() {
 // CHECK:STDOUT:   %.loc15_32.1: ref X = temporary_storage
 // CHECK:STDOUT:   %.loc15_32.2: init X = call %Make.ref.loc15_28() to %.loc15_32.1
 // CHECK:STDOUT:   %.loc15_34.1: (X, X) = tuple_literal (%.loc15_24.2, %.loc15_32.2)
-// CHECK:STDOUT:   %X.ref.loc15_40: type = name_ref X, file.%X [template = file.%X]
-// CHECK:STDOUT:   %X.ref.loc15_43: type = name_ref X, file.%X [template = file.%X]
+// CHECK:STDOUT:   %X.ref.loc15_40: type = name_ref X, file.%X [template = constants.%X]
+// CHECK:STDOUT:   %X.ref.loc15_43: type = name_ref X, file.%X [template = constants.%X]
 // CHECK:STDOUT:   %.loc15_44.1: (type, type) = tuple_literal (%X.ref.loc15_40, %X.ref.loc15_43)
 // CHECK:STDOUT:   %.loc15_44.2: type = converted %.loc15_44.1, constants.%.5 [template = constants.%.5]
 // CHECK:STDOUT:   %.loc15_24.3: ref X = temporary %.loc15_24.1, %.loc15_24.2
@@ -77,8 +78,8 @@ fn Var() {
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @Var() {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %X.ref.loc20_11: type = name_ref X, file.%X [template = file.%X]
-// CHECK:STDOUT:   %X.ref.loc20_14: type = name_ref X, file.%X [template = file.%X]
+// CHECK:STDOUT:   %X.ref.loc20_11: type = name_ref X, file.%X [template = constants.%X]
+// CHECK:STDOUT:   %X.ref.loc20_14: type = name_ref X, file.%X [template = constants.%X]
 // CHECK:STDOUT:   %.loc20_15.1: (type, type) = tuple_literal (%X.ref.loc20_11, %X.ref.loc20_14)
 // CHECK:STDOUT:   %.loc20_15.2: type = converted %.loc20_15.1, constants.%.5 [template = constants.%.5]
 // CHECK:STDOUT:   %b.var: ref (X, X) = var b
@@ -90,8 +91,8 @@ fn Var() {
 // CHECK:STDOUT:   %.loc20_34.2: ref X = tuple_access %b.var, element1
 // CHECK:STDOUT:   %.loc20_32: init X = call %Make.ref.loc20_28() to %.loc20_34.2
 // CHECK:STDOUT:   %.loc20_34.3: (X, X) = tuple_literal (%.loc20_24, %.loc20_32)
-// CHECK:STDOUT:   %X.ref.loc20_40: type = name_ref X, file.%X [template = file.%X]
-// CHECK:STDOUT:   %X.ref.loc20_43: type = name_ref X, file.%X [template = file.%X]
+// CHECK:STDOUT:   %X.ref.loc20_40: type = name_ref X, file.%X [template = constants.%X]
+// CHECK:STDOUT:   %X.ref.loc20_43: type = name_ref X, file.%X [template = constants.%X]
 // CHECK:STDOUT:   %.loc20_44.1: (type, type) = tuple_literal (%X.ref.loc20_40, %X.ref.loc20_43)
 // CHECK:STDOUT:   %.loc20_44.2: type = converted %.loc20_44.1, constants.%.5 [template = constants.%.5]
 // CHECK:STDOUT:   %.loc20_34.4: init (X, X) = tuple_init (%.loc20_24, %.loc20_32) to %b.var

+ 44 - 51
toolchain/check/testdata/basics/numeric_literals.carbon

@@ -33,33 +33,26 @@ fn F() {
 // CHECK:STDOUT:   %.3: type = ptr_type [i32; 5] [template]
 // CHECK:STDOUT:   %.4: i32 = int_literal 8 [template]
 // CHECK:STDOUT:   %.5: i32 = int_literal 9 [template]
-// CHECK:STDOUT:   %.6: i32 = int_literal 8 [template]
-// CHECK:STDOUT:   %.7: i32 = int_literal 8 [template]
-// CHECK:STDOUT:   %.8: i32 = int_literal 39999999999999999993 [template]
-// CHECK:STDOUT:   %.9: type = tuple_type (i32, i32, i32, i32, i32) [template]
-// CHECK:STDOUT:   %.10: i32 = int_literal 0 [template]
-// CHECK:STDOUT:   %.11: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.12: i32 = int_literal 2 [template]
-// CHECK:STDOUT:   %.13: i32 = int_literal 3 [template]
-// CHECK:STDOUT:   %.14: i32 = int_literal 4 [template]
-// CHECK:STDOUT:   %.15: i32 = int_literal 7 [template]
-// CHECK:STDOUT:   %.16: type = array_type %.15, f64 [template]
-// CHECK:STDOUT:   %.17: type = ptr_type [f64; 7] [template]
-// CHECK:STDOUT:   %.18: f64 = real_literal 9e-1 [template]
-// CHECK:STDOUT:   %.19: f64 = real_literal 80e-1 [template]
-// CHECK:STDOUT:   %.20: f64 = real_literal 800e-1 [template]
-// CHECK:STDOUT:   %.21: f64 = real_literal 10e6 [template]
-// CHECK:STDOUT:   %.22: f64 = real_literal 10e7 [template]
-// CHECK:STDOUT:   %.23: f64 = real_literal 10e-9 [template]
-// CHECK:STDOUT:   %.24: f64 = real_literal 399999999999999999930e39999999999999999992 [template]
-// CHECK:STDOUT:   %.25: type = tuple_type (f64, f64, f64, f64, f64, f64, f64) [template]
-// CHECK:STDOUT:   %.26: i32 = int_literal 0 [template]
-// CHECK:STDOUT:   %.27: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.28: i32 = int_literal 2 [template]
-// CHECK:STDOUT:   %.29: i32 = int_literal 3 [template]
-// CHECK:STDOUT:   %.30: i32 = int_literal 4 [template]
-// CHECK:STDOUT:   %.31: i32 = int_literal 5 [template]
-// CHECK:STDOUT:   %.32: i32 = int_literal 6 [template]
+// CHECK:STDOUT:   %.6: i32 = int_literal 39999999999999999993 [template]
+// CHECK:STDOUT:   %.7: type = tuple_type (i32, i32, i32, i32, i32) [template]
+// CHECK:STDOUT:   %.8: i32 = int_literal 0 [template]
+// CHECK:STDOUT:   %.9: i32 = int_literal 1 [template]
+// CHECK:STDOUT:   %.10: i32 = int_literal 2 [template]
+// CHECK:STDOUT:   %.11: i32 = int_literal 3 [template]
+// CHECK:STDOUT:   %.12: i32 = int_literal 4 [template]
+// CHECK:STDOUT:   %.13: i32 = int_literal 7 [template]
+// CHECK:STDOUT:   %.14: type = array_type %.13, f64 [template]
+// CHECK:STDOUT:   %.15: type = ptr_type [f64; 7] [template]
+// CHECK:STDOUT:   %.16: f64 = real_literal 9e-1 [template]
+// CHECK:STDOUT:   %.17: f64 = real_literal 80e-1 [template]
+// CHECK:STDOUT:   %.18: f64 = real_literal 800e-1 [template]
+// CHECK:STDOUT:   %.19: f64 = real_literal 10e6 [template]
+// CHECK:STDOUT:   %.20: f64 = real_literal 10e7 [template]
+// CHECK:STDOUT:   %.21: f64 = real_literal 10e-9 [template]
+// CHECK:STDOUT:   %.22: f64 = real_literal 399999999999999999930e39999999999999999992 [template]
+// CHECK:STDOUT:   %.23: type = tuple_type (f64, f64, f64, f64, f64, f64, f64) [template]
+// CHECK:STDOUT:   %.24: i32 = int_literal 5 [template]
+// CHECK:STDOUT:   %.25: i32 = int_literal 6 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -75,59 +68,59 @@ fn F() {
 // CHECK:STDOUT:   %ints: ref [i32; 5] = bind_name ints, %ints.var
 // CHECK:STDOUT:   %.loc11: i32 = int_literal 8 [template = constants.%.4]
 // CHECK:STDOUT:   %.loc12: i32 = int_literal 9 [template = constants.%.5]
-// CHECK:STDOUT:   %.loc13: i32 = int_literal 8 [template = constants.%.6]
-// CHECK:STDOUT:   %.loc14: i32 = int_literal 8 [template = constants.%.7]
-// CHECK:STDOUT:   %.loc15: i32 = int_literal 39999999999999999993 [template = constants.%.8]
+// CHECK:STDOUT:   %.loc13: i32 = int_literal 8 [template = constants.%.4]
+// CHECK:STDOUT:   %.loc14: i32 = int_literal 8 [template = constants.%.4]
+// CHECK:STDOUT:   %.loc15: i32 = int_literal 39999999999999999993 [template = constants.%.6]
 // CHECK:STDOUT:   %.loc16_3.1: (i32, i32, i32, i32, i32) = tuple_literal (%.loc11, %.loc12, %.loc13, %.loc14, %.loc15)
-// CHECK:STDOUT:   %.loc16_3.2: i32 = int_literal 0 [template = constants.%.10]
+// CHECK:STDOUT:   %.loc16_3.2: i32 = int_literal 0 [template = constants.%.8]
 // CHECK:STDOUT:   %.loc16_3.3: ref i32 = array_index %ints.var, %.loc16_3.2
 // CHECK:STDOUT:   %.loc16_3.4: init i32 = initialize_from %.loc11 to %.loc16_3.3
-// CHECK:STDOUT:   %.loc16_3.5: i32 = int_literal 1 [template = constants.%.11]
+// CHECK:STDOUT:   %.loc16_3.5: i32 = int_literal 1 [template = constants.%.9]
 // CHECK:STDOUT:   %.loc16_3.6: ref i32 = array_index %ints.var, %.loc16_3.5
 // CHECK:STDOUT:   %.loc16_3.7: init i32 = initialize_from %.loc12 to %.loc16_3.6
-// CHECK:STDOUT:   %.loc16_3.8: i32 = int_literal 2 [template = constants.%.12]
+// CHECK:STDOUT:   %.loc16_3.8: i32 = int_literal 2 [template = constants.%.10]
 // CHECK:STDOUT:   %.loc16_3.9: ref i32 = array_index %ints.var, %.loc16_3.8
 // CHECK:STDOUT:   %.loc16_3.10: init i32 = initialize_from %.loc13 to %.loc16_3.9
-// CHECK:STDOUT:   %.loc16_3.11: i32 = int_literal 3 [template = constants.%.13]
+// CHECK:STDOUT:   %.loc16_3.11: i32 = int_literal 3 [template = constants.%.11]
 // CHECK:STDOUT:   %.loc16_3.12: ref i32 = array_index %ints.var, %.loc16_3.11
 // CHECK:STDOUT:   %.loc16_3.13: init i32 = initialize_from %.loc14 to %.loc16_3.12
-// CHECK:STDOUT:   %.loc16_3.14: i32 = int_literal 4 [template = constants.%.14]
+// CHECK:STDOUT:   %.loc16_3.14: i32 = int_literal 4 [template = constants.%.12]
 // CHECK:STDOUT:   %.loc16_3.15: ref i32 = array_index %ints.var, %.loc16_3.14
 // CHECK:STDOUT:   %.loc16_3.16: init i32 = initialize_from %.loc15 to %.loc16_3.15
 // CHECK:STDOUT:   %.loc16_3.17: init [i32; 5] = array_init (%.loc16_3.4, %.loc16_3.7, %.loc16_3.10, %.loc16_3.13, %.loc16_3.16) to %ints.var
 // CHECK:STDOUT:   %.loc16_3.18: init [i32; 5] = converted %.loc16_3.1, %.loc16_3.17
 // CHECK:STDOUT:   assign %ints.var, %.loc16_3.18
-// CHECK:STDOUT:   %.loc17_21: i32 = int_literal 7 [template = constants.%.15]
-// CHECK:STDOUT:   %.loc17_22: type = array_type %.loc17_21, f64 [template = constants.%.16]
+// CHECK:STDOUT:   %.loc17_21: i32 = int_literal 7 [template = constants.%.13]
+// CHECK:STDOUT:   %.loc17_22: type = array_type %.loc17_21, f64 [template = constants.%.14]
 // CHECK:STDOUT:   %floats.var: ref [f64; 7] = var floats
 // CHECK:STDOUT:   %floats: ref [f64; 7] = bind_name floats, %floats.var
-// CHECK:STDOUT:   %.loc18: f64 = real_literal 9e-1 [template = constants.%.18]
-// CHECK:STDOUT:   %.loc19: f64 = real_literal 80e-1 [template = constants.%.19]
-// CHECK:STDOUT:   %.loc20: f64 = real_literal 800e-1 [template = constants.%.20]
-// CHECK:STDOUT:   %.loc21: f64 = real_literal 10e6 [template = constants.%.21]
-// CHECK:STDOUT:   %.loc22: f64 = real_literal 10e7 [template = constants.%.22]
-// CHECK:STDOUT:   %.loc23: f64 = real_literal 10e-9 [template = constants.%.23]
-// CHECK:STDOUT:   %.loc24: f64 = real_literal 399999999999999999930e39999999999999999992 [template = constants.%.24]
+// CHECK:STDOUT:   %.loc18: f64 = real_literal 9e-1 [template = constants.%.16]
+// CHECK:STDOUT:   %.loc19: f64 = real_literal 80e-1 [template = constants.%.17]
+// CHECK:STDOUT:   %.loc20: f64 = real_literal 800e-1 [template = constants.%.18]
+// CHECK:STDOUT:   %.loc21: f64 = real_literal 10e6 [template = constants.%.19]
+// CHECK:STDOUT:   %.loc22: f64 = real_literal 10e7 [template = constants.%.20]
+// CHECK:STDOUT:   %.loc23: f64 = real_literal 10e-9 [template = constants.%.21]
+// CHECK:STDOUT:   %.loc24: f64 = real_literal 399999999999999999930e39999999999999999992 [template = constants.%.22]
 // CHECK:STDOUT:   %.loc25_3.1: (f64, f64, f64, f64, f64, f64, f64) = tuple_literal (%.loc18, %.loc19, %.loc20, %.loc21, %.loc22, %.loc23, %.loc24)
-// CHECK:STDOUT:   %.loc25_3.2: i32 = int_literal 0 [template = constants.%.26]
+// CHECK:STDOUT:   %.loc25_3.2: i32 = int_literal 0 [template = constants.%.8]
 // CHECK:STDOUT:   %.loc25_3.3: ref f64 = array_index %floats.var, %.loc25_3.2
 // CHECK:STDOUT:   %.loc25_3.4: init f64 = initialize_from %.loc18 to %.loc25_3.3
-// CHECK:STDOUT:   %.loc25_3.5: i32 = int_literal 1 [template = constants.%.27]
+// CHECK:STDOUT:   %.loc25_3.5: i32 = int_literal 1 [template = constants.%.9]
 // CHECK:STDOUT:   %.loc25_3.6: ref f64 = array_index %floats.var, %.loc25_3.5
 // CHECK:STDOUT:   %.loc25_3.7: init f64 = initialize_from %.loc19 to %.loc25_3.6
-// CHECK:STDOUT:   %.loc25_3.8: i32 = int_literal 2 [template = constants.%.28]
+// CHECK:STDOUT:   %.loc25_3.8: i32 = int_literal 2 [template = constants.%.10]
 // CHECK:STDOUT:   %.loc25_3.9: ref f64 = array_index %floats.var, %.loc25_3.8
 // CHECK:STDOUT:   %.loc25_3.10: init f64 = initialize_from %.loc20 to %.loc25_3.9
-// CHECK:STDOUT:   %.loc25_3.11: i32 = int_literal 3 [template = constants.%.29]
+// CHECK:STDOUT:   %.loc25_3.11: i32 = int_literal 3 [template = constants.%.11]
 // CHECK:STDOUT:   %.loc25_3.12: ref f64 = array_index %floats.var, %.loc25_3.11
 // CHECK:STDOUT:   %.loc25_3.13: init f64 = initialize_from %.loc21 to %.loc25_3.12
-// CHECK:STDOUT:   %.loc25_3.14: i32 = int_literal 4 [template = constants.%.30]
+// CHECK:STDOUT:   %.loc25_3.14: i32 = int_literal 4 [template = constants.%.12]
 // CHECK:STDOUT:   %.loc25_3.15: ref f64 = array_index %floats.var, %.loc25_3.14
 // CHECK:STDOUT:   %.loc25_3.16: init f64 = initialize_from %.loc22 to %.loc25_3.15
-// CHECK:STDOUT:   %.loc25_3.17: i32 = int_literal 5 [template = constants.%.31]
+// CHECK:STDOUT:   %.loc25_3.17: i32 = int_literal 5 [template = constants.%.24]
 // CHECK:STDOUT:   %.loc25_3.18: ref f64 = array_index %floats.var, %.loc25_3.17
 // CHECK:STDOUT:   %.loc25_3.19: init f64 = initialize_from %.loc23 to %.loc25_3.18
-// CHECK:STDOUT:   %.loc25_3.20: i32 = int_literal 6 [template = constants.%.32]
+// CHECK:STDOUT:   %.loc25_3.20: i32 = int_literal 6 [template = constants.%.25]
 // CHECK:STDOUT:   %.loc25_3.21: ref f64 = array_index %floats.var, %.loc25_3.20
 // CHECK:STDOUT:   %.loc25_3.22: init f64 = initialize_from %.loc24 to %.loc25_3.21
 // CHECK:STDOUT:   %.loc25_3.23: init [f64; 7] = array_init (%.loc25_3.4, %.loc25_3.7, %.loc25_3.10, %.loc25_3.13, %.loc25_3.16, %.loc25_3.19, %.loc25_3.22) to %floats.var

+ 25 - 20
toolchain/check/testdata/class/base.carbon

@@ -25,32 +25,37 @@ fn Access(d: Derived) -> (i32, i32) {
 // CHECK:STDOUT: --- base.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = struct_type {.b: i32} [template]
-// CHECK:STDOUT:   %.2: type = ptr_type {.b: i32} [template]
-// CHECK:STDOUT:   %.3: type = struct_type {.base: Base, .d: i32} [template]
-// CHECK:STDOUT:   %.4: type = struct_type {.base: {.b: i32}*, .d: i32} [template]
-// CHECK:STDOUT:   %.5: type = ptr_type {.base: {.b: i32}*, .d: i32} [template]
-// CHECK:STDOUT:   %.6: type = ptr_type {.base: Base, .d: i32} [template]
-// CHECK:STDOUT:   %.7: i32 = int_literal 4 [template]
-// CHECK:STDOUT:   %.8: i32 = int_literal 7 [template]
-// CHECK:STDOUT:   %.9: type = struct_type {.base: {.b: i32}, .d: i32} [template]
-// CHECK:STDOUT:   %.10: type = tuple_type (type, type) [template]
-// CHECK:STDOUT:   %.11: type = tuple_type (i32, i32) [template]
-// CHECK:STDOUT:   %.12: type = ptr_type (i32, i32) [template]
+// CHECK:STDOUT:   %Base: type = class_type @Base [template]
+// CHECK:STDOUT:   %.1: type = unbound_element_type Base, i32 [template]
+// CHECK:STDOUT:   %.2: type = struct_type {.b: i32} [template]
+// CHECK:STDOUT:   %Derived: type = class_type @Derived [template]
+// CHECK:STDOUT:   %.3: type = ptr_type {.b: i32} [template]
+// CHECK:STDOUT:   %.4: type = unbound_element_type Derived, Base [template]
+// CHECK:STDOUT:   %.5: type = unbound_element_type Derived, i32 [template]
+// CHECK:STDOUT:   %.6: type = struct_type {.base: Base, .d: i32} [template]
+// CHECK:STDOUT:   %.7: type = struct_type {.base: {.b: i32}*, .d: i32} [template]
+// CHECK:STDOUT:   %.8: type = ptr_type {.base: {.b: i32}*, .d: i32} [template]
+// CHECK:STDOUT:   %.9: type = ptr_type {.base: Base, .d: i32} [template]
+// CHECK:STDOUT:   %.10: i32 = int_literal 4 [template]
+// CHECK:STDOUT:   %.11: i32 = int_literal 7 [template]
+// CHECK:STDOUT:   %.12: type = struct_type {.base: {.b: i32}, .d: i32} [template]
+// CHECK:STDOUT:   %.13: type = tuple_type (type, type) [template]
+// CHECK:STDOUT:   %.14: type = tuple_type (i32, i32) [template]
+// CHECK:STDOUT:   %.15: type = ptr_type (i32, i32) [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Base = %Base.decl, .Derived = %Derived.decl, .Make = %Make, .Access = %Access} [template]
 // CHECK:STDOUT:   %Base.decl = class_decl @Base, ()
-// CHECK:STDOUT:   %Base: type = class_type @Base [template]
+// CHECK:STDOUT:   %Base: type = class_type @Base [template = constants.%Base]
 // CHECK:STDOUT:   %Derived.decl = class_decl @Derived, ()
-// CHECK:STDOUT:   %Derived: type = class_type @Derived [template]
+// CHECK:STDOUT:   %Derived: type = class_type @Derived [template = constants.%Derived]
 // CHECK:STDOUT:   %Make: <function> = fn_decl @Make [template]
 // CHECK:STDOUT:   %Access: <function> = fn_decl @Access [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Base {
-// CHECK:STDOUT:   %.loc8_8.1: type = unbound_element_type Base, i32 [template]
+// CHECK:STDOUT:   %.loc8_8.1: type = unbound_element_type Base, i32 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc8_8.2: <unbound element of class Base> = field_decl b, element0 [template]
 // CHECK:STDOUT:   %b: <unbound element of class Base> = bind_name b, %.loc8_8.2 [template = %.loc8_8.2]
 // CHECK:STDOUT:
@@ -59,10 +64,10 @@ fn Access(d: Derived) -> (i32, i32) {
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Derived {
-// CHECK:STDOUT:   %Base.ref: type = name_ref Base, file.%Base [template = file.%Base]
-// CHECK:STDOUT:   %.loc12_20.1: type = unbound_element_type Derived, Base [template]
+// CHECK:STDOUT:   %Base.ref: type = name_ref Base, file.%Base [template = constants.%Base]
+// CHECK:STDOUT:   %.loc12_20.1: type = unbound_element_type Derived, Base [template = constants.%.4]
 // CHECK:STDOUT:   %.loc12_20.2: <unbound element of class Derived> = base_decl Base, element0 [template]
-// CHECK:STDOUT:   %.loc14_8.1: type = unbound_element_type Derived, i32 [template]
+// CHECK:STDOUT:   %.loc14_8.1: type = unbound_element_type Derived, i32 [template = constants.%.5]
 // CHECK:STDOUT:   %.loc14_8.2: <unbound element of class Derived> = field_decl d, element1 [template]
 // CHECK:STDOUT:   %d: <unbound element of class Derived> = bind_name d, %.loc14_8.2 [template = %.loc14_8.2]
 // CHECK:STDOUT:
@@ -74,9 +79,9 @@ fn Access(d: Derived) -> (i32, i32) {
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @Make() -> %return: Derived {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %.loc18_25: i32 = int_literal 4 [template = constants.%.7]
+// CHECK:STDOUT:   %.loc18_25: i32 = int_literal 4 [template = constants.%.10]
 // CHECK:STDOUT:   %.loc18_26.1: {.b: i32} = struct_literal (%.loc18_25)
-// CHECK:STDOUT:   %.loc18_34: i32 = int_literal 7 [template = constants.%.8]
+// CHECK:STDOUT:   %.loc18_34: i32 = int_literal 7 [template = constants.%.11]
 // CHECK:STDOUT:   %.loc18_35.1: {.base: {.b: i32}, .d: i32} = struct_literal (%.loc18_26.1, %.loc18_34)
 // CHECK:STDOUT:   %.loc18_35.2: ref Base = class_element_access %return, element0
 // CHECK:STDOUT:   %.loc18_26.2: ref i32 = class_element_access %.loc18_35.2, element0

+ 22 - 15
toolchain/check/testdata/class/base_field.carbon

@@ -24,31 +24,38 @@ fn Access(p: Derived*) -> i32* {
 // CHECK:STDOUT: --- base_field.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = struct_type {.a: i32, .b: i32, .c: i32} [template]
-// CHECK:STDOUT:   %.2: type = ptr_type {.a: i32, .b: i32, .c: i32} [template]
-// CHECK:STDOUT:   %.3: type = struct_type {.base: Base, .d: i32, .e: i32} [template]
-// CHECK:STDOUT:   %.4: type = struct_type {.base: {.a: i32, .b: i32, .c: i32}*, .d: i32, .e: i32} [template]
-// CHECK:STDOUT:   %.5: type = ptr_type {.base: {.a: i32, .b: i32, .c: i32}*, .d: i32, .e: i32} [template]
-// CHECK:STDOUT:   %.6: type = ptr_type {.base: Base, .d: i32, .e: i32} [template]
+// CHECK:STDOUT:   %Base: type = class_type @Base [template]
+// CHECK:STDOUT:   %.1: type = unbound_element_type Base, i32 [template]
+// CHECK:STDOUT:   %.2: type = struct_type {.a: i32, .b: i32, .c: i32} [template]
+// CHECK:STDOUT:   %Derived: type = class_type @Derived [template]
+// CHECK:STDOUT:   %.3: type = ptr_type {.a: i32, .b: i32, .c: i32} [template]
+// CHECK:STDOUT:   %.4: type = unbound_element_type Derived, Base [template]
+// CHECK:STDOUT:   %.5: type = unbound_element_type Derived, i32 [template]
+// CHECK:STDOUT:   %.6: type = struct_type {.base: Base, .d: i32, .e: i32} [template]
+// CHECK:STDOUT:   %.7: type = ptr_type Derived [template]
+// CHECK:STDOUT:   %.8: type = ptr_type i32 [template]
+// CHECK:STDOUT:   %.9: type = struct_type {.base: {.a: i32, .b: i32, .c: i32}*, .d: i32, .e: i32} [template]
+// CHECK:STDOUT:   %.10: type = ptr_type {.base: {.a: i32, .b: i32, .c: i32}*, .d: i32, .e: i32} [template]
+// CHECK:STDOUT:   %.11: type = ptr_type {.base: Base, .d: i32, .e: i32} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Base = %Base.decl, .Derived = %Derived.decl, .Access = %Access} [template]
 // CHECK:STDOUT:   %Base.decl = class_decl @Base, ()
-// CHECK:STDOUT:   %Base: type = class_type @Base [template]
+// CHECK:STDOUT:   %Base: type = class_type @Base [template = constants.%Base]
 // CHECK:STDOUT:   %Derived.decl = class_decl @Derived, ()
-// CHECK:STDOUT:   %Derived: type = class_type @Derived [template]
+// CHECK:STDOUT:   %Derived: type = class_type @Derived [template = constants.%Derived]
 // CHECK:STDOUT:   %Access: <function> = fn_decl @Access [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Base {
-// CHECK:STDOUT:   %.loc8_8.1: type = unbound_element_type Base, i32 [template]
+// CHECK:STDOUT:   %.loc8_8.1: type = unbound_element_type Base, i32 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc8_8.2: <unbound element of class Base> = field_decl a, element0 [template]
 // CHECK:STDOUT:   %a: <unbound element of class Base> = bind_name a, %.loc8_8.2 [template = %.loc8_8.2]
-// CHECK:STDOUT:   %.loc9_8.1: type = unbound_element_type Base, i32 [template]
+// CHECK:STDOUT:   %.loc9_8.1: type = unbound_element_type Base, i32 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc9_8.2: <unbound element of class Base> = field_decl b, element1 [template]
 // CHECK:STDOUT:   %b: <unbound element of class Base> = bind_name b, %.loc9_8.2 [template = %.loc9_8.2]
-// CHECK:STDOUT:   %.loc10_8.1: type = unbound_element_type Base, i32 [template]
+// CHECK:STDOUT:   %.loc10_8.1: type = unbound_element_type Base, i32 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc10_8.2: <unbound element of class Base> = field_decl c, element2 [template]
 // CHECK:STDOUT:   %c: <unbound element of class Base> = bind_name c, %.loc10_8.2 [template = %.loc10_8.2]
 // CHECK:STDOUT:
@@ -59,13 +66,13 @@ fn Access(p: Derived*) -> i32* {
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Derived {
-// CHECK:STDOUT:   %Base.ref: type = name_ref Base, file.%Base [template = file.%Base]
-// CHECK:STDOUT:   %.loc14_20.1: type = unbound_element_type Derived, Base [template]
+// CHECK:STDOUT:   %Base.ref: type = name_ref Base, file.%Base [template = constants.%Base]
+// CHECK:STDOUT:   %.loc14_20.1: type = unbound_element_type Derived, Base [template = constants.%.4]
 // CHECK:STDOUT:   %.loc14_20.2: <unbound element of class Derived> = base_decl Base, element0 [template]
-// CHECK:STDOUT:   %.loc16_8.1: type = unbound_element_type Derived, i32 [template]
+// CHECK:STDOUT:   %.loc16_8.1: type = unbound_element_type Derived, i32 [template = constants.%.5]
 // CHECK:STDOUT:   %.loc16_8.2: <unbound element of class Derived> = field_decl d, element1 [template]
 // CHECK:STDOUT:   %d: <unbound element of class Derived> = bind_name d, %.loc16_8.2 [template = %.loc16_8.2]
-// CHECK:STDOUT:   %.loc17_8.1: type = unbound_element_type Derived, i32 [template]
+// CHECK:STDOUT:   %.loc17_8.1: type = unbound_element_type Derived, i32 [template = constants.%.5]
 // CHECK:STDOUT:   %.loc17_8.2: <unbound element of class Derived> = field_decl e, element2 [template]
 // CHECK:STDOUT:   %e: <unbound element of class Derived> = bind_name e, %.loc17_8.2 [template = %.loc17_8.2]
 // CHECK:STDOUT:

+ 8 - 5
toolchain/check/testdata/class/base_function_unqualified.carbon

@@ -22,18 +22,21 @@ fn Derived.H() {
 // CHECK:STDOUT: --- base_function_unqualified.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %Base: type = class_type @Base [template]
 // CHECK:STDOUT:   %.1: type = struct_type {} [template]
+// CHECK:STDOUT:   %Derived: type = class_type @Derived [template]
 // CHECK:STDOUT:   %.2: type = tuple_type () [template]
 // CHECK:STDOUT:   %.3: type = ptr_type {} [template]
-// CHECK:STDOUT:   %.4: type = struct_type {.base: Base} [template]
+// CHECK:STDOUT:   %.4: type = unbound_element_type Derived, Base [template]
+// CHECK:STDOUT:   %.5: type = struct_type {.base: Base} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Base = %Base.decl, .Derived = %Derived.decl} [template]
 // CHECK:STDOUT:   %Base.decl = class_decl @Base, ()
-// CHECK:STDOUT:   %Base: type = class_type @Base [template]
+// CHECK:STDOUT:   %Base: type = class_type @Base [template = constants.%Base]
 // CHECK:STDOUT:   %Derived.decl = class_decl @Derived, ()
-// CHECK:STDOUT:   %Derived: type = class_type @Derived [template]
+// CHECK:STDOUT:   %Derived: type = class_type @Derived [template = constants.%Derived]
 // CHECK:STDOUT:   %H: <function> = fn_decl @H [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
@@ -45,8 +48,8 @@ fn Derived.H() {
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Derived {
-// CHECK:STDOUT:   %Base.ref: type = name_ref Base, file.%Base [template = file.%Base]
-// CHECK:STDOUT:   %.loc12_20.1: type = unbound_element_type Derived, Base [template]
+// CHECK:STDOUT:   %Base.ref: type = name_ref Base, file.%Base [template = constants.%Base]
+// CHECK:STDOUT:   %.loc12_20.1: type = unbound_element_type Derived, Base [template = constants.%.4]
 // CHECK:STDOUT:   %.loc12_20.2: <unbound element of class Derived> = base_decl Base, element0 [template]
 // CHECK:STDOUT:   %G: <function> = fn_decl @G [template]
 // CHECK:STDOUT:   %H: <function> = fn_decl @H [template]

+ 19 - 13
toolchain/check/testdata/class/base_method.carbon

@@ -25,27 +25,33 @@ fn Call(p: Derived*) {
 // CHECK:STDOUT: --- base_method.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = struct_type {.a: i32} [template]
-// CHECK:STDOUT:   %.2: type = ptr_type {.a: i32} [template]
-// CHECK:STDOUT:   %.3: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.4: type = struct_type {.base: Base} [template]
-// CHECK:STDOUT:   %.5: type = struct_type {.base: {.a: i32}*} [template]
-// CHECK:STDOUT:   %.6: type = ptr_type {.base: Base} [template]
-// CHECK:STDOUT:   %.7: type = tuple_type () [template]
+// CHECK:STDOUT:   %Base: type = class_type @Base [template]
+// CHECK:STDOUT:   %.1: type = unbound_element_type Base, i32 [template]
+// CHECK:STDOUT:   %.2: type = ptr_type Base [template]
+// CHECK:STDOUT:   %.3: type = struct_type {.a: i32} [template]
+// CHECK:STDOUT:   %.4: type = ptr_type {.a: i32} [template]
+// CHECK:STDOUT:   %.5: i32 = int_literal 1 [template]
+// CHECK:STDOUT:   %Derived: type = class_type @Derived [template]
+// CHECK:STDOUT:   %.6: type = unbound_element_type Derived, Base [template]
+// CHECK:STDOUT:   %.7: type = struct_type {.base: Base} [template]
+// CHECK:STDOUT:   %.8: type = ptr_type Derived [template]
+// CHECK:STDOUT:   %.9: type = struct_type {.base: {.a: i32}*} [template]
+// CHECK:STDOUT:   %.10: type = ptr_type {.base: Base} [template]
+// CHECK:STDOUT:   %.11: type = tuple_type () [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Base = %Base.decl, .Derived = %Derived.decl, .Call = %Call} [template]
 // CHECK:STDOUT:   %Base.decl = class_decl @Base, ()
-// CHECK:STDOUT:   %Base: type = class_type @Base [template]
+// CHECK:STDOUT:   %Base: type = class_type @Base [template = constants.%Base]
 // CHECK:STDOUT:   %F: <function> = fn_decl @F [template]
 // CHECK:STDOUT:   %Derived.decl = class_decl @Derived, ()
-// CHECK:STDOUT:   %Derived: type = class_type @Derived [template]
+// CHECK:STDOUT:   %Derived: type = class_type @Derived [template = constants.%Derived]
 // CHECK:STDOUT:   %Call: <function> = fn_decl @Call [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Base {
-// CHECK:STDOUT:   %.loc8_8.1: type = unbound_element_type Base, i32 [template]
+// CHECK:STDOUT:   %.loc8_8.1: type = unbound_element_type Base, i32 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc8_8.2: <unbound element of class Base> = field_decl a, element0 [template]
 // CHECK:STDOUT:   %a: <unbound element of class Base> = bind_name a, %.loc8_8.2 [template = %.loc8_8.2]
 // CHECK:STDOUT:   %F: <function> = fn_decl @F [template]
@@ -56,8 +62,8 @@ fn Call(p: Derived*) {
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Derived {
-// CHECK:STDOUT:   %Base.ref: type = name_ref Base, file.%Base [template = file.%Base]
-// CHECK:STDOUT:   %.loc18_20.1: type = unbound_element_type Derived, Base [template]
+// CHECK:STDOUT:   %Base.ref: type = name_ref Base, file.%Base [template = constants.%Base]
+// CHECK:STDOUT:   %.loc18_20.1: type = unbound_element_type Derived, Base [template = constants.%.6]
 // CHECK:STDOUT:   %.loc18_20.2: <unbound element of class Derived> = base_decl Base, element0 [template]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:
@@ -70,7 +76,7 @@ fn Call(p: Derived*) {
 // CHECK:STDOUT:   %self.ref: Base* = name_ref self, %self
 // CHECK:STDOUT:   %.loc14_4: ref Base = deref %self.ref
 // CHECK:STDOUT:   %.loc14_10: ref i32 = class_element_access %.loc14_4, element0
-// CHECK:STDOUT:   %.loc14_15: i32 = int_literal 1 [template = constants.%.3]
+// CHECK:STDOUT:   %.loc14_15: i32 = int_literal 1 [template = constants.%.5]
 // CHECK:STDOUT:   assign %.loc14_10, %.loc14_15
 // CHECK:STDOUT:   return
 // CHECK:STDOUT: }

+ 30 - 19
toolchain/check/testdata/class/base_method_shadow.carbon

@@ -32,27 +32,38 @@ fn Call(a: A*, b: B*, c: C*, d: D*) {
 // CHECK:STDOUT: --- base_method_shadow.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = struct_type {} [template]
-// CHECK:STDOUT:   %.2: type = tuple_type () [template]
-// CHECK:STDOUT:   %.3: type = ptr_type {} [template]
-// CHECK:STDOUT:   %.4: type = struct_type {.base: A} [template]
-// CHECK:STDOUT:   %.5: type = struct_type {.base: {}*} [template]
-// CHECK:STDOUT:   %.6: type = ptr_type {.base: A} [template]
-// CHECK:STDOUT:   %.7: type = struct_type {.base: B} [template]
-// CHECK:STDOUT:   %.8: type = struct_type {.base: {.base: A}*} [template]
-// CHECK:STDOUT:   %.9: type = ptr_type {.base: B} [template]
+// CHECK:STDOUT:   %A: type = class_type @A [template]
+// CHECK:STDOUT:   %.1: type = ptr_type A [template]
+// CHECK:STDOUT:   %.2: type = struct_type {} [template]
+// CHECK:STDOUT:   %B: type = class_type @B [template]
+// CHECK:STDOUT:   %.3: type = tuple_type () [template]
+// CHECK:STDOUT:   %.4: type = ptr_type {} [template]
+// CHECK:STDOUT:   %.5: type = unbound_element_type B, A [template]
+// CHECK:STDOUT:   %.6: type = ptr_type B [template]
+// CHECK:STDOUT:   %.7: type = struct_type {.base: A} [template]
+// CHECK:STDOUT:   %C: type = class_type @C [template]
+// CHECK:STDOUT:   %.8: type = struct_type {.base: {}*} [template]
+// CHECK:STDOUT:   %.9: type = ptr_type {.base: A} [template]
+// CHECK:STDOUT:   %.10: type = unbound_element_type C, B [template]
+// CHECK:STDOUT:   %.11: type = ptr_type C [template]
+// CHECK:STDOUT:   %.12: type = struct_type {.base: B} [template]
+// CHECK:STDOUT:   %D: type = class_type @D [template]
+// CHECK:STDOUT:   %.13: type = unbound_element_type D, B [template]
+// CHECK:STDOUT:   %.14: type = ptr_type D [template]
+// CHECK:STDOUT:   %.15: type = struct_type {.base: {.base: A}*} [template]
+// CHECK:STDOUT:   %.16: type = ptr_type {.base: B} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.A = %A.decl, .B = %B.decl, .C = %C.decl, .D = %D.decl, .Call = %Call} [template]
 // CHECK:STDOUT:   %A.decl = class_decl @A, ()
-// CHECK:STDOUT:   %A: type = class_type @A [template]
+// CHECK:STDOUT:   %A: type = class_type @A [template = constants.%A]
 // CHECK:STDOUT:   %B.decl = class_decl @B, ()
-// CHECK:STDOUT:   %B: type = class_type @B [template]
+// CHECK:STDOUT:   %B: type = class_type @B [template = constants.%B]
 // CHECK:STDOUT:   %C.decl = class_decl @C, ()
-// CHECK:STDOUT:   %C: type = class_type @C [template]
+// CHECK:STDOUT:   %C: type = class_type @C [template = constants.%C]
 // CHECK:STDOUT:   %D.decl = class_decl @D, ()
-// CHECK:STDOUT:   %D: type = class_type @D [template]
+// CHECK:STDOUT:   %D: type = class_type @D [template = constants.%D]
 // CHECK:STDOUT:   %Call: <function> = fn_decl @Call [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
@@ -64,8 +75,8 @@ fn Call(a: A*, b: B*, c: C*, d: D*) {
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @B {
-// CHECK:STDOUT:   %A.ref: type = name_ref A, file.%A [template = file.%A]
-// CHECK:STDOUT:   %.loc12_17.1: type = unbound_element_type B, A [template]
+// CHECK:STDOUT:   %A.ref: type = name_ref A, file.%A [template = constants.%A]
+// CHECK:STDOUT:   %.loc12_17.1: type = unbound_element_type B, A [template = constants.%.5]
 // CHECK:STDOUT:   %.loc12_17.2: <unbound element of class B> = base_decl A, element0 [template]
 // CHECK:STDOUT:   %F: <function> = fn_decl @F.2 [template]
 // CHECK:STDOUT:
@@ -76,8 +87,8 @@ fn Call(a: A*, b: B*, c: C*, d: D*) {
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @C {
-// CHECK:STDOUT:   %B.ref: type = name_ref B, file.%B [template = file.%B]
-// CHECK:STDOUT:   %.loc17_17.1: type = unbound_element_type C, B [template]
+// CHECK:STDOUT:   %B.ref: type = name_ref B, file.%B [template = constants.%B]
+// CHECK:STDOUT:   %.loc17_17.1: type = unbound_element_type C, B [template = constants.%.10]
 // CHECK:STDOUT:   %.loc17_17.2: <unbound element of class C> = base_decl B, element0 [template]
 // CHECK:STDOUT:   %F: <function> = fn_decl @F.3 [template]
 // CHECK:STDOUT:
@@ -88,8 +99,8 @@ fn Call(a: A*, b: B*, c: C*, d: D*) {
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @D {
-// CHECK:STDOUT:   %B.ref: type = name_ref B, file.%B [template = file.%B]
-// CHECK:STDOUT:   %.loc22_17.1: type = unbound_element_type D, B [template]
+// CHECK:STDOUT:   %B.ref: type = name_ref B, file.%B [template = constants.%B]
+// CHECK:STDOUT:   %.loc22_17.1: type = unbound_element_type D, B [template = constants.%.13]
 // CHECK:STDOUT:   %.loc22_17.2: <unbound element of class D> = base_decl B, element0 [template]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:

+ 8 - 6
toolchain/check/testdata/class/basic.carbon

@@ -25,14 +25,16 @@ fn Run() -> i32 {
 // CHECK:STDOUT: --- basic.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = struct_type {.k: i32} [template]
-// CHECK:STDOUT:   %.2: i32 = int_literal 4 [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %.1: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.2: type = struct_type {.k: i32} [template]
+// CHECK:STDOUT:   %.3: i32 = int_literal 4 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Class = %Class.decl, .Run = %Run} [template]
 // CHECK:STDOUT:   %Class.decl = class_decl @Class, ()
-// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template = constants.%Class]
 // CHECK:STDOUT:   %G: <function> = fn_decl @G [template]
 // CHECK:STDOUT:   %Run: <function> = fn_decl @Run [template]
 // CHECK:STDOUT: }
@@ -40,7 +42,7 @@ fn Run() -> i32 {
 // CHECK:STDOUT: class @Class {
 // CHECK:STDOUT:   %F: <function> = fn_decl @F [template]
 // CHECK:STDOUT:   %G: <function> = fn_decl @G [template]
-// CHECK:STDOUT:   %.loc14_8.1: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.loc14_8.1: type = unbound_element_type Class, i32 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc14_8.2: <unbound element of class Class> = field_decl k, element0 [template]
 // CHECK:STDOUT:   %k: <unbound element of class Class> = bind_name k, %.loc14_8.2 [template = %.loc14_8.2]
 // CHECK:STDOUT:
@@ -64,9 +66,9 @@ fn Run() -> i32 {
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @Run() -> i32 {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %Class.ref: type = name_ref Class, file.%Class [template = file.%Class]
+// CHECK:STDOUT:   %Class.ref: type = name_ref Class, file.%Class [template = constants.%Class]
 // CHECK:STDOUT:   %F.ref: <function> = name_ref F, @Class.%F [template = @Class.%F]
-// CHECK:STDOUT:   %.loc22_18: i32 = int_literal 4 [template = constants.%.2]
+// CHECK:STDOUT:   %.loc22_18: i32 = int_literal 4 [template = constants.%.3]
 // CHECK:STDOUT:   %.loc22_17.1: init i32 = call %F.ref(%.loc22_18)
 // CHECK:STDOUT:   %.loc22_20: i32 = value_of_initializer %.loc22_17.1
 // CHECK:STDOUT:   %.loc22_17.2: i32 = converted %.loc22_17.1, %.loc22_20

+ 43 - 32
toolchain/check/testdata/class/derived_to_base.carbon

@@ -37,31 +37,42 @@ fn ConvertInit() {
 // CHECK:STDOUT: --- derived_to_base.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = struct_type {.a: i32} [template]
-// CHECK:STDOUT:   %.2: type = ptr_type {.a: i32} [template]
-// CHECK:STDOUT:   %.3: type = struct_type {.base: A, .b: i32} [template]
-// CHECK:STDOUT:   %.4: type = struct_type {.base: {.a: i32}*, .b: i32} [template]
-// CHECK:STDOUT:   %.5: type = ptr_type {.base: {.a: i32}*, .b: i32} [template]
-// CHECK:STDOUT:   %.6: type = ptr_type {.base: A, .b: i32} [template]
-// CHECK:STDOUT:   %.7: type = struct_type {.base: B, .c: i32} [template]
-// CHECK:STDOUT:   %.8: type = struct_type {.base: {.base: A, .b: i32}*, .c: i32} [template]
-// CHECK:STDOUT:   %.9: type = ptr_type {.base: {.base: A, .b: i32}*, .c: i32} [template]
-// CHECK:STDOUT:   %.10: type = ptr_type {.base: B, .c: i32} [template]
-// CHECK:STDOUT:   %.11: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.12: i32 = int_literal 2 [template]
-// CHECK:STDOUT:   %.13: type = struct_type {.base: {.a: i32}, .b: i32} [template]
-// CHECK:STDOUT:   %.14: i32 = int_literal 3 [template]
-// CHECK:STDOUT:   %.15: type = struct_type {.base: {.base: {.a: i32}, .b: i32}, .c: i32} [template]
+// CHECK:STDOUT:   %A: type = class_type @A [template]
+// CHECK:STDOUT:   %.1: type = unbound_element_type A, i32 [template]
+// CHECK:STDOUT:   %.2: type = struct_type {.a: i32} [template]
+// CHECK:STDOUT:   %B: type = class_type @B [template]
+// CHECK:STDOUT:   %.3: type = ptr_type {.a: i32} [template]
+// CHECK:STDOUT:   %.4: type = unbound_element_type B, A [template]
+// CHECK:STDOUT:   %.5: type = unbound_element_type B, i32 [template]
+// CHECK:STDOUT:   %.6: type = struct_type {.base: A, .b: i32} [template]
+// CHECK:STDOUT:   %C: type = class_type @C [template]
+// CHECK:STDOUT:   %.7: type = struct_type {.base: {.a: i32}*, .b: i32} [template]
+// CHECK:STDOUT:   %.8: type = ptr_type {.base: {.a: i32}*, .b: i32} [template]
+// CHECK:STDOUT:   %.9: type = ptr_type {.base: A, .b: i32} [template]
+// CHECK:STDOUT:   %.10: type = unbound_element_type C, B [template]
+// CHECK:STDOUT:   %.11: type = unbound_element_type C, i32 [template]
+// CHECK:STDOUT:   %.12: type = struct_type {.base: B, .c: i32} [template]
+// CHECK:STDOUT:   %.13: type = ptr_type C [template]
+// CHECK:STDOUT:   %.14: type = ptr_type B [template]
+// CHECK:STDOUT:   %.15: type = struct_type {.base: {.base: A, .b: i32}*, .c: i32} [template]
+// CHECK:STDOUT:   %.16: type = ptr_type {.base: {.base: A, .b: i32}*, .c: i32} [template]
+// CHECK:STDOUT:   %.17: type = ptr_type {.base: B, .c: i32} [template]
+// CHECK:STDOUT:   %.18: type = ptr_type A [template]
+// CHECK:STDOUT:   %.19: i32 = int_literal 1 [template]
+// CHECK:STDOUT:   %.20: i32 = int_literal 2 [template]
+// CHECK:STDOUT:   %.21: type = struct_type {.base: {.a: i32}, .b: i32} [template]
+// CHECK:STDOUT:   %.22: i32 = int_literal 3 [template]
+// CHECK:STDOUT:   %.23: type = struct_type {.base: {.base: {.a: i32}, .b: i32}, .c: i32} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.A = %A.decl, .B = %B.decl, .C = %C.decl, .ConvertCToB = %ConvertCToB, .ConvertBToA = %ConvertBToA, .ConvertCToA = %ConvertCToA, .ConvertValue = %ConvertValue, .ConvertRef = %ConvertRef, .ConvertInit = %ConvertInit} [template]
 // CHECK:STDOUT:   %A.decl = class_decl @A, ()
-// CHECK:STDOUT:   %A: type = class_type @A [template]
+// CHECK:STDOUT:   %A: type = class_type @A [template = constants.%A]
 // CHECK:STDOUT:   %B.decl = class_decl @B, ()
-// CHECK:STDOUT:   %B: type = class_type @B [template]
+// CHECK:STDOUT:   %B: type = class_type @B [template = constants.%B]
 // CHECK:STDOUT:   %C.decl = class_decl @C, ()
-// CHECK:STDOUT:   %C: type = class_type @C [template]
+// CHECK:STDOUT:   %C: type = class_type @C [template = constants.%C]
 // CHECK:STDOUT:   %ConvertCToB: <function> = fn_decl @ConvertCToB [template]
 // CHECK:STDOUT:   %ConvertBToA: <function> = fn_decl @ConvertBToA [template]
 // CHECK:STDOUT:   %ConvertCToA: <function> = fn_decl @ConvertCToA [template]
@@ -71,7 +82,7 @@ fn ConvertInit() {
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @A {
-// CHECK:STDOUT:   %.loc8_8.1: type = unbound_element_type A, i32 [template]
+// CHECK:STDOUT:   %.loc8_8.1: type = unbound_element_type A, i32 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc8_8.2: <unbound element of class A> = field_decl a, element0 [template]
 // CHECK:STDOUT:   %a: <unbound element of class A> = bind_name a, %.loc8_8.2 [template = %.loc8_8.2]
 // CHECK:STDOUT:
@@ -80,10 +91,10 @@ fn ConvertInit() {
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @B {
-// CHECK:STDOUT:   %A.ref: type = name_ref A, file.%A [template = file.%A]
-// CHECK:STDOUT:   %.loc12_17.1: type = unbound_element_type B, A [template]
+// CHECK:STDOUT:   %A.ref: type = name_ref A, file.%A [template = constants.%A]
+// CHECK:STDOUT:   %.loc12_17.1: type = unbound_element_type B, A [template = constants.%.4]
 // CHECK:STDOUT:   %.loc12_17.2: <unbound element of class B> = base_decl A, element0 [template]
-// CHECK:STDOUT:   %.loc13_8.1: type = unbound_element_type B, i32 [template]
+// CHECK:STDOUT:   %.loc13_8.1: type = unbound_element_type B, i32 [template = constants.%.5]
 // CHECK:STDOUT:   %.loc13_8.2: <unbound element of class B> = field_decl b, element1 [template]
 // CHECK:STDOUT:   %b: <unbound element of class B> = bind_name b, %.loc13_8.2 [template = %.loc13_8.2]
 // CHECK:STDOUT:
@@ -94,10 +105,10 @@ fn ConvertInit() {
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @C {
-// CHECK:STDOUT:   %B.ref: type = name_ref B, file.%B [template = file.%B]
-// CHECK:STDOUT:   %.loc17_17.1: type = unbound_element_type C, B [template]
+// CHECK:STDOUT:   %B.ref: type = name_ref B, file.%B [template = constants.%B]
+// CHECK:STDOUT:   %.loc17_17.1: type = unbound_element_type C, B [template = constants.%.10]
 // CHECK:STDOUT:   %.loc17_17.2: <unbound element of class C> = base_decl B, element0 [template]
-// CHECK:STDOUT:   %.loc18_8.1: type = unbound_element_type C, i32 [template]
+// CHECK:STDOUT:   %.loc18_8.1: type = unbound_element_type C, i32 [template = constants.%.11]
 // CHECK:STDOUT:   %.loc18_8.2: <unbound element of class C> = field_decl c, element1 [template]
 // CHECK:STDOUT:   %c: <unbound element of class C> = bind_name c, %.loc18_8.2 [template = %.loc18_8.2]
 // CHECK:STDOUT:
@@ -140,7 +151,7 @@ fn ConvertInit() {
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @ConvertValue(%c: C) {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %A.ref: type = name_ref A, file.%A [template = file.%A]
+// CHECK:STDOUT:   %A.ref: type = name_ref A, file.%A [template = constants.%A]
 // CHECK:STDOUT:   %c.ref: C = name_ref c, %c
 // CHECK:STDOUT:   %.loc26_15.1: ref B = class_element_access %c.ref, element0
 // CHECK:STDOUT:   %.loc26_15.2: ref A = class_element_access %.loc26_15.1, element0
@@ -154,7 +165,7 @@ fn ConvertInit() {
 // CHECK:STDOUT: !entry:
 // CHECK:STDOUT:   %c.ref: C* = name_ref c, %c
 // CHECK:STDOUT:   %.loc30_12.1: ref C = deref %c.ref
-// CHECK:STDOUT:   %A.ref: type = name_ref A, file.%A [template = file.%A]
+// CHECK:STDOUT:   %A.ref: type = name_ref A, file.%A [template = constants.%A]
 // CHECK:STDOUT:   %.loc30_15.1: ref B = class_element_access %.loc30_12.1, element0
 // CHECK:STDOUT:   %.loc30_15.2: ref A = class_element_access %.loc30_15.1, element0
 // CHECK:STDOUT:   %.loc30_12.2: ref A = converted %.loc30_12.1, %.loc30_15.2
@@ -164,14 +175,14 @@ fn ConvertInit() {
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @ConvertInit() {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %A.ref: type = name_ref A, file.%A [template = file.%A]
-// CHECK:STDOUT:   %.loc34_38: i32 = int_literal 1 [template = constants.%.11]
+// CHECK:STDOUT:   %A.ref: type = name_ref A, file.%A [template = constants.%A]
+// CHECK:STDOUT:   %.loc34_38: i32 = int_literal 1 [template = constants.%.19]
 // CHECK:STDOUT:   %.loc34_39.1: {.a: i32} = struct_literal (%.loc34_38)
-// CHECK:STDOUT:   %.loc34_47: i32 = int_literal 2 [template = constants.%.12]
+// CHECK:STDOUT:   %.loc34_47: i32 = int_literal 2 [template = constants.%.20]
 // CHECK:STDOUT:   %.loc34_48.1: {.base: {.a: i32}, .b: i32} = struct_literal (%.loc34_39.1, %.loc34_47)
-// CHECK:STDOUT:   %.loc34_56: i32 = int_literal 3 [template = constants.%.14]
+// CHECK:STDOUT:   %.loc34_56: i32 = int_literal 3 [template = constants.%.22]
 // CHECK:STDOUT:   %.loc34_57.1: {.base: {.base: {.a: i32}, .b: i32}, .c: i32} = struct_literal (%.loc34_48.1, %.loc34_56)
-// CHECK:STDOUT:   %C.ref: type = name_ref C, file.%C [template = file.%C]
+// CHECK:STDOUT:   %C.ref: type = name_ref C, file.%C [template = constants.%C]
 // CHECK:STDOUT:   %.loc34_57.2: ref C = temporary_storage
 // CHECK:STDOUT:   %.loc34_57.3: ref B = class_element_access %.loc34_57.2, element0
 // CHECK:STDOUT:   %.loc34_48.2: ref A = class_element_access %.loc34_57.3, element0

+ 25 - 20
toolchain/check/testdata/class/fail_abstract.carbon

@@ -29,32 +29,37 @@ fn Access(d: Derived) -> (i32, i32) {
 // CHECK:STDOUT: --- fail_abstract.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = struct_type {.a: i32} [template]
-// CHECK:STDOUT:   %.2: type = ptr_type {.a: i32} [template]
-// CHECK:STDOUT:   %.3: type = struct_type {.base: Abstract, .d: i32} [template]
-// CHECK:STDOUT:   %.4: type = struct_type {.base: {.a: i32}*, .d: i32} [template]
-// CHECK:STDOUT:   %.5: type = ptr_type {.base: {.a: i32}*, .d: i32} [template]
-// CHECK:STDOUT:   %.6: type = ptr_type {.base: Abstract, .d: i32} [template]
-// CHECK:STDOUT:   %.7: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.8: i32 = int_literal 7 [template]
-// CHECK:STDOUT:   %.9: type = struct_type {.base: {.a: i32}, .d: i32} [template]
-// CHECK:STDOUT:   %.10: type = tuple_type (type, type) [template]
-// CHECK:STDOUT:   %.11: type = tuple_type (i32, i32) [template]
-// CHECK:STDOUT:   %.12: type = ptr_type (i32, i32) [template]
+// CHECK:STDOUT:   %Abstract: type = class_type @Abstract [template]
+// CHECK:STDOUT:   %.1: type = unbound_element_type Abstract, i32 [template]
+// CHECK:STDOUT:   %.2: type = struct_type {.a: i32} [template]
+// CHECK:STDOUT:   %Derived: type = class_type @Derived [template]
+// CHECK:STDOUT:   %.3: type = ptr_type {.a: i32} [template]
+// CHECK:STDOUT:   %.4: type = unbound_element_type Derived, Abstract [template]
+// CHECK:STDOUT:   %.5: type = unbound_element_type Derived, i32 [template]
+// CHECK:STDOUT:   %.6: type = struct_type {.base: Abstract, .d: i32} [template]
+// CHECK:STDOUT:   %.7: type = struct_type {.base: {.a: i32}*, .d: i32} [template]
+// CHECK:STDOUT:   %.8: type = ptr_type {.base: {.a: i32}*, .d: i32} [template]
+// CHECK:STDOUT:   %.9: type = ptr_type {.base: Abstract, .d: i32} [template]
+// CHECK:STDOUT:   %.10: i32 = int_literal 1 [template]
+// CHECK:STDOUT:   %.11: i32 = int_literal 7 [template]
+// CHECK:STDOUT:   %.12: type = struct_type {.base: {.a: i32}, .d: i32} [template]
+// CHECK:STDOUT:   %.13: type = tuple_type (type, type) [template]
+// CHECK:STDOUT:   %.14: type = tuple_type (i32, i32) [template]
+// CHECK:STDOUT:   %.15: type = ptr_type (i32, i32) [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Abstract = %Abstract.decl, .Derived = %Derived.decl, .Make = %Make, .Access = %Access} [template]
 // CHECK:STDOUT:   %Abstract.decl = class_decl @Abstract, ()
-// CHECK:STDOUT:   %Abstract: type = class_type @Abstract [template]
+// CHECK:STDOUT:   %Abstract: type = class_type @Abstract [template = constants.%Abstract]
 // CHECK:STDOUT:   %Derived.decl = class_decl @Derived, ()
-// CHECK:STDOUT:   %Derived: type = class_type @Derived [template]
+// CHECK:STDOUT:   %Derived: type = class_type @Derived [template = constants.%Derived]
 // CHECK:STDOUT:   %Make: <function> = fn_decl @Make [template]
 // CHECK:STDOUT:   %Access: <function> = fn_decl @Access [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Abstract {
-// CHECK:STDOUT:   %.loc8_8.1: type = unbound_element_type Abstract, i32 [template]
+// CHECK:STDOUT:   %.loc8_8.1: type = unbound_element_type Abstract, i32 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc8_8.2: <unbound element of class Abstract> = field_decl a, element0 [template]
 // CHECK:STDOUT:   %a: <unbound element of class Abstract> = bind_name a, %.loc8_8.2 [template = %.loc8_8.2]
 // CHECK:STDOUT:
@@ -63,10 +68,10 @@ fn Access(d: Derived) -> (i32, i32) {
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Derived {
-// CHECK:STDOUT:   %Abstract.ref: type = name_ref Abstract, file.%Abstract [template = file.%Abstract]
-// CHECK:STDOUT:   %.loc12_24.1: type = unbound_element_type Derived, Abstract [template]
+// CHECK:STDOUT:   %Abstract.ref: type = name_ref Abstract, file.%Abstract [template = constants.%Abstract]
+// CHECK:STDOUT:   %.loc12_24.1: type = unbound_element_type Derived, Abstract [template = constants.%.4]
 // CHECK:STDOUT:   %.loc12_24.2: <unbound element of class Derived> = base_decl Abstract, element0 [template]
-// CHECK:STDOUT:   %.loc14_8.1: type = unbound_element_type Derived, i32 [template]
+// CHECK:STDOUT:   %.loc14_8.1: type = unbound_element_type Derived, i32 [template = constants.%.5]
 // CHECK:STDOUT:   %.loc14_8.2: <unbound element of class Derived> = field_decl d, element1 [template]
 // CHECK:STDOUT:   %d: <unbound element of class Derived> = bind_name d, %.loc14_8.2 [template = %.loc14_8.2]
 // CHECK:STDOUT:
@@ -78,9 +83,9 @@ fn Access(d: Derived) -> (i32, i32) {
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @Make() -> %return: Derived {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %.loc22_25: i32 = int_literal 1 [template = constants.%.7]
+// CHECK:STDOUT:   %.loc22_25: i32 = int_literal 1 [template = constants.%.10]
 // CHECK:STDOUT:   %.loc22_26: {.a: i32} = struct_literal (%.loc22_25)
-// CHECK:STDOUT:   %.loc22_34: i32 = int_literal 7 [template = constants.%.8]
+// CHECK:STDOUT:   %.loc22_34: i32 = int_literal 7 [template = constants.%.11]
 // CHECK:STDOUT:   %.loc22_35: {.base: {.a: i32}, .d: i32} = struct_literal (%.loc22_26, %.loc22_34)
 // CHECK:STDOUT:   return <error>
 // CHECK:STDOUT: }

+ 4 - 2
toolchain/check/testdata/class/fail_addr_not_self.carbon

@@ -19,13 +19,15 @@ class Class {
 // CHECK:STDOUT: --- fail_addr_not_self.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = struct_type {} [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %.1: type = ptr_type Class [template]
+// CHECK:STDOUT:   %.2: type = struct_type {} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Class = %Class.decl} [template]
 // CHECK:STDOUT:   %Class.decl = class_decl @Class, ()
-// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template = constants.%Class]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Class {

+ 6 - 4
toolchain/check/testdata/class/fail_addr_self.carbon

@@ -41,15 +41,17 @@ fn F(c: Class, p: Class*) {
 // CHECK:STDOUT: --- fail_addr_self.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = struct_type {} [template]
-// CHECK:STDOUT:   %.2: type = tuple_type () [template]
-// CHECK:STDOUT:   %.3: type = ptr_type {} [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %.1: type = ptr_type Class [template]
+// CHECK:STDOUT:   %.2: type = struct_type {} [template]
+// CHECK:STDOUT:   %.3: type = tuple_type () [template]
+// CHECK:STDOUT:   %.4: type = ptr_type {} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Class = %Class.decl, .F = %F} [template]
 // CHECK:STDOUT:   %Class.decl = class_decl @Class, ()
-// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template = constants.%Class]
 // CHECK:STDOUT:   %F: <function> = fn_decl @F.2 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:

+ 68 - 38
toolchain/check/testdata/class/fail_base_bad_type.carbon

@@ -120,55 +120,85 @@ fn AccessMemberWithInvalidBaseFinal_NoMember(p: DeriveFromFinal*) -> i32 {
 // CHECK:STDOUT: --- fail_base_bad_type.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %Base: type = class_type @Base [template]
 // CHECK:STDOUT:   %.1: type = struct_type {} [template]
-// CHECK:STDOUT:   %.2: type = struct_type {.a: i32} [template]
-// CHECK:STDOUT:   %.3: type = struct_type {.base: <error>} [template]
-// CHECK:STDOUT:   %.4: type = ptr_type {.base: <error>} [template]
-// CHECK:STDOUT:   %.5: i32 = int_literal 32 [template]
-// CHECK:STDOUT:   %.6: type = tuple_type (type) [template]
-// CHECK:STDOUT:   %.7: type = tuple_type (Base) [template]
-// CHECK:STDOUT:   %.8: type = tuple_type () [template]
-// CHECK:STDOUT:   %.9: type = ptr_type {} [template]
-// CHECK:STDOUT:   %.10: type = tuple_type ({}*) [template]
-// CHECK:STDOUT:   %.11: type = ptr_type {.a: i32, .b: i32} [template]
-// CHECK:STDOUT:   %.12: type = ptr_type {.a: i32} [template]
-// CHECK:STDOUT:   %.13: type = struct_type {.base: Final} [template]
-// CHECK:STDOUT:   %.14: type = struct_type {.base: {.a: i32}*} [template]
-// CHECK:STDOUT:   %.15: type = ptr_type {.base: Final} [template]
+// CHECK:STDOUT:   %Final: type = class_type @Final [template]
+// CHECK:STDOUT:   %.2: type = unbound_element_type Final, i32 [template]
+// CHECK:STDOUT:   %.3: type = struct_type {.a: i32} [template]
+// CHECK:STDOUT:   %DeriveFromError: type = class_type @DeriveFromError [template]
+// CHECK:STDOUT:   %.4: type = unbound_element_type DeriveFromError, <error> [template]
+// CHECK:STDOUT:   %.5: type = struct_type {.base: <error>} [template]
+// CHECK:STDOUT:   %.6: type = ptr_type DeriveFromError [template]
+// CHECK:STDOUT:   %.7: type = ptr_type {.base: <error>} [template]
+// CHECK:STDOUT:   %DeriveFromNonType: type = class_type @DeriveFromNonType [template]
+// CHECK:STDOUT:   %.8: i32 = int_literal 32 [template]
+// CHECK:STDOUT:   %.9: type = unbound_element_type DeriveFromNonType, <error> [template]
+// CHECK:STDOUT:   %.10: type = ptr_type DeriveFromNonType [template]
+// CHECK:STDOUT:   %DeriveFromi32: type = class_type @DeriveFromi32 [template]
+// CHECK:STDOUT:   %.11: type = unbound_element_type DeriveFromi32, <error> [template]
+// CHECK:STDOUT:   %.12: type = ptr_type DeriveFromi32 [template]
+// CHECK:STDOUT:   %.13: type = ptr_type i32 [template]
+// CHECK:STDOUT:   %DeriveFromTuple: type = class_type @DeriveFromTuple [template]
+// CHECK:STDOUT:   %.14: type = tuple_type (type) [template]
+// CHECK:STDOUT:   %.15: type = tuple_type (Base) [template]
+// CHECK:STDOUT:   %.16: type = tuple_type () [template]
+// CHECK:STDOUT:   %.17: type = ptr_type {} [template]
+// CHECK:STDOUT:   %.18: type = tuple_type ({}*) [template]
+// CHECK:STDOUT:   %.19: type = unbound_element_type DeriveFromTuple, <error> [template]
+// CHECK:STDOUT:   %.20: type = ptr_type DeriveFromTuple [template]
+// CHECK:STDOUT:   %.21: type = ptr_type (Base,) [template]
+// CHECK:STDOUT:   %DeriveFromStruct: type = class_type @DeriveFromStruct [template]
+// CHECK:STDOUT:   %.22: type = struct_type {.a: i32, .b: i32} [template]
+// CHECK:STDOUT:   %.23: type = ptr_type {.a: i32, .b: i32} [template]
+// CHECK:STDOUT:   %.24: type = unbound_element_type DeriveFromStruct, <error> [template]
+// CHECK:STDOUT:   %.25: type = ptr_type DeriveFromStruct [template]
+// CHECK:STDOUT:   %Incomplete: type = class_type @Incomplete [template]
+// CHECK:STDOUT:   %DeriveFromIncomplete: type = class_type @DeriveFromIncomplete [template]
+// CHECK:STDOUT:   %.26: type = unbound_element_type DeriveFromIncomplete, <error> [template]
+// CHECK:STDOUT:   %.27: type = ptr_type DeriveFromIncomplete [template]
+// CHECK:STDOUT:   %.28: type = ptr_type Incomplete [template]
+// CHECK:STDOUT:   %DeriveFromFinal: type = class_type @DeriveFromFinal [template]
+// CHECK:STDOUT:   %.29: type = ptr_type {.a: i32} [template]
+// CHECK:STDOUT:   %.30: type = unbound_element_type DeriveFromFinal, Final [template]
+// CHECK:STDOUT:   %.31: type = struct_type {.base: Final} [template]
+// CHECK:STDOUT:   %.32: type = ptr_type DeriveFromFinal [template]
+// CHECK:STDOUT:   %.33: type = ptr_type Final [template]
+// CHECK:STDOUT:   %.34: type = struct_type {.base: {.a: i32}*} [template]
+// CHECK:STDOUT:   %.35: type = ptr_type {.base: Final} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Base = %Base.decl, .Final = %Final.decl, .DeriveFromError = %DeriveFromError.decl, .AccessMemberWithInvalidBaseError = %AccessMemberWithInvalidBaseError, .DeriveFromNonType = %DeriveFromNonType.decl, .AccessMemberWithInvalidBasNonType = %AccessMemberWithInvalidBasNonType, .DeriveFromi32 = %DeriveFromi32.decl, .ConvertToBadBasei32 = %ConvertToBadBasei32, .AccessMemberWithInvalidBasei32 = %AccessMemberWithInvalidBasei32, .DeriveFromTuple = %DeriveFromTuple.decl, .ConvertToBadBaseTuple = %ConvertToBadBaseTuple, .AccessMemberWithInvalidBaseTuple = %AccessMemberWithInvalidBaseTuple, .DeriveFromStruct = %DeriveFromStruct.decl, .ConvertToBadBaseStruct = %ConvertToBadBaseStruct, .AccessMemberWithInvalidBaseStruct = %AccessMemberWithInvalidBaseStruct, .Incomplete = %Incomplete.decl, .DeriveFromIncomplete = %DeriveFromIncomplete.decl, .ConvertToBadBaseIncomplete = %ConvertToBadBaseIncomplete, .AccessMemberWithInvalidBaseIncomplete = %AccessMemberWithInvalidBaseIncomplete, .DeriveFromFinal = %DeriveFromFinal.decl, .ConvertToBadBaseFinal = %ConvertToBadBaseFinal, .AccessMemberWithInvalidBaseFinal_WithMember = %AccessMemberWithInvalidBaseFinal_WithMember, .AccessMemberWithInvalidBaseFinal_NoMember = %AccessMemberWithInvalidBaseFinal_NoMember} [template]
 // CHECK:STDOUT:   %Base.decl = class_decl @Base, ()
-// CHECK:STDOUT:   %Base: type = class_type @Base [template]
+// CHECK:STDOUT:   %Base: type = class_type @Base [template = constants.%Base]
 // CHECK:STDOUT:   %Final.decl = class_decl @Final, ()
-// CHECK:STDOUT:   %Final: type = class_type @Final [template]
+// CHECK:STDOUT:   %Final: type = class_type @Final [template = constants.%Final]
 // CHECK:STDOUT:   %DeriveFromError.decl = class_decl @DeriveFromError, ()
-// CHECK:STDOUT:   %DeriveFromError: type = class_type @DeriveFromError [template]
+// CHECK:STDOUT:   %DeriveFromError: type = class_type @DeriveFromError [template = constants.%DeriveFromError]
 // CHECK:STDOUT:   %AccessMemberWithInvalidBaseError: <function> = fn_decl @AccessMemberWithInvalidBaseError [template]
 // CHECK:STDOUT:   %DeriveFromNonType.decl = class_decl @DeriveFromNonType, ()
-// CHECK:STDOUT:   %DeriveFromNonType: type = class_type @DeriveFromNonType [template]
+// CHECK:STDOUT:   %DeriveFromNonType: type = class_type @DeriveFromNonType [template = constants.%DeriveFromNonType]
 // CHECK:STDOUT:   %AccessMemberWithInvalidBasNonType: <function> = fn_decl @AccessMemberWithInvalidBasNonType [template]
 // CHECK:STDOUT:   %DeriveFromi32.decl = class_decl @DeriveFromi32, ()
-// CHECK:STDOUT:   %DeriveFromi32: type = class_type @DeriveFromi32 [template]
+// CHECK:STDOUT:   %DeriveFromi32: type = class_type @DeriveFromi32 [template = constants.%DeriveFromi32]
 // CHECK:STDOUT:   %ConvertToBadBasei32: <function> = fn_decl @ConvertToBadBasei32 [template]
 // CHECK:STDOUT:   %AccessMemberWithInvalidBasei32: <function> = fn_decl @AccessMemberWithInvalidBasei32 [template]
 // CHECK:STDOUT:   %DeriveFromTuple.decl = class_decl @DeriveFromTuple, ()
-// CHECK:STDOUT:   %DeriveFromTuple: type = class_type @DeriveFromTuple [template]
+// CHECK:STDOUT:   %DeriveFromTuple: type = class_type @DeriveFromTuple [template = constants.%DeriveFromTuple]
 // CHECK:STDOUT:   %ConvertToBadBaseTuple: <function> = fn_decl @ConvertToBadBaseTuple [template]
 // CHECK:STDOUT:   %AccessMemberWithInvalidBaseTuple: <function> = fn_decl @AccessMemberWithInvalidBaseTuple [template]
 // CHECK:STDOUT:   %DeriveFromStruct.decl = class_decl @DeriveFromStruct, ()
-// CHECK:STDOUT:   %DeriveFromStruct: type = class_type @DeriveFromStruct [template]
+// CHECK:STDOUT:   %DeriveFromStruct: type = class_type @DeriveFromStruct [template = constants.%DeriveFromStruct]
 // CHECK:STDOUT:   %ConvertToBadBaseStruct: <function> = fn_decl @ConvertToBadBaseStruct [template]
 // CHECK:STDOUT:   %AccessMemberWithInvalidBaseStruct: <function> = fn_decl @AccessMemberWithInvalidBaseStruct [template]
 // CHECK:STDOUT:   %Incomplete.decl = class_decl @Incomplete, ()
-// CHECK:STDOUT:   %Incomplete: type = class_type @Incomplete [template]
+// CHECK:STDOUT:   %Incomplete: type = class_type @Incomplete [template = constants.%Incomplete]
 // CHECK:STDOUT:   %DeriveFromIncomplete.decl = class_decl @DeriveFromIncomplete, ()
-// CHECK:STDOUT:   %DeriveFromIncomplete: type = class_type @DeriveFromIncomplete [template]
+// CHECK:STDOUT:   %DeriveFromIncomplete: type = class_type @DeriveFromIncomplete [template = constants.%DeriveFromIncomplete]
 // CHECK:STDOUT:   %ConvertToBadBaseIncomplete: <function> = fn_decl @ConvertToBadBaseIncomplete [template]
 // CHECK:STDOUT:   %AccessMemberWithInvalidBaseIncomplete: <function> = fn_decl @AccessMemberWithInvalidBaseIncomplete [template]
 // CHECK:STDOUT:   %DeriveFromFinal.decl = class_decl @DeriveFromFinal, ()
-// CHECK:STDOUT:   %DeriveFromFinal: type = class_type @DeriveFromFinal [template]
+// CHECK:STDOUT:   %DeriveFromFinal: type = class_type @DeriveFromFinal [template = constants.%DeriveFromFinal]
 // CHECK:STDOUT:   %ConvertToBadBaseFinal: <function> = fn_decl @ConvertToBadBaseFinal [template]
 // CHECK:STDOUT:   %AccessMemberWithInvalidBaseFinal_WithMember: <function> = fn_decl @AccessMemberWithInvalidBaseFinal_WithMember [template]
 // CHECK:STDOUT:   %AccessMemberWithInvalidBaseFinal_NoMember: <function> = fn_decl @AccessMemberWithInvalidBaseFinal_NoMember [template]
@@ -180,7 +210,7 @@ fn AccessMemberWithInvalidBaseFinal_NoMember(p: DeriveFromFinal*) -> i32 {
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Final {
-// CHECK:STDOUT:   %.loc9_8.1: type = unbound_element_type Final, i32 [template]
+// CHECK:STDOUT:   %.loc9_8.1: type = unbound_element_type Final, i32 [template = constants.%.2]
 // CHECK:STDOUT:   %.loc9_8.2: <unbound element of class Final> = field_decl a, element0 [template]
 // CHECK:STDOUT:   %a: <unbound element of class Final> = bind_name a, %.loc9_8.2 [template = %.loc9_8.2]
 // CHECK:STDOUT:
@@ -190,7 +220,7 @@ fn AccessMemberWithInvalidBaseFinal_NoMember(p: DeriveFromFinal*) -> i32 {
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @DeriveFromError {
 // CHECK:STDOUT:   %error.ref: <error> = name_ref error, <error>
-// CHECK:STDOUT:   %.loc16_21.1: type = unbound_element_type DeriveFromError, <error> [template]
+// CHECK:STDOUT:   %.loc16_21.1: type = unbound_element_type DeriveFromError, <error> [template = constants.%.4]
 // CHECK:STDOUT:   %.loc16_21.2: <unbound element of class DeriveFromError> = base_decl <error>, element0 [template]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:
@@ -199,8 +229,8 @@ fn AccessMemberWithInvalidBaseFinal_NoMember(p: DeriveFromFinal*) -> i32 {
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @DeriveFromNonType {
-// CHECK:STDOUT:   %.loc26_16: i32 = int_literal 32 [template = constants.%.5]
-// CHECK:STDOUT:   %.loc26_18.1: type = unbound_element_type DeriveFromNonType, <error> [template]
+// CHECK:STDOUT:   %.loc26_16: i32 = int_literal 32 [template = constants.%.8]
+// CHECK:STDOUT:   %.loc26_18.1: type = unbound_element_type DeriveFromNonType, <error> [template = constants.%.9]
 // CHECK:STDOUT:   %.loc26_18.2: <unbound element of class DeriveFromNonType> = base_decl <error>, element0 [template]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:
@@ -209,7 +239,7 @@ fn AccessMemberWithInvalidBaseFinal_NoMember(p: DeriveFromFinal*) -> i32 {
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @DeriveFromi32 {
-// CHECK:STDOUT:   %.loc35_19.1: type = unbound_element_type DeriveFromi32, <error> [template]
+// CHECK:STDOUT:   %.loc35_19.1: type = unbound_element_type DeriveFromi32, <error> [template = constants.%.11]
 // CHECK:STDOUT:   %.loc35_19.2: <unbound element of class DeriveFromi32> = base_decl <error>, element0 [template]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:
@@ -218,10 +248,10 @@ fn AccessMemberWithInvalidBaseFinal_NoMember(p: DeriveFromFinal*) -> i32 {
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @DeriveFromTuple {
-// CHECK:STDOUT:   %Base.ref: type = name_ref Base, file.%Base [template = file.%Base]
+// CHECK:STDOUT:   %Base.ref: type = name_ref Base, file.%Base [template = constants.%Base]
 // CHECK:STDOUT:   %.loc51_22.1: (type,) = tuple_literal (%Base.ref)
-// CHECK:STDOUT:   %.loc51_22.2: type = converted %.loc51_22.1, constants.%.7 [template = constants.%.7]
-// CHECK:STDOUT:   %.loc51_23.1: type = unbound_element_type DeriveFromTuple, <error> [template]
+// CHECK:STDOUT:   %.loc51_22.2: type = converted %.loc51_22.1, constants.%.15 [template = constants.%.15]
+// CHECK:STDOUT:   %.loc51_23.1: type = unbound_element_type DeriveFromTuple, <error> [template = constants.%.19]
 // CHECK:STDOUT:   %.loc51_23.2: <unbound element of class DeriveFromTuple> = base_decl <error>, element0 [template]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:
@@ -230,8 +260,8 @@ fn AccessMemberWithInvalidBaseFinal_NoMember(p: DeriveFromFinal*) -> i32 {
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @DeriveFromStruct {
-// CHECK:STDOUT:   %.loc67_33: type = struct_type {.a: i32, .b: i32} [template]
-// CHECK:STDOUT:   %.loc67_34.1: type = unbound_element_type DeriveFromStruct, <error> [template]
+// CHECK:STDOUT:   %.loc67_33: type = struct_type {.a: i32, .b: i32} [template = constants.%.22]
+// CHECK:STDOUT:   %.loc67_34.1: type = unbound_element_type DeriveFromStruct, <error> [template = constants.%.24]
 // CHECK:STDOUT:   %.loc67_34.2: <unbound element of class DeriveFromStruct> = base_decl <error>, element0 [template]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:
@@ -242,8 +272,8 @@ fn AccessMemberWithInvalidBaseFinal_NoMember(p: DeriveFromFinal*) -> i32 {
 // CHECK:STDOUT: class @Incomplete;
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @DeriveFromIncomplete {
-// CHECK:STDOUT:   %Incomplete.ref: type = name_ref Incomplete, file.%Incomplete [template = file.%Incomplete]
-// CHECK:STDOUT:   %.loc87_26.1: type = unbound_element_type DeriveFromIncomplete, <error> [template]
+// CHECK:STDOUT:   %Incomplete.ref: type = name_ref Incomplete, file.%Incomplete [template = constants.%Incomplete]
+// CHECK:STDOUT:   %.loc87_26.1: type = unbound_element_type DeriveFromIncomplete, <error> [template = constants.%.26]
 // CHECK:STDOUT:   %.loc87_26.2: <unbound element of class DeriveFromIncomplete> = base_decl <error>, element0 [template]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:
@@ -252,8 +282,8 @@ fn AccessMemberWithInvalidBaseFinal_NoMember(p: DeriveFromFinal*) -> i32 {
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @DeriveFromFinal {
-// CHECK:STDOUT:   %Final.ref: type = name_ref Final, file.%Final [template = file.%Final]
-// CHECK:STDOUT:   %.loc101_21.1: type = unbound_element_type DeriveFromFinal, Final [template]
+// CHECK:STDOUT:   %Final.ref: type = name_ref Final, file.%Final [template = constants.%Final]
+// CHECK:STDOUT:   %.loc101_21.1: type = unbound_element_type DeriveFromFinal, Final [template = constants.%.30]
 // CHECK:STDOUT:   %.loc101_21.2: <unbound element of class DeriveFromFinal> = base_decl Final, element0 [template]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:

+ 10 - 6
toolchain/check/testdata/class/fail_base_method_define.carbon

@@ -29,18 +29,22 @@ fn D.C.F() {}
 // CHECK:STDOUT: --- fail_base_method_define.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %B: type = class_type @B [template]
+// CHECK:STDOUT:   %C: type = class_type @C [template]
 // CHECK:STDOUT:   %.1: type = struct_type {} [template]
+// CHECK:STDOUT:   %D: type = class_type @D [template]
 // CHECK:STDOUT:   %.2: type = tuple_type () [template]
 // CHECK:STDOUT:   %.3: type = ptr_type {} [template]
-// CHECK:STDOUT:   %.4: type = struct_type {.base: B} [template]
+// CHECK:STDOUT:   %.4: type = unbound_element_type D, B [template]
+// CHECK:STDOUT:   %.5: type = struct_type {.base: B} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.B = %B.decl, .D = %D.decl} [template]
 // CHECK:STDOUT:   %B.decl = class_decl @B, ()
-// CHECK:STDOUT:   %B: type = class_type @B [template]
+// CHECK:STDOUT:   %B: type = class_type @B [template = constants.%B]
 // CHECK:STDOUT:   %D.decl = class_decl @D, ()
-// CHECK:STDOUT:   %D: type = class_type @D [template]
+// CHECK:STDOUT:   %D: type = class_type @D [template = constants.%D]
 // CHECK:STDOUT:   %F: <function> = fn_decl @F.3 [template]
 // CHECK:STDOUT:   %.loc27: <function> = fn_decl @.1 [template]
 // CHECK:STDOUT: }
@@ -48,7 +52,7 @@ fn D.C.F() {}
 // CHECK:STDOUT: class @B {
 // CHECK:STDOUT:   %F: <function> = fn_decl @F.1 [template]
 // CHECK:STDOUT:   %C.decl = class_decl @C, ()
-// CHECK:STDOUT:   %C: type = class_type @C [template]
+// CHECK:STDOUT:   %C: type = class_type @C [template = constants.%C]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:
 // CHECK:STDOUT:   .F = %F
@@ -63,8 +67,8 @@ fn D.C.F() {}
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @D {
-// CHECK:STDOUT:   %B.ref: type = name_ref B, file.%B [template = file.%B]
-// CHECK:STDOUT:   %.loc16_17.1: type = unbound_element_type D, B [template]
+// CHECK:STDOUT:   %B.ref: type = name_ref B, file.%B [template = constants.%B]
+// CHECK:STDOUT:   %.loc16_17.1: type = unbound_element_type D, B [template = constants.%.4]
 // CHECK:STDOUT:   %.loc16_17.2: <unbound element of class D> = base_decl B, element0 [template]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:

+ 1 - 0
toolchain/check/testdata/class/fail_base_misplaced.carbon

@@ -24,6 +24,7 @@ fn F() {
 // CHECK:STDOUT: --- fail_base_misplaced.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %B: type = class_type @B [template]
 // CHECK:STDOUT:   %.1: type = struct_type {} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:

+ 23 - 14
toolchain/check/testdata/class/fail_base_modifiers.carbon

@@ -46,24 +46,33 @@ class C4 {
 // CHECK:STDOUT: --- fail_base_modifiers.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %B: type = class_type @B [template]
 // CHECK:STDOUT:   %.1: type = struct_type {} [template]
+// CHECK:STDOUT:   %C1: type = class_type @C1 [template]
 // CHECK:STDOUT:   %.2: type = tuple_type () [template]
 // CHECK:STDOUT:   %.3: type = ptr_type {} [template]
-// CHECK:STDOUT:   %.4: type = struct_type {.base: B} [template]
+// CHECK:STDOUT:   %.4: type = unbound_element_type C1, B [template]
+// CHECK:STDOUT:   %.5: type = struct_type {.base: B} [template]
+// CHECK:STDOUT:   %C2: type = class_type @C2 [template]
+// CHECK:STDOUT:   %.6: type = unbound_element_type C2, B [template]
+// CHECK:STDOUT:   %C3: type = class_type @C3 [template]
+// CHECK:STDOUT:   %.7: type = unbound_element_type C3, B [template]
+// CHECK:STDOUT:   %C4: type = class_type @C4 [template]
+// CHECK:STDOUT:   %.8: type = unbound_element_type C4, B [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.B = %B.decl, .C1 = %C1.decl, .C2 = %C2.decl, .C3 = %C3.decl, .C4 = %C4.decl} [template]
 // CHECK:STDOUT:   %B.decl = class_decl @B, ()
-// CHECK:STDOUT:   %B: type = class_type @B [template]
+// CHECK:STDOUT:   %B: type = class_type @B [template = constants.%B]
 // CHECK:STDOUT:   %C1.decl = class_decl @C1, ()
-// CHECK:STDOUT:   %C1: type = class_type @C1 [template]
+// CHECK:STDOUT:   %C1: type = class_type @C1 [template = constants.%C1]
 // CHECK:STDOUT:   %C2.decl = class_decl @C2, ()
-// CHECK:STDOUT:   %C2: type = class_type @C2 [template]
+// CHECK:STDOUT:   %C2: type = class_type @C2 [template = constants.%C2]
 // CHECK:STDOUT:   %C3.decl = class_decl @C3, ()
-// CHECK:STDOUT:   %C3: type = class_type @C3 [template]
+// CHECK:STDOUT:   %C3: type = class_type @C3 [template = constants.%C3]
 // CHECK:STDOUT:   %C4.decl = class_decl @C4, ()
-// CHECK:STDOUT:   %C4: type = class_type @C4 [template]
+// CHECK:STDOUT:   %C4: type = class_type @C4 [template = constants.%C4]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @B {
@@ -72,8 +81,8 @@ class C4 {
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @C1 {
-// CHECK:STDOUT:   %B.ref: type = name_ref B, file.%B [template = file.%B]
-// CHECK:STDOUT:   %.loc13_25.1: type = unbound_element_type C1, B [template]
+// CHECK:STDOUT:   %B.ref: type = name_ref B, file.%B [template = constants.%B]
+// CHECK:STDOUT:   %.loc13_25.1: type = unbound_element_type C1, B [template = constants.%.4]
 // CHECK:STDOUT:   %.loc13_25.2: <unbound element of class C1> = base_decl B, element0 [template]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:
@@ -82,8 +91,8 @@ class C4 {
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @C2 {
-// CHECK:STDOUT:   %B.ref: type = name_ref B, file.%B [template = file.%B]
-// CHECK:STDOUT:   %.loc23_19.1: type = unbound_element_type C2, B [template]
+// CHECK:STDOUT:   %B.ref: type = name_ref B, file.%B [template = constants.%B]
+// CHECK:STDOUT:   %.loc23_19.1: type = unbound_element_type C2, B [template = constants.%.6]
 // CHECK:STDOUT:   %.loc23_19.2: <unbound element of class C2> = base_decl B, element0 [template]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:
@@ -91,8 +100,8 @@ class C4 {
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @C3 {
-// CHECK:STDOUT:   %B.ref: type = name_ref B, file.%B [template = file.%B]
-// CHECK:STDOUT:   %.loc33_25.1: type = unbound_element_type C3, B [template]
+// CHECK:STDOUT:   %B.ref: type = name_ref B, file.%B [template = constants.%B]
+// CHECK:STDOUT:   %.loc33_25.1: type = unbound_element_type C3, B [template = constants.%.7]
 // CHECK:STDOUT:   %.loc33_25.2: <unbound element of class C3> = base_decl B, element0 [template]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:
@@ -101,8 +110,8 @@ class C4 {
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @C4 {
-// CHECK:STDOUT:   %B.ref: type = name_ref B, file.%B [template = file.%B]
-// CHECK:STDOUT:   %.loc43_24.1: type = unbound_element_type C4, B [template]
+// CHECK:STDOUT:   %B.ref: type = name_ref B, file.%B [template = constants.%B]
+// CHECK:STDOUT:   %.loc43_24.1: type = unbound_element_type C4, B [template = constants.%.8]
 // CHECK:STDOUT:   %.loc43_24.2: <unbound element of class C4> = base_decl B, element0 [template]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:

+ 8 - 5
toolchain/check/testdata/class/fail_base_no_extend.carbon

@@ -16,18 +16,21 @@ class C {
 // CHECK:STDOUT: --- fail_base_no_extend.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %B: type = class_type @B [template]
 // CHECK:STDOUT:   %.1: type = struct_type {} [template]
+// CHECK:STDOUT:   %C: type = class_type @C [template]
 // CHECK:STDOUT:   %.2: type = tuple_type () [template]
 // CHECK:STDOUT:   %.3: type = ptr_type {} [template]
-// CHECK:STDOUT:   %.4: type = struct_type {.base: B} [template]
+// CHECK:STDOUT:   %.4: type = unbound_element_type C, B [template]
+// CHECK:STDOUT:   %.5: type = struct_type {.base: B} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.B = %B.decl, .C = %C.decl} [template]
 // CHECK:STDOUT:   %B.decl = class_decl @B, ()
-// CHECK:STDOUT:   %B: type = class_type @B [template]
+// CHECK:STDOUT:   %B: type = class_type @B [template = constants.%B]
 // CHECK:STDOUT:   %C.decl = class_decl @C, ()
-// CHECK:STDOUT:   %C: type = class_type @C [template]
+// CHECK:STDOUT:   %C: type = class_type @C [template = constants.%C]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @B {
@@ -36,8 +39,8 @@ class C {
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @C {
-// CHECK:STDOUT:   %B.ref: type = name_ref B, file.%B [template = file.%B]
-// CHECK:STDOUT:   %.loc13_10.1: type = unbound_element_type C, B [template]
+// CHECK:STDOUT:   %B.ref: type = name_ref B, file.%B [template = constants.%B]
+// CHECK:STDOUT:   %.loc13_10.1: type = unbound_element_type C, B [template = constants.%.4]
 // CHECK:STDOUT:   %.loc13_10.2: <unbound element of class C> = base_decl B, element0 [template]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:

+ 17 - 11
toolchain/check/testdata/class/fail_base_repeated.carbon

@@ -33,22 +33,28 @@ class D {
 // CHECK:STDOUT: --- fail_base_repeated.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %B1: type = class_type @B1 [template]
 // CHECK:STDOUT:   %.1: type = struct_type {} [template]
+// CHECK:STDOUT:   %B2: type = class_type @B2 [template]
+// CHECK:STDOUT:   %C: type = class_type @C [template]
 // CHECK:STDOUT:   %.2: type = tuple_type () [template]
 // CHECK:STDOUT:   %.3: type = ptr_type {} [template]
-// CHECK:STDOUT:   %.4: type = struct_type {.base: B1} [template]
+// CHECK:STDOUT:   %.4: type = unbound_element_type C, B1 [template]
+// CHECK:STDOUT:   %.5: type = struct_type {.base: B1} [template]
+// CHECK:STDOUT:   %D: type = class_type @D [template]
+// CHECK:STDOUT:   %.6: type = unbound_element_type D, B1 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.B1 = %B1.decl, .B2 = %B2.decl, .C = %C.decl, .D = %D.decl} [template]
 // CHECK:STDOUT:   %B1.decl = class_decl @B1, ()
-// CHECK:STDOUT:   %B1: type = class_type @B1 [template]
+// CHECK:STDOUT:   %B1: type = class_type @B1 [template = constants.%B1]
 // CHECK:STDOUT:   %B2.decl = class_decl @B2, ()
-// CHECK:STDOUT:   %B2: type = class_type @B2 [template]
+// CHECK:STDOUT:   %B2: type = class_type @B2 [template = constants.%B2]
 // CHECK:STDOUT:   %C.decl = class_decl @C, ()
-// CHECK:STDOUT:   %C: type = class_type @C [template]
+// CHECK:STDOUT:   %C: type = class_type @C [template = constants.%C]
 // CHECK:STDOUT:   %D.decl = class_decl @D, ()
-// CHECK:STDOUT:   %D: type = class_type @D [template]
+// CHECK:STDOUT:   %D: type = class_type @D [template = constants.%D]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @B1 {
@@ -62,10 +68,10 @@ class D {
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @C {
-// CHECK:STDOUT:   %B1.ref: type = name_ref B1, file.%B1 [template = file.%B1]
-// CHECK:STDOUT:   %.loc11_18.1: type = unbound_element_type C, B1 [template]
+// CHECK:STDOUT:   %B1.ref: type = name_ref B1, file.%B1 [template = constants.%B1]
+// CHECK:STDOUT:   %.loc11_18.1: type = unbound_element_type C, B1 [template = constants.%.4]
 // CHECK:STDOUT:   %.loc11_18.2: <unbound element of class C> = base_decl B1, element0 [template]
-// CHECK:STDOUT:   %B2.ref: type = name_ref B2, file.%B2 [template = file.%B2]
+// CHECK:STDOUT:   %B2.ref: type = name_ref B2, file.%B2 [template = constants.%B2]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:
 // CHECK:STDOUT:   .base = %.loc11_18.2
@@ -73,10 +79,10 @@ class D {
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @D {
-// CHECK:STDOUT:   %B1.ref.loc23: type = name_ref B1, file.%B1 [template = file.%B1]
-// CHECK:STDOUT:   %.loc23_18.1: type = unbound_element_type D, B1 [template]
+// CHECK:STDOUT:   %B1.ref.loc23: type = name_ref B1, file.%B1 [template = constants.%B1]
+// CHECK:STDOUT:   %.loc23_18.1: type = unbound_element_type D, B1 [template = constants.%.6]
 // CHECK:STDOUT:   %.loc23_18.2: <unbound element of class D> = base_decl B1, element0 [template]
-// CHECK:STDOUT:   %B1.ref.loc30: type = name_ref B1, file.%B1 [template = file.%B1]
+// CHECK:STDOUT:   %B1.ref.loc30: type = name_ref B1, file.%B1 [template = constants.%B1]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:
 // CHECK:STDOUT:   .base = %.loc23_18.2

+ 10 - 7
toolchain/check/testdata/class/fail_base_unbound.carbon

@@ -18,20 +18,23 @@ let b: B = C.base;
 // CHECK:STDOUT: --- fail_base_unbound.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %B: type = class_type @B [template]
 // CHECK:STDOUT:   %.1: type = struct_type {} [template]
+// CHECK:STDOUT:   %C: type = class_type @C [template]
 // CHECK:STDOUT:   %.2: type = tuple_type () [template]
 // CHECK:STDOUT:   %.3: type = ptr_type {} [template]
-// CHECK:STDOUT:   %.4: type = struct_type {.base: B} [template]
+// CHECK:STDOUT:   %.4: type = unbound_element_type C, B [template]
+// CHECK:STDOUT:   %.5: type = struct_type {.base: B} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.B = %B.decl, .C = %C.decl} [template]
 // CHECK:STDOUT:   %B.decl = class_decl @B, ()
-// CHECK:STDOUT:   %B: type = class_type @B [template]
+// CHECK:STDOUT:   %B: type = class_type @B [template = constants.%B]
 // CHECK:STDOUT:   %C.decl = class_decl @C, ()
-// CHECK:STDOUT:   %C: type = class_type @C [template]
-// CHECK:STDOUT:   %B.ref: type = name_ref B, %B [template = %B]
-// CHECK:STDOUT:   %C.ref: type = name_ref C, %C [template = %C]
+// CHECK:STDOUT:   %C: type = class_type @C [template = constants.%C]
+// CHECK:STDOUT:   %B.ref: type = name_ref B, %B [template = constants.%B]
+// CHECK:STDOUT:   %C.ref: type = name_ref C, %C [template = constants.%C]
 // CHECK:STDOUT:   %base.ref: <unbound element of class C> = name_ref base, @C.%.loc10_17.2 [template = @C.%.loc10_17.2]
 // CHECK:STDOUT:   %b: B = bind_name b, <error>
 // CHECK:STDOUT: }
@@ -42,8 +45,8 @@ let b: B = C.base;
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @C {
-// CHECK:STDOUT:   %B.ref: type = name_ref B, file.%B [template = file.%B]
-// CHECK:STDOUT:   %.loc10_17.1: type = unbound_element_type C, B [template]
+// CHECK:STDOUT:   %B.ref: type = name_ref B, file.%B [template = constants.%B]
+// CHECK:STDOUT:   %.loc10_17.1: type = unbound_element_type C, B [template = constants.%.4]
 // CHECK:STDOUT:   %.loc10_17.2: <unbound element of class C> = base_decl B, element0 [template]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:

+ 27 - 15
toolchain/check/testdata/class/fail_derived_to_base.carbon

@@ -32,30 +32,42 @@ fn ConvertIncomplete(p: Incomplete*) -> A2* { return p; }
 // CHECK:STDOUT: --- fail_derived_to_base.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = struct_type {.a: i32} [template]
-// CHECK:STDOUT:   %.2: type = ptr_type {.a: i32} [template]
-// CHECK:STDOUT:   %.3: type = struct_type {.base: A2, .b: i32} [template]
-// CHECK:STDOUT:   %.4: type = struct_type {.base: {.a: i32}*, .b: i32} [template]
-// CHECK:STDOUT:   %.5: type = ptr_type {.base: {.a: i32}*, .b: i32} [template]
-// CHECK:STDOUT:   %.6: type = ptr_type {.base: A2, .b: i32} [template]
+// CHECK:STDOUT:   %A1: type = class_type @A1 [template]
+// CHECK:STDOUT:   %.1: type = unbound_element_type A1, i32 [template]
+// CHECK:STDOUT:   %.2: type = struct_type {.a: i32} [template]
+// CHECK:STDOUT:   %A2: type = class_type @A2 [template]
+// CHECK:STDOUT:   %.3: type = unbound_element_type A2, i32 [template]
+// CHECK:STDOUT:   %B2: type = class_type @B2 [template]
+// CHECK:STDOUT:   %.4: type = ptr_type {.a: i32} [template]
+// CHECK:STDOUT:   %.5: type = unbound_element_type B2, A2 [template]
+// CHECK:STDOUT:   %.6: type = unbound_element_type B2, i32 [template]
+// CHECK:STDOUT:   %.7: type = struct_type {.base: A2, .b: i32} [template]
+// CHECK:STDOUT:   %.8: type = ptr_type B2 [template]
+// CHECK:STDOUT:   %.9: type = ptr_type A1 [template]
+// CHECK:STDOUT:   %.10: type = struct_type {.base: {.a: i32}*, .b: i32} [template]
+// CHECK:STDOUT:   %.11: type = ptr_type {.base: {.a: i32}*, .b: i32} [template]
+// CHECK:STDOUT:   %.12: type = ptr_type {.base: A2, .b: i32} [template]
+// CHECK:STDOUT:   %Incomplete: type = class_type @Incomplete [template]
+// CHECK:STDOUT:   %.13: type = ptr_type Incomplete [template]
+// CHECK:STDOUT:   %.14: type = ptr_type A2 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.A1 = %A1.decl, .A2 = %A2.decl, .B2 = %B2.decl, .ConvertUnrelated = %ConvertUnrelated, .Incomplete = %Incomplete.decl, .ConvertIncomplete = %ConvertIncomplete} [template]
 // CHECK:STDOUT:   %A1.decl = class_decl @A1, ()
-// CHECK:STDOUT:   %A1: type = class_type @A1 [template]
+// CHECK:STDOUT:   %A1: type = class_type @A1 [template = constants.%A1]
 // CHECK:STDOUT:   %A2.decl = class_decl @A2, ()
-// CHECK:STDOUT:   %A2: type = class_type @A2 [template]
+// CHECK:STDOUT:   %A2: type = class_type @A2 [template = constants.%A2]
 // CHECK:STDOUT:   %B2.decl = class_decl @B2, ()
-// CHECK:STDOUT:   %B2: type = class_type @B2 [template]
+// CHECK:STDOUT:   %B2: type = class_type @B2 [template = constants.%B2]
 // CHECK:STDOUT:   %ConvertUnrelated: <function> = fn_decl @ConvertUnrelated [template]
 // CHECK:STDOUT:   %Incomplete.decl = class_decl @Incomplete, ()
-// CHECK:STDOUT:   %Incomplete: type = class_type @Incomplete [template]
+// CHECK:STDOUT:   %Incomplete: type = class_type @Incomplete [template = constants.%Incomplete]
 // CHECK:STDOUT:   %ConvertIncomplete: <function> = fn_decl @ConvertIncomplete [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @A1 {
-// CHECK:STDOUT:   %.loc8_8.1: type = unbound_element_type A1, i32 [template]
+// CHECK:STDOUT:   %.loc8_8.1: type = unbound_element_type A1, i32 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc8_8.2: <unbound element of class A1> = field_decl a, element0 [template]
 // CHECK:STDOUT:   %a: <unbound element of class A1> = bind_name a, %.loc8_8.2 [template = %.loc8_8.2]
 // CHECK:STDOUT:
@@ -64,7 +76,7 @@ fn ConvertIncomplete(p: Incomplete*) -> A2* { return p; }
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @A2 {
-// CHECK:STDOUT:   %.loc12_8.1: type = unbound_element_type A2, i32 [template]
+// CHECK:STDOUT:   %.loc12_8.1: type = unbound_element_type A2, i32 [template = constants.%.3]
 // CHECK:STDOUT:   %.loc12_8.2: <unbound element of class A2> = field_decl a, element0 [template]
 // CHECK:STDOUT:   %a: <unbound element of class A2> = bind_name a, %.loc12_8.2 [template = %.loc12_8.2]
 // CHECK:STDOUT:
@@ -73,10 +85,10 @@ fn ConvertIncomplete(p: Incomplete*) -> A2* { return p; }
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @B2 {
-// CHECK:STDOUT:   %A2.ref: type = name_ref A2, file.%A2 [template = file.%A2]
-// CHECK:STDOUT:   %.loc16_18.1: type = unbound_element_type B2, A2 [template]
+// CHECK:STDOUT:   %A2.ref: type = name_ref A2, file.%A2 [template = constants.%A2]
+// CHECK:STDOUT:   %.loc16_18.1: type = unbound_element_type B2, A2 [template = constants.%.5]
 // CHECK:STDOUT:   %.loc16_18.2: <unbound element of class B2> = base_decl A2, element0 [template]
-// CHECK:STDOUT:   %.loc17_8.1: type = unbound_element_type B2, i32 [template]
+// CHECK:STDOUT:   %.loc17_8.1: type = unbound_element_type B2, i32 [template = constants.%.6]
 // CHECK:STDOUT:   %.loc17_8.2: <unbound element of class B2> = field_decl b, element1 [template]
 // CHECK:STDOUT:   %b: <unbound element of class B2> = bind_name b, %.loc17_8.2 [template = %.loc17_8.2]
 // CHECK:STDOUT:

+ 12 - 10
toolchain/check/testdata/class/fail_field_modifiers.carbon

@@ -30,28 +30,30 @@ class Class {
 // CHECK:STDOUT: --- fail_field_modifiers.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: i32 = int_literal 0 [template]
-// CHECK:STDOUT:   %.2: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.3: type = struct_type {.j: i32, .k: i32} [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %.1: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.2: i32 = int_literal 0 [template]
+// CHECK:STDOUT:   %.3: i32 = int_literal 1 [template]
+// CHECK:STDOUT:   %.4: type = struct_type {.j: i32, .k: i32} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Class = %Class.decl} [template]
 // CHECK:STDOUT:   %Class.decl = class_decl @Class, ()
-// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template = constants.%Class]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Class {
-// CHECK:STDOUT:   %.loc12_16.1: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.loc12_16.1: type = unbound_element_type Class, i32 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc12_16.2: <unbound element of class Class> = field_decl j, element0 [template]
 // CHECK:STDOUT:   %j: <unbound element of class Class> = bind_name j, %.loc12_16.2 [template = %.loc12_16.2]
-// CHECK:STDOUT:   %.loc17_14.1: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.loc17_14.1: type = unbound_element_type Class, i32 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc17_14.2: <unbound element of class Class> = field_decl k, element1 [template]
 // CHECK:STDOUT:   %k: <unbound element of class Class> = bind_name k, %.loc17_14.2 [template = %.loc17_14.2]
-// CHECK:STDOUT:   %.loc22: i32 = int_literal 0 [template = constants.%.1]
-// CHECK:STDOUT:   %l: i32 = bind_name l, %.loc22 [template = constants.%.1]
-// CHECK:STDOUT:   %.loc27: i32 = int_literal 1 [template = constants.%.2]
-// CHECK:STDOUT:   %m: i32 = bind_name m, %.loc27 [template = constants.%.2]
+// CHECK:STDOUT:   %.loc22: i32 = int_literal 0 [template = constants.%.2]
+// CHECK:STDOUT:   %l: i32 = bind_name l, %.loc22 [template = constants.%.2]
+// CHECK:STDOUT:   %.loc27: i32 = int_literal 1 [template = constants.%.3]
+// CHECK:STDOUT:   %m: i32 = bind_name m, %.loc27 [template = constants.%.3]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:
 // CHECK:STDOUT:   .j = %j

+ 7 - 5
toolchain/check/testdata/class/fail_incomplete.carbon

@@ -118,17 +118,19 @@ fn CallReturnIncomplete() {
 // CHECK:STDOUT: --- fail_incomplete.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %Class: type = class_type @Class [template]
 // CHECK:STDOUT:   %.1: type = struct_type {} [template]
-// CHECK:STDOUT:   %.2: type = tuple_type () [template]
+// CHECK:STDOUT:   %.2: type = ptr_type Class [template]
+// CHECK:STDOUT:   %.3: type = tuple_type () [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Class = %Class.decl, .CallClassFunction = %CallClassFunction, .global_var = %global_var, .ConvertFromStruct = %ConvertFromStruct, .MemberAccess = %MemberAccess, .Copy = %Copy, .Let = %Let, .TakeIncomplete = %TakeIncomplete, .ReturnIncomplete = %ReturnIncomplete, .CallTakeIncomplete = %CallTakeIncomplete, .CallReturnIncomplete = %CallReturnIncomplete} [template]
 // CHECK:STDOUT:   %Class.decl = class_decl @Class, ()
-// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template = constants.%Class]
 // CHECK:STDOUT:   %.loc15: <function> = fn_decl @.1 [template]
 // CHECK:STDOUT:   %CallClassFunction: <function> = fn_decl @CallClassFunction [template]
-// CHECK:STDOUT:   %Class.ref: type = name_ref Class, %Class [template = %Class]
+// CHECK:STDOUT:   %Class.ref: type = name_ref Class, %Class [template = constants.%Class]
 // CHECK:STDOUT:   %global_var.var: ref <error> = var global_var
 // CHECK:STDOUT:   %global_var: ref <error> = bind_name global_var, %global_var.var
 // CHECK:STDOUT:   %ConvertFromStruct: <function> = fn_decl @ConvertFromStruct [template]
@@ -150,7 +152,7 @@ fn CallReturnIncomplete() {
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @CallClassFunction() {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %Class.ref: type = name_ref Class, file.%Class [template = file.%Class]
+// CHECK:STDOUT:   %Class.ref: type = name_ref Class, file.%Class [template = constants.%Class]
 // CHECK:STDOUT:   %Function.ref: <error> = name_ref Function, <error>
 // CHECK:STDOUT:   return
 // CHECK:STDOUT: }
@@ -177,7 +179,7 @@ fn CallReturnIncomplete() {
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @Let(%p: Class*) {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %Class.ref: type = name_ref Class, file.%Class [template = file.%Class]
+// CHECK:STDOUT:   %Class.ref: type = name_ref Class, file.%Class [template = constants.%Class]
 // CHECK:STDOUT:   %p.ref: Class* = name_ref p, %p
 // CHECK:STDOUT:   %.loc75: ref Class = deref %p.ref
 // CHECK:STDOUT:   %c: <error> = bind_name c, <error>

+ 19 - 20
toolchain/check/testdata/class/fail_init.carbon

@@ -27,31 +27,30 @@ fn F() {
 // CHECK:STDOUT: --- fail_init.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = struct_type {.a: i32, .b: i32} [template]
-// CHECK:STDOUT:   %.2: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.3: type = struct_type {.a: i32} [template]
-// CHECK:STDOUT:   %.4: type = ptr_type {.a: i32, .b: i32} [template]
-// CHECK:STDOUT:   %.5: i32 = int_literal 1 [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %.1: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.2: type = struct_type {.a: i32, .b: i32} [template]
+// CHECK:STDOUT:   %.3: i32 = int_literal 1 [template]
+// CHECK:STDOUT:   %.4: type = struct_type {.a: i32} [template]
+// CHECK:STDOUT:   %.5: type = ptr_type {.a: i32, .b: i32} [template]
 // CHECK:STDOUT:   %.6: i32 = int_literal 2 [template]
 // CHECK:STDOUT:   %.7: type = struct_type {.a: i32, .c: i32} [template]
-// CHECK:STDOUT:   %.8: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.9: i32 = int_literal 2 [template]
-// CHECK:STDOUT:   %.10: i32 = int_literal 3 [template]
-// CHECK:STDOUT:   %.11: type = struct_type {.a: i32, .b: i32, .c: i32} [template]
+// CHECK:STDOUT:   %.8: i32 = int_literal 3 [template]
+// CHECK:STDOUT:   %.9: type = struct_type {.a: i32, .b: i32, .c: i32} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Class = %Class.decl, .F = %F} [template]
 // CHECK:STDOUT:   %Class.decl = class_decl @Class, ()
-// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template = constants.%Class]
 // CHECK:STDOUT:   %F: <function> = fn_decl @F [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Class {
-// CHECK:STDOUT:   %.loc8_8.1: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.loc8_8.1: type = unbound_element_type Class, i32 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc8_8.2: <unbound element of class Class> = field_decl a, element0 [template]
 // CHECK:STDOUT:   %a: <unbound element of class Class> = bind_name a, %.loc8_8.2 [template = %.loc8_8.2]
-// CHECK:STDOUT:   %.loc9_8.1: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.loc9_8.1: type = unbound_element_type Class, i32 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc9_8.2: <unbound element of class Class> = field_decl b, element1 [template]
 // CHECK:STDOUT:   %b: <unbound element of class Class> = bind_name b, %.loc9_8.2 [template = %.loc9_8.2]
 // CHECK:STDOUT:
@@ -62,26 +61,26 @@ fn F() {
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @F() {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %.loc16_9: i32 = int_literal 1 [template = constants.%.2]
+// CHECK:STDOUT:   %.loc16_9: i32 = int_literal 1 [template = constants.%.3]
 // CHECK:STDOUT:   %.loc16_10.1: {.a: i32} = struct_literal (%.loc16_9)
-// CHECK:STDOUT:   %Class.ref.loc16: type = name_ref Class, file.%Class [template = file.%Class]
+// CHECK:STDOUT:   %Class.ref.loc16: type = name_ref Class, file.%Class [template = constants.%Class]
 // CHECK:STDOUT:   %.loc16_10.2: ref Class = temporary_storage
 // CHECK:STDOUT:   %.loc16_10.3: ref Class = temporary %.loc16_10.2, <error>
 // CHECK:STDOUT:   %.loc16_10.4: ref Class = converted %.loc16_10.1, %.loc16_10.3
-// CHECK:STDOUT:   %.loc20_9: i32 = int_literal 1 [template = constants.%.5]
+// CHECK:STDOUT:   %.loc20_9: i32 = int_literal 1 [template = constants.%.3]
 // CHECK:STDOUT:   %.loc20_17: i32 = int_literal 2 [template = constants.%.6]
 // CHECK:STDOUT:   %.loc20_18.1: {.a: i32, .c: i32} = struct_literal (%.loc20_9, %.loc20_17)
-// CHECK:STDOUT:   %Class.ref.loc20: type = name_ref Class, file.%Class [template = file.%Class]
+// CHECK:STDOUT:   %Class.ref.loc20: type = name_ref Class, file.%Class [template = constants.%Class]
 // CHECK:STDOUT:   %.loc20_18.2: ref Class = temporary_storage
 // CHECK:STDOUT:   %.loc20_18.3: ref i32 = class_element_access %.loc20_18.2, element0
 // CHECK:STDOUT:   %.loc20_18.4: init i32 = initialize_from %.loc20_9 to %.loc20_18.3
 // CHECK:STDOUT:   %.loc20_18.5: ref Class = temporary %.loc20_18.2, <error>
 // CHECK:STDOUT:   %.loc20_18.6: ref Class = converted %.loc20_18.1, %.loc20_18.5
-// CHECK:STDOUT:   %.loc24_9: i32 = int_literal 1 [template = constants.%.8]
-// CHECK:STDOUT:   %.loc24_17: i32 = int_literal 2 [template = constants.%.9]
-// CHECK:STDOUT:   %.loc24_25: i32 = int_literal 3 [template = constants.%.10]
+// CHECK:STDOUT:   %.loc24_9: i32 = int_literal 1 [template = constants.%.3]
+// CHECK:STDOUT:   %.loc24_17: i32 = int_literal 2 [template = constants.%.6]
+// CHECK:STDOUT:   %.loc24_25: i32 = int_literal 3 [template = constants.%.8]
 // CHECK:STDOUT:   %.loc24_26.1: {.a: i32, .b: i32, .c: i32} = struct_literal (%.loc24_9, %.loc24_17, %.loc24_25)
-// CHECK:STDOUT:   %Class.ref.loc24: type = name_ref Class, file.%Class [template = file.%Class]
+// CHECK:STDOUT:   %Class.ref.loc24: type = name_ref Class, file.%Class [template = constants.%Class]
 // CHECK:STDOUT:   %.loc24_26.2: ref Class = temporary_storage
 // CHECK:STDOUT:   %.loc24_26.3: ref Class = temporary %.loc24_26.2, <error>
 // CHECK:STDOUT:   %.loc24_26.4: ref Class = converted %.loc24_26.1, %.loc24_26.3

+ 15 - 12
toolchain/check/testdata/class/fail_init_as_inplace.carbon

@@ -25,26 +25,29 @@ fn F() {
 // CHECK:STDOUT: --- fail_init_as_inplace.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = struct_type {.a: i32, .b: i32} [template]
-// CHECK:STDOUT:   %.2: type = ptr_type {.a: i32, .b: i32} [template]
-// CHECK:STDOUT:   %.3: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.4: i32 = int_literal 2 [template]
-// CHECK:STDOUT:   %.5: type = tuple_type () [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %.1: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.2: type = struct_type {.a: i32, .b: i32} [template]
+// CHECK:STDOUT:   %.3: type = ptr_type Class [template]
+// CHECK:STDOUT:   %.4: type = ptr_type {.a: i32, .b: i32} [template]
+// CHECK:STDOUT:   %.5: i32 = int_literal 1 [template]
+// CHECK:STDOUT:   %.6: i32 = int_literal 2 [template]
+// CHECK:STDOUT:   %.7: type = tuple_type () [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Class = %Class.decl, .G = %G, .F = %F} [template]
 // CHECK:STDOUT:   %Class.decl = class_decl @Class, ()
-// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template = constants.%Class]
 // CHECK:STDOUT:   %G: <function> = fn_decl @G [template]
 // CHECK:STDOUT:   %F: <function> = fn_decl @F [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Class {
-// CHECK:STDOUT:   %.loc8_8.1: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.loc8_8.1: type = unbound_element_type Class, i32 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc8_8.2: <unbound element of class Class> = field_decl a, element0 [template]
 // CHECK:STDOUT:   %a: <unbound element of class Class> = bind_name a, %.loc8_8.2 [template = %.loc8_8.2]
-// CHECK:STDOUT:   %.loc9_8.1: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.loc9_8.1: type = unbound_element_type Class, i32 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc9_8.2: <unbound element of class Class> = field_decl b, element1 [template]
 // CHECK:STDOUT:   %b: <unbound element of class Class> = bind_name b, %.loc9_8.2 [template = %.loc9_8.2]
 // CHECK:STDOUT:
@@ -57,13 +60,13 @@ fn F() {
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @F() {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %Class.ref.loc21_10: type = name_ref Class, file.%Class [template = file.%Class]
+// CHECK:STDOUT:   %Class.ref.loc21_10: type = name_ref Class, file.%Class [template = constants.%Class]
 // CHECK:STDOUT:   %c.var: ref Class = var c
 // CHECK:STDOUT:   %c: ref Class = bind_name c, %c.var
-// CHECK:STDOUT:   %.loc21_24: i32 = int_literal 1 [template = constants.%.3]
-// CHECK:STDOUT:   %.loc21_32: i32 = int_literal 2 [template = constants.%.4]
+// CHECK:STDOUT:   %.loc21_24: i32 = int_literal 1 [template = constants.%.5]
+// CHECK:STDOUT:   %.loc21_32: i32 = int_literal 2 [template = constants.%.6]
 // CHECK:STDOUT:   %.loc21_33.1: {.a: i32, .b: i32} = struct_literal (%.loc21_24, %.loc21_32)
-// CHECK:STDOUT:   %Class.ref.loc21_38: type = name_ref Class, file.%Class [template = file.%Class]
+// CHECK:STDOUT:   %Class.ref.loc21_38: type = name_ref Class, file.%Class [template = constants.%Class]
 // CHECK:STDOUT:   %.loc21_33.2: ref Class = temporary_storage
 // CHECK:STDOUT:   %.loc21_33.3: ref i32 = class_element_access %.loc21_33.2, element0
 // CHECK:STDOUT:   %.loc21_33.4: init i32 = initialize_from %.loc21_24 to %.loc21_33.3

+ 15 - 10
toolchain/check/testdata/class/fail_memaccess_category.carbon

@@ -36,20 +36,25 @@ fn F(s: {.a: A}, b: B) {
 // CHECK:STDOUT: --- fail_memaccess_category.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = struct_type {} [template]
-// CHECK:STDOUT:   %.2: type = tuple_type () [template]
-// CHECK:STDOUT:   %.3: type = ptr_type {} [template]
-// CHECK:STDOUT:   %.4: type = struct_type {.a: A} [template]
-// CHECK:STDOUT:   %.5: type = struct_type {.a: {}*} [template]
-// CHECK:STDOUT:   %.6: type = ptr_type {.a: A} [template]
+// CHECK:STDOUT:   %A: type = class_type @A [template]
+// CHECK:STDOUT:   %.1: type = ptr_type A [template]
+// CHECK:STDOUT:   %.2: type = struct_type {} [template]
+// CHECK:STDOUT:   %B: type = class_type @B [template]
+// CHECK:STDOUT:   %.3: type = tuple_type () [template]
+// CHECK:STDOUT:   %.4: type = ptr_type {} [template]
+// CHECK:STDOUT:   %.5: type = unbound_element_type B, A [template]
+// CHECK:STDOUT:   %.6: type = struct_type {.a: A} [template]
+// CHECK:STDOUT:   %.7: type = struct_type {.a: A} [template]
+// CHECK:STDOUT:   %.8: type = struct_type {.a: {}*} [template]
+// CHECK:STDOUT:   %.9: type = ptr_type {.a: A} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.A = %A.decl, .B = %B.decl, .F = %F} [template]
 // CHECK:STDOUT:   %A.decl = class_decl @A, ()
-// CHECK:STDOUT:   %A: type = class_type @A [template]
+// CHECK:STDOUT:   %A: type = class_type @A [template = constants.%A]
 // CHECK:STDOUT:   %B.decl = class_decl @B, ()
-// CHECK:STDOUT:   %B: type = class_type @B [template]
+// CHECK:STDOUT:   %B: type = class_type @B [template = constants.%B]
 // CHECK:STDOUT:   %F: <function> = fn_decl @F.2 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
@@ -61,8 +66,8 @@ fn F(s: {.a: A}, b: B) {
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @B {
-// CHECK:STDOUT:   %A.ref: type = name_ref A, file.%A [template = file.%A]
-// CHECK:STDOUT:   %.loc12_8.1: type = unbound_element_type B, A [template]
+// CHECK:STDOUT:   %A.ref: type = name_ref A, file.%A [template = constants.%A]
+// CHECK:STDOUT:   %.loc12_8.1: type = unbound_element_type B, A [template = constants.%.5]
 // CHECK:STDOUT:   %.loc12_8.2: <unbound element of class B> = field_decl a, element0 [template]
 // CHECK:STDOUT:   %a: <unbound element of class B> = bind_name a, %.loc12_8.2 [template = %.loc12_8.2]
 // CHECK:STDOUT:

+ 4 - 3
toolchain/check/testdata/class/fail_member_of_let.carbon

@@ -21,15 +21,16 @@ fn T.F() {}
 // CHECK:STDOUT: --- fail_member_of_let.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %Class: type = class_type @Class [template]
 // CHECK:STDOUT:   %.1: type = struct_type {} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Class = %Class.decl} [template]
 // CHECK:STDOUT:   %Class.decl = class_decl @Class, ()
-// CHECK:STDOUT:   %Class: type = class_type @Class [template]
-// CHECK:STDOUT:   %Class.ref: type = name_ref Class, %Class [template = %Class]
-// CHECK:STDOUT:   %T: type = bind_name T, %Class.ref [template = %Class]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template = constants.%Class]
+// CHECK:STDOUT:   %Class.ref: type = name_ref Class, %Class [template = constants.%Class]
+// CHECK:STDOUT:   %T: type = bind_name T, %Class.ref [template = constants.%Class]
 // CHECK:STDOUT:   %.loc19: <function> = fn_decl @.1 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:

+ 5 - 4
toolchain/check/testdata/class/fail_method.carbon

@@ -33,6 +33,7 @@ fn F(c: Class) {
 // CHECK:STDOUT: --- fail_method.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %Class: type = class_type @Class [template]
 // CHECK:STDOUT:   %.1: type = struct_type {} [template]
 // CHECK:STDOUT:   %.2: type = tuple_type () [template]
 // CHECK:STDOUT:   %.3: type = ptr_type {} [template]
@@ -41,7 +42,7 @@ fn F(c: Class) {
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Class = %Class.decl, .F = %F} [template]
 // CHECK:STDOUT:   %Class.decl = class_decl @Class, ()
-// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template = constants.%Class]
 // CHECK:STDOUT:   %F: <function> = fn_decl @F [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
@@ -66,13 +67,13 @@ fn F(c: Class) {
 // CHECK:STDOUT:   %c.ref.loc14: Class = name_ref c, %c
 // CHECK:STDOUT:   %.loc14_4: <bound method> = bound_method %c.ref.loc14, @Class.%WithSelf
 // CHECK:STDOUT:   %.loc14_13: init () = call %.loc14_4(%c.ref.loc14)
-// CHECK:STDOUT:   %Class.ref.loc16: type = name_ref Class, file.%Class [template = file.%Class]
+// CHECK:STDOUT:   %Class.ref.loc16: type = name_ref Class, file.%Class [template = constants.%Class]
 // CHECK:STDOUT:   %NoSelf.ref.loc16: <function> = name_ref NoSelf, @Class.%NoSelf [template = @Class.%NoSelf]
 // CHECK:STDOUT:   %.loc16: init () = call %NoSelf.ref.loc16()
-// CHECK:STDOUT:   %Class.ref.loc23: type = name_ref Class, file.%Class [template = file.%Class]
+// CHECK:STDOUT:   %Class.ref.loc23: type = name_ref Class, file.%Class [template = constants.%Class]
 // CHECK:STDOUT:   %WithSelf.ref.loc23: <function> = name_ref WithSelf, @Class.%WithSelf [template = @Class.%WithSelf]
 // CHECK:STDOUT:   %.loc23: init () = call %WithSelf.ref.loc23(<invalid>)
-// CHECK:STDOUT:   %Class.ref.loc30: type = name_ref Class, file.%Class [template = file.%Class]
+// CHECK:STDOUT:   %Class.ref.loc30: type = name_ref Class, file.%Class [template = constants.%Class]
 // CHECK:STDOUT:   %WithSelf.ref.loc30: <function> = name_ref WithSelf, @Class.%WithSelf [template = @Class.%WithSelf]
 // CHECK:STDOUT:   %c.ref.loc30: Class = name_ref c, %c
 // CHECK:STDOUT:   %.loc30: init () = call %WithSelf.ref.loc30(<invalid>)

+ 6 - 3
toolchain/check/testdata/class/fail_method_modifiers.carbon

@@ -50,17 +50,20 @@ base class BaseClass {
 // CHECK:STDOUT: --- fail_method_modifiers.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %FinalClass: type = class_type @FinalClass [template]
 // CHECK:STDOUT:   %.1: type = struct_type {} [template]
+// CHECK:STDOUT:   %AbstractClass: type = class_type @AbstractClass [template]
+// CHECK:STDOUT:   %BaseClass: type = class_type @BaseClass [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.FinalClass = %FinalClass.decl, .AbstractClass = %AbstractClass.decl, .BaseClass = %BaseClass.decl} [template]
 // CHECK:STDOUT:   %FinalClass.decl = class_decl @FinalClass, ()
-// CHECK:STDOUT:   %FinalClass: type = class_type @FinalClass [template]
+// CHECK:STDOUT:   %FinalClass: type = class_type @FinalClass [template = constants.%FinalClass]
 // CHECK:STDOUT:   %AbstractClass.decl = class_decl @AbstractClass, ()
-// CHECK:STDOUT:   %AbstractClass: type = class_type @AbstractClass [template]
+// CHECK:STDOUT:   %AbstractClass: type = class_type @AbstractClass [template = constants.%AbstractClass]
 // CHECK:STDOUT:   %BaseClass.decl = class_decl @BaseClass, ()
-// CHECK:STDOUT:   %BaseClass: type = class_type @BaseClass [template]
+// CHECK:STDOUT:   %BaseClass: type = class_type @BaseClass [template = constants.%BaseClass]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @FinalClass {

+ 12 - 6
toolchain/check/testdata/class/fail_modifiers.carbon

@@ -67,23 +67,29 @@ abstract base class AbstractAndBase {}
 // CHECK:STDOUT: --- fail_modifiers.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %DuplicatePrivate: type = class_type @DuplicatePrivate [template]
+// CHECK:STDOUT:   %TwoAccess: type = class_type @TwoAccess [template]
 // CHECK:STDOUT:   %.1: type = struct_type {} [template]
+// CHECK:STDOUT:   %TwoAbstract: type = class_type @TwoAbstract [template]
+// CHECK:STDOUT:   %Virtual: type = class_type @Virtual [template]
+// CHECK:STDOUT:   %WrongOrder: type = class_type @WrongOrder [template]
+// CHECK:STDOUT:   %AbstractAndBase: type = class_type @AbstractAndBase [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.DuplicatePrivate = %DuplicatePrivate.decl, .TwoAccess = %TwoAccess.decl, .TwoAbstract = %TwoAbstract.decl, .Virtual = %Virtual.decl, .WrongOrder = %WrongOrder.decl, .AbstractAndBase = %AbstractAndBase.decl} [template]
 // CHECK:STDOUT:   %DuplicatePrivate.decl = class_decl @DuplicatePrivate, ()
-// CHECK:STDOUT:   %DuplicatePrivate: type = class_type @DuplicatePrivate [template]
+// CHECK:STDOUT:   %DuplicatePrivate: type = class_type @DuplicatePrivate [template = constants.%DuplicatePrivate]
 // CHECK:STDOUT:   %TwoAccess.decl = class_decl @TwoAccess, ()
-// CHECK:STDOUT:   %TwoAccess: type = class_type @TwoAccess [template]
+// CHECK:STDOUT:   %TwoAccess: type = class_type @TwoAccess [template = constants.%TwoAccess]
 // CHECK:STDOUT:   %TwoAbstract.decl = class_decl @TwoAbstract, ()
-// CHECK:STDOUT:   %TwoAbstract: type = class_type @TwoAbstract [template]
+// CHECK:STDOUT:   %TwoAbstract: type = class_type @TwoAbstract [template = constants.%TwoAbstract]
 // CHECK:STDOUT:   %Virtual.decl = class_decl @Virtual, ()
-// CHECK:STDOUT:   %Virtual: type = class_type @Virtual [template]
+// CHECK:STDOUT:   %Virtual: type = class_type @Virtual [template = constants.%Virtual]
 // CHECK:STDOUT:   %WrongOrder.decl = class_decl @WrongOrder, ()
-// CHECK:STDOUT:   %WrongOrder: type = class_type @WrongOrder [template]
+// CHECK:STDOUT:   %WrongOrder: type = class_type @WrongOrder [template = constants.%WrongOrder]
 // CHECK:STDOUT:   %AbstractAndBase.decl = class_decl @AbstractAndBase, ()
-// CHECK:STDOUT:   %AbstractAndBase: type = class_type @AbstractAndBase [template]
+// CHECK:STDOUT:   %AbstractAndBase: type = class_type @AbstractAndBase [template = constants.%AbstractAndBase]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @DuplicatePrivate;

+ 2 - 1
toolchain/check/testdata/class/fail_out_of_line_decl.carbon

@@ -14,13 +14,14 @@ fn C.F() {}
 // CHECK:STDOUT: --- fail_out_of_line_decl.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %C: type = class_type @C [template]
 // CHECK:STDOUT:   %.1: type = struct_type {} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.C = %C.decl} [template]
 // CHECK:STDOUT:   %C.decl = class_decl @C, ()
-// CHECK:STDOUT:   %C: type = class_type @C [template]
+// CHECK:STDOUT:   %C: type = class_type @C [template = constants.%C]
 // CHECK:STDOUT:   %F: <function> = fn_decl @F [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:

+ 14 - 7
toolchain/check/testdata/class/fail_redeclaration_introducer.carbon

@@ -77,31 +77,38 @@ base class G;
 // CHECK:STDOUT: --- fail_redeclaration_introducer.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:   %C: type = class_type @C [template]
+// CHECK:STDOUT:   %D: type = class_type @D [template]
+// CHECK:STDOUT:   %E: type = class_type @E [template]
+// CHECK:STDOUT:   %F: type = class_type @F [template]
+// CHECK:STDOUT:   %G: type = class_type @G [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.A = %A.decl.loc7, .B = %B.decl.loc16, .C = %C.decl.loc25, .D = %D.decl.loc34, .E = %E.decl.loc43, .F = %F.decl.loc52, .G = %G.decl.loc61} [template]
 // CHECK:STDOUT:   %A.decl.loc7 = class_decl @A, ()
-// CHECK:STDOUT:   %A: type = class_type @A [template]
+// CHECK:STDOUT:   %A: type = class_type @A [template = constants.%A]
 // CHECK:STDOUT:   %A.decl.loc14 = class_decl @A, ()
 // CHECK:STDOUT:   %B.decl.loc16 = class_decl @B, ()
-// CHECK:STDOUT:   %B: type = class_type @B [template]
+// CHECK:STDOUT:   %B: type = class_type @B [template = constants.%B]
 // CHECK:STDOUT:   %B.decl.loc23 = class_decl @B, ()
 // CHECK:STDOUT:   %C.decl.loc25 = class_decl @C, ()
-// CHECK:STDOUT:   %C: type = class_type @C [template]
+// CHECK:STDOUT:   %C: type = class_type @C [template = constants.%C]
 // CHECK:STDOUT:   %C.decl.loc32 = class_decl @C, ()
 // CHECK:STDOUT:   %D.decl.loc34 = class_decl @D, ()
-// CHECK:STDOUT:   %D: type = class_type @D [template]
+// CHECK:STDOUT:   %D: type = class_type @D [template = constants.%D]
 // CHECK:STDOUT:   %D.decl.loc41 = class_decl @D, ()
 // CHECK:STDOUT:   %E.decl.loc43 = class_decl @E, ()
-// CHECK:STDOUT:   %E: type = class_type @E [template]
+// CHECK:STDOUT:   %E: type = class_type @E [template = constants.%E]
 // CHECK:STDOUT:   %E.decl.loc50 = class_decl @E, ()
 // CHECK:STDOUT:   %F.decl.loc52 = class_decl @F, ()
-// CHECK:STDOUT:   %F: type = class_type @F [template]
+// CHECK:STDOUT:   %F: type = class_type @F [template = constants.%F]
 // CHECK:STDOUT:   %F.decl.loc59 = class_decl @F, ()
 // CHECK:STDOUT:   %G.decl.loc61 = class_decl @G, ()
-// CHECK:STDOUT:   %G: type = class_type @G [template]
+// CHECK:STDOUT:   %G: type = class_type @G [template = constants.%G]
 // CHECK:STDOUT:   %G.decl.loc68 = class_decl @G, ()
 // CHECK:STDOUT:   %G.decl.loc75 = class_decl @G, ()
 // CHECK:STDOUT: }

+ 14 - 7
toolchain/check/testdata/class/fail_redeclaration_scope.carbon

@@ -24,23 +24,30 @@ class Y {
 // CHECK:STDOUT: --- fail_redeclaration_scope.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %A.1: type = class_type @A.1 [template]
+// CHECK:STDOUT:   %X: type = class_type @X [template]
+// CHECK:STDOUT:   %A.2: type = class_type @A.2 [template]
+// CHECK:STDOUT:   %B.1: type = class_type @B.1 [template]
 // CHECK:STDOUT:   %.1: type = struct_type {} [template]
+// CHECK:STDOUT:   %B.2: type = class_type @B.2 [template]
+// CHECK:STDOUT:   %Y: type = class_type @Y [template]
+// CHECK:STDOUT:   %.2: type = class_type @.1 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.A = %A.decl.loc7, .X = %X.decl, .Y = %Y.decl} [template]
 // CHECK:STDOUT:   %A.decl.loc7 = class_decl @A.1, ()
-// CHECK:STDOUT:   %A: type = class_type @A.1 [template]
+// CHECK:STDOUT:   %A: type = class_type @A.1 [template = constants.%A.1]
 // CHECK:STDOUT:   %X.decl = class_decl @X, ()
-// CHECK:STDOUT:   %X: type = class_type @X [template]
+// CHECK:STDOUT:   %X: type = class_type @X [template = constants.%X]
 // CHECK:STDOUT:   %A.decl.loc15 = class_decl @A.1, ()
 // CHECK:STDOUT:   %Y.decl = class_decl @Y, ()
-// CHECK:STDOUT:   %Y: type = class_type @Y [template]
+// CHECK:STDOUT:   %Y: type = class_type @Y [template = constants.%Y]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @A.1 {
 // CHECK:STDOUT:   %B.decl = class_decl @B.2, ()
-// CHECK:STDOUT:   %B: type = class_type @B.2 [template]
+// CHECK:STDOUT:   %B: type = class_type @B.2 [template = constants.%B.2]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:
 // CHECK:STDOUT:   .B = %B.decl
@@ -48,7 +55,7 @@ class Y {
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @X {
 // CHECK:STDOUT:   %A.decl = class_decl @A.2, ()
-// CHECK:STDOUT:   %A: type = class_type @A.2 [template]
+// CHECK:STDOUT:   %A: type = class_type @A.2 [template = constants.%A.2]
 // CHECK:STDOUT:   %B.decl = class_decl @B.1, ()
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:
@@ -57,7 +64,7 @@ class Y {
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @A.2 {
 // CHECK:STDOUT:   %B.decl = class_decl @B.1, ()
-// CHECK:STDOUT:   %B: type = class_type @B.1 [template]
+// CHECK:STDOUT:   %B: type = class_type @B.1 [template = constants.%B.1]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:
 // CHECK:STDOUT:   .B = %B.decl
@@ -72,7 +79,7 @@ class Y {
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Y {
 // CHECK:STDOUT:   %.decl = class_decl @.1, ()
-// CHECK:STDOUT:   %.loc21: type = class_type @.1 [template]
+// CHECK:STDOUT:   %.loc21: type = class_type @.1 [template = constants.%.2]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:
 // CHECK:STDOUT: }

+ 4 - 3
toolchain/check/testdata/class/fail_redefinition.carbon

@@ -27,13 +27,14 @@ fn Class.H() {}
 // CHECK:STDOUT: --- fail_redefinition.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %Class: type = class_type @Class [template]
 // CHECK:STDOUT:   %.1: type = struct_type {} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Class = %Class.decl.loc7} [template]
 // CHECK:STDOUT:   %Class.decl.loc7 = class_decl @Class, ()
-// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template = constants.%Class]
 // CHECK:STDOUT:   %Class.decl.loc18 = class_decl @Class, ()
 // CHECK:STDOUT:   %F: <function> = fn_decl @F [template]
 // CHECK:STDOUT:   %G: <function> = fn_decl @G [template]
@@ -45,8 +46,8 @@ fn Class.H() {}
 // CHECK:STDOUT:   %H: <function> = fn_decl @H [template]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:
-// CHECK:STDOUT:   .F = <unexpected instref inst+3>
-// CHECK:STDOUT:   .H = <unexpected instref inst+4>
+// CHECK:STDOUT:   .F = <unexpected instref inst+4>
+// CHECK:STDOUT:   .H = <unexpected instref inst+5>
 // CHECK:STDOUT:   .G = %G
 // CHECK:STDOUT: }
 // CHECK:STDOUT:

+ 3 - 2
toolchain/check/testdata/class/fail_reorder.carbon

@@ -28,6 +28,7 @@ class Class {
 // CHECK:STDOUT: --- fail_reorder.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %Class: type = class_type @Class [template]
 // CHECK:STDOUT:   %.1: i32 = int_literal 1 [template]
 // CHECK:STDOUT:   %.2: type = struct_type {} [template]
 // CHECK:STDOUT: }
@@ -35,7 +36,7 @@ class Class {
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Class = %Class.decl} [template]
 // CHECK:STDOUT:   %Class.decl = class_decl @Class, ()
-// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template = constants.%Class]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Class {
@@ -49,7 +50,7 @@ class Class {
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @G() -> i32 {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %Class.ref: type = name_ref Class, file.%Class [template = file.%Class]
+// CHECK:STDOUT:   %Class.ref: type = name_ref Class, file.%Class [template = constants.%Class]
 // CHECK:STDOUT:   %F.ref: <error> = name_ref F, <error>
 // CHECK:STDOUT:   return <error>
 // CHECK:STDOUT: }

+ 2 - 1
toolchain/check/testdata/class/fail_scope.carbon

@@ -20,6 +20,7 @@ fn G() -> i32 {
 // CHECK:STDOUT: --- fail_scope.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %Class: type = class_type @Class [template]
 // CHECK:STDOUT:   %.1: i32 = int_literal 1 [template]
 // CHECK:STDOUT:   %.2: type = struct_type {} [template]
 // CHECK:STDOUT: }
@@ -27,7 +28,7 @@ fn G() -> i32 {
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Class = %Class.decl, .G = %G} [template]
 // CHECK:STDOUT:   %Class.decl = class_decl @Class, ()
-// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template = constants.%Class]
 // CHECK:STDOUT:   %G: <function> = fn_decl @G [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:

+ 5 - 3
toolchain/check/testdata/class/fail_self.carbon

@@ -53,19 +53,21 @@ fn CallWrongSelf(ws: WrongSelf) {
 // CHECK:STDOUT: --- fail_self.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %Class: type = class_type @Class [template]
 // CHECK:STDOUT:   %.1: type = struct_type {} [template]
 // CHECK:STDOUT:   %.2: type = tuple_type () [template]
 // CHECK:STDOUT:   %.3: type = ptr_type {} [template]
+// CHECK:STDOUT:   %WrongSelf: type = class_type @WrongSelf [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Class = %Class.decl, .WrongSelf = %WrongSelf.decl, .CallWrongSelf = %CallWrongSelf} [template]
 // CHECK:STDOUT:   %Class.decl = class_decl @Class, ()
-// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template = constants.%Class]
 // CHECK:STDOUT:   %F: <function> = fn_decl @F.1 [template]
 // CHECK:STDOUT:   %G: <function> = fn_decl @G [template]
 // CHECK:STDOUT:   %WrongSelf.decl = class_decl @WrongSelf, ()
-// CHECK:STDOUT:   %WrongSelf: type = class_type @WrongSelf [template]
+// CHECK:STDOUT:   %WrongSelf: type = class_type @WrongSelf [template = constants.%WrongSelf]
 // CHECK:STDOUT:   %CallWrongSelf: <function> = fn_decl @CallWrongSelf [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
@@ -92,7 +94,7 @@ fn CallWrongSelf(ws: WrongSelf) {
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @G() -> %return: Class {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %Class.ref: type = name_ref Class, file.%Class [template = file.%Class]
+// CHECK:STDOUT:   %Class.ref: type = name_ref Class, file.%Class [template = constants.%Class]
 // CHECK:STDOUT:   %self.var: ref Class = var self
 // CHECK:STDOUT:   %self: ref Class = bind_name self, %self.var
 // CHECK:STDOUT:   %self.ref: ref Class = name_ref self, %self

+ 5 - 1
toolchain/check/testdata/class/fail_todo_generic.carbon

@@ -14,10 +14,14 @@ class C[]();
 
 // CHECK:STDOUT: --- fail_todo_generic.carbon
 // CHECK:STDOUT:
+// CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %C: type = class_type @C [template]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.C = %C.decl} [template]
 // CHECK:STDOUT:   %C.decl = class_decl @C, ()
-// CHECK:STDOUT:   %C: type = class_type @C [template]
+// CHECK:STDOUT:   %C: type = class_type @C [template = constants.%C]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @C;

+ 11 - 7
toolchain/check/testdata/class/fail_todo_modifiers.carbon

@@ -61,27 +61,31 @@ abstract class Abstract {
 // CHECK:STDOUT: --- fail_todo_modifiers.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = struct_type {.k: i32, .l: i32} [template]
-// CHECK:STDOUT:   %.2: type = struct_type {} [template]
+// CHECK:STDOUT:   %Access: type = class_type @Access [template]
+// CHECK:STDOUT:   %.1: type = unbound_element_type Access, i32 [template]
+// CHECK:STDOUT:   %.2: type = struct_type {.k: i32, .l: i32} [template]
+// CHECK:STDOUT:   %Base: type = class_type @Base [template]
+// CHECK:STDOUT:   %.3: type = struct_type {} [template]
+// CHECK:STDOUT:   %Abstract: type = class_type @Abstract [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Access = %Access.decl, .Base = %Base.decl, .Abstract = %Abstract.decl} [template]
 // CHECK:STDOUT:   %Access.decl = class_decl @Access, ()
-// CHECK:STDOUT:   %Access: type = class_type @Access [template]
+// CHECK:STDOUT:   %Access: type = class_type @Access [template = constants.%Access]
 // CHECK:STDOUT:   %Base.decl = class_decl @Base, ()
-// CHECK:STDOUT:   %Base: type = class_type @Base [template]
+// CHECK:STDOUT:   %Base: type = class_type @Base [template = constants.%Base]
 // CHECK:STDOUT:   %Abstract.decl = class_decl @Abstract, ()
-// CHECK:STDOUT:   %Abstract: type = class_type @Abstract [template]
+// CHECK:STDOUT:   %Abstract: type = class_type @Abstract [template = constants.%Abstract]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Access {
 // CHECK:STDOUT:   %F: <function> = fn_decl @F [template]
 // CHECK:STDOUT:   %G: <function> = fn_decl @G [template]
-// CHECK:STDOUT:   %.loc22_16.1: type = unbound_element_type Access, i32 [template]
+// CHECK:STDOUT:   %.loc22_16.1: type = unbound_element_type Access, i32 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc22_16.2: <unbound element of class Access> = field_decl k, element0 [template]
 // CHECK:STDOUT:   %k: <unbound element of class Access> = bind_name k, %.loc22_16.2 [template = %.loc22_16.2]
-// CHECK:STDOUT:   %.loc27_18.1: type = unbound_element_type Access, i32 [template]
+// CHECK:STDOUT:   %.loc27_18.1: type = unbound_element_type Access, i32 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc27_18.2: <unbound element of class Access> = field_decl l, element1 [template]
 // CHECK:STDOUT:   %l: <unbound element of class Access> = bind_name l, %.loc27_18.2 [template = %.loc27_18.2]
 // CHECK:STDOUT:

+ 6 - 4
toolchain/check/testdata/class/fail_unbound_field.carbon

@@ -24,18 +24,20 @@ fn G() -> i32 {
 // CHECK:STDOUT: --- fail_unbound_field.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = struct_type {.field: i32} [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %.1: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.2: type = struct_type {.field: i32} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Class = %Class.decl, .G = %G} [template]
 // CHECK:STDOUT:   %Class.decl = class_decl @Class, ()
-// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template = constants.%Class]
 // CHECK:STDOUT:   %G: <function> = fn_decl @G [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Class {
-// CHECK:STDOUT:   %.loc8_12.1: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.loc8_12.1: type = unbound_element_type Class, i32 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc8_12.2: <unbound element of class Class> = field_decl field, element0 [template]
 // CHECK:STDOUT:   %field: <unbound element of class Class> = bind_name field, %.loc8_12.2 [template = %.loc8_12.2]
 // CHECK:STDOUT:   %F: <function> = fn_decl @F [template]
@@ -53,7 +55,7 @@ fn G() -> i32 {
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @G() -> i32 {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %Class.ref: type = name_ref Class, file.%Class [template = file.%Class]
+// CHECK:STDOUT:   %Class.ref: type = name_ref Class, file.%Class [template = constants.%Class]
 // CHECK:STDOUT:   %field.ref: <unbound element of class Class> = name_ref field, @Class.%field [template = @Class.%.loc8_12.2]
 // CHECK:STDOUT:   return <error>
 // CHECK:STDOUT: }

+ 6 - 4
toolchain/check/testdata/class/fail_unknown_member.carbon

@@ -19,19 +19,21 @@ fn G(c: Class) -> i32 {
 // CHECK:STDOUT: --- fail_unknown_member.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = struct_type {.n: i32} [template]
-// CHECK:STDOUT:   %.2: type = ptr_type {.n: i32} [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %.1: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.2: type = struct_type {.n: i32} [template]
+// CHECK:STDOUT:   %.3: type = ptr_type {.n: i32} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Class = %Class.decl, .G = %G} [template]
 // CHECK:STDOUT:   %Class.decl = class_decl @Class, ()
-// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template = constants.%Class]
 // CHECK:STDOUT:   %G: <function> = fn_decl @G [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Class {
-// CHECK:STDOUT:   %.loc8_8.1: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.loc8_8.1: type = unbound_element_type Class, i32 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc8_8.2: <unbound element of class Class> = field_decl n, element0 [template]
 // CHECK:STDOUT:   %n: <unbound element of class Class> = bind_name n, %.loc8_8.2 [template = %.loc8_8.2]
 // CHECK:STDOUT:

+ 12 - 10
toolchain/check/testdata/class/field_access.carbon

@@ -20,24 +20,26 @@ fn Run() {
 // CHECK:STDOUT: --- field_access.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = struct_type {.j: i32, .k: i32} [template]
-// CHECK:STDOUT:   %.2: type = ptr_type {.j: i32, .k: i32} [template]
-// CHECK:STDOUT:   %.3: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.4: i32 = int_literal 2 [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %.1: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.2: type = struct_type {.j: i32, .k: i32} [template]
+// CHECK:STDOUT:   %.3: type = ptr_type {.j: i32, .k: i32} [template]
+// CHECK:STDOUT:   %.4: i32 = int_literal 1 [template]
+// CHECK:STDOUT:   %.5: i32 = int_literal 2 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Class = %Class.decl, .Run = %Run} [template]
 // CHECK:STDOUT:   %Class.decl = class_decl @Class, ()
-// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template = constants.%Class]
 // CHECK:STDOUT:   %Run: <function> = fn_decl @Run [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Class {
-// CHECK:STDOUT:   %.loc8_8.1: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.loc8_8.1: type = unbound_element_type Class, i32 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc8_8.2: <unbound element of class Class> = field_decl j, element0 [template]
 // CHECK:STDOUT:   %j: <unbound element of class Class> = bind_name j, %.loc8_8.2 [template = %.loc8_8.2]
-// CHECK:STDOUT:   %.loc9_8.1: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.loc9_8.1: type = unbound_element_type Class, i32 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc9_8.2: <unbound element of class Class> = field_decl k, element1 [template]
 // CHECK:STDOUT:   %k: <unbound element of class Class> = bind_name k, %.loc9_8.2 [template = %.loc9_8.2]
 // CHECK:STDOUT:
@@ -48,16 +50,16 @@ fn Run() {
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @Run() {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %Class.ref: type = name_ref Class, file.%Class [template = file.%Class]
+// CHECK:STDOUT:   %Class.ref: type = name_ref Class, file.%Class [template = constants.%Class]
 // CHECK:STDOUT:   %c.var: ref Class = var c
 // CHECK:STDOUT:   %c: ref Class = bind_name c, %c.var
 // CHECK:STDOUT:   %c.ref.loc14: ref Class = name_ref c, %c
 // CHECK:STDOUT:   %.loc14_4: ref i32 = class_element_access %c.ref.loc14, element0
-// CHECK:STDOUT:   %.loc14_9: i32 = int_literal 1 [template = constants.%.3]
+// CHECK:STDOUT:   %.loc14_9: i32 = int_literal 1 [template = constants.%.4]
 // CHECK:STDOUT:   assign %.loc14_4, %.loc14_9
 // CHECK:STDOUT:   %c.ref.loc15: ref Class = name_ref c, %c
 // CHECK:STDOUT:   %.loc15_4: ref i32 = class_element_access %c.ref.loc15, element1
-// CHECK:STDOUT:   %.loc15_9: i32 = int_literal 2 [template = constants.%.4]
+// CHECK:STDOUT:   %.loc15_9: i32 = int_literal 2 [template = constants.%.5]
 // CHECK:STDOUT:   assign %.loc15_4, %.loc15_9
 // CHECK:STDOUT:   %cj.var: ref i32 = var cj
 // CHECK:STDOUT:   %cj: ref i32 = bind_name cj, %cj.var

+ 13 - 11
toolchain/check/testdata/class/field_access_in_value.carbon

@@ -21,24 +21,26 @@ fn Test() {
 // CHECK:STDOUT: --- field_access_in_value.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = struct_type {.j: i32, .k: i32} [template]
-// CHECK:STDOUT:   %.2: type = ptr_type {.j: i32, .k: i32} [template]
-// CHECK:STDOUT:   %.3: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.4: i32 = int_literal 2 [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %.1: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.2: type = struct_type {.j: i32, .k: i32} [template]
+// CHECK:STDOUT:   %.3: type = ptr_type {.j: i32, .k: i32} [template]
+// CHECK:STDOUT:   %.4: i32 = int_literal 1 [template]
+// CHECK:STDOUT:   %.5: i32 = int_literal 2 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Class = %Class.decl, .Test = %Test} [template]
 // CHECK:STDOUT:   %Class.decl = class_decl @Class, ()
-// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template = constants.%Class]
 // CHECK:STDOUT:   %Test: <function> = fn_decl @Test [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Class {
-// CHECK:STDOUT:   %.loc8_8.1: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.loc8_8.1: type = unbound_element_type Class, i32 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc8_8.2: <unbound element of class Class> = field_decl j, element0 [template]
 // CHECK:STDOUT:   %j: <unbound element of class Class> = bind_name j, %.loc8_8.2 [template = %.loc8_8.2]
-// CHECK:STDOUT:   %.loc9_8.1: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.loc9_8.1: type = unbound_element_type Class, i32 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc9_8.2: <unbound element of class Class> = field_decl k, element1 [template]
 // CHECK:STDOUT:   %k: <unbound element of class Class> = bind_name k, %.loc9_8.2 [template = %.loc9_8.2]
 // CHECK:STDOUT:
@@ -49,18 +51,18 @@ fn Test() {
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @Test() {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %Class.ref.loc13: type = name_ref Class, file.%Class [template = file.%Class]
+// CHECK:STDOUT:   %Class.ref.loc13: type = name_ref Class, file.%Class [template = constants.%Class]
 // CHECK:STDOUT:   %cv.var: ref Class = var cv
 // CHECK:STDOUT:   %cv: ref Class = bind_name cv, %cv.var
 // CHECK:STDOUT:   %cv.ref.loc14: ref Class = name_ref cv, %cv
 // CHECK:STDOUT:   %.loc14_5: ref i32 = class_element_access %cv.ref.loc14, element0
-// CHECK:STDOUT:   %.loc14_10: i32 = int_literal 1 [template = constants.%.3]
+// CHECK:STDOUT:   %.loc14_10: i32 = int_literal 1 [template = constants.%.4]
 // CHECK:STDOUT:   assign %.loc14_5, %.loc14_10
 // CHECK:STDOUT:   %cv.ref.loc15: ref Class = name_ref cv, %cv
 // CHECK:STDOUT:   %.loc15_5: ref i32 = class_element_access %cv.ref.loc15, element1
-// CHECK:STDOUT:   %.loc15_10: i32 = int_literal 2 [template = constants.%.4]
+// CHECK:STDOUT:   %.loc15_10: i32 = int_literal 2 [template = constants.%.5]
 // CHECK:STDOUT:   assign %.loc15_5, %.loc15_10
-// CHECK:STDOUT:   %Class.ref.loc16: type = name_ref Class, file.%Class [template = file.%Class]
+// CHECK:STDOUT:   %Class.ref.loc16: type = name_ref Class, file.%Class [template = constants.%Class]
 // CHECK:STDOUT:   %cv.ref.loc16: ref Class = name_ref cv, %cv
 // CHECK:STDOUT:   %.loc16: Class = bind_value %cv.ref.loc16
 // CHECK:STDOUT:   %c: Class = bind_name c, %.loc16

+ 6 - 1
toolchain/check/testdata/class/forward_declared.carbon

@@ -10,10 +10,15 @@ fn F(p: Class*) -> Class* { return p; }
 
 // CHECK:STDOUT: --- forward_declared.carbon
 // CHECK:STDOUT:
+// CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %.1: type = ptr_type Class [template]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Class = %Class.decl, .F = %F} [template]
 // CHECK:STDOUT:   %Class.decl = class_decl @Class, ()
-// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template = constants.%Class]
 // CHECK:STDOUT:   %F: <function> = fn_decl @F [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:

+ 12 - 8
toolchain/check/testdata/class/init.carbon

@@ -20,26 +20,30 @@ fn MakeReorder(n: i32, next: Class*) -> Class {
 // CHECK:STDOUT: --- init.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = struct_type {.n: i32, .next: Class*} [template]
-// CHECK:STDOUT:   %.2: type = ptr_type {.n: i32, .next: Class*} [template]
-// CHECK:STDOUT:   %.3: type = struct_type {.next: Class*, .n: i32} [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %.1: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.2: type = ptr_type Class [template]
+// CHECK:STDOUT:   %.3: type = unbound_element_type Class, Class* [template]
+// CHECK:STDOUT:   %.4: type = struct_type {.n: i32, .next: Class*} [template]
+// CHECK:STDOUT:   %.5: type = ptr_type {.n: i32, .next: Class*} [template]
+// CHECK:STDOUT:   %.6: type = struct_type {.next: Class*, .n: i32} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Class = %Class.decl, .Make = %Make, .MakeReorder = %MakeReorder} [template]
 // CHECK:STDOUT:   %Class.decl = class_decl @Class, ()
-// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template = constants.%Class]
 // CHECK:STDOUT:   %Make: <function> = fn_decl @Make [template]
 // CHECK:STDOUT:   %MakeReorder: <function> = fn_decl @MakeReorder [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Class {
-// CHECK:STDOUT:   %.loc8_8.1: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.loc8_8.1: type = unbound_element_type Class, i32 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc8_8.2: <unbound element of class Class> = field_decl n, element0 [template]
 // CHECK:STDOUT:   %n: <unbound element of class Class> = bind_name n, %.loc8_8.2 [template = %.loc8_8.2]
-// CHECK:STDOUT:   %Class.ref: type = name_ref Class, file.%Class [template = file.%Class]
-// CHECK:STDOUT:   %.loc9_18: type = ptr_type Class [template]
-// CHECK:STDOUT:   %.loc9_11.1: type = unbound_element_type Class, Class* [template]
+// CHECK:STDOUT:   %Class.ref: type = name_ref Class, file.%Class [template = constants.%Class]
+// CHECK:STDOUT:   %.loc9_18: type = ptr_type Class [template = constants.%.2]
+// CHECK:STDOUT:   %.loc9_11.1: type = unbound_element_type Class, Class* [template = constants.%.3]
 // CHECK:STDOUT:   %.loc9_11.2: <unbound element of class Class> = field_decl next, element1 [template]
 // CHECK:STDOUT:   %next: <unbound element of class Class> = bind_name next, %.loc9_11.2 [template = %.loc9_11.2]
 // CHECK:STDOUT:

+ 12 - 10
toolchain/check/testdata/class/init_as.carbon

@@ -16,24 +16,26 @@ fn F() -> i32 {
 // CHECK:STDOUT: --- init_as.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = struct_type {.a: i32, .b: i32} [template]
-// CHECK:STDOUT:   %.2: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.3: i32 = int_literal 2 [template]
-// CHECK:STDOUT:   %.4: type = ptr_type {.a: i32, .b: i32} [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %.1: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.2: type = struct_type {.a: i32, .b: i32} [template]
+// CHECK:STDOUT:   %.3: i32 = int_literal 1 [template]
+// CHECK:STDOUT:   %.4: i32 = int_literal 2 [template]
+// CHECK:STDOUT:   %.5: type = ptr_type {.a: i32, .b: i32} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Class = %Class.decl, .F = %F} [template]
 // CHECK:STDOUT:   %Class.decl = class_decl @Class, ()
-// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template = constants.%Class]
 // CHECK:STDOUT:   %F: <function> = fn_decl @F [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Class {
-// CHECK:STDOUT:   %.loc8_8.1: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.loc8_8.1: type = unbound_element_type Class, i32 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc8_8.2: <unbound element of class Class> = field_decl a, element0 [template]
 // CHECK:STDOUT:   %a: <unbound element of class Class> = bind_name a, %.loc8_8.2 [template = %.loc8_8.2]
-// CHECK:STDOUT:   %.loc9_8.1: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.loc9_8.1: type = unbound_element_type Class, i32 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc9_8.2: <unbound element of class Class> = field_decl b, element1 [template]
 // CHECK:STDOUT:   %b: <unbound element of class Class> = bind_name b, %.loc9_8.2 [template = %.loc9_8.2]
 // CHECK:STDOUT:
@@ -44,10 +46,10 @@ fn F() -> i32 {
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @F() -> i32 {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %.loc13_17: i32 = int_literal 1 [template = constants.%.2]
-// CHECK:STDOUT:   %.loc13_25: i32 = int_literal 2 [template = constants.%.3]
+// CHECK:STDOUT:   %.loc13_17: i32 = int_literal 1 [template = constants.%.3]
+// CHECK:STDOUT:   %.loc13_25: i32 = int_literal 2 [template = constants.%.4]
 // CHECK:STDOUT:   %.loc13_26.1: {.a: i32, .b: i32} = struct_literal (%.loc13_17, %.loc13_25)
-// CHECK:STDOUT:   %Class.ref: type = name_ref Class, file.%Class [template = file.%Class]
+// CHECK:STDOUT:   %Class.ref: type = name_ref Class, file.%Class [template = constants.%Class]
 // CHECK:STDOUT:   %.loc13_26.2: ref Class = temporary_storage
 // CHECK:STDOUT:   %.loc13_26.3: ref i32 = class_element_access %.loc13_26.2, element0
 // CHECK:STDOUT:   %.loc13_26.4: init i32 = initialize_from %.loc13_17 to %.loc13_26.3

+ 18 - 14
toolchain/check/testdata/class/init_nested.carbon

@@ -23,29 +23,33 @@ fn MakeOuter() -> Outer {
 // CHECK:STDOUT: --- init_nested.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = struct_type {.a: i32, .b: i32} [template]
-// CHECK:STDOUT:   %.2: type = ptr_type {.a: i32, .b: i32} [template]
-// CHECK:STDOUT:   %.3: type = struct_type {.c: Inner, .d: Inner} [template]
-// CHECK:STDOUT:   %.4: type = struct_type {.c: {.a: i32, .b: i32}*, .d: {.a: i32, .b: i32}*} [template]
-// CHECK:STDOUT:   %.5: type = ptr_type {.c: {.a: i32, .b: i32}*, .d: {.a: i32, .b: i32}*} [template]
-// CHECK:STDOUT:   %.6: type = ptr_type {.c: Inner, .d: Inner} [template]
+// CHECK:STDOUT:   %Inner: type = class_type @Inner [template]
+// CHECK:STDOUT:   %.1: type = unbound_element_type Inner, i32 [template]
+// CHECK:STDOUT:   %.2: type = struct_type {.a: i32, .b: i32} [template]
+// CHECK:STDOUT:   %.3: type = ptr_type {.a: i32, .b: i32} [template]
+// CHECK:STDOUT:   %Outer: type = class_type @Outer [template]
+// CHECK:STDOUT:   %.4: type = unbound_element_type Outer, Inner [template]
+// CHECK:STDOUT:   %.5: type = struct_type {.c: Inner, .d: Inner} [template]
+// CHECK:STDOUT:   %.6: type = struct_type {.c: {.a: i32, .b: i32}*, .d: {.a: i32, .b: i32}*} [template]
+// CHECK:STDOUT:   %.7: type = ptr_type {.c: {.a: i32, .b: i32}*, .d: {.a: i32, .b: i32}*} [template]
+// CHECK:STDOUT:   %.8: type = ptr_type {.c: Inner, .d: Inner} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Inner = %Inner.decl, .MakeInner = %MakeInner, .Outer = %Outer.decl, .MakeOuter = %MakeOuter} [template]
 // CHECK:STDOUT:   %Inner.decl = class_decl @Inner, ()
-// CHECK:STDOUT:   %Inner: type = class_type @Inner [template]
+// CHECK:STDOUT:   %Inner: type = class_type @Inner [template = constants.%Inner]
 // CHECK:STDOUT:   %MakeInner: <function> = fn_decl @MakeInner [template]
 // CHECK:STDOUT:   %Outer.decl = class_decl @Outer, ()
-// CHECK:STDOUT:   %Outer: type = class_type @Outer [template]
+// CHECK:STDOUT:   %Outer: type = class_type @Outer [template = constants.%Outer]
 // CHECK:STDOUT:   %MakeOuter: <function> = fn_decl @MakeOuter [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Inner {
-// CHECK:STDOUT:   %.loc8_8.1: type = unbound_element_type Inner, i32 [template]
+// CHECK:STDOUT:   %.loc8_8.1: type = unbound_element_type Inner, i32 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc8_8.2: <unbound element of class Inner> = field_decl a, element0 [template]
 // CHECK:STDOUT:   %a: <unbound element of class Inner> = bind_name a, %.loc8_8.2 [template = %.loc8_8.2]
-// CHECK:STDOUT:   %.loc9_8.1: type = unbound_element_type Inner, i32 [template]
+// CHECK:STDOUT:   %.loc9_8.1: type = unbound_element_type Inner, i32 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc9_8.2: <unbound element of class Inner> = field_decl b, element1 [template]
 // CHECK:STDOUT:   %b: <unbound element of class Inner> = bind_name b, %.loc9_8.2 [template = %.loc9_8.2]
 // CHECK:STDOUT:
@@ -55,12 +59,12 @@ fn MakeOuter() -> Outer {
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Outer {
-// CHECK:STDOUT:   %Inner.ref.loc15: type = name_ref Inner, file.%Inner [template = file.%Inner]
-// CHECK:STDOUT:   %.loc15_8.1: type = unbound_element_type Outer, Inner [template]
+// CHECK:STDOUT:   %Inner.ref.loc15: type = name_ref Inner, file.%Inner [template = constants.%Inner]
+// CHECK:STDOUT:   %.loc15_8.1: type = unbound_element_type Outer, Inner [template = constants.%.4]
 // CHECK:STDOUT:   %.loc15_8.2: <unbound element of class Outer> = field_decl c, element0 [template]
 // CHECK:STDOUT:   %c: <unbound element of class Outer> = bind_name c, %.loc15_8.2 [template = %.loc15_8.2]
-// CHECK:STDOUT:   %Inner.ref.loc16: type = name_ref Inner, file.%Inner [template = file.%Inner]
-// CHECK:STDOUT:   %.loc16_8.1: type = unbound_element_type Outer, Inner [template]
+// CHECK:STDOUT:   %Inner.ref.loc16: type = name_ref Inner, file.%Inner [template = constants.%Inner]
+// CHECK:STDOUT:   %.loc16_8.1: type = unbound_element_type Outer, Inner [template = constants.%.4]
 // CHECK:STDOUT:   %.loc16_8.2: <unbound element of class Outer> = field_decl d, element1 [template]
 // CHECK:STDOUT:   %d: <unbound element of class Outer> = bind_name d, %.loc16_8.2 [template = %.loc16_8.2]
 // CHECK:STDOUT:

+ 11 - 8
toolchain/check/testdata/class/method.carbon

@@ -51,15 +51,18 @@ fn CallGOnInitializingExpr() -> i32 {
 // CHECK:STDOUT: --- method.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = struct_type {.k: i32} [template]
-// CHECK:STDOUT:   %.2: type = ptr_type {.k: i32} [template]
-// CHECK:STDOUT:   %.3: i32 = int_literal 1 [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %.1: type = ptr_type Class [template]
+// CHECK:STDOUT:   %.2: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.3: type = struct_type {.k: i32} [template]
+// CHECK:STDOUT:   %.4: type = ptr_type {.k: i32} [template]
+// CHECK:STDOUT:   %.5: i32 = int_literal 1 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Class = %Class.decl, .Call = %Call, .CallOnConstBoundMethod = %CallOnConstBoundMethod, .CallWithAddr = %CallWithAddr, .CallFThroughPointer = %CallFThroughPointer, .CallGThroughPointer = %CallGThroughPointer, .Make = %Make, .CallFOnInitializingExpr = %CallFOnInitializingExpr, .CallGOnInitializingExpr = %CallGOnInitializingExpr} [template]
 // CHECK:STDOUT:   %Class.decl = class_decl @Class, ()
-// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template = constants.%Class]
 // CHECK:STDOUT:   %F: <function> = fn_decl @F [template]
 // CHECK:STDOUT:   %Call: <function> = fn_decl @Call [template]
 // CHECK:STDOUT:   %CallOnConstBoundMethod: <function> = fn_decl @CallOnConstBoundMethod [template]
@@ -74,7 +77,7 @@ fn CallGOnInitializingExpr() -> i32 {
 // CHECK:STDOUT: class @Class {
 // CHECK:STDOUT:   %F: <function> = fn_decl @F [template]
 // CHECK:STDOUT:   %G: <function> = fn_decl @G [template]
-// CHECK:STDOUT:   %.loc11_8.1: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.loc11_8.1: type = unbound_element_type Class, i32 [template = constants.%.2]
 // CHECK:STDOUT:   %.loc11_8.2: <unbound element of class Class> = field_decl k, element0 [template]
 // CHECK:STDOUT:   %k: <unbound element of class Class> = bind_name k, %.loc11_8.2 [template = %.loc11_8.2]
 // CHECK:STDOUT:
@@ -106,9 +109,9 @@ fn CallGOnInitializingExpr() -> i32 {
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @CallOnConstBoundMethod() -> i32 {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %.loc25_17: i32 = int_literal 1 [template = constants.%.3]
+// CHECK:STDOUT:   %.loc25_17: i32 = int_literal 1 [template = constants.%.5]
 // CHECK:STDOUT:   %.loc25_18.1: {.k: i32} = struct_literal (%.loc25_17)
-// CHECK:STDOUT:   %Class.ref: type = name_ref Class, file.%Class [template = file.%Class]
+// CHECK:STDOUT:   %Class.ref: type = name_ref Class, file.%Class [template = constants.%Class]
 // CHECK:STDOUT:   %.loc25_18.2: ref Class = temporary_storage
 // CHECK:STDOUT:   %.loc25_18.3: ref i32 = class_element_access %.loc25_18.2, element0
 // CHECK:STDOUT:   %.loc25_18.4: init i32 = initialize_from %.loc25_17 to %.loc25_18.3
@@ -125,7 +128,7 @@ fn CallGOnInitializingExpr() -> i32 {
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @CallWithAddr() -> i32 {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %Class.ref: type = name_ref Class, file.%Class [template = file.%Class]
+// CHECK:STDOUT:   %Class.ref: type = name_ref Class, file.%Class [template = constants.%Class]
 // CHECK:STDOUT:   %c.var: ref Class = var c
 // CHECK:STDOUT:   %c: ref Class = bind_name c, %c.var
 // CHECK:STDOUT:   %c.ref: ref Class = name_ref c, %c

+ 32 - 24
toolchain/check/testdata/class/nested.carbon

@@ -31,35 +31,43 @@ fn F(a: Outer*) {
 // CHECK:STDOUT: --- nested.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = struct_type {.pi: Inner*, .po: Outer*, .qi: Inner*} [template]
-// CHECK:STDOUT:   %.2: type = struct_type {.po: Outer*, .qo: Outer*, .pi: Inner*} [template]
-// CHECK:STDOUT:   %.3: type = ptr_type {.po: Outer*, .qo: Outer*, .pi: Inner*} [template]
-// CHECK:STDOUT:   %.4: type = ptr_type {.pi: Inner*, .po: Outer*, .qi: Inner*} [template]
+// CHECK:STDOUT:   %Outer: type = class_type @Outer [template]
+// CHECK:STDOUT:   %Inner: type = class_type @Inner [template]
+// CHECK:STDOUT:   %.1: type = ptr_type Inner [template]
+// CHECK:STDOUT:   %.2: type = unbound_element_type Inner, Inner* [template]
+// CHECK:STDOUT:   %.3: type = ptr_type Outer [template]
+// CHECK:STDOUT:   %.4: type = unbound_element_type Inner, Outer* [template]
+// CHECK:STDOUT:   %.5: type = struct_type {.pi: Inner*, .po: Outer*, .qi: Inner*} [template]
+// CHECK:STDOUT:   %.6: type = unbound_element_type Outer, Outer* [template]
+// CHECK:STDOUT:   %.7: type = unbound_element_type Outer, Inner* [template]
+// CHECK:STDOUT:   %.8: type = struct_type {.po: Outer*, .qo: Outer*, .pi: Inner*} [template]
+// CHECK:STDOUT:   %.9: type = ptr_type {.po: Outer*, .qo: Outer*, .pi: Inner*} [template]
+// CHECK:STDOUT:   %.10: type = ptr_type {.pi: Inner*, .po: Outer*, .qi: Inner*} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Outer = %Outer.decl, .F = %F} [template]
 // CHECK:STDOUT:   %Outer.decl = class_decl @Outer, ()
-// CHECK:STDOUT:   %Outer: type = class_type @Outer [template]
+// CHECK:STDOUT:   %Outer: type = class_type @Outer [template = constants.%Outer]
 // CHECK:STDOUT:   %F: <function> = fn_decl @F [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Outer {
 // CHECK:STDOUT:   %Inner.decl = class_decl @Inner, ()
-// CHECK:STDOUT:   %Inner: type = class_type @Inner [template]
-// CHECK:STDOUT:   %Self.ref: type = name_ref Self, file.%Outer [template = file.%Outer]
-// CHECK:STDOUT:   %.loc14_15: type = ptr_type Outer [template]
-// CHECK:STDOUT:   %.loc14_9.1: type = unbound_element_type Outer, Outer* [template]
+// CHECK:STDOUT:   %Inner: type = class_type @Inner [template = constants.%Inner]
+// CHECK:STDOUT:   %Self.ref: type = name_ref Self, file.%Outer [template = constants.%Outer]
+// CHECK:STDOUT:   %.loc14_15: type = ptr_type Outer [template = constants.%.3]
+// CHECK:STDOUT:   %.loc14_9.1: type = unbound_element_type Outer, Outer* [template = constants.%.6]
 // CHECK:STDOUT:   %.loc14_9.2: <unbound element of class Outer> = field_decl po, element0 [template]
 // CHECK:STDOUT:   %po: <unbound element of class Outer> = bind_name po, %.loc14_9.2 [template = %.loc14_9.2]
-// CHECK:STDOUT:   %Outer.ref: type = name_ref Outer, file.%Outer [template = file.%Outer]
-// CHECK:STDOUT:   %.loc15_16: type = ptr_type Outer [template]
-// CHECK:STDOUT:   %.loc15_9.1: type = unbound_element_type Outer, Outer* [template]
+// CHECK:STDOUT:   %Outer.ref: type = name_ref Outer, file.%Outer [template = constants.%Outer]
+// CHECK:STDOUT:   %.loc15_16: type = ptr_type Outer [template = constants.%.3]
+// CHECK:STDOUT:   %.loc15_9.1: type = unbound_element_type Outer, Outer* [template = constants.%.6]
 // CHECK:STDOUT:   %.loc15_9.2: <unbound element of class Outer> = field_decl qo, element1 [template]
 // CHECK:STDOUT:   %qo: <unbound element of class Outer> = bind_name qo, %.loc15_9.2 [template = %.loc15_9.2]
-// CHECK:STDOUT:   %Inner.ref: type = name_ref Inner, %Inner [template = %Inner]
-// CHECK:STDOUT:   %.loc16_16: type = ptr_type Inner [template]
-// CHECK:STDOUT:   %.loc16_9.1: type = unbound_element_type Outer, Inner* [template]
+// CHECK:STDOUT:   %Inner.ref: type = name_ref Inner, %Inner [template = constants.%Inner]
+// CHECK:STDOUT:   %.loc16_16: type = ptr_type Inner [template = constants.%.1]
+// CHECK:STDOUT:   %.loc16_9.1: type = unbound_element_type Outer, Inner* [template = constants.%.7]
 // CHECK:STDOUT:   %.loc16_9.2: <unbound element of class Outer> = field_decl pi, element2 [template]
 // CHECK:STDOUT:   %pi: <unbound element of class Outer> = bind_name pi, %.loc16_9.2 [template = %.loc16_9.2]
 // CHECK:STDOUT:
@@ -71,19 +79,19 @@ fn F(a: Outer*) {
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Inner {
-// CHECK:STDOUT:   %Self.ref: type = name_ref Self, @Outer.%Inner [template = @Outer.%Inner]
-// CHECK:STDOUT:   %.loc9_17: type = ptr_type Inner [template]
-// CHECK:STDOUT:   %.loc9_11.1: type = unbound_element_type Inner, Inner* [template]
+// CHECK:STDOUT:   %Self.ref: type = name_ref Self, @Outer.%Inner [template = constants.%Inner]
+// CHECK:STDOUT:   %.loc9_17: type = ptr_type Inner [template = constants.%.1]
+// CHECK:STDOUT:   %.loc9_11.1: type = unbound_element_type Inner, Inner* [template = constants.%.2]
 // CHECK:STDOUT:   %.loc9_11.2: <unbound element of class Inner> = field_decl pi, element0 [template]
 // CHECK:STDOUT:   %pi: <unbound element of class Inner> = bind_name pi, %.loc9_11.2 [template = %.loc9_11.2]
-// CHECK:STDOUT:   %Outer.ref: type = name_ref Outer, file.%Outer [template = file.%Outer]
-// CHECK:STDOUT:   %.loc10_18: type = ptr_type Outer [template]
-// CHECK:STDOUT:   %.loc10_11.1: type = unbound_element_type Inner, Outer* [template]
+// CHECK:STDOUT:   %Outer.ref: type = name_ref Outer, file.%Outer [template = constants.%Outer]
+// CHECK:STDOUT:   %.loc10_18: type = ptr_type Outer [template = constants.%.3]
+// CHECK:STDOUT:   %.loc10_11.1: type = unbound_element_type Inner, Outer* [template = constants.%.4]
 // CHECK:STDOUT:   %.loc10_11.2: <unbound element of class Inner> = field_decl po, element1 [template]
 // CHECK:STDOUT:   %po: <unbound element of class Inner> = bind_name po, %.loc10_11.2 [template = %.loc10_11.2]
-// CHECK:STDOUT:   %Inner.ref: type = name_ref Inner, @Outer.%Inner [template = @Outer.%Inner]
-// CHECK:STDOUT:   %.loc11_18: type = ptr_type Inner [template]
-// CHECK:STDOUT:   %.loc11_11.1: type = unbound_element_type Inner, Inner* [template]
+// CHECK:STDOUT:   %Inner.ref: type = name_ref Inner, @Outer.%Inner [template = constants.%Inner]
+// CHECK:STDOUT:   %.loc11_18: type = ptr_type Inner [template = constants.%.1]
+// CHECK:STDOUT:   %.loc11_11.1: type = unbound_element_type Inner, Inner* [template = constants.%.2]
 // CHECK:STDOUT:   %.loc11_11.2: <unbound element of class Inner> = field_decl qi, element2 [template]
 // CHECK:STDOUT:   %qi: <unbound element of class Inner> = bind_name qi, %.loc11_11.2 [template = %.loc11_11.2]
 // CHECK:STDOUT:

+ 12 - 9
toolchain/check/testdata/class/nested_name.carbon

@@ -21,31 +21,34 @@ fn G(o: Outer) {
 // CHECK:STDOUT: --- nested_name.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = struct_type {.n: i32} [template]
-// CHECK:STDOUT:   %.2: type = struct_type {} [template]
-// CHECK:STDOUT:   %.3: type = ptr_type {.n: i32} [template]
-// CHECK:STDOUT:   %.4: type = tuple_type () [template]
-// CHECK:STDOUT:   %.5: type = ptr_type {} [template]
+// CHECK:STDOUT:   %Outer: type = class_type @Outer [template]
+// CHECK:STDOUT:   %Inner: type = class_type @Inner [template]
+// CHECK:STDOUT:   %.1: type = unbound_element_type Inner, i32 [template]
+// CHECK:STDOUT:   %.2: type = struct_type {.n: i32} [template]
+// CHECK:STDOUT:   %.3: type = struct_type {} [template]
+// CHECK:STDOUT:   %.4: type = ptr_type {.n: i32} [template]
+// CHECK:STDOUT:   %.5: type = tuple_type () [template]
+// CHECK:STDOUT:   %.6: type = ptr_type {} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Outer = %Outer.decl, .F = %F, .G = %G} [template]
 // CHECK:STDOUT:   %Outer.decl = class_decl @Outer, ()
-// CHECK:STDOUT:   %Outer: type = class_type @Outer [template]
+// CHECK:STDOUT:   %Outer: type = class_type @Outer [template = constants.%Outer]
 // CHECK:STDOUT:   %F: <function> = fn_decl @F [template]
 // CHECK:STDOUT:   %G: <function> = fn_decl @G [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Outer {
 // CHECK:STDOUT:   %Inner.decl = class_decl @Inner, ()
-// CHECK:STDOUT:   %Inner: type = class_type @Inner [template]
+// CHECK:STDOUT:   %Inner: type = class_type @Inner [template = constants.%Inner]
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:
 // CHECK:STDOUT:   .Inner = %Inner.decl
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Inner {
-// CHECK:STDOUT:   %.loc9_10.1: type = unbound_element_type Inner, i32 [template]
+// CHECK:STDOUT:   %.loc9_10.1: type = unbound_element_type Inner, i32 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc9_10.2: <unbound element of class Inner> = field_decl n, element0 [template]
 // CHECK:STDOUT:   %n: <unbound element of class Inner> = bind_name n, %.loc9_10.2 [template = %.loc9_10.2]
 // CHECK:STDOUT:
@@ -64,7 +67,7 @@ fn G(o: Outer) {
 // CHECK:STDOUT: fn @G(%o: Outer) {
 // CHECK:STDOUT: !entry:
 // CHECK:STDOUT:   %o.ref: Outer = name_ref o, %o
-// CHECK:STDOUT:   %Inner.ref: type = name_ref Inner, @Outer.%Inner [template = @Outer.%Inner]
+// CHECK:STDOUT:   %Inner.ref: type = name_ref Inner, @Outer.%Inner [template = constants.%Inner]
 // CHECK:STDOUT:   %i.var: ref Inner = var i
 // CHECK:STDOUT:   %i: ref Inner = bind_name i, %i.var
 // CHECK:STDOUT:   return

+ 10 - 7
toolchain/check/testdata/class/raw_self.carbon

@@ -21,17 +21,20 @@ fn Class.G[self: Class](r#self: i32) -> (i32, i32) {
 // CHECK:STDOUT: --- raw_self.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = tuple_type (type, type) [template]
-// CHECK:STDOUT:   %.2: type = tuple_type (i32, i32) [template]
-// CHECK:STDOUT:   %.3: type = ptr_type (i32, i32) [template]
-// CHECK:STDOUT:   %.4: type = struct_type {.n: i32} [template]
-// CHECK:STDOUT:   %.5: type = ptr_type {.n: i32} [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %.1: type = ptr_type Class [template]
+// CHECK:STDOUT:   %.2: type = tuple_type (type, type) [template]
+// CHECK:STDOUT:   %.3: type = tuple_type (i32, i32) [template]
+// CHECK:STDOUT:   %.4: type = ptr_type (i32, i32) [template]
+// CHECK:STDOUT:   %.5: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.6: type = struct_type {.n: i32} [template]
+// CHECK:STDOUT:   %.7: type = ptr_type {.n: i32} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Class = %Class.decl} [template]
 // CHECK:STDOUT:   %Class.decl = class_decl @Class, ()
-// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template = constants.%Class]
 // CHECK:STDOUT:   %F: <function> = fn_decl @F [template]
 // CHECK:STDOUT:   %G: <function> = fn_decl @G [template]
 // CHECK:STDOUT: }
@@ -39,7 +42,7 @@ fn Class.G[self: Class](r#self: i32) -> (i32, i32) {
 // CHECK:STDOUT: class @Class {
 // CHECK:STDOUT:   %F: <function> = fn_decl @F [template]
 // CHECK:STDOUT:   %G: <function> = fn_decl @G [template]
-// CHECK:STDOUT:   %.loc10_8.1: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.loc10_8.1: type = unbound_element_type Class, i32 [template = constants.%.5]
 // CHECK:STDOUT:   %.loc10_8.2: <unbound element of class Class> = field_decl n, element0 [template]
 // CHECK:STDOUT:   %n: <unbound element of class Class> = bind_name n, %.loc10_8.2 [template = %.loc10_8.2]
 // CHECK:STDOUT:

+ 8 - 6
toolchain/check/testdata/class/raw_self_type.carbon

@@ -14,13 +14,15 @@ class Class {
 // CHECK:STDOUT: --- raw_self_type.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = struct_type {} [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %.1: type = ptr_type Class [template]
+// CHECK:STDOUT:   %.2: type = struct_type {} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Class = %Class.decl} [template]
 // CHECK:STDOUT:   %Class.decl = class_decl @Class, ()
-// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template = constants.%Class]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Class {
@@ -32,12 +34,12 @@ class Class {
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @F() {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %Self.ref.loc9: type = name_ref Self, file.%Class [template = file.%Class]
-// CHECK:STDOUT:   %.loc9: type = ptr_type Class [template]
+// CHECK:STDOUT:   %Self.ref.loc9: type = name_ref Self, file.%Class [template = constants.%Class]
+// CHECK:STDOUT:   %.loc9: type = ptr_type Class [template = constants.%.1]
 // CHECK:STDOUT:   %Self.var: ref Class* = var r#Self
 // CHECK:STDOUT:   %Self: ref Class* = bind_name r#Self, %Self.var
-// CHECK:STDOUT:   %Self.ref.loc10_12: type = name_ref Self, file.%Class [template = file.%Class]
-// CHECK:STDOUT:   %.loc10_16: type = ptr_type Class [template]
+// CHECK:STDOUT:   %Self.ref.loc10_12: type = name_ref Self, file.%Class [template = constants.%Class]
+// CHECK:STDOUT:   %.loc10_16: type = ptr_type Class [template = constants.%.1]
 // CHECK:STDOUT:   %p.var: ref Class* = var p
 // CHECK:STDOUT:   %p: ref Class* = bind_name p, %p.var
 // CHECK:STDOUT:   %Self.ref.loc10_20: ref Class* = name_ref r#Self, %Self

+ 2 - 1
toolchain/check/testdata/class/redeclaration.carbon

@@ -15,13 +15,14 @@ fn Class.F() {}
 // CHECK:STDOUT: --- redeclaration.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %Class: type = class_type @Class [template]
 // CHECK:STDOUT:   %.1: type = struct_type {} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Class = %Class.decl.loc7} [template]
 // CHECK:STDOUT:   %Class.decl.loc7 = class_decl @Class, ()
-// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template = constants.%Class]
 // CHECK:STDOUT:   %Class.decl.loc9 = class_decl @Class, ()
 // CHECK:STDOUT:   %F: <function> = fn_decl @F [template]
 // CHECK:STDOUT: }

+ 6 - 3
toolchain/check/testdata/class/redeclaration_introducer.carbon

@@ -15,17 +15,20 @@ abstract class C {}
 // CHECK:STDOUT: --- redeclaration_introducer.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %A: type = class_type @A [template]
+// CHECK:STDOUT:   %B: type = class_type @B [template]
+// CHECK:STDOUT:   %C: type = class_type @C [template]
 // CHECK:STDOUT:   %.1: type = struct_type {} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.A = %A.decl.loc7, .B = %B.decl.loc8, .C = %C.decl.loc9} [template]
 // CHECK:STDOUT:   %A.decl.loc7 = class_decl @A, ()
-// CHECK:STDOUT:   %A: type = class_type @A [template]
+// CHECK:STDOUT:   %A: type = class_type @A [template = constants.%A]
 // CHECK:STDOUT:   %B.decl.loc8 = class_decl @B, ()
-// CHECK:STDOUT:   %B: type = class_type @B [template]
+// CHECK:STDOUT:   %B: type = class_type @B [template = constants.%B]
 // CHECK:STDOUT:   %C.decl.loc9 = class_decl @C, ()
-// CHECK:STDOUT:   %C: type = class_type @C [template]
+// CHECK:STDOUT:   %C: type = class_type @C [template = constants.%C]
 // CHECK:STDOUT:   %A.decl.loc11 = class_decl @A, ()
 // CHECK:STDOUT:   %B.decl.loc12 = class_decl @B, ()
 // CHECK:STDOUT:   %C.decl.loc13 = class_decl @C, ()

+ 2 - 1
toolchain/check/testdata/class/reenter_scope.carbon

@@ -16,13 +16,14 @@ fn Class.F() -> i32 {
 // CHECK:STDOUT: --- reenter_scope.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %Class: type = class_type @Class [template]
 // CHECK:STDOUT:   %.1: type = struct_type {} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Class = %Class.decl} [template]
 // CHECK:STDOUT:   %Class.decl = class_decl @Class, ()
-// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template = constants.%Class]
 // CHECK:STDOUT:   %F: <function> = fn_decl @F [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:

+ 3 - 2
toolchain/check/testdata/class/scope.carbon

@@ -26,6 +26,7 @@ fn Run() {
 // CHECK:STDOUT: --- scope.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %Class: type = class_type @Class [template]
 // CHECK:STDOUT:   %.1: i32 = int_literal 1 [template]
 // CHECK:STDOUT:   %.2: type = struct_type {} [template]
 // CHECK:STDOUT:   %.3: i32 = int_literal 2 [template]
@@ -34,7 +35,7 @@ fn Run() {
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Class = %Class.decl, .F = %F, .Run = %Run} [template]
 // CHECK:STDOUT:   %Class.decl = class_decl @Class, ()
-// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template = constants.%Class]
 // CHECK:STDOUT:   %F: <function> = fn_decl @F.2 [template]
 // CHECK:STDOUT:   %Run: <function> = fn_decl @Run [template]
 // CHECK:STDOUT: }
@@ -78,7 +79,7 @@ fn Run() {
 // CHECK:STDOUT:   assign %a.var, %.loc22
 // CHECK:STDOUT:   %b.var: ref i32 = var b
 // CHECK:STDOUT:   %b: ref i32 = bind_name b, %b.var
-// CHECK:STDOUT:   %Class.ref: type = name_ref Class, file.%Class [template = file.%Class]
+// CHECK:STDOUT:   %Class.ref: type = name_ref Class, file.%Class [template = constants.%Class]
 // CHECK:STDOUT:   %F.ref.loc23: <function> = name_ref F, @Class.%F [template = @Class.%F]
 // CHECK:STDOUT:   %.loc23: init i32 = call %F.ref.loc23()
 // CHECK:STDOUT:   assign %b.var, %.loc23

+ 7 - 4
toolchain/check/testdata/class/self.carbon

@@ -22,14 +22,17 @@ fn Class.G[addr self: Class*]() -> i32 {
 // CHECK:STDOUT: --- self.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = struct_type {.n: i32} [template]
-// CHECK:STDOUT:   %.2: type = ptr_type {.n: i32} [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %.1: type = ptr_type Class [template]
+// CHECK:STDOUT:   %.2: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.3: type = struct_type {.n: i32} [template]
+// CHECK:STDOUT:   %.4: type = ptr_type {.n: i32} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Class = %Class.decl} [template]
 // CHECK:STDOUT:   %Class.decl = class_decl @Class, ()
-// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template = constants.%Class]
 // CHECK:STDOUT:   %F: <function> = fn_decl @F [template]
 // CHECK:STDOUT:   %G: <function> = fn_decl @G [template]
 // CHECK:STDOUT: }
@@ -37,7 +40,7 @@ fn Class.G[addr self: Class*]() -> i32 {
 // CHECK:STDOUT: class @Class {
 // CHECK:STDOUT:   %F: <function> = fn_decl @F [template]
 // CHECK:STDOUT:   %G: <function> = fn_decl @G [template]
-// CHECK:STDOUT:   %.loc11_8.1: type = unbound_element_type Class, i32 [template]
+// CHECK:STDOUT:   %.loc11_8.1: type = unbound_element_type Class, i32 [template = constants.%.2]
 // CHECK:STDOUT:   %.loc11_8.2: <unbound element of class Class> = field_decl n, element0 [template]
 // CHECK:STDOUT:   %n: <unbound element of class Class> = bind_name n, %.loc11_8.2 [template = %.loc11_8.2]
 // CHECK:STDOUT:

+ 19 - 13
toolchain/check/testdata/class/self_conversion.carbon

@@ -31,28 +31,34 @@ fn Call(p: Derived*) -> i32 {
 // CHECK:STDOUT: --- self_conversion.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = struct_type {.a: i32} [template]
-// CHECK:STDOUT:   %.2: type = ptr_type {.a: i32} [template]
-// CHECK:STDOUT:   %.3: type = struct_type {.base: Base} [template]
-// CHECK:STDOUT:   %.4: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.5: type = struct_type {.base: {.a: i32}*} [template]
-// CHECK:STDOUT:   %.6: type = ptr_type {.base: Base} [template]
-// CHECK:STDOUT:   %.7: type = tuple_type () [template]
+// CHECK:STDOUT:   %Base: type = class_type @Base [template]
+// CHECK:STDOUT:   %.1: type = unbound_element_type Base, i32 [template]
+// CHECK:STDOUT:   %.2: type = struct_type {.a: i32} [template]
+// CHECK:STDOUT:   %Derived: type = class_type @Derived [template]
+// CHECK:STDOUT:   %.3: type = ptr_type {.a: i32} [template]
+// CHECK:STDOUT:   %.4: type = unbound_element_type Derived, Base [template]
+// CHECK:STDOUT:   %.5: type = ptr_type Base [template]
+// CHECK:STDOUT:   %.6: type = struct_type {.base: Base} [template]
+// CHECK:STDOUT:   %.7: i32 = int_literal 1 [template]
+// CHECK:STDOUT:   %.8: type = ptr_type Derived [template]
+// CHECK:STDOUT:   %.9: type = struct_type {.base: {.a: i32}*} [template]
+// CHECK:STDOUT:   %.10: type = ptr_type {.base: Base} [template]
+// CHECK:STDOUT:   %.11: type = tuple_type () [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Base = %Base.decl, .Derived = %Derived.decl, .Call = %Call} [template]
 // CHECK:STDOUT:   %Base.decl = class_decl @Base, ()
-// CHECK:STDOUT:   %Base: type = class_type @Base [template]
+// CHECK:STDOUT:   %Base: type = class_type @Base [template = constants.%Base]
 // CHECK:STDOUT:   %Derived.decl = class_decl @Derived, ()
-// CHECK:STDOUT:   %Derived: type = class_type @Derived [template]
+// CHECK:STDOUT:   %Derived: type = class_type @Derived [template = constants.%Derived]
 // CHECK:STDOUT:   %SelfBase: <function> = fn_decl @SelfBase [template]
 // CHECK:STDOUT:   %AddrSelfBase: <function> = fn_decl @AddrSelfBase [template]
 // CHECK:STDOUT:   %Call: <function> = fn_decl @Call [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Base {
-// CHECK:STDOUT:   %.loc8_8.1: type = unbound_element_type Base, i32 [template]
+// CHECK:STDOUT:   %.loc8_8.1: type = unbound_element_type Base, i32 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc8_8.2: <unbound element of class Base> = field_decl a, element0 [template]
 // CHECK:STDOUT:   %a: <unbound element of class Base> = bind_name a, %.loc8_8.2 [template = %.loc8_8.2]
 // CHECK:STDOUT:
@@ -61,8 +67,8 @@ fn Call(p: Derived*) -> i32 {
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Derived {
-// CHECK:STDOUT:   %Base.ref: type = name_ref Base, file.%Base [template = file.%Base]
-// CHECK:STDOUT:   %.loc12_20.1: type = unbound_element_type Derived, Base [template]
+// CHECK:STDOUT:   %Base.ref: type = name_ref Base, file.%Base [template = constants.%Base]
+// CHECK:STDOUT:   %.loc12_20.1: type = unbound_element_type Derived, Base [template = constants.%.4]
 // CHECK:STDOUT:   %.loc12_20.2: <unbound element of class Derived> = base_decl Base, element0 [template]
 // CHECK:STDOUT:   %SelfBase: <function> = fn_decl @SelfBase [template]
 // CHECK:STDOUT:   %AddrSelfBase: <function> = fn_decl @AddrSelfBase [template]
@@ -87,7 +93,7 @@ fn Call(p: Derived*) -> i32 {
 // CHECK:STDOUT:   %self.ref: Base* = name_ref self, %self
 // CHECK:STDOUT:   %.loc23_4: ref Base = deref %self.ref
 // CHECK:STDOUT:   %.loc23_10: ref i32 = class_element_access %.loc23_4, element0
-// CHECK:STDOUT:   %.loc23_15: i32 = int_literal 1 [template = constants.%.4]
+// CHECK:STDOUT:   %.loc23_15: i32 = int_literal 1 [template = constants.%.7]
 // CHECK:STDOUT:   assign %.loc23_10, %.loc23_15
 // CHECK:STDOUT:   return
 // CHECK:STDOUT: }

+ 9 - 6
toolchain/check/testdata/class/self_type.carbon

@@ -19,22 +19,25 @@ fn Class.F[self: Class]() -> i32 {
 // CHECK:STDOUT: --- self_type.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = struct_type {.p: Class*} [template]
-// CHECK:STDOUT:   %.2: type = ptr_type {.p: Class*} [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %.1: type = ptr_type Class [template]
+// CHECK:STDOUT:   %.2: type = unbound_element_type Class, Class* [template]
+// CHECK:STDOUT:   %.3: type = struct_type {.p: Class*} [template]
+// CHECK:STDOUT:   %.4: type = ptr_type {.p: Class*} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Class = %Class.decl} [template]
 // CHECK:STDOUT:   %Class.decl = class_decl @Class, ()
-// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template = constants.%Class]
 // CHECK:STDOUT:   %F: <function> = fn_decl @F [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @Class {
 // CHECK:STDOUT:   %F: <function> = fn_decl @F [template]
-// CHECK:STDOUT:   %Self.ref: type = name_ref Self, file.%Class [template = file.%Class]
-// CHECK:STDOUT:   %.loc9_14: type = ptr_type Class [template]
-// CHECK:STDOUT:   %.loc9_8.1: type = unbound_element_type Class, Class* [template]
+// CHECK:STDOUT:   %Self.ref: type = name_ref Self, file.%Class [template = constants.%Class]
+// CHECK:STDOUT:   %.loc9_14: type = ptr_type Class [template = constants.%.1]
+// CHECK:STDOUT:   %.loc9_8.1: type = unbound_element_type Class, Class* [template = constants.%.2]
 // CHECK:STDOUT:   %.loc9_8.2: <unbound element of class Class> = field_decl p, element0 [template]
 // CHECK:STDOUT:   %p: <unbound element of class Class> = bind_name p, %.loc9_8.2 [template = %.loc9_8.2]
 // CHECK:STDOUT:

+ 3 - 2
toolchain/check/testdata/class/static_method.carbon

@@ -16,6 +16,7 @@ fn Run() -> i32 {
 // CHECK:STDOUT: --- static_method.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %Class: type = class_type @Class [template]
 // CHECK:STDOUT:   %.1: type = struct_type {} [template]
 // CHECK:STDOUT:   %.2: type = tuple_type () [template]
 // CHECK:STDOUT:   %.3: type = ptr_type {} [template]
@@ -24,7 +25,7 @@ fn Run() -> i32 {
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Class = %Class.decl, .Run = %Run} [template]
 // CHECK:STDOUT:   %Class.decl = class_decl @Class, ()
-// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template = constants.%Class]
 // CHECK:STDOUT:   %Run: <function> = fn_decl @Run [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
@@ -39,7 +40,7 @@ fn Run() -> i32 {
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @Run() -> i32 {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %Class.ref: type = name_ref Class, file.%Class [template = file.%Class]
+// CHECK:STDOUT:   %Class.ref: type = name_ref Class, file.%Class [template = constants.%Class]
 // CHECK:STDOUT:   %c.var: ref Class = var c
 // CHECK:STDOUT:   %c: ref Class = bind_name c, %c.var
 // CHECK:STDOUT:   %c.ref: ref Class = name_ref c, %c

+ 7 - 0
toolchain/check/testdata/const/collapse.carbon

@@ -14,6 +14,13 @@ fn F(p: const i32**) -> const (const i32)** {
 
 // CHECK:STDOUT: --- collapse.carbon
 // CHECK:STDOUT:
+// CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %.1: type = const_type i32 [template]
+// CHECK:STDOUT:   %.2: type = ptr_type const i32 [template]
+// CHECK:STDOUT:   %.3: type = ptr_type const i32* [template]
+// CHECK:STDOUT:   %.4: type = const_type const i32 [template]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.F = %F} [template]
 // CHECK:STDOUT:   %F: <function> = fn_decl @F [template]

+ 9 - 0
toolchain/check/testdata/const/fail_collapse.carbon

@@ -16,6 +16,15 @@ fn G(p: const (const i32)**) -> i32** {
 
 // CHECK:STDOUT: --- fail_collapse.carbon
 // CHECK:STDOUT:
+// CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %.1: type = const_type i32 [template]
+// CHECK:STDOUT:   %.2: type = const_type const i32 [template]
+// CHECK:STDOUT:   %.3: type = ptr_type const i32 [template]
+// CHECK:STDOUT:   %.4: type = ptr_type const i32* [template]
+// CHECK:STDOUT:   %.5: type = ptr_type i32 [template]
+// CHECK:STDOUT:   %.6: type = ptr_type i32* [template]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.G = %G} [template]
 // CHECK:STDOUT:   %G: <function> = fn_decl @G [template]

+ 4 - 8
toolchain/check/testdata/function/call/fail_param_count.carbon

@@ -61,10 +61,6 @@ fn Main() {
 // CHECK:STDOUT:   %.1: i32 = int_literal 1 [template]
 // CHECK:STDOUT:   %.2: type = tuple_type () [template]
 // CHECK:STDOUT:   %.3: i32 = int_literal 0 [template]
-// CHECK:STDOUT:   %.4: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.5: i32 = int_literal 0 [template]
-// CHECK:STDOUT:   %.6: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.7: i32 = int_literal 0 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -97,18 +93,18 @@ fn Main() {
 // CHECK:STDOUT:   %.loc18_7: init () = call %Run0.ref.loc18(<invalid>)
 // CHECK:STDOUT:   %Run0.ref.loc25: <function> = name_ref Run0, file.%Run0 [template = file.%Run0]
 // CHECK:STDOUT:   %.loc25_8: i32 = int_literal 0 [template = constants.%.3]
-// CHECK:STDOUT:   %.loc25_11: i32 = int_literal 1 [template = constants.%.4]
+// CHECK:STDOUT:   %.loc25_11: i32 = int_literal 1 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc25_7: init () = call %Run0.ref.loc25(<invalid>)
 // CHECK:STDOUT:   %Run1.ref.loc33: <function> = name_ref Run1, file.%Run1 [template = file.%Run1]
 // CHECK:STDOUT:   %.loc33: init () = call %Run1.ref.loc33(<invalid>)
 // CHECK:STDOUT:   %Run1.ref.loc40: <function> = name_ref Run1, file.%Run1 [template = file.%Run1]
-// CHECK:STDOUT:   %.loc40_8: i32 = int_literal 0 [template = constants.%.5]
-// CHECK:STDOUT:   %.loc40_11: i32 = int_literal 1 [template = constants.%.6]
+// CHECK:STDOUT:   %.loc40_8: i32 = int_literal 0 [template = constants.%.3]
+// CHECK:STDOUT:   %.loc40_11: i32 = int_literal 1 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc40_7: init () = call %Run1.ref.loc40(<invalid>)
 // CHECK:STDOUT:   %Run2.ref.loc48: <function> = name_ref Run2, file.%Run2 [template = file.%Run2]
 // CHECK:STDOUT:   %.loc48: init () = call %Run2.ref.loc48(<invalid>)
 // CHECK:STDOUT:   %Run2.ref.loc55: <function> = name_ref Run2, file.%Run2 [template = file.%Run2]
-// CHECK:STDOUT:   %.loc55_8: i32 = int_literal 0 [template = constants.%.7]
+// CHECK:STDOUT:   %.loc55_8: i32 = int_literal 0 [template = constants.%.3]
 // CHECK:STDOUT:   %.loc55_7: init () = call %Run2.ref.loc55(<invalid>)
 // CHECK:STDOUT:   return
 // CHECK:STDOUT: }

+ 1 - 2
toolchain/check/testdata/function/call/params_one_comma.carbon

@@ -16,7 +16,6 @@ fn Main() {
 // CHECK:STDOUT: constants {
 // CHECK:STDOUT:   %.1: i32 = int_literal 1 [template]
 // CHECK:STDOUT:   %.2: type = tuple_type () [template]
-// CHECK:STDOUT:   %.3: i32 = int_literal 1 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -36,7 +35,7 @@ fn Main() {
 // CHECK:STDOUT:   %.loc10_7: i32 = int_literal 1 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc10_6: init () = call %Foo.ref.loc10(%.loc10_7)
 // CHECK:STDOUT:   %Foo.ref.loc11: <function> = name_ref Foo, file.%Foo [template = file.%Foo]
-// CHECK:STDOUT:   %.loc11_7: i32 = int_literal 1 [template = constants.%.3]
+// CHECK:STDOUT:   %.loc11_7: i32 = int_literal 1 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc11_6: init () = call %Foo.ref.loc11(%.loc11_7)
 // CHECK:STDOUT:   return
 // CHECK:STDOUT: }

+ 2 - 4
toolchain/check/testdata/function/call/params_two_comma.carbon

@@ -17,8 +17,6 @@ fn Main() {
 // CHECK:STDOUT:   %.1: i32 = int_literal 1 [template]
 // CHECK:STDOUT:   %.2: i32 = int_literal 2 [template]
 // CHECK:STDOUT:   %.3: type = tuple_type () [template]
-// CHECK:STDOUT:   %.4: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.5: i32 = int_literal 2 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -39,8 +37,8 @@ fn Main() {
 // CHECK:STDOUT:   %.loc10_10: i32 = int_literal 2 [template = constants.%.2]
 // CHECK:STDOUT:   %.loc10_6: init () = call %Foo.ref.loc10(%.loc10_7, %.loc10_10)
 // CHECK:STDOUT:   %Foo.ref.loc11: <function> = name_ref Foo, file.%Foo [template = file.%Foo]
-// CHECK:STDOUT:   %.loc11_7: i32 = int_literal 1 [template = constants.%.4]
-// CHECK:STDOUT:   %.loc11_10: i32 = int_literal 2 [template = constants.%.5]
+// CHECK:STDOUT:   %.loc11_7: i32 = int_literal 1 [template = constants.%.1]
+// CHECK:STDOUT:   %.loc11_10: i32 = int_literal 2 [template = constants.%.2]
 // CHECK:STDOUT:   %.loc11_6: init () = call %Foo.ref.loc11(%.loc11_7, %.loc11_10)
 // CHECK:STDOUT:   return
 // CHECK:STDOUT: }

+ 5 - 1
toolchain/check/testdata/function/generic/fail_type_param_mismatch.carbon

@@ -14,6 +14,10 @@ fn F(T:! type, U:! type) {
 
 // CHECK:STDOUT: --- fail_type_param_mismatch.carbon
 // CHECK:STDOUT:
+// CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %.1: type = ptr_type T [template]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.F = %F} [template]
 // CHECK:STDOUT:   %F: <function> = fn_decl @F [template]
@@ -22,7 +26,7 @@ fn F(T:! type, U:! type) {
 // CHECK:STDOUT: fn @F(%T: type, %U: type) {
 // CHECK:STDOUT: !entry:
 // CHECK:STDOUT:   %T.ref: type = name_ref T, %T [symbolic = %T]
-// CHECK:STDOUT:   %.loc8: type = ptr_type T [template]
+// CHECK:STDOUT:   %.loc8: type = ptr_type T [template = constants.%.1]
 // CHECK:STDOUT:   %p.var: ref T* = var p
 // CHECK:STDOUT:   %p: ref T* = bind_name p, %p.var
 // CHECK:STDOUT:   %U.ref: type = name_ref U, %U [symbolic = %U]

+ 5 - 1
toolchain/check/testdata/function/generic/type_param.carbon

@@ -11,6 +11,10 @@ fn F(T:! type) {
 
 // CHECK:STDOUT: --- type_param.carbon
 // CHECK:STDOUT:
+// CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %.1: type = ptr_type T [template]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.F = %F} [template]
 // CHECK:STDOUT:   %F: <function> = fn_decl @F [template]
@@ -19,7 +23,7 @@ fn F(T:! type) {
 // CHECK:STDOUT: fn @F(%T: type) {
 // CHECK:STDOUT: !entry:
 // CHECK:STDOUT:   %T.ref.loc8: type = name_ref T, %T [symbolic = %T]
-// CHECK:STDOUT:   %.loc8: type = ptr_type T [template]
+// CHECK:STDOUT:   %.loc8: type = ptr_type T [template = constants.%.1]
 // CHECK:STDOUT:   %p.var: ref T* = var p
 // CHECK:STDOUT:   %p: ref T* = bind_name p, %p.var
 // CHECK:STDOUT:   %T.ref.loc9: type = name_ref T, %T [symbolic = %T]

+ 1 - 2
toolchain/check/testdata/if/fail_reachable_fallthrough.carbon

@@ -38,7 +38,6 @@ fn If3(b: bool) -> i32 {
 // CHECK:STDOUT: constants {
 // CHECK:STDOUT:   %.1: i32 = int_literal 1 [template]
 // CHECK:STDOUT:   %.2: i32 = int_literal 2 [template]
-// CHECK:STDOUT:   %.3: i32 = int_literal 1 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -84,7 +83,7 @@ fn If3(b: bool) -> i32 {
 // CHECK:STDOUT:   if %b.ref br !if.then else br !if.else
 // CHECK:STDOUT:
 // CHECK:STDOUT: !if.then:
-// CHECK:STDOUT:   %.loc29: i32 = int_literal 1 [template = constants.%.3]
+// CHECK:STDOUT:   %.loc29: i32 = int_literal 1 [template = constants.%.1]
 // CHECK:STDOUT:   return %.loc29
 // CHECK:STDOUT:
 // CHECK:STDOUT: !if.else:

+ 5 - 4
toolchain/check/testdata/if_expr/fail_not_in_function.carbon

@@ -39,7 +39,8 @@ class C {
 // CHECK:STDOUT:   %.1: bool = bool_literal true [template]
 // CHECK:STDOUT:   %.2: i32 = int_literal 1 [template]
 // CHECK:STDOUT:   %.3: i32 = int_literal 0 [template]
-// CHECK:STDOUT:   %.4: bool = bool_literal true [template]
+// CHECK:STDOUT:   %C: type = class_type @C [template]
+// CHECK:STDOUT:   %.4: type = unbound_element_type C, <error> [template]
 // CHECK:STDOUT:   %.5: type = struct_type {.n: <error>} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
@@ -47,14 +48,14 @@ class C {
 // CHECK:STDOUT:   %.loc17: i32 = block_arg <unexpected instblockref block5>
 // CHECK:STDOUT:   %x: i32 = bind_name x, %.loc17
 // CHECK:STDOUT:   %C.decl = class_decl @C, ()
-// CHECK:STDOUT:   %C: type = class_type @C [template]
+// CHECK:STDOUT:   %C: type = class_type @C [template = constants.%C]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: class @C {
-// CHECK:STDOUT:   %.loc33: bool = bool_literal true [template = constants.%.4]
+// CHECK:STDOUT:   %.loc33: bool = bool_literal true [template = constants.%.1]
 // CHECK:STDOUT:   if %.loc33 br !if.expr.then else br !if.expr.else
 // CHECK:STDOUT:
 // CHECK:STDOUT: !members:
-// CHECK:STDOUT:   .n = <unexpected instref inst+25>
+// CHECK:STDOUT:   .n = <unexpected instref inst+27>
 // CHECK:STDOUT: }
 // CHECK:STDOUT:

+ 8 - 7
toolchain/check/testdata/if_expr/struct.carbon

@@ -14,10 +14,11 @@ fn F(cond: bool) {
 // CHECK:STDOUT: --- struct.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = ptr_type {.a: i32, .b: i32} [template]
-// CHECK:STDOUT:   %.2: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.3: i32 = int_literal 2 [template]
-// CHECK:STDOUT:   %.4: type = tuple_type () [template]
+// CHECK:STDOUT:   %.1: type = struct_type {.a: i32, .b: i32} [template]
+// CHECK:STDOUT:   %.2: type = ptr_type {.a: i32, .b: i32} [template]
+// CHECK:STDOUT:   %.3: i32 = int_literal 1 [template]
+// CHECK:STDOUT:   %.4: i32 = int_literal 2 [template]
+// CHECK:STDOUT:   %.5: type = tuple_type () [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -30,11 +31,11 @@ fn F(cond: bool) {
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @F(%cond: bool) {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %.loc10_27: type = struct_type {.a: i32, .b: i32} [template]
+// CHECK:STDOUT:   %.loc10_27: type = struct_type {.a: i32, .b: i32} [template = constants.%.1]
 // CHECK:STDOUT:   %a.var: ref {.a: i32, .b: i32} = var a
 // CHECK:STDOUT:   %a: ref {.a: i32, .b: i32} = bind_name a, %a.var
-// CHECK:STDOUT:   %.loc10_37: i32 = int_literal 1 [template = constants.%.2]
-// CHECK:STDOUT:   %.loc10_45: i32 = int_literal 2 [template = constants.%.3]
+// CHECK:STDOUT:   %.loc10_37: i32 = int_literal 1 [template = constants.%.3]
+// CHECK:STDOUT:   %.loc10_45: i32 = int_literal 2 [template = constants.%.4]
 // CHECK:STDOUT:   %.loc10_46.1: {.a: i32, .b: i32} = struct_literal (%.loc10_37, %.loc10_45)
 // CHECK:STDOUT:   %.loc10_46.2: ref i32 = struct_access %a.var, element0
 // CHECK:STDOUT:   %.loc10_46.3: init i32 = initialize_from %.loc10_37 to %.loc10_46.2

+ 30 - 48
toolchain/check/testdata/index/expr_category.carbon

@@ -30,33 +30,15 @@ fn ValueBinding(b: [i32; 3]) {
 // CHECK:STDOUT:   %.1: i32 = int_literal 3 [template]
 // CHECK:STDOUT:   %.2: type = array_type %.1, i32 [template]
 // CHECK:STDOUT:   %.3: type = ptr_type [i32; 3] [template]
-// CHECK:STDOUT:   %.4: i32 = int_literal 3 [template]
-// CHECK:STDOUT:   %.5: type = array_type %.4, i32 [template]
-// CHECK:STDOUT:   %.6: i32 = int_literal 3 [template]
-// CHECK:STDOUT:   %.7: type = array_type %.6, i32 [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, i32) [template]
+// CHECK:STDOUT:   %.7: i32 = int_literal 0 [template]
 // CHECK:STDOUT:   %.8: i32 = int_literal 1 [template]
 // CHECK:STDOUT:   %.9: i32 = int_literal 2 [template]
-// CHECK:STDOUT:   %.10: i32 = int_literal 3 [template]
-// CHECK:STDOUT:   %.11: type = tuple_type (i32, i32, i32) [template]
-// CHECK:STDOUT:   %.12: i32 = int_literal 0 [template]
-// CHECK:STDOUT:   %.13: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.14: i32 = int_literal 2 [template]
-// CHECK:STDOUT:   %.15: i32 = int_literal 0 [template]
-// CHECK:STDOUT:   %.16: i32 = int_literal 0 [template]
-// CHECK:STDOUT:   %.17: i32 = int_literal 4 [template]
-// CHECK:STDOUT:   %.18: i32 = int_literal 3 [template]
-// CHECK:STDOUT:   %.19: type = array_type %.18, i32 [template]
-// CHECK:STDOUT:   %.20: i32 = int_literal 3 [template]
-// CHECK:STDOUT:   %.21: type = array_type %.20, i32 [template]
-// CHECK:STDOUT:   %.22: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.23: i32 = int_literal 2 [template]
-// CHECK:STDOUT:   %.24: i32 = int_literal 3 [template]
-// CHECK:STDOUT:   %.25: i32 = int_literal 0 [template]
-// CHECK:STDOUT:   %.26: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.27: i32 = int_literal 2 [template]
-// CHECK:STDOUT:   %.28: i32 = int_literal 0 [template]
-// CHECK:STDOUT:   %.29: i32 = int_literal 0 [template]
-// CHECK:STDOUT:   %.30: i32 = int_literal 0 [template]
+// CHECK:STDOUT:   %.10: type = ptr_type i32 [template]
+// CHECK:STDOUT:   %.11: i32 = int_literal 0 [template]
+// CHECK:STDOUT:   %.12: i32 = int_literal 4 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -70,76 +52,76 @@ fn ValueBinding(b: [i32; 3]) {
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @G(%b: [i32; 3]) {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %.loc10_16: i32 = int_literal 3 [template = constants.%.6]
-// CHECK:STDOUT:   %.loc10_17: type = array_type %.loc10_16, i32 [template = constants.%.7]
+// CHECK:STDOUT:   %.loc10_16: i32 = int_literal 3 [template = constants.%.1]
+// CHECK:STDOUT:   %.loc10_17: type = array_type %.loc10_16, i32 [template = constants.%.2]
 // CHECK:STDOUT:   %a.var: ref [i32; 3] = var a
 // CHECK:STDOUT:   %a: ref [i32; 3] = bind_name a, %a.var
-// CHECK:STDOUT:   %.loc10_22: i32 = int_literal 1 [template = constants.%.8]
-// CHECK:STDOUT:   %.loc10_25: i32 = int_literal 2 [template = constants.%.9]
-// CHECK:STDOUT:   %.loc10_28: i32 = int_literal 3 [template = constants.%.10]
+// CHECK:STDOUT:   %.loc10_22: i32 = int_literal 1 [template = constants.%.4]
+// CHECK:STDOUT:   %.loc10_25: i32 = int_literal 2 [template = constants.%.5]
+// CHECK:STDOUT:   %.loc10_28: i32 = int_literal 3 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc10_29.1: (i32, i32, i32) = tuple_literal (%.loc10_22, %.loc10_25, %.loc10_28)
-// CHECK:STDOUT:   %.loc10_29.2: i32 = int_literal 0 [template = constants.%.12]
+// CHECK:STDOUT:   %.loc10_29.2: i32 = int_literal 0 [template = constants.%.7]
 // CHECK:STDOUT:   %.loc10_29.3: ref i32 = array_index %a.var, %.loc10_29.2
 // CHECK:STDOUT:   %.loc10_29.4: init i32 = initialize_from %.loc10_22 to %.loc10_29.3
-// CHECK:STDOUT:   %.loc10_29.5: i32 = int_literal 1 [template = constants.%.13]
+// CHECK:STDOUT:   %.loc10_29.5: i32 = int_literal 1 [template = constants.%.8]
 // CHECK:STDOUT:   %.loc10_29.6: ref i32 = array_index %a.var, %.loc10_29.5
 // CHECK:STDOUT:   %.loc10_29.7: init i32 = initialize_from %.loc10_25 to %.loc10_29.6
-// CHECK:STDOUT:   %.loc10_29.8: i32 = int_literal 2 [template = constants.%.14]
+// CHECK:STDOUT:   %.loc10_29.8: i32 = int_literal 2 [template = constants.%.9]
 // CHECK:STDOUT:   %.loc10_29.9: ref i32 = array_index %a.var, %.loc10_29.8
 // CHECK:STDOUT:   %.loc10_29.10: init i32 = initialize_from %.loc10_28 to %.loc10_29.9
 // CHECK:STDOUT:   %.loc10_29.11: init [i32; 3] = array_init (%.loc10_29.4, %.loc10_29.7, %.loc10_29.10) to %a.var
 // CHECK:STDOUT:   %.loc10_29.12: init [i32; 3] = converted %.loc10_29.1, %.loc10_29.11
 // CHECK:STDOUT:   assign %a.var, %.loc10_29.12
-// CHECK:STDOUT:   %.loc13_14: type = ptr_type i32 [template]
+// CHECK:STDOUT:   %.loc13_14: type = ptr_type i32 [template = constants.%.10]
 // CHECK:STDOUT:   %pa.var: ref i32* = var pa
 // CHECK:STDOUT:   %pa: ref i32* = bind_name pa, %pa.var
 // CHECK:STDOUT:   %a.ref.loc13: ref [i32; 3] = name_ref a, %a
-// CHECK:STDOUT:   %.loc13_21: i32 = int_literal 0 [template = constants.%.15]
+// CHECK:STDOUT:   %.loc13_21: i32 = int_literal 0 [template = constants.%.11]
 // CHECK:STDOUT:   %.loc13_22: ref i32 = array_index %a.ref.loc13, %.loc13_21
 // CHECK:STDOUT:   %.loc13_18: i32* = addr_of %.loc13_22
 // CHECK:STDOUT:   assign %pa.var, %.loc13_18
 // CHECK:STDOUT:   %a.ref.loc14: ref [i32; 3] = name_ref a, %a
-// CHECK:STDOUT:   %.loc14_5: i32 = int_literal 0 [template = constants.%.16]
+// CHECK:STDOUT:   %.loc14_5: i32 = int_literal 0 [template = constants.%.11]
 // CHECK:STDOUT:   %.loc14_6: ref i32 = array_index %a.ref.loc14, %.loc14_5
-// CHECK:STDOUT:   %.loc14_10: i32 = int_literal 4 [template = constants.%.17]
+// CHECK:STDOUT:   %.loc14_10: i32 = int_literal 4 [template = constants.%.12]
 // CHECK:STDOUT:   assign %.loc14_6, %.loc14_10
 // CHECK:STDOUT:   return
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @ValueBinding(%b: [i32; 3]) {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %.loc18_16: i32 = int_literal 3 [template = constants.%.20]
-// CHECK:STDOUT:   %.loc18_17: type = array_type %.loc18_16, i32 [template = constants.%.21]
+// CHECK:STDOUT:   %.loc18_16: i32 = int_literal 3 [template = constants.%.1]
+// CHECK:STDOUT:   %.loc18_17: type = array_type %.loc18_16, i32 [template = constants.%.2]
 // CHECK:STDOUT:   %a.var: ref [i32; 3] = var a
 // CHECK:STDOUT:   %a: ref [i32; 3] = bind_name a, %a.var
-// CHECK:STDOUT:   %.loc18_22: i32 = int_literal 1 [template = constants.%.22]
-// CHECK:STDOUT:   %.loc18_25: i32 = int_literal 2 [template = constants.%.23]
-// CHECK:STDOUT:   %.loc18_28: i32 = int_literal 3 [template = constants.%.24]
+// CHECK:STDOUT:   %.loc18_22: i32 = int_literal 1 [template = constants.%.4]
+// CHECK:STDOUT:   %.loc18_25: i32 = int_literal 2 [template = constants.%.5]
+// CHECK:STDOUT:   %.loc18_28: i32 = int_literal 3 [template = constants.%.1]
 // CHECK:STDOUT:   %.loc18_29.1: (i32, i32, i32) = tuple_literal (%.loc18_22, %.loc18_25, %.loc18_28)
-// CHECK:STDOUT:   %.loc18_29.2: i32 = int_literal 0 [template = constants.%.25]
+// CHECK:STDOUT:   %.loc18_29.2: i32 = int_literal 0 [template = constants.%.7]
 // CHECK:STDOUT:   %.loc18_29.3: ref i32 = array_index %a.var, %.loc18_29.2
 // CHECK:STDOUT:   %.loc18_29.4: init i32 = initialize_from %.loc18_22 to %.loc18_29.3
-// CHECK:STDOUT:   %.loc18_29.5: i32 = int_literal 1 [template = constants.%.26]
+// CHECK:STDOUT:   %.loc18_29.5: i32 = int_literal 1 [template = constants.%.8]
 // CHECK:STDOUT:   %.loc18_29.6: ref i32 = array_index %a.var, %.loc18_29.5
 // CHECK:STDOUT:   %.loc18_29.7: init i32 = initialize_from %.loc18_25 to %.loc18_29.6
-// CHECK:STDOUT:   %.loc18_29.8: i32 = int_literal 2 [template = constants.%.27]
+// CHECK:STDOUT:   %.loc18_29.8: i32 = int_literal 2 [template = constants.%.9]
 // CHECK:STDOUT:   %.loc18_29.9: ref i32 = array_index %a.var, %.loc18_29.8
 // CHECK:STDOUT:   %.loc18_29.10: init i32 = initialize_from %.loc18_28 to %.loc18_29.9
 // CHECK:STDOUT:   %.loc18_29.11: init [i32; 3] = array_init (%.loc18_29.4, %.loc18_29.7, %.loc18_29.10) to %a.var
 // CHECK:STDOUT:   %.loc18_29.12: init [i32; 3] = converted %.loc18_29.1, %.loc18_29.11
 // CHECK:STDOUT:   assign %a.var, %.loc18_29.12
 // CHECK:STDOUT:   %a.ref: ref [i32; 3] = name_ref a, %a
-// CHECK:STDOUT:   %.loc22_5: i32 = int_literal 0 [template = constants.%.28]
+// CHECK:STDOUT:   %.loc22_5: i32 = int_literal 0 [template = constants.%.11]
 // CHECK:STDOUT:   %.loc22_6: ref i32 = array_index %a.ref, %.loc22_5
 // CHECK:STDOUT:   %b.ref: [i32; 3] = name_ref b, %b
-// CHECK:STDOUT:   %.loc23_5: i32 = int_literal 0 [template = constants.%.29]
+// CHECK:STDOUT:   %.loc23_5: i32 = int_literal 0 [template = constants.%.11]
 // CHECK:STDOUT:   %.loc23_6.1: ref [i32; 3] = value_as_ref %b.ref
 // CHECK:STDOUT:   %.loc23_6.2: ref i32 = array_index %.loc23_6.1, %.loc23_5
 // CHECK:STDOUT:   %.loc23_6.3: i32 = bind_value %.loc23_6.2
 // CHECK:STDOUT:   %F.ref: <function> = name_ref F, file.%F [template = file.%F]
 // CHECK:STDOUT:   %.loc24_4.1: ref [i32; 3] = temporary_storage
 // CHECK:STDOUT:   %.loc24_4.2: init [i32; 3] = call %F.ref() to %.loc24_4.1
-// CHECK:STDOUT:   %.loc24_7: i32 = int_literal 0 [template = constants.%.30]
+// CHECK:STDOUT:   %.loc24_7: i32 = int_literal 0 [template = constants.%.11]
 // CHECK:STDOUT:   %.loc24_4.3: ref [i32; 3] = temporary %.loc24_4.1, %.loc24_4.2
 // CHECK:STDOUT:   %.loc24_8.1: ref i32 = array_index %.loc24_4.3, %.loc24_7
 // CHECK:STDOUT:   %.loc24_8.2: i32 = bind_value %.loc24_8.1

+ 11 - 16
toolchain/check/testdata/index/fail_expr_category.carbon

@@ -35,14 +35,9 @@ fn G(b: [i32; 3]) {
 // CHECK:STDOUT:   %.1: i32 = int_literal 3 [template]
 // CHECK:STDOUT:   %.2: type = array_type %.1, i32 [template]
 // CHECK:STDOUT:   %.3: type = ptr_type [i32; 3] [template]
-// CHECK:STDOUT:   %.4: i32 = int_literal 3 [template]
-// CHECK:STDOUT:   %.5: type = array_type %.4, i32 [template]
-// CHECK:STDOUT:   %.6: i32 = int_literal 0 [template]
-// CHECK:STDOUT:   %.7: i32 = int_literal 0 [template]
-// CHECK:STDOUT:   %.8: i32 = int_literal 4 [template]
-// CHECK:STDOUT:   %.9: i32 = int_literal 0 [template]
-// CHECK:STDOUT:   %.10: i32 = int_literal 0 [template]
-// CHECK:STDOUT:   %.11: i32 = int_literal 4 [template]
+// CHECK:STDOUT:   %.4: type = ptr_type i32 [template]
+// CHECK:STDOUT:   %.5: i32 = int_literal 0 [template]
+// CHECK:STDOUT:   %.6: i32 = int_literal 4 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -55,30 +50,30 @@ fn G(b: [i32; 3]) {
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @G(%b: [i32; 3]) {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %.loc14_14: type = ptr_type i32 [template]
+// CHECK:STDOUT:   %.loc14_14: type = ptr_type i32 [template = constants.%.4]
 // CHECK:STDOUT:   %pb.var: ref i32* = var pb
 // CHECK:STDOUT:   %pb: ref i32* = bind_name pb, %pb.var
 // CHECK:STDOUT:   %b.ref.loc14: [i32; 3] = name_ref b, %b
-// CHECK:STDOUT:   %.loc14_21: i32 = int_literal 0 [template = constants.%.6]
+// CHECK:STDOUT:   %.loc14_21: i32 = int_literal 0 [template = constants.%.5]
 // CHECK:STDOUT:   %.loc14_22.1: ref [i32; 3] = value_as_ref %b.ref.loc14
 // CHECK:STDOUT:   %.loc14_22.2: ref i32 = array_index %.loc14_22.1, %.loc14_21
 // CHECK:STDOUT:   %.loc14_22.3: i32 = bind_value %.loc14_22.2
 // CHECK:STDOUT:   %.loc14_18: i32* = addr_of %.loc14_22.3
 // CHECK:STDOUT:   assign %pb.var, %.loc14_18
 // CHECK:STDOUT:   %b.ref.loc18: [i32; 3] = name_ref b, %b
-// CHECK:STDOUT:   %.loc18_5: i32 = int_literal 0 [template = constants.%.7]
+// CHECK:STDOUT:   %.loc18_5: i32 = int_literal 0 [template = constants.%.5]
 // CHECK:STDOUT:   %.loc18_6.1: ref [i32; 3] = value_as_ref %b.ref.loc18
 // CHECK:STDOUT:   %.loc18_6.2: ref i32 = array_index %.loc18_6.1, %.loc18_5
 // CHECK:STDOUT:   %.loc18_6.3: i32 = bind_value %.loc18_6.2
-// CHECK:STDOUT:   %.loc18_10: i32 = int_literal 4 [template = constants.%.8]
+// CHECK:STDOUT:   %.loc18_10: i32 = int_literal 4 [template = constants.%.6]
 // CHECK:STDOUT:   assign %.loc18_6.3, %.loc18_10
-// CHECK:STDOUT:   %.loc25_14: type = ptr_type i32 [template]
+// CHECK:STDOUT:   %.loc25_14: type = ptr_type i32 [template = constants.%.4]
 // CHECK:STDOUT:   %pf.var: ref i32* = var pf
 // CHECK:STDOUT:   %pf: ref i32* = bind_name pf, %pf.var
 // CHECK:STDOUT:   %F.ref.loc25: <function> = name_ref F, file.%F [template = file.%F]
 // CHECK:STDOUT:   %.loc25_20.1: ref [i32; 3] = temporary_storage
 // CHECK:STDOUT:   %.loc25_20.2: init [i32; 3] = call %F.ref.loc25() to %.loc25_20.1
-// CHECK:STDOUT:   %.loc25_23: i32 = int_literal 0 [template = constants.%.9]
+// CHECK:STDOUT:   %.loc25_23: i32 = int_literal 0 [template = constants.%.5]
 // CHECK:STDOUT:   %.loc25_20.3: ref [i32; 3] = temporary %.loc25_20.1, %.loc25_20.2
 // CHECK:STDOUT:   %.loc25_24.1: ref i32 = array_index %.loc25_20.3, %.loc25_23
 // CHECK:STDOUT:   %.loc25_24.2: i32 = bind_value %.loc25_24.1
@@ -87,11 +82,11 @@ fn G(b: [i32; 3]) {
 // CHECK:STDOUT:   %F.ref.loc29: <function> = name_ref F, file.%F [template = file.%F]
 // CHECK:STDOUT:   %.loc29_4.1: ref [i32; 3] = temporary_storage
 // CHECK:STDOUT:   %.loc29_4.2: init [i32; 3] = call %F.ref.loc29() to %.loc29_4.1
-// CHECK:STDOUT:   %.loc29_7: i32 = int_literal 0 [template = constants.%.10]
+// CHECK:STDOUT:   %.loc29_7: i32 = int_literal 0 [template = constants.%.5]
 // CHECK:STDOUT:   %.loc29_4.3: ref [i32; 3] = temporary %.loc29_4.1, %.loc29_4.2
 // CHECK:STDOUT:   %.loc29_8.1: ref i32 = array_index %.loc29_4.3, %.loc29_7
 // CHECK:STDOUT:   %.loc29_8.2: i32 = bind_value %.loc29_8.1
-// CHECK:STDOUT:   %.loc29_12: i32 = int_literal 4 [template = constants.%.11]
+// CHECK:STDOUT:   %.loc29_12: i32 = int_literal 4 [template = constants.%.6]
 // CHECK:STDOUT:   assign %.loc29_8.2, %.loc29_12
 // CHECK:STDOUT:   return
 // CHECK:STDOUT: }

+ 12 - 14
toolchain/check/testdata/index/fail_invalid_base.carbon

@@ -35,13 +35,11 @@ var d: i32 = {.a: i32, .b: i32}[0];
 // CHECK:STDOUT: constants {
 // CHECK:STDOUT:   %.1: i32 = int_literal 0 [template]
 // CHECK:STDOUT:   %.2: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.3: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.4: i32 = int_literal 2 [template]
-// CHECK:STDOUT:   %.5: type = struct_type {.a: i32, .b: i32} [template]
-// CHECK:STDOUT:   %.6: i32 = int_literal 0 [template]
-// CHECK:STDOUT:   %.7: type = ptr_type {.a: i32, .b: i32} [template]
-// CHECK:STDOUT:   %.8: {.a: i32, .b: i32} = struct_value (%.3, %.4) [template]
-// CHECK:STDOUT:   %.9: i32 = int_literal 0 [template]
+// CHECK:STDOUT:   %.3: i32 = int_literal 2 [template]
+// CHECK:STDOUT:   %.4: type = struct_type {.a: i32, .b: i32} [template]
+// CHECK:STDOUT:   %.5: type = ptr_type {.a: i32, .b: i32} [template]
+// CHECK:STDOUT:   %.6: {.a: i32, .b: i32} = struct_value (%.2, %.3) [template]
+// CHECK:STDOUT:   %.7: type = struct_type {.a: i32, .b: i32} [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -60,17 +58,17 @@ var d: i32 = {.a: i32, .b: i32}[0];
 // CHECK:STDOUT:   assign %b.var, <error>
 // CHECK:STDOUT:   %c.var: ref i32 = var c
 // CHECK:STDOUT:   %c: ref i32 = bind_name c, %c.var
-// CHECK:STDOUT:   %.loc26_20: i32 = int_literal 1 [template = constants.%.3]
-// CHECK:STDOUT:   %.loc26_28: i32 = int_literal 2 [template = constants.%.4]
+// CHECK:STDOUT:   %.loc26_20: i32 = int_literal 1 [template = constants.%.2]
+// CHECK:STDOUT:   %.loc26_28: i32 = int_literal 2 [template = constants.%.3]
 // CHECK:STDOUT:   %.loc26_29.1: {.a: i32, .b: i32} = struct_literal (%.loc26_20, %.loc26_28)
-// CHECK:STDOUT:   %.loc26_31: i32 = int_literal 0 [template = constants.%.6]
-// CHECK:STDOUT:   %.loc26_29.2: {.a: i32, .b: i32} = struct_value (%.loc26_20, %.loc26_28) [template = constants.%.8]
-// CHECK:STDOUT:   %.loc26_29.3: {.a: i32, .b: i32} = converted %.loc26_29.1, %.loc26_29.2 [template = constants.%.8]
+// CHECK:STDOUT:   %.loc26_31: i32 = int_literal 0 [template = constants.%.1]
+// CHECK:STDOUT:   %.loc26_29.2: {.a: i32, .b: i32} = struct_value (%.loc26_20, %.loc26_28) [template = constants.%.6]
+// CHECK:STDOUT:   %.loc26_29.3: {.a: i32, .b: i32} = converted %.loc26_29.1, %.loc26_29.2 [template = constants.%.6]
 // CHECK:STDOUT:   assign %c.var, <error>
 // CHECK:STDOUT:   %d.var: ref i32 = var d
 // CHECK:STDOUT:   %d: ref i32 = bind_name d, %d.var
-// CHECK:STDOUT:   %.loc31_31: type = struct_type {.a: i32, .b: i32} [template]
-// CHECK:STDOUT:   %.loc31_33: i32 = int_literal 0 [template = constants.%.9]
+// CHECK:STDOUT:   %.loc31_31: type = struct_type {.a: i32, .b: i32} [template = constants.%.7]
+// CHECK:STDOUT:   %.loc31_33: i32 = int_literal 0 [template = constants.%.1]
 // CHECK:STDOUT:   assign %d.var, <error>
 // CHECK:STDOUT: }
 // CHECK:STDOUT:

+ 1 - 2
toolchain/check/testdata/index/tuple_return_value_access.carbon

@@ -17,7 +17,6 @@ fn Run() -> i32 {
 // CHECK:STDOUT:   %.2: type = tuple_type (i32) [template]
 // CHECK:STDOUT:   %.3: i32 = int_literal 0 [template]
 // CHECK:STDOUT:   %.4: (i32,) = tuple_value (%.3) [template]
-// CHECK:STDOUT:   %.5: i32 = int_literal 0 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -39,7 +38,7 @@ fn Run() -> i32 {
 // CHECK:STDOUT: !entry:
 // CHECK:STDOUT:   %F.ref: <function> = name_ref F, file.%F [template = file.%F]
 // CHECK:STDOUT:   %.loc10_11.1: init (i32,) = call %F.ref()
-// CHECK:STDOUT:   %.loc10_14: i32 = int_literal 0 [template = constants.%.5]
+// CHECK:STDOUT:   %.loc10_14: i32 = int_literal 0 [template = constants.%.3]
 // CHECK:STDOUT:   %.loc10_11.2: ref (i32,) = temporary_storage
 // CHECK:STDOUT:   %.loc10_11.3: ref (i32,) = temporary %.loc10_11.2, %.loc10_11.1
 // CHECK:STDOUT:   %.loc10_15.1: ref i32 = tuple_index %.loc10_11.3, %.loc10_14

+ 5 - 1
toolchain/check/testdata/interface/fail_duplicate.carbon

@@ -38,6 +38,10 @@ interface Class { }
 
 // CHECK:STDOUT: --- fail_duplicate.carbon
 // CHECK:STDOUT:
+// CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.Interface = %Interface.decl.loc7, .Function = %Function, .Class = %Class.decl} [template]
 // CHECK:STDOUT:   %Interface.decl.loc7 = interface_decl @Interface, ()
@@ -45,7 +49,7 @@ interface Class { }
 // CHECK:STDOUT:   %Function: <function> = fn_decl @Function [template]
 // CHECK:STDOUT:   %.decl.loc27 = interface_decl @.1, ()
 // CHECK:STDOUT:   %Class.decl = class_decl @Class, ()
-// CHECK:STDOUT:   %Class: type = class_type @Class [template]
+// CHECK:STDOUT:   %Class: type = class_type @Class [template = constants.%Class]
 // CHECK:STDOUT:   %.decl.loc37 = interface_decl @.2, ()
 // CHECK:STDOUT: }
 // CHECK:STDOUT:

+ 3 - 4
toolchain/check/testdata/ir/duplicate_name_same_line.carbon

@@ -11,8 +11,7 @@ fn A() { if (true) { var n: i32 = 1; } if (true) { var n: i32 = 2; } }
 // CHECK:STDOUT: constants {
 // CHECK:STDOUT:   %.1: bool = bool_literal true [template]
 // CHECK:STDOUT:   %.2: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.3: bool = bool_literal true [template]
-// CHECK:STDOUT:   %.4: i32 = int_literal 2 [template]
+// CHECK:STDOUT:   %.3: i32 = int_literal 2 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -33,13 +32,13 @@ fn A() { if (true) { var n: i32 = 1; } if (true) { var n: i32 = 2; } }
 // CHECK:STDOUT:   br !if.else.loc7_18
 // CHECK:STDOUT:
 // CHECK:STDOUT: !if.else.loc7_18:
-// CHECK:STDOUT:   %.loc7_44: bool = bool_literal true [template = constants.%.3]
+// CHECK:STDOUT:   %.loc7_44: bool = bool_literal true [template = constants.%.1]
 // CHECK:STDOUT:   if %.loc7_44 br !if.then.loc7_48 else br !if.else.loc7_48
 // CHECK:STDOUT:
 // CHECK:STDOUT: !if.then.loc7_48:
 // CHECK:STDOUT:   %n.var.loc7_56: ref i32 = var n
 // CHECK:STDOUT:   %n.loc7_56: ref i32 = bind_name n, %n.var.loc7_56
-// CHECK:STDOUT:   %.loc7_65: i32 = int_literal 2 [template = constants.%.4]
+// CHECK:STDOUT:   %.loc7_65: i32 = int_literal 2 [template = constants.%.3]
 // CHECK:STDOUT:   assign %n.var.loc7_56, %.loc7_65
 // CHECK:STDOUT:   br !if.else.loc7_48
 // CHECK:STDOUT:

+ 1 - 2
toolchain/check/testdata/let/convert.carbon

@@ -20,7 +20,6 @@ fn F() -> i32 {
 // CHECK:STDOUT:   %.4: i32 = int_literal 1 [template]
 // CHECK:STDOUT:   %.5: i32 = int_literal 2 [template]
 // CHECK:STDOUT:   %.6: i32 = int_literal 3 [template]
-// CHECK:STDOUT:   %.7: i32 = int_literal 1 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -60,7 +59,7 @@ fn F() -> i32 {
 // CHECK:STDOUT:   %.loc10_28.8: (i32, i32, i32) = converted %v.ref, %.loc10_28.7
 // CHECK:STDOUT:   %w: (i32, i32, i32) = bind_name w, %.loc10_28.8
 // CHECK:STDOUT:   %w.ref: (i32, i32, i32) = name_ref w, %w
-// CHECK:STDOUT:   %.loc11_12: i32 = int_literal 1 [template = constants.%.7]
+// CHECK:STDOUT:   %.loc11_12: i32 = int_literal 1 [template = constants.%.4]
 // CHECK:STDOUT:   %.loc11_13: i32 = tuple_index %w.ref, %.loc11_12
 // CHECK:STDOUT:   return %.loc11_13
 // CHECK:STDOUT: }

+ 14 - 21
toolchain/check/testdata/let/fail_modifiers.carbon

@@ -72,32 +72,25 @@ protected protected let i: i32 = 1;
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
 // CHECK:STDOUT:   %.1: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.2: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.3: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.4: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.5: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.6: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.7: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.8: i32 = int_literal 1 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {} [template]
 // CHECK:STDOUT:   %.loc10: i32 = int_literal 1 [template = constants.%.1]
 // CHECK:STDOUT:   %b: i32 = bind_name b, %.loc10 [template = constants.%.1]
-// CHECK:STDOUT:   %.loc15: i32 = int_literal 1 [template = constants.%.2]
-// CHECK:STDOUT:   %c: i32 = bind_name c, %.loc15 [template = constants.%.2]
-// CHECK:STDOUT:   %.loc20: i32 = int_literal 1 [template = constants.%.3]
-// CHECK:STDOUT:   %d: i32 = bind_name d, %.loc20 [template = constants.%.3]
-// CHECK:STDOUT:   %.loc25: i32 = int_literal 1 [template = constants.%.4]
-// CHECK:STDOUT:   %e: i32 = bind_name e, %.loc25 [template = constants.%.4]
-// CHECK:STDOUT:   %.loc36: i32 = int_literal 1 [template = constants.%.5]
-// CHECK:STDOUT:   %f: i32 = bind_name f, %.loc36 [template = constants.%.5]
-// CHECK:STDOUT:   %.loc47: i32 = int_literal 1 [template = constants.%.6]
-// CHECK:STDOUT:   %g: i32 = bind_name g, %.loc47 [template = constants.%.6]
-// CHECK:STDOUT:   %.loc58: i32 = int_literal 1 [template = constants.%.7]
-// CHECK:STDOUT:   %h: i32 = bind_name h, %.loc58 [template = constants.%.7]
-// CHECK:STDOUT:   %.loc69: i32 = int_literal 1 [template = constants.%.8]
-// CHECK:STDOUT:   %i: i32 = bind_name i, %.loc69 [template = constants.%.8]
+// CHECK:STDOUT:   %.loc15: i32 = int_literal 1 [template = constants.%.1]
+// CHECK:STDOUT:   %c: i32 = bind_name c, %.loc15 [template = constants.%.1]
+// CHECK:STDOUT:   %.loc20: i32 = int_literal 1 [template = constants.%.1]
+// CHECK:STDOUT:   %d: i32 = bind_name d, %.loc20 [template = constants.%.1]
+// CHECK:STDOUT:   %.loc25: i32 = int_literal 1 [template = constants.%.1]
+// CHECK:STDOUT:   %e: i32 = bind_name e, %.loc25 [template = constants.%.1]
+// CHECK:STDOUT:   %.loc36: i32 = int_literal 1 [template = constants.%.1]
+// CHECK:STDOUT:   %f: i32 = bind_name f, %.loc36 [template = constants.%.1]
+// CHECK:STDOUT:   %.loc47: i32 = int_literal 1 [template = constants.%.1]
+// CHECK:STDOUT:   %g: i32 = bind_name g, %.loc47 [template = constants.%.1]
+// CHECK:STDOUT:   %.loc58: i32 = int_literal 1 [template = constants.%.1]
+// CHECK:STDOUT:   %h: i32 = bind_name h, %.loc58 [template = constants.%.1]
+// CHECK:STDOUT:   %.loc69: i32 = int_literal 1 [template = constants.%.1]
+// CHECK:STDOUT:   %i: i32 = bind_name i, %.loc69 [template = constants.%.1]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:

+ 5 - 1
toolchain/check/testdata/let/generic.carbon

@@ -12,6 +12,10 @@ fn F() {
 
 // CHECK:STDOUT: --- generic.carbon
 // CHECK:STDOUT:
+// CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %.1: type = ptr_type T [template]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
 // CHECK:STDOUT: file {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.F = %F} [template]
 // CHECK:STDOUT:   %F: <function> = fn_decl @F [template]
@@ -21,7 +25,7 @@ fn F() {
 // CHECK:STDOUT: !entry:
 // CHECK:STDOUT:   %T: type = bind_symbolic_name T, i32 [symbolic]
 // CHECK:STDOUT:   %T.ref.loc9: type = name_ref T, %T [symbolic = %T]
-// CHECK:STDOUT:   %.loc9: type = ptr_type T [template]
+// CHECK:STDOUT:   %.loc9: type = ptr_type T [template = constants.%.1]
 // CHECK:STDOUT:   %p.var: ref T* = var p
 // CHECK:STDOUT:   %p: ref T* = bind_name p, %p.var
 // CHECK:STDOUT:   %T.ref.loc10: type = name_ref T, %T [symbolic = %T]

+ 1 - 2
toolchain/check/testdata/namespace/shadow.carbon

@@ -29,7 +29,6 @@ fn N.M.B() -> i32 {
 // CHECK:STDOUT:   %.1: type = tuple_type () [template]
 // CHECK:STDOUT:   %.2: bool = bool_literal true [template]
 // CHECK:STDOUT:   %.3: i32 = int_literal 0 [template]
-// CHECK:STDOUT:   %.4: i32 = int_literal 0 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -62,7 +61,7 @@ fn N.M.B() -> i32 {
 // CHECK:STDOUT:   return %.loc21
 // CHECK:STDOUT:
 // CHECK:STDOUT: !if.else:
-// CHECK:STDOUT:   %.loc23: i32 = int_literal 0 [template = constants.%.4]
+// CHECK:STDOUT:   %.loc23: i32 = int_literal 0 [template = constants.%.3]
 // CHECK:STDOUT:   return %.loc23
 // CHECK:STDOUT: }
 // CHECK:STDOUT:

+ 3 - 4
toolchain/check/testdata/operators/and.carbon

@@ -15,8 +15,7 @@ fn And() -> bool {
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
 // CHECK:STDOUT:   %.1: bool = bool_literal true [template]
-// CHECK:STDOUT:   %.2: bool = bool_literal true [template]
-// CHECK:STDOUT:   %.3: bool = bool_literal false [template]
+// CHECK:STDOUT:   %.2: bool = bool_literal false [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -34,7 +33,7 @@ fn And() -> bool {
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @G() -> bool {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %.loc8: bool = bool_literal true [template = constants.%.2]
+// CHECK:STDOUT:   %.loc8: bool = bool_literal true [template = constants.%.1]
 // CHECK:STDOUT:   return %.loc8
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
@@ -44,7 +43,7 @@ fn And() -> bool {
 // CHECK:STDOUT:   %.loc11_11.1: init bool = call %F.ref()
 // CHECK:STDOUT:   %.loc11_14.1: bool = value_of_initializer %.loc11_11.1
 // CHECK:STDOUT:   %.loc11_11.2: bool = converted %.loc11_11.1, %.loc11_14.1
-// CHECK:STDOUT:   %.loc11_14.2: bool = bool_literal false [template = constants.%.3]
+// CHECK:STDOUT:   %.loc11_14.2: bool = bool_literal false [template = constants.%.2]
 // CHECK:STDOUT:   if %.loc11_11.2 br !and.rhs else br !and.result(%.loc11_14.2)
 // CHECK:STDOUT:
 // CHECK:STDOUT: !and.rhs:

+ 17 - 20
toolchain/check/testdata/operators/assignment.carbon

@@ -34,16 +34,13 @@ fn Main() {
 // CHECK:STDOUT:   %.7: i32 = int_literal 2 [template]
 // CHECK:STDOUT:   %.8: i32 = int_literal 0 [template]
 // CHECK:STDOUT:   %.9: i32 = int_literal 3 [template]
-// CHECK:STDOUT:   %.10: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.11: i32 = int_literal 4 [template]
+// CHECK:STDOUT:   %.10: i32 = int_literal 4 [template]
+// CHECK:STDOUT:   %.11: type = struct_type {.a: i32, .b: i32} [template]
 // CHECK:STDOUT:   %.12: type = ptr_type {.a: i32, .b: i32} [template]
-// CHECK:STDOUT:   %.13: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.14: i32 = int_literal 2 [template]
-// CHECK:STDOUT:   %.15: i32 = int_literal 3 [template]
-// CHECK:STDOUT:   %.16: i32 = int_literal 4 [template]
-// CHECK:STDOUT:   %.17: i32 = int_literal 5 [template]
-// CHECK:STDOUT:   %.18: bool = bool_literal true [template]
-// CHECK:STDOUT:   %.19: i32 = int_literal 10 [template]
+// CHECK:STDOUT:   %.13: type = ptr_type i32 [template]
+// CHECK:STDOUT:   %.14: i32 = int_literal 5 [template]
+// CHECK:STDOUT:   %.15: bool = bool_literal true [template]
+// CHECK:STDOUT:   %.16: i32 = int_literal 10 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -80,15 +77,15 @@ fn Main() {
 // CHECK:STDOUT:   %.loc12_10: i32 = int_literal 3 [template = constants.%.9]
 // CHECK:STDOUT:   assign %.loc12_6, %.loc12_10
 // CHECK:STDOUT:   %b.ref.loc13: ref (i32, i32) = name_ref b, %b
-// CHECK:STDOUT:   %.loc13_5: i32 = int_literal 1 [template = constants.%.10]
+// CHECK:STDOUT:   %.loc13_5: i32 = int_literal 1 [template = constants.%.6]
 // CHECK:STDOUT:   %.loc13_6: ref i32 = tuple_index %b.ref.loc13, %.loc13_5
-// CHECK:STDOUT:   %.loc13_10: i32 = int_literal 4 [template = constants.%.11]
+// CHECK:STDOUT:   %.loc13_10: i32 = int_literal 4 [template = constants.%.10]
 // CHECK:STDOUT:   assign %.loc13_6, %.loc13_10
-// CHECK:STDOUT:   %.loc15_27: type = struct_type {.a: i32, .b: i32} [template]
+// CHECK:STDOUT:   %.loc15_27: type = struct_type {.a: i32, .b: i32} [template = constants.%.11]
 // CHECK:STDOUT:   %c.var: ref {.a: i32, .b: i32} = var c
 // CHECK:STDOUT:   %c: ref {.a: i32, .b: i32} = bind_name c, %c.var
-// CHECK:STDOUT:   %.loc15_37: i32 = int_literal 1 [template = constants.%.13]
-// CHECK:STDOUT:   %.loc15_45: i32 = int_literal 2 [template = constants.%.14]
+// CHECK:STDOUT:   %.loc15_37: i32 = int_literal 1 [template = constants.%.6]
+// CHECK:STDOUT:   %.loc15_45: i32 = int_literal 2 [template = constants.%.7]
 // CHECK:STDOUT:   %.loc15_46.1: {.a: i32, .b: i32} = struct_literal (%.loc15_37, %.loc15_45)
 // CHECK:STDOUT:   %.loc15_46.2: ref i32 = struct_access %c.var, element0
 // CHECK:STDOUT:   %.loc15_46.3: init i32 = initialize_from %.loc15_37 to %.loc15_46.2
@@ -99,13 +96,13 @@ fn Main() {
 // CHECK:STDOUT:   assign %c.var, %.loc15_46.7
 // CHECK:STDOUT:   %c.ref.loc16: ref {.a: i32, .b: i32} = name_ref c, %c
 // CHECK:STDOUT:   %.loc16_4: ref i32 = struct_access %c.ref.loc16, element0
-// CHECK:STDOUT:   %.loc16_9: i32 = int_literal 3 [template = constants.%.15]
+// CHECK:STDOUT:   %.loc16_9: i32 = int_literal 3 [template = constants.%.9]
 // CHECK:STDOUT:   assign %.loc16_4, %.loc16_9
 // CHECK:STDOUT:   %c.ref.loc17: ref {.a: i32, .b: i32} = name_ref c, %c
 // CHECK:STDOUT:   %.loc17_4: ref i32 = struct_access %c.ref.loc17, element1
-// CHECK:STDOUT:   %.loc17_9: i32 = int_literal 4 [template = constants.%.16]
+// CHECK:STDOUT:   %.loc17_9: i32 = int_literal 4 [template = constants.%.10]
 // CHECK:STDOUT:   assign %.loc17_4, %.loc17_9
-// CHECK:STDOUT:   %.loc19_13: type = ptr_type i32 [template]
+// CHECK:STDOUT:   %.loc19_13: type = ptr_type i32 [template = constants.%.13]
 // CHECK:STDOUT:   %p.var: ref i32* = var p
 // CHECK:STDOUT:   %p: ref i32* = bind_name p, %p.var
 // CHECK:STDOUT:   %a.ref.loc19: ref i32 = name_ref a, %a
@@ -114,9 +111,9 @@ fn Main() {
 // CHECK:STDOUT:   %p.ref.loc20: ref i32* = name_ref p, %p
 // CHECK:STDOUT:   %.loc20_4: i32* = bind_value %p.ref.loc20
 // CHECK:STDOUT:   %.loc20_3: ref i32 = deref %.loc20_4
-// CHECK:STDOUT:   %.loc20_8: i32 = int_literal 5 [template = constants.%.17]
+// CHECK:STDOUT:   %.loc20_8: i32 = int_literal 5 [template = constants.%.14]
 // CHECK:STDOUT:   assign %.loc20_3, %.loc20_8
-// CHECK:STDOUT:   %.loc22_8: bool = bool_literal true [template = constants.%.18]
+// CHECK:STDOUT:   %.loc22_8: bool = bool_literal true [template = constants.%.15]
 // CHECK:STDOUT:   if %.loc22_8 br !if.expr.then else br !if.expr.else
 // CHECK:STDOUT:
 // CHECK:STDOUT: !if.expr.then:
@@ -132,7 +129,7 @@ fn Main() {
 // CHECK:STDOUT: !if.expr.result:
 // CHECK:STDOUT:   %.loc22_5: i32* = block_arg !if.expr.result
 // CHECK:STDOUT:   %.loc22_3: ref i32 = deref %.loc22_5
-// CHECK:STDOUT:   %.loc22_31: i32 = int_literal 10 [template = constants.%.19]
+// CHECK:STDOUT:   %.loc22_31: i32 = int_literal 10 [template = constants.%.16]
 // CHECK:STDOUT:   assign %.loc22_3, %.loc22_31
 // CHECK:STDOUT:   return
 // CHECK:STDOUT: }

+ 1 - 2
toolchain/check/testdata/operators/fail_assignment_to_error.carbon

@@ -19,7 +19,6 @@ fn Main() {
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
 // CHECK:STDOUT:   %.1: i32 = int_literal 42 [template]
-// CHECK:STDOUT:   %.2: i32 = int_literal 42 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -34,7 +33,7 @@ fn Main() {
 // CHECK:STDOUT:   assign %undeclared.ref, <error>
 // CHECK:STDOUT:   %also_undeclared.ref: <error> = name_ref also_undeclared, <error>
 // CHECK:STDOUT:   %.loc15_3: ref <error> = deref <error>
-// CHECK:STDOUT:   %.loc15_22: i32 = int_literal 42 [template = constants.%.2]
+// CHECK:STDOUT:   %.loc15_22: i32 = int_literal 42 [template = constants.%.1]
 // CHECK:STDOUT:   assign %.loc15_3, <error>
 // CHECK:STDOUT:   return
 // CHECK:STDOUT: }

+ 35 - 47
toolchain/check/testdata/operators/fail_assignment_to_non_assignable.carbon

@@ -50,30 +50,18 @@ fn Main() {
 // CHECK:STDOUT: constants {
 // CHECK:STDOUT:   %.1: i32 = int_literal 1 [template]
 // CHECK:STDOUT:   %.2: i32 = int_literal 2 [template]
-// CHECK:STDOUT:   %.3: i32 = int_literal 1 [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: i32 = int_literal 3 [template]
-// CHECK:STDOUT:   %.8: i32 = int_literal 4 [template]
-// CHECK:STDOUT:   %.9: type = ptr_type (i32, i32) [template]
-// CHECK:STDOUT:   %.10: (i32, i32) = tuple_value (%.4, %.5) [template]
-// CHECK:STDOUT:   %.11: i32 = int_literal 0 [template]
-// CHECK:STDOUT:   %.12: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.13: i32 = int_literal 2 [template]
-// CHECK:STDOUT:   %.14: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.15: i32 = int_literal 2 [template]
-// CHECK:STDOUT:   %.16: type = struct_type {.x: i32, .y: i32} [template]
-// CHECK:STDOUT:   %.17: i32 = int_literal 3 [template]
-// CHECK:STDOUT:   %.18: i32 = int_literal 4 [template]
-// CHECK:STDOUT:   %.19: type = ptr_type {.x: i32, .y: i32} [template]
-// CHECK:STDOUT:   %.20: {.x: i32, .y: i32} = struct_value (%.14, %.15) [template]
-// CHECK:STDOUT:   %.21: bool = bool_literal true [template]
-// CHECK:STDOUT:   %.22: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.23: i32 = int_literal 2 [template]
-// CHECK:STDOUT:   %.24: i32 = int_literal 3 [template]
-// CHECK:STDOUT:   %.25: bool = bool_literal true [template]
-// CHECK:STDOUT:   %.26: i32 = int_literal 10 [template]
+// CHECK:STDOUT:   %.3: type = tuple_type (i32, i32) [template]
+// CHECK:STDOUT:   %.4: i32 = int_literal 3 [template]
+// CHECK:STDOUT:   %.5: i32 = int_literal 4 [template]
+// CHECK:STDOUT:   %.6: type = ptr_type (i32, i32) [template]
+// CHECK:STDOUT:   %.7: (i32, i32) = tuple_value (%.1, %.2) [template]
+// CHECK:STDOUT:   %.8: i32 = int_literal 0 [template]
+// CHECK:STDOUT:   %.9: type = ptr_type i32 [template]
+// CHECK:STDOUT:   %.10: type = struct_type {.x: i32, .y: i32} [template]
+// CHECK:STDOUT:   %.11: type = ptr_type {.x: i32, .y: i32} [template]
+// CHECK:STDOUT:   %.12: {.x: i32, .y: i32} = struct_value (%.1, %.2) [template]
+// CHECK:STDOUT:   %.13: bool = bool_literal true [template]
+// CHECK:STDOUT:   %.14: i32 = int_literal 10 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -91,13 +79,13 @@ fn Main() {
 // CHECK:STDOUT:   assign %.loc13_3, %.loc13_7
 // CHECK:STDOUT:   %F.ref: <function> = name_ref F, file.%F [template = file.%F]
 // CHECK:STDOUT:   %.loc17_4: init i32 = call %F.ref()
-// CHECK:STDOUT:   %.loc17_9: i32 = int_literal 1 [template = constants.%.3]
+// CHECK:STDOUT:   %.loc17_9: i32 = int_literal 1 [template = constants.%.1]
 // CHECK:STDOUT:   assign %.loc17_4, %.loc17_9
-// CHECK:STDOUT:   %.loc21_4: i32 = int_literal 1 [template = constants.%.4]
-// CHECK:STDOUT:   %.loc21_7: i32 = int_literal 2 [template = constants.%.5]
+// CHECK:STDOUT:   %.loc21_4: i32 = int_literal 1 [template = constants.%.1]
+// CHECK:STDOUT:   %.loc21_7: i32 = int_literal 2 [template = constants.%.2]
 // CHECK:STDOUT:   %.loc21_8.1: (i32, i32) = tuple_literal (%.loc21_4, %.loc21_7)
-// CHECK:STDOUT:   %.loc21_13: i32 = int_literal 3 [template = constants.%.7]
-// CHECK:STDOUT:   %.loc21_16: i32 = int_literal 4 [template = constants.%.8]
+// CHECK:STDOUT:   %.loc21_13: i32 = int_literal 3 [template = constants.%.4]
+// CHECK:STDOUT:   %.loc21_16: i32 = int_literal 4 [template = constants.%.5]
 // CHECK:STDOUT:   %.loc21_17.1: (i32, i32) = tuple_literal (%.loc21_13, %.loc21_16)
 // CHECK:STDOUT:   %.loc21_17.2: i32 = tuple_access %.loc21_8.1, element0
 // CHECK:STDOUT:   %.loc21_17.3: init i32 = initialize_from %.loc21_13 to %.loc21_17.2
@@ -106,17 +94,17 @@ fn Main() {
 // CHECK:STDOUT:   %.loc21_17.6: init (i32, i32) = tuple_init (%.loc21_17.3, %.loc21_17.5) to %.loc21_8.1
 // CHECK:STDOUT:   %.loc21_17.7: init (i32, i32) = converted %.loc21_17.1, %.loc21_17.6
 // CHECK:STDOUT:   assign %.loc21_8.1, %.loc21_17.7
-// CHECK:STDOUT:   %.loc21_8.2: (i32, i32) = tuple_value (%.loc21_4, %.loc21_7) [template = constants.%.10]
-// CHECK:STDOUT:   %.loc21_8.3: (i32, i32) = converted %.loc21_8.1, %.loc21_8.2 [template = constants.%.10]
+// CHECK:STDOUT:   %.loc21_8.2: (i32, i32) = tuple_value (%.loc21_4, %.loc21_7) [template = constants.%.7]
+// CHECK:STDOUT:   %.loc21_8.3: (i32, i32) = converted %.loc21_8.1, %.loc21_8.2 [template = constants.%.7]
 // CHECK:STDOUT:   %n.var: ref i32 = var n
 // CHECK:STDOUT:   %n: ref i32 = bind_name n, %n.var
-// CHECK:STDOUT:   %.loc22: i32 = int_literal 0 [template = constants.%.11]
+// CHECK:STDOUT:   %.loc22: i32 = int_literal 0 [template = constants.%.8]
 // CHECK:STDOUT:   assign %n.var, %.loc22
 // CHECK:STDOUT:   %n.ref.loc26_4: ref i32 = name_ref n, %n
 // CHECK:STDOUT:   %n.ref.loc26_7: ref i32 = name_ref n, %n
 // CHECK:STDOUT:   %.loc26_8.1: (i32, i32) = tuple_literal (%n.ref.loc26_4, %n.ref.loc26_7)
-// CHECK:STDOUT:   %.loc26_13: i32 = int_literal 1 [template = constants.%.12]
-// CHECK:STDOUT:   %.loc26_16: i32 = int_literal 2 [template = constants.%.13]
+// CHECK:STDOUT:   %.loc26_13: i32 = int_literal 1 [template = constants.%.1]
+// CHECK:STDOUT:   %.loc26_16: i32 = int_literal 2 [template = constants.%.2]
 // CHECK:STDOUT:   %.loc26_17.1: (i32, i32) = tuple_literal (%.loc26_13, %.loc26_16)
 // CHECK:STDOUT:   %.loc26_17.2: i32 = tuple_access %.loc26_8.1, element0
 // CHECK:STDOUT:   %.loc26_17.3: init i32 = initialize_from %.loc26_13 to %.loc26_17.2
@@ -129,13 +117,13 @@ fn Main() {
 // CHECK:STDOUT:   %.loc26_7: i32 = bind_value %n.ref.loc26_7
 // CHECK:STDOUT:   %.loc26_8.2: (i32, i32) = tuple_value (%.loc26_4, %.loc26_7)
 // CHECK:STDOUT:   %.loc26_8.3: (i32, i32) = converted %.loc26_8.1, %.loc26_8.2
-// CHECK:STDOUT:   %.loc30: type = ptr_type i32 [template]
+// CHECK:STDOUT:   %.loc30: type = ptr_type i32 [template = constants.%.9]
 // CHECK:STDOUT:   assign i32, %.loc30
-// CHECK:STDOUT:   %.loc34_9: i32 = int_literal 1 [template = constants.%.14]
-// CHECK:STDOUT:   %.loc34_17: i32 = int_literal 2 [template = constants.%.15]
+// CHECK:STDOUT:   %.loc34_9: i32 = int_literal 1 [template = constants.%.1]
+// CHECK:STDOUT:   %.loc34_17: i32 = int_literal 2 [template = constants.%.2]
 // CHECK:STDOUT:   %.loc34_18.1: {.x: i32, .y: i32} = struct_literal (%.loc34_9, %.loc34_17)
-// CHECK:STDOUT:   %.loc34_28: i32 = int_literal 3 [template = constants.%.17]
-// CHECK:STDOUT:   %.loc34_36: i32 = int_literal 4 [template = constants.%.18]
+// CHECK:STDOUT:   %.loc34_28: i32 = int_literal 3 [template = constants.%.4]
+// CHECK:STDOUT:   %.loc34_36: i32 = int_literal 4 [template = constants.%.5]
 // CHECK:STDOUT:   %.loc34_37.1: {.x: i32, .y: i32} = struct_literal (%.loc34_28, %.loc34_36)
 // CHECK:STDOUT:   %.loc34_37.2: i32 = struct_access %.loc34_18.1, element0
 // CHECK:STDOUT:   %.loc34_37.3: init i32 = initialize_from %.loc34_28 to %.loc34_37.2
@@ -144,26 +132,26 @@ fn Main() {
 // CHECK:STDOUT:   %.loc34_37.6: init {.x: i32, .y: i32} = struct_init (%.loc34_37.3, %.loc34_37.5) to %.loc34_18.1
 // CHECK:STDOUT:   %.loc34_37.7: init {.x: i32, .y: i32} = converted %.loc34_37.1, %.loc34_37.6
 // CHECK:STDOUT:   assign %.loc34_18.1, %.loc34_37.7
-// CHECK:STDOUT:   %.loc34_18.2: {.x: i32, .y: i32} = struct_value (%.loc34_9, %.loc34_17) [template = constants.%.20]
-// CHECK:STDOUT:   %.loc34_18.3: {.x: i32, .y: i32} = converted %.loc34_18.1, %.loc34_18.2 [template = constants.%.20]
-// CHECK:STDOUT:   %.loc38_7: bool = bool_literal true [template = constants.%.21]
+// CHECK:STDOUT:   %.loc34_18.2: {.x: i32, .y: i32} = struct_value (%.loc34_9, %.loc34_17) [template = constants.%.12]
+// CHECK:STDOUT:   %.loc34_18.3: {.x: i32, .y: i32} = converted %.loc34_18.1, %.loc34_18.2 [template = constants.%.12]
+// CHECK:STDOUT:   %.loc38_7: bool = bool_literal true [template = constants.%.13]
 // CHECK:STDOUT:   if %.loc38_7 br !if.expr.then.loc38 else br !if.expr.else.loc38
 // CHECK:STDOUT:
 // CHECK:STDOUT: !if.expr.then.loc38:
-// CHECK:STDOUT:   %.loc38_17: i32 = int_literal 1 [template = constants.%.22]
+// CHECK:STDOUT:   %.loc38_17: i32 = int_literal 1 [template = constants.%.1]
 // CHECK:STDOUT:   br !if.expr.result.loc38(%.loc38_17)
 // CHECK:STDOUT:
 // CHECK:STDOUT: !if.expr.else.loc38:
-// CHECK:STDOUT:   %.loc38_24: i32 = int_literal 2 [template = constants.%.23]
+// CHECK:STDOUT:   %.loc38_24: i32 = int_literal 2 [template = constants.%.2]
 // CHECK:STDOUT:   br !if.expr.result.loc38(%.loc38_24)
 // CHECK:STDOUT:
 // CHECK:STDOUT: !if.expr.result.loc38:
 // CHECK:STDOUT:   %.loc38_4: i32 = block_arg !if.expr.result.loc38
-// CHECK:STDOUT:   %.loc38_29: i32 = int_literal 3 [template = constants.%.24]
+// CHECK:STDOUT:   %.loc38_29: i32 = int_literal 3 [template = constants.%.4]
 // CHECK:STDOUT:   assign %.loc38_4, %.loc38_29
 // CHECK:STDOUT:   %a.var: ref i32 = var a
 // CHECK:STDOUT:   %a: ref i32 = bind_name a, %a.var
-// CHECK:STDOUT:   %.loc45_7: bool = bool_literal true [template = constants.%.25]
+// CHECK:STDOUT:   %.loc45_7: bool = bool_literal true [template = constants.%.13]
 // CHECK:STDOUT:   if %.loc45_7 br !if.expr.then.loc45 else br !if.expr.else.loc45
 // CHECK:STDOUT:
 // CHECK:STDOUT: !if.expr.then.loc45:
@@ -178,7 +166,7 @@ fn Main() {
 // CHECK:STDOUT:
 // CHECK:STDOUT: !if.expr.result.loc45:
 // CHECK:STDOUT:   %.loc45_4: i32 = block_arg !if.expr.result.loc45
-// CHECK:STDOUT:   %.loc45_29: i32 = int_literal 10 [template = constants.%.26]
+// CHECK:STDOUT:   %.loc45_29: i32 = int_literal 10 [template = constants.%.14]
 // CHECK:STDOUT:   assign %.loc45_4, %.loc45_29
 // CHECK:STDOUT:   return
 // CHECK:STDOUT: }

+ 2 - 4
toolchain/check/testdata/operators/or.carbon

@@ -15,8 +15,6 @@ fn Or() -> bool {
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
 // CHECK:STDOUT:   %.1: bool = bool_literal true [template]
-// CHECK:STDOUT:   %.2: bool = bool_literal true [template]
-// CHECK:STDOUT:   %.3: bool = bool_literal true [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -34,7 +32,7 @@ fn Or() -> bool {
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @G() -> bool {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %.loc8: bool = bool_literal true [template = constants.%.2]
+// CHECK:STDOUT:   %.loc8: bool = bool_literal true [template = constants.%.1]
 // CHECK:STDOUT:   return %.loc8
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
@@ -45,7 +43,7 @@ fn Or() -> bool {
 // CHECK:STDOUT:   %.loc11_14.1: bool = value_of_initializer %.loc11_11.1
 // CHECK:STDOUT:   %.loc11_11.2: bool = converted %.loc11_11.1, %.loc11_14.1
 // CHECK:STDOUT:   %.loc11_14.2: bool = not %.loc11_11.2
-// CHECK:STDOUT:   %.loc11_14.3: bool = bool_literal true [template = constants.%.3]
+// CHECK:STDOUT:   %.loc11_14.3: bool = bool_literal true [template = constants.%.1]
 // CHECK:STDOUT:   if %.loc11_14.2 br !or.rhs else br !or.result(%.loc11_14.3)
 // CHECK:STDOUT:
 // CHECK:STDOUT: !or.rhs:

+ 3 - 5
toolchain/check/testdata/operators/unary_op.carbon

@@ -16,8 +16,6 @@ let not_false: bool = not false;
 // CHECK:STDOUT: constants {
 // CHECK:STDOUT:   %.1: bool = bool_literal true [template]
 // CHECK:STDOUT:   %.2: bool = bool_literal false [template]
-// CHECK:STDOUT:   %.3: bool = bool_literal false [template]
-// CHECK:STDOUT:   %.4: bool = bool_literal true [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -26,9 +24,9 @@ let not_false: bool = not false;
 // CHECK:STDOUT:   %.loc11_26: bool = bool_literal true [template = constants.%.1]
 // CHECK:STDOUT:   %.loc11_22: bool = not %.loc11_26 [template = constants.%.2]
 // CHECK:STDOUT:   %not_true: bool = bind_name not_true, %.loc11_22 [template = constants.%.2]
-// CHECK:STDOUT:   %.loc12_27: bool = bool_literal false [template = constants.%.3]
-// CHECK:STDOUT:   %.loc12_23: bool = not %.loc12_27 [template = constants.%.4]
-// CHECK:STDOUT:   %not_false: bool = bind_name not_false, %.loc12_23 [template = constants.%.4]
+// CHECK:STDOUT:   %.loc12_27: bool = bool_literal false [template = constants.%.2]
+// CHECK:STDOUT:   %.loc12_23: bool = not %.loc12_27 [template = constants.%.1]
+// CHECK:STDOUT:   %not_false: bool = bind_name not_false, %.loc12_23 [template = constants.%.1]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @Not(%b: bool) -> bool {

+ 3 - 2
toolchain/check/testdata/package_expr/syntax.carbon

@@ -107,6 +107,7 @@ fn Main() {
 // CHECK:STDOUT: --- namespace.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %C: type = class_type @C [template]
 // CHECK:STDOUT:   %.1: type = struct_type {} [template]
 // CHECK:STDOUT:   %.2: type = tuple_type () [template]
 // CHECK:STDOUT: }
@@ -115,7 +116,7 @@ fn Main() {
 // CHECK:STDOUT:   package: <namespace> = namespace package, {.NS = %.loc4, .Main = %Main} [template]
 // CHECK:STDOUT:   %.loc4: <namespace> = namespace NS, {.C = %C.decl} [template]
 // CHECK:STDOUT:   %C.decl = class_decl @C, ()
-// CHECK:STDOUT:   %C: type = class_type @C [template]
+// CHECK:STDOUT:   %C: type = class_type @C [template = constants.%C]
 // CHECK:STDOUT:   %Main: <function> = fn_decl @Main [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
@@ -135,7 +136,7 @@ fn Main() {
 // CHECK:STDOUT: !entry:
 // CHECK:STDOUT:   %package.ref: <namespace> = name_ref package, package [template = package]
 // CHECK:STDOUT:   %NS.ref: <namespace> = name_ref NS, file.%.loc4 [template = file.%.loc4]
-// CHECK:STDOUT:   %C.ref: type = name_ref C, file.%C [template = file.%C]
+// CHECK:STDOUT:   %C.ref: type = name_ref C, file.%C [template = constants.%C]
 // CHECK:STDOUT:   %Foo.ref: <function> = name_ref Foo, @C.%Foo [template = @C.%Foo]
 // CHECK:STDOUT:   %.loc11: init () = call %Foo.ref()
 // CHECK:STDOUT:   return

+ 21 - 22
toolchain/check/testdata/pointer/address_of_lvalue.carbon

@@ -19,16 +19,15 @@ fn F() {
 // CHECK:STDOUT: --- address_of_lvalue.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %.1: type = ptr_type {.a: i32, .b: i32} [template]
-// CHECK:STDOUT:   %.2: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.3: i32 = int_literal 2 [template]
-// CHECK:STDOUT:   %.4: type = tuple_type (type, type) [template]
-// CHECK:STDOUT:   %.5: type = tuple_type (i32, i32) [template]
-// CHECK:STDOUT:   %.6: type = ptr_type (i32, i32) [template]
-// CHECK:STDOUT:   %.7: i32 = int_literal 1 [template]
-// CHECK:STDOUT:   %.8: i32 = int_literal 2 [template]
+// CHECK:STDOUT:   %.1: type = struct_type {.a: i32, .b: i32} [template]
+// CHECK:STDOUT:   %.2: type = ptr_type {.a: i32, .b: i32} [template]
+// CHECK:STDOUT:   %.3: i32 = int_literal 1 [template]
+// CHECK:STDOUT:   %.4: i32 = int_literal 2 [template]
+// CHECK:STDOUT:   %.5: type = ptr_type i32 [template]
+// CHECK:STDOUT:   %.6: type = tuple_type (type, type) [template]
+// CHECK:STDOUT:   %.7: type = tuple_type (i32, i32) [template]
+// CHECK:STDOUT:   %.8: type = ptr_type (i32, i32) [template]
 // CHECK:STDOUT:   %.9: i32 = int_literal 0 [template]
-// CHECK:STDOUT:   %.10: i32 = int_literal 1 [template]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: file {
@@ -38,11 +37,11 @@ fn F() {
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @F() {
 // CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %.loc8_27: type = struct_type {.a: i32, .b: i32} [template]
+// CHECK:STDOUT:   %.loc8_27: type = struct_type {.a: i32, .b: i32} [template = constants.%.1]
 // CHECK:STDOUT:   %s.var: ref {.a: i32, .b: i32} = var s
 // CHECK:STDOUT:   %s: ref {.a: i32, .b: i32} = bind_name s, %s.var
-// CHECK:STDOUT:   %.loc8_37: i32 = int_literal 1 [template = constants.%.2]
-// CHECK:STDOUT:   %.loc8_45: i32 = int_literal 2 [template = constants.%.3]
+// CHECK:STDOUT:   %.loc8_37: i32 = int_literal 1 [template = constants.%.3]
+// CHECK:STDOUT:   %.loc8_45: i32 = int_literal 2 [template = constants.%.4]
 // CHECK:STDOUT:   %.loc8_46.1: {.a: i32, .b: i32} = struct_literal (%.loc8_37, %.loc8_45)
 // CHECK:STDOUT:   %.loc8_46.2: ref i32 = struct_access %s.var, element0
 // CHECK:STDOUT:   %.loc8_46.3: init i32 = initialize_from %.loc8_37 to %.loc8_46.2
@@ -51,21 +50,21 @@ fn F() {
 // CHECK:STDOUT:   %.loc8_46.6: init {.a: i32, .b: i32} = struct_init (%.loc8_46.3, %.loc8_46.5) to %s.var
 // CHECK:STDOUT:   %.loc8_46.7: init {.a: i32, .b: i32} = converted %.loc8_46.1, %.loc8_46.6
 // CHECK:STDOUT:   assign %s.var, %.loc8_46.7
-// CHECK:STDOUT:   %.loc10_27: type = struct_type {.a: i32, .b: i32} [template]
-// CHECK:STDOUT:   %.loc10_28: type = ptr_type {.a: i32, .b: i32} [template]
+// CHECK:STDOUT:   %.loc10_27: type = struct_type {.a: i32, .b: i32} [template = constants.%.1]
+// CHECK:STDOUT:   %.loc10_28: type = ptr_type {.a: i32, .b: i32} [template = constants.%.2]
 // CHECK:STDOUT:   %p.var: ref {.a: i32, .b: i32}* = var p
 // CHECK:STDOUT:   %p: ref {.a: i32, .b: i32}* = bind_name p, %p.var
 // CHECK:STDOUT:   %s.ref.loc10: ref {.a: i32, .b: i32} = name_ref s, %s
 // CHECK:STDOUT:   %.loc10_32: {.a: i32, .b: i32}* = addr_of %s.ref.loc10
 // CHECK:STDOUT:   assign %p.var, %.loc10_32
-// CHECK:STDOUT:   %.loc11_13: type = ptr_type i32 [template]
+// CHECK:STDOUT:   %.loc11_13: type = ptr_type i32 [template = constants.%.5]
 // CHECK:STDOUT:   %q.var: ref i32* = var q
 // CHECK:STDOUT:   %q: ref i32* = bind_name q, %q.var
 // CHECK:STDOUT:   %s.ref.loc11: ref {.a: i32, .b: i32} = name_ref s, %s
 // CHECK:STDOUT:   %.loc11_19: ref i32 = struct_access %s.ref.loc11, element0
 // CHECK:STDOUT:   %.loc11_17: i32* = addr_of %.loc11_19
 // CHECK:STDOUT:   assign %q.var, %.loc11_17
-// CHECK:STDOUT:   %.loc12_13: type = ptr_type i32 [template]
+// CHECK:STDOUT:   %.loc12_13: type = ptr_type i32 [template = constants.%.5]
 // CHECK:STDOUT:   %r.var: ref i32* = var r
 // CHECK:STDOUT:   %r: ref i32* = bind_name r, %r.var
 // CHECK:STDOUT:   %s.ref.loc12: ref {.a: i32, .b: i32} = name_ref s, %s
@@ -73,11 +72,11 @@ fn F() {
 // CHECK:STDOUT:   %.loc12_17: i32* = addr_of %.loc12_19
 // CHECK:STDOUT:   assign %r.var, %.loc12_17
 // CHECK:STDOUT:   %.loc14_19.1: (type, type) = tuple_literal (i32, i32)
-// CHECK:STDOUT:   %.loc14_19.2: type = converted %.loc14_19.1, constants.%.5 [template = constants.%.5]
+// CHECK:STDOUT:   %.loc14_19.2: type = converted %.loc14_19.1, constants.%.7 [template = constants.%.7]
 // CHECK:STDOUT:   %t.var: ref (i32, i32) = var t
 // CHECK:STDOUT:   %t: ref (i32, i32) = bind_name t, %t.var
-// CHECK:STDOUT:   %.loc14_24: i32 = int_literal 1 [template = constants.%.7]
-// CHECK:STDOUT:   %.loc14_27: i32 = int_literal 2 [template = constants.%.8]
+// CHECK:STDOUT:   %.loc14_24: i32 = int_literal 1 [template = constants.%.3]
+// CHECK:STDOUT:   %.loc14_27: i32 = int_literal 2 [template = constants.%.4]
 // CHECK:STDOUT:   %.loc14_28.1: (i32, i32) = tuple_literal (%.loc14_24, %.loc14_27)
 // CHECK:STDOUT:   %.loc14_28.2: ref i32 = tuple_access %t.var, element0
 // CHECK:STDOUT:   %.loc14_28.3: init i32 = initialize_from %.loc14_24 to %.loc14_28.2
@@ -86,7 +85,7 @@ fn F() {
 // CHECK:STDOUT:   %.loc14_28.6: init (i32, i32) = tuple_init (%.loc14_28.3, %.loc14_28.5) to %t.var
 // CHECK:STDOUT:   %.loc14_28.7: init (i32, i32) = converted %.loc14_28.1, %.loc14_28.6
 // CHECK:STDOUT:   assign %t.var, %.loc14_28.7
-// CHECK:STDOUT:   %.loc15_14: type = ptr_type i32 [template]
+// CHECK:STDOUT:   %.loc15_14: type = ptr_type i32 [template = constants.%.5]
 // CHECK:STDOUT:   %t0.var: ref i32* = var t0
 // CHECK:STDOUT:   %t0: ref i32* = bind_name t0, %t0.var
 // CHECK:STDOUT:   %t.ref.loc15: ref (i32, i32) = name_ref t, %t
@@ -94,11 +93,11 @@ fn F() {
 // CHECK:STDOUT:   %.loc15_22: ref i32 = tuple_index %t.ref.loc15, %.loc15_21
 // CHECK:STDOUT:   %.loc15_18: i32* = addr_of %.loc15_22
 // CHECK:STDOUT:   assign %t0.var, %.loc15_18
-// CHECK:STDOUT:   %.loc16_14: type = ptr_type i32 [template]
+// CHECK:STDOUT:   %.loc16_14: type = ptr_type i32 [template = constants.%.5]
 // CHECK:STDOUT:   %t1.var: ref i32* = var t1
 // CHECK:STDOUT:   %t1: ref i32* = bind_name t1, %t1.var
 // CHECK:STDOUT:   %t.ref.loc16: ref (i32, i32) = name_ref t, %t
-// CHECK:STDOUT:   %.loc16_21: i32 = int_literal 1 [template = constants.%.10]
+// CHECK:STDOUT:   %.loc16_21: i32 = int_literal 1 [template = constants.%.3]
 // CHECK:STDOUT:   %.loc16_22: ref i32 = tuple_index %t.ref.loc16, %.loc16_21
 // CHECK:STDOUT:   %.loc16_18: i32* = addr_of %.loc16_22
 // CHECK:STDOUT:   assign %t1.var, %.loc16_18

Некоторые файлы не были показаны из-за большого количества измененных файлов