generic_import.carbon 9.7 KB

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