import.carbon 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 @HasF, %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: %F.type.2: type = fn_type @F.2 [template]
  37. // CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [template]
  38. // CHECK:STDOUT: %.6: <witness> = interface_witness (%F.2) [template]
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: file {
  42. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  43. // CHECK:STDOUT: .Core = %Core
  44. // CHECK:STDOUT: .HasF = %HasF.decl
  45. // CHECK:STDOUT: .C = %C.decl
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  48. // CHECK:STDOUT: %HasF.decl: type = interface_decl @HasF [template = constants.%.1] {}
  49. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  50. // CHECK:STDOUT: impl_decl @impl {
  51. // CHECK:STDOUT: %C.ref: type = name_ref C, %C.decl [template = constants.%C]
  52. // CHECK:STDOUT: %HasF.ref: type = name_ref HasF, %HasF.decl [template = constants.%.1]
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: interface @HasF {
  57. // CHECK:STDOUT: %Self: %.1 = bind_symbolic_name Self 0 [symbolic = constants.%Self]
  58. // CHECK:STDOUT: %F.decl: %F.type.1 = fn_decl @F.1 [template = constants.%F.1] {}
  59. // CHECK:STDOUT: %.loc5: %.3 = assoc_entity element0, %F.decl [template = constants.%.4]
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: !members:
  62. // CHECK:STDOUT: .Self = %Self
  63. // CHECK:STDOUT: .F = %.loc5
  64. // CHECK:STDOUT: witness = (%F.decl)
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: impl @impl: %C as %.1 {
  68. // CHECK:STDOUT: %F.decl: %F.type.2 = fn_decl @F.2 [template = constants.%F.2] {}
  69. // CHECK:STDOUT: %.1: <witness> = interface_witness (%F.decl) [template = constants.%.6]
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: !members:
  72. // CHECK:STDOUT: .F = %F.decl
  73. // CHECK:STDOUT: witness = %.1
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: class @C {
  77. // CHECK:STDOUT: !members:
  78. // CHECK:STDOUT: .Self = constants.%C
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: fn @F.1()
  82. // CHECK:STDOUT: generic [@HasF.%Self: %.1];
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: fn @F.2() {
  85. // CHECK:STDOUT: !entry:
  86. // CHECK:STDOUT: return
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: --- use.carbon
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: constants {
  92. // CHECK:STDOUT: %C: type = class_type @C [template]
  93. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  94. // CHECK:STDOUT: %.2: type = interface_type @HasF [template]
  95. // CHECK:STDOUT: %Self: %.2 = bind_symbolic_name Self 0 [symbolic]
  96. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  97. // CHECK:STDOUT: %.3: type = tuple_type () [template]
  98. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  99. // CHECK:STDOUT: %.4: type = ptr_type %.1 [template]
  100. // CHECK:STDOUT: %F.type.1: type = fn_type @F.1 [template]
  101. // CHECK:STDOUT: %F.1: %F.type.1 = struct_value () [template]
  102. // CHECK:STDOUT: %.5: type = assoc_entity_type @HasF, %F.type.1 [template]
  103. // CHECK:STDOUT: %.6: %.5 = assoc_entity element0, file.%import_ref.8 [template]
  104. // CHECK:STDOUT: %F.type.2: type = fn_type @F.2 [template]
  105. // CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [template]
  106. // CHECK:STDOUT: %.7: <witness> = interface_witness (%F.2) [template]
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: file {
  110. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  111. // CHECK:STDOUT: .Core = %Core
  112. // CHECK:STDOUT: .Impl = %Impl
  113. // CHECK:STDOUT: .G = %G.decl
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  116. // CHECK:STDOUT: %Impl: <namespace> = namespace [template] {}
  117. // CHECK:STDOUT: %import_ref.1 = import_ref ir8, inst+14, unloaded
  118. // CHECK:STDOUT: %import_ref.2 = import_ref ir8, inst+4, unloaded
  119. // CHECK:STDOUT: %import_ref.3: %.5 = import_ref ir8, inst+11, loaded [template = constants.%.6]
  120. // CHECK:STDOUT: %import_ref.4 = import_ref ir8, inst+6, unloaded
  121. // CHECK:STDOUT: %import_ref.5: <witness> = import_ref ir8, inst+22, loaded [template = constants.%.7]
  122. // CHECK:STDOUT: %import_ref.6: type = import_ref ir8, inst+13, loaded [template = constants.%C]
  123. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  124. // CHECK:STDOUT: %Impl.ref: <namespace> = name_ref Impl, %Impl [template = %Impl]
  125. // CHECK:STDOUT: %C.ref: type = name_ref C, %import_ref.6 [template = constants.%C]
  126. // CHECK:STDOUT: %c.loc4_6.1: %C = param c
  127. // CHECK:STDOUT: @G.%c: %C = bind_name c, %c.loc4_6.1
  128. // CHECK:STDOUT: }
  129. // CHECK:STDOUT: %import_ref.7: type = import_ref ir8, inst+2, loaded [template = constants.%.2]
  130. // CHECK:STDOUT: %import_ref.8 = import_ref ir8, inst+6, unloaded
  131. // CHECK:STDOUT: }
  132. // CHECK:STDOUT:
  133. // CHECK:STDOUT: interface @HasF {
  134. // CHECK:STDOUT: !members:
  135. // CHECK:STDOUT: .Self = file.%import_ref.2
  136. // CHECK:STDOUT: .F = file.%import_ref.3
  137. // CHECK:STDOUT: witness = (file.%import_ref.4)
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT:
  140. // CHECK:STDOUT: impl @impl: %C as %.2;
  141. // CHECK:STDOUT:
  142. // CHECK:STDOUT: class @C {
  143. // CHECK:STDOUT: !members:
  144. // CHECK:STDOUT: .Self = file.%import_ref.1
  145. // CHECK:STDOUT: }
  146. // CHECK:STDOUT:
  147. // CHECK:STDOUT: fn @G(%c: %C) {
  148. // CHECK:STDOUT: !entry:
  149. // CHECK:STDOUT: %c.ref: %C = name_ref c, %c
  150. // CHECK:STDOUT: %Impl.ref: <namespace> = name_ref Impl, file.%Impl [template = file.%Impl]
  151. // CHECK:STDOUT: %HasF.ref: type = name_ref HasF, file.%import_ref.7 [template = constants.%.2]
  152. // CHECK:STDOUT: %F.ref: %.5 = name_ref F, file.%import_ref.3 [template = constants.%.6]
  153. // CHECK:STDOUT: %.1: %F.type.1 = interface_witness_access file.%import_ref.5, element0 [template = constants.%F.2]
  154. // CHECK:STDOUT: %F.call: init %.3 = call %.1()
  155. // CHECK:STDOUT: return
  156. // CHECK:STDOUT: }
  157. // CHECK:STDOUT:
  158. // CHECK:STDOUT: fn @F.1();
  159. // CHECK:STDOUT:
  160. // CHECK:STDOUT: fn @F.2();
  161. // CHECK:STDOUT: