import_specific.carbon 8.9 KB

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