import_specific.carbon 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. // AUTOUPDATE
  6. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/function/generic/no_prelude/import_specific.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/generic/no_prelude/import_specific.carbon
  10. // --- library.carbon
  11. library "[[@TEST_NAME]]";
  12. fn F(T:! type) {
  13. }
  14. fn G(T:! type) {
  15. F(T);
  16. }
  17. // --- user.carbon
  18. library "[[@TEST_NAME]]";
  19. import library "library";
  20. class C {}
  21. fn H() {
  22. // TODO: We currently crash when importing G if we don't force F to be imported first.
  23. F(C);
  24. G(C);
  25. }
  26. // CHECK:STDOUT: --- library.carbon
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: constants {
  29. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  30. // CHECK:STDOUT: %T.patt: type = symbolic_binding_pattern T, 0 [symbolic]
  31. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  32. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
  33. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  34. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  35. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  36. // CHECK:STDOUT: %.1: <specific function> = specific_function %F, @F(%T) [symbolic]
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT:
  39. // CHECK:STDOUT: file {
  40. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  41. // CHECK:STDOUT: .F = %F.decl
  42. // CHECK:STDOUT: .G = %G.decl
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  45. // CHECK:STDOUT: %T.patt.loc4_6.1: type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc4_6.2 (constants.%T.patt)]
  46. // CHECK:STDOUT: %T.param_patt: type = value_param_pattern %T.patt.loc4_6.1, runtime_param<invalid> [symbolic = %T.patt.loc4_6.2 (constants.%T.patt)]
  47. // CHECK:STDOUT: } {
  48. // CHECK:STDOUT: %T.param: type = value_param runtime_param<invalid>
  49. // CHECK:STDOUT: %T.loc4_6.1: type = bind_symbolic_name T, 0, %T.param [symbolic = %T.loc4_6.2 (constants.%T)]
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  52. // CHECK:STDOUT: %T.patt.loc7_6.1: type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc7_6.2 (constants.%T.patt)]
  53. // CHECK:STDOUT: %T.param_patt: type = value_param_pattern %T.patt.loc7_6.1, runtime_param<invalid> [symbolic = %T.patt.loc7_6.2 (constants.%T.patt)]
  54. // CHECK:STDOUT: } {
  55. // CHECK:STDOUT: %T.param: type = value_param runtime_param<invalid>
  56. // CHECK:STDOUT: %T.loc7_6.1: type = bind_symbolic_name T, 0, %T.param [symbolic = %T.loc7_6.2 (constants.%T)]
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: generic fn @F(%T.loc4_6.1: type) {
  61. // CHECK:STDOUT: %T.loc4_6.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc4_6.2 (constants.%T)]
  62. // CHECK:STDOUT: %T.patt.loc4_6.2: type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc4_6.2 (constants.%T.patt)]
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: !definition:
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: fn(%T.param_patt: type) {
  67. // CHECK:STDOUT: !entry:
  68. // CHECK:STDOUT: return
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: generic fn @G(%T.loc7_6.1: type) {
  73. // CHECK:STDOUT: %T.loc7_6.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc7_6.2 (constants.%T)]
  74. // CHECK:STDOUT: %T.patt.loc7_6.2: type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc7_6.2 (constants.%T.patt)]
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: !definition:
  77. // CHECK:STDOUT: %.loc8_3.2: <specific function> = specific_function constants.%F, @F(%T.loc7_6.2) [symbolic = %.loc8_3.2 (constants.%.1)]
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: fn(%T.param_patt: type) {
  80. // CHECK:STDOUT: !entry:
  81. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  82. // CHECK:STDOUT: %T.ref: type = name_ref T, %T.loc7_6.1 [symbolic = %T.loc7_6.2 (constants.%T)]
  83. // CHECK:STDOUT: %.loc8_3.1: <specific function> = specific_function %F.ref, @F(constants.%T) [symbolic = %.loc8_3.2 (constants.%.1)]
  84. // CHECK:STDOUT: %F.call: init %empty_tuple.type = call %.loc8_3.1()
  85. // CHECK:STDOUT: return
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: specific @F(constants.%T) {
  90. // CHECK:STDOUT: %T.loc4_6.2 => constants.%T
  91. // CHECK:STDOUT: %T.patt.loc4_6.2 => constants.%T
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: !definition:
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: specific @G(constants.%T) {
  97. // CHECK:STDOUT: %T.loc7_6.2 => constants.%T
  98. // CHECK:STDOUT: %T.patt.loc7_6.2 => constants.%T
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: specific @F(@G.%T.loc7_6.2) {
  102. // CHECK:STDOUT: %T.loc4_6.2 => constants.%T
  103. // CHECK:STDOUT: %T.patt.loc4_6.2 => constants.%T
  104. // CHECK:STDOUT: }
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: --- user.carbon
  107. // CHECK:STDOUT:
  108. // CHECK:STDOUT: constants {
  109. // CHECK:STDOUT: %C: type = class_type @C [template]
  110. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  111. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  112. // CHECK:STDOUT: %H.type: type = fn_type @H [template]
  113. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
  114. // CHECK:STDOUT: %H: %H.type = struct_value () [template]
  115. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  116. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  117. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  118. // CHECK:STDOUT: %T.patt: type = symbolic_binding_pattern T, 0 [symbolic]
  119. // CHECK:STDOUT: %.3: <specific function> = specific_function %F, @F(%C) [template]
  120. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  121. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  122. // CHECK:STDOUT: %.4: <specific function> = specific_function %F, @F(%T) [symbolic]
  123. // CHECK:STDOUT: %.5: <specific function> = specific_function %G, @G(%C) [template]
  124. // CHECK:STDOUT: }
  125. // CHECK:STDOUT:
  126. // CHECK:STDOUT: imports {
  127. // CHECK:STDOUT: %import_ref.1: %F.type = import_ref Main//library, inst+7, loaded [template = constants.%F]
  128. // CHECK:STDOUT: %import_ref.2: %G.type = import_ref Main//library, inst+18, loaded [template = constants.%G]
  129. // CHECK:STDOUT: }
  130. // CHECK:STDOUT:
  131. // CHECK:STDOUT: file {
  132. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  133. // CHECK:STDOUT: .F = imports.%import_ref.1
  134. // CHECK:STDOUT: .G = imports.%import_ref.2
  135. // CHECK:STDOUT: .C = %C.decl
  136. // CHECK:STDOUT: .H = %H.decl
  137. // CHECK:STDOUT: }
  138. // CHECK:STDOUT: %default.import = import <invalid>
  139. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  140. // CHECK:STDOUT: %H.decl: %H.type = fn_decl @H [template = constants.%H] {} {}
  141. // CHECK:STDOUT: }
  142. // CHECK:STDOUT:
  143. // CHECK:STDOUT: class @C {
  144. // CHECK:STDOUT: %.loc6: <witness> = complete_type_witness %.1 [template = constants.%.2]
  145. // CHECK:STDOUT:
  146. // CHECK:STDOUT: !members:
  147. // CHECK:STDOUT: .Self = constants.%C
  148. // CHECK:STDOUT: }
  149. // CHECK:STDOUT:
  150. // CHECK:STDOUT: fn @H() {
  151. // CHECK:STDOUT: !entry:
  152. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, imports.%import_ref.1 [template = constants.%F]
  153. // CHECK:STDOUT: %C.ref.loc10: type = name_ref C, file.%C.decl [template = constants.%C]
  154. // CHECK:STDOUT: %.loc10: <specific function> = specific_function %F.ref, @F(constants.%C) [template = constants.%.3]
  155. // CHECK:STDOUT: %F.call: init %empty_tuple.type = call %.loc10()
  156. // CHECK:STDOUT: %G.ref: %G.type = name_ref G, imports.%import_ref.2 [template = constants.%G]
  157. // CHECK:STDOUT: %C.ref.loc12: type = name_ref C, file.%C.decl [template = constants.%C]
  158. // CHECK:STDOUT: %.loc12: <specific function> = specific_function %G.ref, @G(constants.%C) [template = constants.%.5]
  159. // CHECK:STDOUT: %G.call: init %empty_tuple.type = call %.loc12()
  160. // CHECK:STDOUT: return
  161. // CHECK:STDOUT: }
  162. // CHECK:STDOUT:
  163. // CHECK:STDOUT: generic fn @F(constants.%T: type) {
  164. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic = %T (constants.%T)]
  165. // CHECK:STDOUT: %T.patt: type = symbolic_binding_pattern T, 0 [symbolic = %T.patt (constants.%T.patt)]
  166. // CHECK:STDOUT:
  167. // CHECK:STDOUT: !definition:
  168. // CHECK:STDOUT:
  169. // CHECK:STDOUT: fn(%T.param_patt: type);
  170. // CHECK:STDOUT: }
  171. // CHECK:STDOUT:
  172. // CHECK:STDOUT: generic fn @G(constants.%T: type) {
  173. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic = %T (constants.%T)]
  174. // CHECK:STDOUT: %T.patt: type = symbolic_binding_pattern T, 0 [symbolic = %T.patt (constants.%T.patt)]
  175. // CHECK:STDOUT:
  176. // CHECK:STDOUT: !definition:
  177. // CHECK:STDOUT: %.1: <specific function> = specific_function constants.%F, @F(%T) [symbolic = %.1 (constants.%.4)]
  178. // CHECK:STDOUT:
  179. // CHECK:STDOUT: fn(%T.param_patt: type);
  180. // CHECK:STDOUT: }
  181. // CHECK:STDOUT:
  182. // CHECK:STDOUT: specific @F(constants.%T) {
  183. // CHECK:STDOUT: %T => constants.%T
  184. // CHECK:STDOUT: %T.patt => constants.%T
  185. // CHECK:STDOUT:
  186. // CHECK:STDOUT: !definition:
  187. // CHECK:STDOUT: }
  188. // CHECK:STDOUT:
  189. // CHECK:STDOUT: specific @F(constants.%C) {
  190. // CHECK:STDOUT: %T => constants.%C
  191. // CHECK:STDOUT: %T.patt => constants.%C
  192. // CHECK:STDOUT:
  193. // CHECK:STDOUT: !definition:
  194. // CHECK:STDOUT: }
  195. // CHECK:STDOUT:
  196. // CHECK:STDOUT: specific @G(constants.%T) {
  197. // CHECK:STDOUT: %T => constants.%T
  198. // CHECK:STDOUT: %T.patt => constants.%T
  199. // CHECK:STDOUT: }
  200. // CHECK:STDOUT:
  201. // CHECK:STDOUT: specific @F(@G.%T) {
  202. // CHECK:STDOUT: %T => constants.%T
  203. // CHECK:STDOUT: %T.patt => constants.%T
  204. // CHECK:STDOUT: }
  205. // CHECK:STDOUT:
  206. // CHECK:STDOUT: specific @G(constants.%C) {
  207. // CHECK:STDOUT: %T => constants.%C
  208. // CHECK:STDOUT: %T.patt => constants.%C
  209. // CHECK:STDOUT:
  210. // CHECK:STDOUT: !definition:
  211. // CHECK:STDOUT: %.1 => constants.%.3
  212. // CHECK:STDOUT: }
  213. // CHECK:STDOUT: