import.carbon 6.7 KB

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