import.carbon 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. // --- impl.carbon
  7. package Impl api;
  8. interface HasF {
  9. fn F();
  10. }
  11. class C {}
  12. impl C as HasF {
  13. fn F() {}
  14. }
  15. // --- use.carbon
  16. import Impl;
  17. fn G(c: Impl.C) {
  18. c.(Impl.HasF.F)();
  19. }
  20. // CHECK:STDOUT: --- impl.carbon
  21. // CHECK:STDOUT:
  22. // CHECK:STDOUT: constants {
  23. // CHECK:STDOUT: %.1: type = interface_type @HasF [template]
  24. // CHECK:STDOUT: %.2: type = assoc_entity_type @HasF, <function> [template]
  25. // CHECK:STDOUT: %.3: <associated <function> in HasF> = assoc_entity element0, @HasF.%F [template]
  26. // CHECK:STDOUT: %C: type = class_type @C [template]
  27. // CHECK:STDOUT: %.4: type = struct_type {} [template]
  28. // CHECK:STDOUT: %.5: <witness> = interface_witness (@impl.%F) [template]
  29. // CHECK:STDOUT: }
  30. // CHECK:STDOUT:
  31. // CHECK:STDOUT: file {
  32. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  33. // CHECK:STDOUT: .Core = %Core
  34. // CHECK:STDOUT: .HasF = %HasF.decl
  35. // CHECK:STDOUT: .C = %C.decl
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  38. // CHECK:STDOUT: %HasF.decl: type = interface_decl @HasF [template = constants.%.1] {}
  39. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  40. // CHECK:STDOUT: impl_decl @impl {
  41. // CHECK:STDOUT: %C.ref: type = name_ref C, %C.decl [template = constants.%C]
  42. // CHECK:STDOUT: %HasF.ref: type = name_ref HasF, %HasF.decl [template = constants.%.1]
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: interface @HasF {
  47. // CHECK:STDOUT: %Self: HasF = bind_symbolic_name Self [symbolic]
  48. // CHECK:STDOUT: %F: <function> = fn_decl @F.1 [template] {}
  49. // CHECK:STDOUT: %.loc5: <associated <function> in HasF> = assoc_entity element0, %F [template = constants.%.3]
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: !members:
  52. // CHECK:STDOUT: .Self = %Self
  53. // CHECK:STDOUT: .F = %.loc5
  54. // CHECK:STDOUT: witness = (%F)
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: impl @impl: C as HasF {
  58. // CHECK:STDOUT: %F: <function> = fn_decl @F.2 [template] {}
  59. // CHECK:STDOUT: %.1: <witness> = interface_witness (%F) [template = constants.%.5]
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: !members:
  62. // CHECK:STDOUT: .F = %F
  63. // CHECK:STDOUT: witness = %.1
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: class @C {
  67. // CHECK:STDOUT: !members:
  68. // CHECK:STDOUT: .Self = constants.%C
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: fn @F.1();
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: fn @F.2() {
  74. // CHECK:STDOUT: !entry:
  75. // CHECK:STDOUT: return
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: --- use.carbon
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: constants {
  81. // CHECK:STDOUT: %C: type = class_type @C [template]
  82. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  83. // CHECK:STDOUT: %.2: type = interface_type @HasF [template]
  84. // CHECK:STDOUT: %.3: type = tuple_type () [template]
  85. // CHECK:STDOUT: %.4: type = ptr_type {} [template]
  86. // CHECK:STDOUT: %.5: type = assoc_entity_type @HasF, <function> [template]
  87. // CHECK:STDOUT: %.6: <associated <function> in HasF> = assoc_entity element0, file.%import_ref.8 [template]
  88. // CHECK:STDOUT: %.7: <witness> = interface_witness (<unexpected instref inst+32>) [template]
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: file {
  92. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  93. // CHECK:STDOUT: .Impl = %Impl
  94. // CHECK:STDOUT: .Core = %Core
  95. // CHECK:STDOUT: .G = %G
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT: %Impl: <namespace> = namespace [template] {}
  98. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  99. // CHECK:STDOUT: %C.decl: invalid = class_decl @C [template = constants.%C] {}
  100. // CHECK:STDOUT: %import_ref.1 = import_ref ir2, inst+10, unloaded
  101. // CHECK:STDOUT: %HasF.decl: invalid = interface_decl @HasF [template = constants.%.2] {}
  102. // CHECK:STDOUT: %import_ref.2: <associated <function> in HasF> = import_ref ir2, inst+7, loc_20 [template = constants.%.6]
  103. // CHECK:STDOUT: %import_ref.3 = import_ref ir2, inst+4, unloaded
  104. // CHECK:STDOUT: %import_ref.4 = import_ref ir2, inst+5, unloaded
  105. // CHECK:STDOUT: %import_ref.5: <witness> = import_ref ir2, inst+16, loc_22 [template = constants.%.7]
  106. // CHECK:STDOUT: %import_ref.6: type = import_ref ir2, inst+9, loc_10 [template = constants.%C]
  107. // CHECK:STDOUT: %G: <function> = fn_decl @G [template] {
  108. // CHECK:STDOUT: %Impl.ref: <namespace> = name_ref Impl, %Impl [template = %Impl]
  109. // CHECK:STDOUT: %C.ref: type = name_ref C, %import_ref.6 [template = constants.%C]
  110. // CHECK:STDOUT: %c.loc4_6.1: C = param c
  111. // CHECK:STDOUT: @G.%c: C = bind_name c, %c.loc4_6.1
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT: %import_ref.7: type = import_ref ir2, inst+2, loc_18 [template = constants.%.2]
  114. // CHECK:STDOUT: %import_ref.8 = import_ref ir2, inst+5, unloaded
  115. // CHECK:STDOUT: }
  116. // CHECK:STDOUT:
  117. // CHECK:STDOUT: interface @HasF {
  118. // CHECK:STDOUT: !members:
  119. // CHECK:STDOUT: .F = file.%import_ref.2
  120. // CHECK:STDOUT: .Self = file.%import_ref.3
  121. // CHECK:STDOUT: witness = (file.%import_ref.4)
  122. // CHECK:STDOUT: }
  123. // CHECK:STDOUT:
  124. // CHECK:STDOUT: impl @impl: C as HasF;
  125. // CHECK:STDOUT:
  126. // CHECK:STDOUT: class @C {
  127. // CHECK:STDOUT: !members:
  128. // CHECK:STDOUT: .Self = file.%import_ref.1
  129. // CHECK:STDOUT: }
  130. // CHECK:STDOUT:
  131. // CHECK:STDOUT: fn @G(%c: C) {
  132. // CHECK:STDOUT: !entry:
  133. // CHECK:STDOUT: %c.ref: C = name_ref c, %c
  134. // CHECK:STDOUT: %Impl.ref: <namespace> = name_ref Impl, file.%Impl [template = file.%Impl]
  135. // CHECK:STDOUT: %HasF.ref: type = name_ref HasF, file.%import_ref.7 [template = constants.%.2]
  136. // CHECK:STDOUT: %F.ref: <associated <function> in HasF> = name_ref F, file.%import_ref.2 [template = constants.%.6]
  137. // CHECK:STDOUT: %.1: <function> = interface_witness_access file.%import_ref.5, element0 [template = <unexpected instref inst+32>]
  138. // CHECK:STDOUT: %.loc5: init () = call %.1()
  139. // CHECK:STDOUT: return
  140. // CHECK:STDOUT: }
  141. // CHECK:STDOUT:
  142. // CHECK:STDOUT: fn @F();
  143. // CHECK:STDOUT: