template_dependence.carbon 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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/convert.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/generic/template_dependence.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/generic/template_dependence.carbon
  12. // --- type.carbon
  13. library "[[@TEST_NAME]]";
  14. //@dump-sem-ir-begin
  15. fn F[template T:! type](x: T**) -> T* {
  16. return *x;
  17. }
  18. //@dump-sem-ir-end
  19. // --- mixed.carbon
  20. library "[[@TEST_NAME]]";
  21. //@dump-sem-ir-begin
  22. fn F(template T:! type, U:! type) -> (T, U) {
  23. return F(T, U);
  24. }
  25. //@dump-sem-ir-end
  26. // CHECK:STDOUT: --- type.carbon
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: constants {
  29. // CHECK:STDOUT: %T.d9fe7a.1: type = symbolic_binding T, 0, template [template]
  30. // CHECK:STDOUT: %pattern_type.98f: type = pattern_type type [concrete]
  31. // CHECK:STDOUT: %ptr.4f0b5c.1: type = ptr_type %T.d9fe7a.1 [template]
  32. // CHECK:STDOUT: %ptr.3f2: type = ptr_type %ptr.4f0b5c.1 [template]
  33. // CHECK:STDOUT: %pattern_type.982: type = pattern_type %ptr.3f2 [template]
  34. // CHECK:STDOUT: %pattern_type.a603a0.1: type = pattern_type %ptr.4f0b5c.1 [template]
  35. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  36. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  37. // CHECK:STDOUT: %require_complete.482d3f.1: <witness> = require_complete_type %ptr.4f0b5c.1 [template]
  38. // CHECK:STDOUT: %require_complete.6d1: <witness> = require_complete_type %ptr.3f2 [template]
  39. // CHECK:STDOUT: %Copy.type: type = facet_type <@Copy> [concrete]
  40. // CHECK:STDOUT: %Copy.Op.type: type = fn_type @Copy.Op [concrete]
  41. // CHECK:STDOUT: %Copy.lookup_impl_witness.c66: <witness> = lookup_impl_witness %ptr.4f0b5c.1, @Copy [template]
  42. // CHECK:STDOUT: %Copy.facet: %Copy.type = facet_value %ptr.4f0b5c.1, (%Copy.lookup_impl_witness.c66) [template]
  43. // CHECK:STDOUT: %.89d: type = fn_type_with_self_type %Copy.Op.type, %Copy.facet [template]
  44. // CHECK:STDOUT: %impl.elem0.928: %.89d = impl_witness_access %Copy.lookup_impl_witness.c66, element0 [template]
  45. // CHECK:STDOUT: %specific_impl_fn.6a1: <specific function> = specific_impl_function %impl.elem0.928, @Copy.Op(%Copy.facet) [template]
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT:
  48. // CHECK:STDOUT: imports {
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: file {
  52. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  53. // CHECK:STDOUT: %T.patt: %pattern_type.98f = symbolic_binding_pattern T, 0, template [concrete]
  54. // CHECK:STDOUT: %x.patt: @F.%pattern_type.loc5_25 (%pattern_type.982) = value_binding_pattern x [concrete]
  55. // CHECK:STDOUT: %x.param_patt: @F.%pattern_type.loc5_25 (%pattern_type.982) = value_param_pattern %x.patt, call_param0 [concrete]
  56. // CHECK:STDOUT: %return.patt: @F.%pattern_type.loc5_33 (%pattern_type.a603a0.1) = return_slot_pattern [concrete]
  57. // CHECK:STDOUT: %return.param_patt: @F.%pattern_type.loc5_33 (%pattern_type.a603a0.1) = out_param_pattern %return.patt, call_param1 [concrete]
  58. // CHECK:STDOUT: } {
  59. // CHECK:STDOUT: %T.ref.loc5_36: type = name_ref T, %T.loc5_15.2 [template = %T.loc5_15.1 (constants.%T.d9fe7a.1)]
  60. // CHECK:STDOUT: %ptr.loc5_37: type = ptr_type %T.ref.loc5_36 [template = %ptr.loc5_29.1 (constants.%ptr.4f0b5c.1)]
  61. // CHECK:STDOUT: <elided>
  62. // CHECK:STDOUT: %T.loc5_15.2: type = symbolic_binding T, 0, template [template = %T.loc5_15.1 (constants.%T.d9fe7a.1)]
  63. // CHECK:STDOUT: %x.param: @F.%ptr.loc5_30.1 (%ptr.3f2) = value_param call_param0
  64. // CHECK:STDOUT: %.loc5: type = splice_block %ptr.loc5_30.2 [template = %ptr.loc5_30.1 (constants.%ptr.3f2)] {
  65. // CHECK:STDOUT: %T.ref.loc5_28: type = name_ref T, %T.loc5_15.2 [template = %T.loc5_15.1 (constants.%T.d9fe7a.1)]
  66. // CHECK:STDOUT: %ptr.loc5_29.2: type = ptr_type %T.ref.loc5_28 [template = %ptr.loc5_29.1 (constants.%ptr.4f0b5c.1)]
  67. // CHECK:STDOUT: %ptr.loc5_30.2: type = ptr_type %ptr.loc5_29.2 [template = %ptr.loc5_30.1 (constants.%ptr.3f2)]
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT: %x: @F.%ptr.loc5_30.1 (%ptr.3f2) = value_binding x, %x.param
  70. // CHECK:STDOUT: %return.param: ref @F.%ptr.loc5_29.1 (%ptr.4f0b5c.1) = out_param call_param1
  71. // CHECK:STDOUT: %return: ref @F.%ptr.loc5_29.1 (%ptr.4f0b5c.1) = return_slot %return.param
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: generic fn @F(%T.loc5_15.2: type) {
  76. // CHECK:STDOUT: %T.loc5_15.1: type = symbolic_binding T, 0, template [template = %T.loc5_15.1 (constants.%T.d9fe7a.1)]
  77. // CHECK:STDOUT: %ptr.loc5_29.1: type = ptr_type %T.loc5_15.1 [template = %ptr.loc5_29.1 (constants.%ptr.4f0b5c.1)]
  78. // CHECK:STDOUT: %ptr.loc5_30.1: type = ptr_type %ptr.loc5_29.1 [template = %ptr.loc5_30.1 (constants.%ptr.3f2)]
  79. // CHECK:STDOUT: %pattern_type.loc5_25: type = pattern_type %ptr.loc5_30.1 [template = %pattern_type.loc5_25 (constants.%pattern_type.982)]
  80. // CHECK:STDOUT: %pattern_type.loc5_33: type = pattern_type %ptr.loc5_29.1 [template = %pattern_type.loc5_33 (constants.%pattern_type.a603a0.1)]
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: !definition:
  83. // CHECK:STDOUT: %require_complete.loc5_33: <witness> = require_complete_type %ptr.loc5_29.1 [template = %require_complete.loc5_33 (constants.%require_complete.482d3f.1)]
  84. // CHECK:STDOUT: %require_complete.loc5_26: <witness> = require_complete_type %ptr.loc5_30.1 [template = %require_complete.loc5_26 (constants.%require_complete.6d1)]
  85. // CHECK:STDOUT: %Copy.lookup_impl_witness: <witness> = lookup_impl_witness %ptr.loc5_29.1, @Copy [template = %Copy.lookup_impl_witness (constants.%Copy.lookup_impl_witness.c66)]
  86. // CHECK:STDOUT: %Copy.facet: %Copy.type = facet_value %ptr.loc5_29.1, (%Copy.lookup_impl_witness) [template = %Copy.facet (constants.%Copy.facet)]
  87. // CHECK:STDOUT: %.loc6_10.4: type = fn_type_with_self_type constants.%Copy.Op.type, %Copy.facet [template = %.loc6_10.4 (constants.%.89d)]
  88. // CHECK:STDOUT: %impl.elem0.loc6_10.2: @F.%.loc6_10.4 (%.89d) = impl_witness_access %Copy.lookup_impl_witness, element0 [template = %impl.elem0.loc6_10.2 (constants.%impl.elem0.928)]
  89. // CHECK:STDOUT: %specific_impl_fn.loc6_10.2: <specific function> = specific_impl_function %impl.elem0.loc6_10.2, @Copy.Op(%Copy.facet) [template = %specific_impl_fn.loc6_10.2 (constants.%specific_impl_fn.6a1)]
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: fn(%x.param: @F.%ptr.loc5_30.1 (%ptr.3f2)) -> @F.%ptr.loc5_29.1 (%ptr.4f0b5c.1) {
  92. // CHECK:STDOUT: !entry:
  93. // CHECK:STDOUT: %x.ref: @F.%ptr.loc5_30.1 (%ptr.3f2) = name_ref x, %x
  94. // CHECK:STDOUT: %.loc6_10.1: ref @F.%ptr.loc5_29.1 (%ptr.4f0b5c.1) = deref %x.ref
  95. // CHECK:STDOUT: %.loc6_10.2: @F.%ptr.loc5_29.1 (%ptr.4f0b5c.1) = acquire_value %.loc6_10.1
  96. // CHECK:STDOUT: %impl.elem0.loc6_10.1: @F.%.loc6_10.4 (%.89d) = impl_witness_access constants.%Copy.lookup_impl_witness.c66, element0 [template = %impl.elem0.loc6_10.2 (constants.%impl.elem0.928)]
  97. // CHECK:STDOUT: %bound_method.loc6_10.1: <bound method> = bound_method %.loc6_10.2, %impl.elem0.loc6_10.1
  98. // CHECK:STDOUT: %specific_impl_fn.loc6_10.1: <specific function> = specific_impl_function %impl.elem0.loc6_10.1, @Copy.Op(constants.%Copy.facet) [template = %specific_impl_fn.loc6_10.2 (constants.%specific_impl_fn.6a1)]
  99. // CHECK:STDOUT: %bound_method.loc6_10.2: <bound method> = bound_method %.loc6_10.2, %specific_impl_fn.loc6_10.1
  100. // CHECK:STDOUT: %.loc6_10.3: init @F.%ptr.loc5_29.1 (%ptr.4f0b5c.1) = call %bound_method.loc6_10.2(%.loc6_10.2)
  101. // CHECK:STDOUT: return %.loc6_10.3 to %return
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT:
  105. // CHECK:STDOUT: specific @F(constants.%T.d9fe7a.1) {
  106. // CHECK:STDOUT: %T.loc5_15.1 => constants.%T.d9fe7a.1
  107. // CHECK:STDOUT: %ptr.loc5_29.1 => constants.%ptr.4f0b5c.1
  108. // CHECK:STDOUT: %ptr.loc5_30.1 => constants.%ptr.3f2
  109. // CHECK:STDOUT: %pattern_type.loc5_25 => constants.%pattern_type.982
  110. // CHECK:STDOUT: %pattern_type.loc5_33 => constants.%pattern_type.a603a0.1
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT:
  113. // CHECK:STDOUT: --- mixed.carbon
  114. // CHECK:STDOUT:
  115. // CHECK:STDOUT: constants {
  116. // CHECK:STDOUT: %T: type = symbolic_binding T, 0, template [template]
  117. // CHECK:STDOUT: %pattern_type.98f: type = pattern_type type [concrete]
  118. // CHECK:STDOUT: %U: type = symbolic_binding U, 1 [symbolic]
  119. // CHECK:STDOUT: %tuple.type.24b: type = tuple_type (type, type) [concrete]
  120. // CHECK:STDOUT: %tuple: %tuple.type.24b = tuple_value (%T, %U) [template]
  121. // CHECK:STDOUT: %tuple.type.d18: type = tuple_type (%T, %U) [template]
  122. // CHECK:STDOUT: %pattern_type.b8b: type = pattern_type %tuple.type.d18 [template]
  123. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  124. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  125. // CHECK:STDOUT: %require_complete: <witness> = require_complete_type %tuple.type.d18 [template]
  126. // CHECK:STDOUT: %F.specific_fn: <specific function> = specific_function %F, @F(%T, %U) [template]
  127. // CHECK:STDOUT: }
  128. // CHECK:STDOUT:
  129. // CHECK:STDOUT: imports {
  130. // CHECK:STDOUT: }
  131. // CHECK:STDOUT:
  132. // CHECK:STDOUT: file {
  133. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  134. // CHECK:STDOUT: %T.patt: %pattern_type.98f = symbolic_binding_pattern T, 0, template [concrete]
  135. // CHECK:STDOUT: %U.patt: %pattern_type.98f = symbolic_binding_pattern U, 1 [concrete]
  136. // CHECK:STDOUT: %return.patt: @F.%pattern_type (%pattern_type.b8b) = return_slot_pattern [concrete]
  137. // CHECK:STDOUT: %return.param_patt: @F.%pattern_type (%pattern_type.b8b) = out_param_pattern %return.patt, call_param0 [concrete]
  138. // CHECK:STDOUT: } {
  139. // CHECK:STDOUT: %T.ref.loc5: type = name_ref T, %T.loc5_15.2 [template = %T.loc5_15.1 (constants.%T)]
  140. // CHECK:STDOUT: %U.ref.loc5: type = name_ref U, %U.loc5_25.2 [symbolic = %U.loc5_25.1 (constants.%U)]
  141. // CHECK:STDOUT: %.loc5_43.1: %tuple.type.24b = tuple_literal (%T.ref.loc5, %U.ref.loc5) [template = %tuple (constants.%tuple)]
  142. // CHECK:STDOUT: %.loc5_43.2: type = converted %.loc5_43.1, constants.%tuple.type.d18 [template = %tuple.type (constants.%tuple.type.d18)]
  143. // CHECK:STDOUT: <elided>
  144. // CHECK:STDOUT: %T.loc5_15.2: type = symbolic_binding T, 0, template [template = %T.loc5_15.1 (constants.%T)]
  145. // CHECK:STDOUT: <elided>
  146. // CHECK:STDOUT: %U.loc5_25.2: type = symbolic_binding U, 1 [symbolic = %U.loc5_25.1 (constants.%U)]
  147. // CHECK:STDOUT: %return.param: ref @F.%tuple.type (%tuple.type.d18) = out_param call_param0
  148. // CHECK:STDOUT: %return: ref @F.%tuple.type (%tuple.type.d18) = return_slot %return.param
  149. // CHECK:STDOUT: }
  150. // CHECK:STDOUT: }
  151. // CHECK:STDOUT:
  152. // CHECK:STDOUT: generic fn @F(%T.loc5_15.2: type, %U.loc5_25.2: type) {
  153. // CHECK:STDOUT: %T.loc5_15.1: type = symbolic_binding T, 0, template [template = %T.loc5_15.1 (constants.%T)]
  154. // CHECK:STDOUT: %U.loc5_25.1: type = symbolic_binding U, 1 [symbolic = %U.loc5_25.1 (constants.%U)]
  155. // CHECK:STDOUT: %tuple: %tuple.type.24b = tuple_value (%T.loc5_15.1, %U.loc5_25.1) [template = %tuple (constants.%tuple)]
  156. // CHECK:STDOUT: %tuple.type: type = tuple_type (%T.loc5_15.1, %U.loc5_25.1) [template = %tuple.type (constants.%tuple.type.d18)]
  157. // CHECK:STDOUT: %pattern_type: type = pattern_type %tuple.type [template = %pattern_type (constants.%pattern_type.b8b)]
  158. // CHECK:STDOUT:
  159. // CHECK:STDOUT: !definition:
  160. // CHECK:STDOUT: %require_complete: <witness> = require_complete_type %tuple.type [template = %require_complete (constants.%require_complete)]
  161. // CHECK:STDOUT: %F.specific_fn.loc6_10.2: <specific function> = specific_function constants.%F, @F(%T.loc5_15.1, %U.loc5_25.1) [template = %F.specific_fn.loc6_10.2 (constants.%F.specific_fn)]
  162. // CHECK:STDOUT:
  163. // CHECK:STDOUT: fn() -> %return.param: @F.%tuple.type (%tuple.type.d18) {
  164. // CHECK:STDOUT: !entry:
  165. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [concrete = constants.%F]
  166. // CHECK:STDOUT: %T.ref.loc6: type = name_ref T, %T.loc5_15.2 [template = %T.loc5_15.1 (constants.%T)]
  167. // CHECK:STDOUT: %U.ref.loc6: type = name_ref U, %U.loc5_25.2 [symbolic = %U.loc5_25.1 (constants.%U)]
  168. // CHECK:STDOUT: %F.specific_fn.loc6_10.1: <specific function> = specific_function %F.ref, @F(constants.%T, constants.%U) [template = %F.specific_fn.loc6_10.2 (constants.%F.specific_fn)]
  169. // CHECK:STDOUT: %.loc5_35: ref @F.%tuple.type (%tuple.type.d18) = splice_block %return {}
  170. // CHECK:STDOUT: %F.call: init @F.%tuple.type (%tuple.type.d18) = call %F.specific_fn.loc6_10.1() to %.loc5_35
  171. // CHECK:STDOUT: return %F.call to %return
  172. // CHECK:STDOUT: }
  173. // CHECK:STDOUT: }
  174. // CHECK:STDOUT:
  175. // CHECK:STDOUT: specific @F(constants.%T, constants.%U) {
  176. // CHECK:STDOUT: %T.loc5_15.1 => constants.%T
  177. // CHECK:STDOUT: %U.loc5_25.1 => constants.%U
  178. // CHECK:STDOUT: %tuple => constants.%tuple
  179. // CHECK:STDOUT: %tuple.type => constants.%tuple.type.d18
  180. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.b8b
  181. // CHECK:STDOUT:
  182. // CHECK:STDOUT: !definition:
  183. // CHECK:STDOUT: %require_complete => constants.%require_complete
  184. // CHECK:STDOUT: %F.specific_fn.loc6_10.2 => constants.%F.specific_fn
  185. // CHECK:STDOUT: }
  186. // CHECK:STDOUT: