generic_import.carbon 9.9 KB

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