import.carbon 9.3 KB

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