dot_self_index.carbon 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/primitives.carbon
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/where_expr/dot_self_index.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/where_expr/dot_self_index.carbon
  12. interface Empty(W:! type) {
  13. let A:! type;
  14. }
  15. // T has index 0
  16. // .Self has index invalid, not 1
  17. // V has index 1, does not match .Self
  18. //@dump-sem-ir-begin
  19. fn H(T:! type, U: Empty(T) where .A = T*, V:! type) {}
  20. //@dump-sem-ir-end
  21. fn G(U: Empty(i32) where .A = i32*) {
  22. H(i32, U, bool);
  23. }
  24. // CHECK:STDOUT: --- dot_self_index.carbon
  25. // CHECK:STDOUT:
  26. // CHECK:STDOUT: constants {
  27. // CHECK:STDOUT: %pattern_type.98f: type = pattern_type type [concrete]
  28. // CHECK:STDOUT: %Empty.type.d5a: type = generic_interface_type @Empty [concrete]
  29. // CHECK:STDOUT: %Empty.generic: %Empty.type.d5a = struct_value () [concrete]
  30. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  31. // CHECK:STDOUT: %Empty.type.3e5fde.2: type = facet_type <@Empty, @Empty(%T)> [symbolic]
  32. // CHECK:STDOUT: %.Self.c95: %Empty.type.3e5fde.2 = bind_symbolic_name .Self [symbolic]
  33. // CHECK:STDOUT: %Empty.assoc_type.3cf698.2: type = assoc_entity_type @Empty, @Empty(%T) [symbolic]
  34. // CHECK:STDOUT: %assoc0.3715ce.2: %Empty.assoc_type.3cf698.2 = assoc_entity element0, @Empty.%A [symbolic]
  35. // CHECK:STDOUT: %require_complete.22f: <witness> = require_complete_type %Empty.type.3e5fde.2 [symbolic]
  36. // CHECK:STDOUT: %.Self.as_type.a75: type = facet_access_type %.Self.c95 [symbolic]
  37. // CHECK:STDOUT: %Empty.lookup_impl_witness.b1d: <witness> = lookup_impl_witness %.Self.c95, @Empty, @Empty(%T) [symbolic]
  38. // CHECK:STDOUT: %impl.elem0.c6e: type = impl_witness_access %Empty.lookup_impl_witness.b1d, element0 [symbolic]
  39. // CHECK:STDOUT: %ptr.79f: type = ptr_type %T [symbolic]
  40. // CHECK:STDOUT: %Empty_where.type.b73: type = facet_type <@Empty, @Empty(%T) where %impl.elem0.c6e = %ptr.79f> [symbolic]
  41. // CHECK:STDOUT: %pattern_type.668: type = pattern_type %Empty_where.type.b73 [symbolic]
  42. // CHECK:STDOUT: %V: type = bind_symbolic_name V, 1 [symbolic]
  43. // CHECK:STDOUT: %H.type: type = fn_type @H [concrete]
  44. // CHECK:STDOUT: %H: %H.type = struct_value () [concrete]
  45. // CHECK:STDOUT: %require_complete.af8: <witness> = require_complete_type %Empty_where.type.b73 [symbolic]
  46. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  47. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  48. // CHECK:STDOUT: %Empty.type.f0b: type = facet_type <@Empty, @Empty(%i32)> [concrete]
  49. // CHECK:STDOUT: %.Self.e6e: %Empty.type.f0b = bind_symbolic_name .Self [symbolic_self]
  50. // CHECK:STDOUT: %Empty.assoc_type.7c7: type = assoc_entity_type @Empty, @Empty(%i32) [concrete]
  51. // CHECK:STDOUT: %assoc0.758: %Empty.assoc_type.7c7 = assoc_entity element0, @Empty.%A [concrete]
  52. // CHECK:STDOUT: %.Self.as_type.920: type = facet_access_type %.Self.e6e [symbolic_self]
  53. // CHECK:STDOUT: %Empty.lookup_impl_witness.4e3: <witness> = lookup_impl_witness %.Self.e6e, @Empty, @Empty(%i32) [symbolic_self]
  54. // CHECK:STDOUT: %impl.elem0.64a: type = impl_witness_access %Empty.lookup_impl_witness.4e3, element0 [symbolic_self]
  55. // CHECK:STDOUT: %ptr.235: type = ptr_type %i32 [concrete]
  56. // CHECK:STDOUT: %Empty_where.type.fc2: type = facet_type <@Empty, @Empty(%i32) where %impl.elem0.64a = %ptr.235> [concrete]
  57. // CHECK:STDOUT: %pattern_type.012: type = pattern_type %Empty_where.type.fc2 [concrete]
  58. // CHECK:STDOUT: %complete_type.091: <witness> = complete_type_witness %Empty.type.f0b [concrete]
  59. // CHECK:STDOUT: %complete_type.a3f: <witness> = complete_type_witness %Empty_where.type.fc2 [concrete]
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: imports {
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: file {
  66. // CHECK:STDOUT: %H.decl: %H.type = fn_decl @H [concrete = constants.%H] {
  67. // CHECK:STDOUT: %T.patt: %pattern_type.98f = symbolic_binding_pattern T, 0 [concrete]
  68. // CHECK:STDOUT: %U.patt: @H.%pattern_type (%pattern_type.668) = binding_pattern U [concrete]
  69. // CHECK:STDOUT: %U.param_patt: @H.%pattern_type (%pattern_type.668) = value_param_pattern %U.patt, call_param0 [concrete]
  70. // CHECK:STDOUT: %V.patt: %pattern_type.98f = symbolic_binding_pattern V, 1 [concrete]
  71. // CHECK:STDOUT: } {
  72. // CHECK:STDOUT: %T.loc21_6.1: type = bind_symbolic_name T, 0 [symbolic = %T.loc21_6.2 (constants.%T)]
  73. // CHECK:STDOUT: %U.param: @H.%Empty_where.type (%Empty_where.type.b73) = value_param call_param0
  74. // CHECK:STDOUT: %.loc21_28.1: type = splice_block %.loc21_28.2 [symbolic = %Empty_where.type (constants.%Empty_where.type.b73)] {
  75. // CHECK:STDOUT: %Empty.ref: %Empty.type.d5a = name_ref Empty, file.%Empty.decl [concrete = constants.%Empty.generic]
  76. // CHECK:STDOUT: %T.ref.loc21_25: type = name_ref T, %T.loc21_6.1 [symbolic = %T.loc21_6.2 (constants.%T)]
  77. // CHECK:STDOUT: %Empty.type.loc21_26.1: type = facet_type <@Empty, @Empty(constants.%T)> [symbolic = %Empty.type.loc21_26.2 (constants.%Empty.type.3e5fde.2)]
  78. // CHECK:STDOUT: <elided>
  79. // CHECK:STDOUT: %.Self.ref: @H.%Empty.type.loc21_26.2 (%Empty.type.3e5fde.2) = name_ref .Self, %.Self.1 [symbolic = %.Self.2 (constants.%.Self.c95)]
  80. // CHECK:STDOUT: %.loc21_34.1: @H.%Empty.assoc_type (%Empty.assoc_type.3cf698.2) = specific_constant @A.%assoc0, @Empty(constants.%T) [symbolic = %assoc0 (constants.%assoc0.3715ce.2)]
  81. // CHECK:STDOUT: %A.ref: @H.%Empty.assoc_type (%Empty.assoc_type.3cf698.2) = name_ref A, %.loc21_34.1 [symbolic = %assoc0 (constants.%assoc0.3715ce.2)]
  82. // CHECK:STDOUT: %.Self.as_type.loc21_34.1: type = facet_access_type %.Self.ref [symbolic = %.Self.as_type.loc21_34.2 (constants.%.Self.as_type.a75)]
  83. // CHECK:STDOUT: %.loc21_34.2: type = converted %.Self.ref, %.Self.as_type.loc21_34.1 [symbolic = %.Self.as_type.loc21_34.2 (constants.%.Self.as_type.a75)]
  84. // CHECK:STDOUT: %impl.elem0.loc21_34.1: type = impl_witness_access constants.%Empty.lookup_impl_witness.b1d, element0 [symbolic = %impl.elem0.loc21_34.2 (constants.%impl.elem0.c6e)]
  85. // CHECK:STDOUT: %T.ref.loc21_39: type = name_ref T, %T.loc21_6.1 [symbolic = %T.loc21_6.2 (constants.%T)]
  86. // CHECK:STDOUT: %ptr.loc21_40.1: type = ptr_type %T.ref.loc21_39 [symbolic = %ptr.loc21_40.2 (constants.%ptr.79f)]
  87. // CHECK:STDOUT: %.loc21_28.2: type = where_expr %.Self.1 [symbolic = %Empty_where.type (constants.%Empty_where.type.b73)] {
  88. // CHECK:STDOUT: requirement_rewrite %impl.elem0.loc21_34.1, %ptr.loc21_40.1
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT: %U: @H.%Empty_where.type (%Empty_where.type.b73) = bind_name U, %U.param
  92. // CHECK:STDOUT: %V.loc21_43.1: type = bind_symbolic_name V, 1 [symbolic = %V.loc21_43.2 (constants.%V)]
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: generic fn @H(%T.loc21_6.1: type, %V.loc21_43.1: type) {
  97. // CHECK:STDOUT: %T.loc21_6.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc21_6.2 (constants.%T)]
  98. // CHECK:STDOUT: %Empty.type.loc21_26.2: type = facet_type <@Empty, @Empty(%T.loc21_6.2)> [symbolic = %Empty.type.loc21_26.2 (constants.%Empty.type.3e5fde.2)]
  99. // CHECK:STDOUT: <elided>
  100. // CHECK:STDOUT: %require_complete.loc21_34: <witness> = require_complete_type %Empty.type.loc21_26.2 [symbolic = %require_complete.loc21_34 (constants.%require_complete.22f)]
  101. // CHECK:STDOUT: %Empty.assoc_type: type = assoc_entity_type @Empty, @Empty(%T.loc21_6.2) [symbolic = %Empty.assoc_type (constants.%Empty.assoc_type.3cf698.2)]
  102. // CHECK:STDOUT: %assoc0: @H.%Empty.assoc_type (%Empty.assoc_type.3cf698.2) = assoc_entity element0, @Empty.%A [symbolic = %assoc0 (constants.%assoc0.3715ce.2)]
  103. // CHECK:STDOUT: %.Self.as_type.loc21_34.2: type = facet_access_type %.Self.2 [symbolic = %.Self.as_type.loc21_34.2 (constants.%.Self.as_type.a75)]
  104. // CHECK:STDOUT: %Empty.lookup_impl_witness: <witness> = lookup_impl_witness %.Self.2, @Empty, @Empty(%T.loc21_6.2) [symbolic = %Empty.lookup_impl_witness (constants.%Empty.lookup_impl_witness.b1d)]
  105. // CHECK:STDOUT: %impl.elem0.loc21_34.2: type = impl_witness_access %Empty.lookup_impl_witness, element0 [symbolic = %impl.elem0.loc21_34.2 (constants.%impl.elem0.c6e)]
  106. // CHECK:STDOUT: %ptr.loc21_40.2: type = ptr_type %T.loc21_6.2 [symbolic = %ptr.loc21_40.2 (constants.%ptr.79f)]
  107. // CHECK:STDOUT: %Empty_where.type: type = facet_type <@Empty, @Empty(%T.loc21_6.2) where %impl.elem0.loc21_34.2 = %ptr.loc21_40.2> [symbolic = %Empty_where.type (constants.%Empty_where.type.b73)]
  108. // CHECK:STDOUT: %pattern_type: type = pattern_type %Empty_where.type [symbolic = %pattern_type (constants.%pattern_type.668)]
  109. // CHECK:STDOUT: %V.loc21_43.2: type = bind_symbolic_name V, 1 [symbolic = %V.loc21_43.2 (constants.%V)]
  110. // CHECK:STDOUT:
  111. // CHECK:STDOUT: !definition:
  112. // CHECK:STDOUT: %require_complete.loc21_17: <witness> = require_complete_type %Empty_where.type [symbolic = %require_complete.loc21_17 (constants.%require_complete.af8)]
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: fn(%U.param: @H.%Empty_where.type (%Empty_where.type.b73)) {
  115. // CHECK:STDOUT: !entry:
  116. // CHECK:STDOUT: return
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT:
  120. // CHECK:STDOUT: specific @H(constants.%T, constants.%V) {
  121. // CHECK:STDOUT: %T.loc21_6.2 => constants.%T
  122. // CHECK:STDOUT: %Empty.type.loc21_26.2 => constants.%Empty.type.3e5fde.2
  123. // CHECK:STDOUT: %.Self.2 => constants.%.Self.c95
  124. // CHECK:STDOUT: %require_complete.loc21_34 => constants.%require_complete.22f
  125. // CHECK:STDOUT: %Empty.assoc_type => constants.%Empty.assoc_type.3cf698.2
  126. // CHECK:STDOUT: %assoc0 => constants.%assoc0.3715ce.2
  127. // CHECK:STDOUT: %.Self.as_type.loc21_34.2 => constants.%.Self.as_type.a75
  128. // CHECK:STDOUT: %Empty.lookup_impl_witness => constants.%Empty.lookup_impl_witness.b1d
  129. // CHECK:STDOUT: %impl.elem0.loc21_34.2 => constants.%impl.elem0.c6e
  130. // CHECK:STDOUT: %ptr.loc21_40.2 => constants.%ptr.79f
  131. // CHECK:STDOUT: %Empty_where.type => constants.%Empty_where.type.b73
  132. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.668
  133. // CHECK:STDOUT: %V.loc21_43.2 => constants.%V
  134. // CHECK:STDOUT: }
  135. // CHECK:STDOUT:
  136. // CHECK:STDOUT: specific @H(constants.%i32, bool) {
  137. // CHECK:STDOUT: %T.loc21_6.2 => constants.%i32
  138. // CHECK:STDOUT: %Empty.type.loc21_26.2 => constants.%Empty.type.f0b
  139. // CHECK:STDOUT: %.Self.2 => constants.%.Self.e6e
  140. // CHECK:STDOUT: %require_complete.loc21_34 => constants.%complete_type.091
  141. // CHECK:STDOUT: %Empty.assoc_type => constants.%Empty.assoc_type.7c7
  142. // CHECK:STDOUT: %assoc0 => constants.%assoc0.758
  143. // CHECK:STDOUT: %.Self.as_type.loc21_34.2 => constants.%.Self.as_type.920
  144. // CHECK:STDOUT: %Empty.lookup_impl_witness => constants.%Empty.lookup_impl_witness.4e3
  145. // CHECK:STDOUT: %impl.elem0.loc21_34.2 => constants.%impl.elem0.64a
  146. // CHECK:STDOUT: %ptr.loc21_40.2 => constants.%ptr.235
  147. // CHECK:STDOUT: %Empty_where.type => constants.%Empty_where.type.fc2
  148. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.012
  149. // CHECK:STDOUT: %V.loc21_43.2 => bool
  150. // CHECK:STDOUT:
  151. // CHECK:STDOUT: !definition:
  152. // CHECK:STDOUT: %require_complete.loc21_17 => constants.%complete_type.a3f
  153. // CHECK:STDOUT: }
  154. // CHECK:STDOUT: