import_self.carbon 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. // --- a.carbon
  7. library "a" api;
  8. interface Add {
  9. fn Op[self: Self](other: Self) -> Self;
  10. }
  11. // --- b.carbon
  12. library "b" api;
  13. import library "a";
  14. impl () as Add {
  15. fn Op[self: Self](other: Self) -> Self { return (); }
  16. }
  17. fn F(x: (), y: ()) -> () {
  18. return x.(Add.Op)(y);
  19. }
  20. // CHECK:STDOUT: --- a.carbon
  21. // CHECK:STDOUT:
  22. // CHECK:STDOUT: constants {
  23. // CHECK:STDOUT: %.1: type = interface_type @Add [template]
  24. // CHECK:STDOUT: %Self: Add = bind_symbolic_name Self 0 [symbolic]
  25. // CHECK:STDOUT: %Op: type = fn_type @Op [template]
  26. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  27. // CHECK:STDOUT: %struct: Op = struct_value () [template]
  28. // CHECK:STDOUT: %.3: type = assoc_entity_type @Add, Op [template]
  29. // CHECK:STDOUT: %.4: <associated Op in Add> = assoc_entity element0, @Add.%Op.decl [template]
  30. // CHECK:STDOUT: }
  31. // CHECK:STDOUT:
  32. // CHECK:STDOUT: file {
  33. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  34. // CHECK:STDOUT: .Add = %Add.decl
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT: %Add.decl: type = interface_decl @Add [template = constants.%.1] {}
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT:
  39. // CHECK:STDOUT: interface @Add {
  40. // CHECK:STDOUT: %Self: Add = bind_symbolic_name Self 0 [symbolic = constants.%Self]
  41. // CHECK:STDOUT: %Op.decl: Op = fn_decl @Op [template = constants.%struct] {
  42. // CHECK:STDOUT: %Self.ref.loc5_15: Add = name_ref Self, %Self [symbolic = constants.%Self]
  43. // CHECK:STDOUT: %.loc5_15.1: type = facet_type_access %Self.ref.loc5_15 [symbolic = constants.%Self]
  44. // CHECK:STDOUT: %.loc5_15.2: type = converted %Self.ref.loc5_15, %.loc5_15.1 [symbolic = constants.%Self]
  45. // CHECK:STDOUT: %self.loc5_9.1: Self = param self
  46. // CHECK:STDOUT: %self.loc5_9.2: Self = bind_name self, %self.loc5_9.1
  47. // CHECK:STDOUT: %Self.ref.loc5_28: Add = name_ref Self, %Self [symbolic = constants.%Self]
  48. // CHECK:STDOUT: %.loc5_28.1: type = facet_type_access %Self.ref.loc5_28 [symbolic = constants.%Self]
  49. // CHECK:STDOUT: %.loc5_28.2: type = converted %Self.ref.loc5_28, %.loc5_28.1 [symbolic = constants.%Self]
  50. // CHECK:STDOUT: %other.loc5_21.1: Self = param other
  51. // CHECK:STDOUT: %other.loc5_21.2: Self = bind_name other, %other.loc5_21.1
  52. // CHECK:STDOUT: %Self.ref.loc5_37: Add = name_ref Self, %Self [symbolic = constants.%Self]
  53. // CHECK:STDOUT: %.loc5_37.1: type = facet_type_access %Self.ref.loc5_37 [symbolic = constants.%Self]
  54. // CHECK:STDOUT: %.loc5_37.2: type = converted %Self.ref.loc5_37, %.loc5_37.1 [symbolic = constants.%Self]
  55. // CHECK:STDOUT: %return.var: ref Self = var <return slot>
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT: %.loc5_41: <associated Op in Add> = assoc_entity element0, %Op.decl [template = constants.%.4]
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: !members:
  60. // CHECK:STDOUT: .Self = %Self
  61. // CHECK:STDOUT: .Op = %.loc5_41
  62. // CHECK:STDOUT: witness = (%Op.decl)
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: fn @Op[@Add.%self.loc5_9.2: Self](@Add.%other.loc5_21.2: Self) -> Self;
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: --- b.carbon
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: constants {
  70. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  71. // CHECK:STDOUT: %.2: type = interface_type @Add [template]
  72. // CHECK:STDOUT: %Self: Add = bind_symbolic_name Self 0 [symbolic]
  73. // CHECK:STDOUT: %Op.1: type = fn_type @Op.1 [template]
  74. // CHECK:STDOUT: %struct.1: Op = struct_value () [template]
  75. // CHECK:STDOUT: %Op.2: type = fn_type @Op.2 [template]
  76. // CHECK:STDOUT: %struct.2: Op = struct_value () [template]
  77. // CHECK:STDOUT: %.3: <witness> = interface_witness (%struct.1) [template]
  78. // CHECK:STDOUT: %tuple: () = tuple_value () [template]
  79. // CHECK:STDOUT: %F: type = fn_type @F [template]
  80. // CHECK:STDOUT: %struct.3: F = struct_value () [template]
  81. // CHECK:STDOUT: %.4: type = assoc_entity_type @Add, Op [template]
  82. // CHECK:STDOUT: %.5: <associated Op in Add> = assoc_entity element0, file.%import_ref.5 [template]
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: file {
  86. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  87. // CHECK:STDOUT: .Add = %import_ref.1
  88. // CHECK:STDOUT: .F = %F.decl
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT: %import_ref.1: type = import_ref ir1, inst+1, loaded [template = constants.%.2]
  91. // CHECK:STDOUT: %import_ref.2: <associated Op in Add> = import_ref ir1, inst+24, loaded [template = constants.%.5]
  92. // CHECK:STDOUT: %import_ref.3 = import_ref ir1, inst+3, unloaded
  93. // CHECK:STDOUT: %import_ref.4: Op = import_ref ir1, inst+19, loaded [template = constants.%struct.2]
  94. // CHECK:STDOUT: impl_decl @impl {
  95. // CHECK:STDOUT: %.loc6_7.1: () = tuple_literal ()
  96. // CHECK:STDOUT: %.loc6_7.2: type = converted %.loc6_7.1, constants.%.1 [template = constants.%.1]
  97. // CHECK:STDOUT: %Add.ref: type = name_ref Add, %import_ref.1 [template = constants.%.2]
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT: %F.decl: F = fn_decl @F [template = constants.%struct.3] {
  100. // CHECK:STDOUT: %.loc10_10.1: () = tuple_literal ()
  101. // CHECK:STDOUT: %.loc10_10.2: type = converted %.loc10_10.1, constants.%.1 [template = constants.%.1]
  102. // CHECK:STDOUT: %x.loc10_6.1: () = param x
  103. // CHECK:STDOUT: @F.%x: () = bind_name x, %x.loc10_6.1
  104. // CHECK:STDOUT: %.loc10_17.1: () = tuple_literal ()
  105. // CHECK:STDOUT: %.loc10_17.2: type = converted %.loc10_17.1, constants.%.1 [template = constants.%.1]
  106. // CHECK:STDOUT: %y.loc10_13.1: () = param y
  107. // CHECK:STDOUT: @F.%y: () = bind_name y, %y.loc10_13.1
  108. // CHECK:STDOUT: %.loc10_24.1: () = tuple_literal ()
  109. // CHECK:STDOUT: %.loc10_24.2: type = converted %.loc10_24.1, constants.%.1 [template = constants.%.1]
  110. // CHECK:STDOUT: @F.%return: ref () = var <return slot>
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT: %import_ref.5 = import_ref ir1, inst+19, unloaded
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT:
  115. // CHECK:STDOUT: interface @Add {
  116. // CHECK:STDOUT: !members:
  117. // CHECK:STDOUT: .Op = file.%import_ref.2
  118. // CHECK:STDOUT: .Self = file.%import_ref.3
  119. // CHECK:STDOUT: witness = (file.%import_ref.4)
  120. // CHECK:STDOUT: }
  121. // CHECK:STDOUT:
  122. // CHECK:STDOUT: impl @impl: () as Add {
  123. // CHECK:STDOUT: %Op.decl: Op = fn_decl @Op.1 [template = constants.%struct.1] {
  124. // CHECK:STDOUT: %Self.ref.loc7_15: type = name_ref Self, constants.%.1 [template = constants.%.1]
  125. // CHECK:STDOUT: %self.loc7_9.1: () = param self
  126. // CHECK:STDOUT: %self.loc7_9.2: () = bind_name self, %self.loc7_9.1
  127. // CHECK:STDOUT: %Self.ref.loc7_28: type = name_ref Self, constants.%.1 [template = constants.%.1]
  128. // CHECK:STDOUT: %other.loc7_21.1: () = param other
  129. // CHECK:STDOUT: %other.loc7_21.2: () = bind_name other, %other.loc7_21.1
  130. // CHECK:STDOUT: %Self.ref.loc7_37: type = name_ref Self, constants.%.1 [template = constants.%.1]
  131. // CHECK:STDOUT: %return.var: ref () = var <return slot>
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT: %.1: <witness> = interface_witness (%Op.decl) [template = constants.%.3]
  134. // CHECK:STDOUT:
  135. // CHECK:STDOUT: !members:
  136. // CHECK:STDOUT: .Op = %Op.decl
  137. // CHECK:STDOUT: witness = %.1
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT:
  140. // CHECK:STDOUT: fn @Op.1[@impl.%self.loc7_9.2: ()](@impl.%other.loc7_21.2: ()) -> () {
  141. // CHECK:STDOUT: !entry:
  142. // CHECK:STDOUT: %.loc7_52: () = tuple_literal ()
  143. // CHECK:STDOUT: %tuple: () = tuple_value () [template = constants.%tuple]
  144. // CHECK:STDOUT: %.loc7_53: () = converted %.loc7_52, %tuple [template = constants.%tuple]
  145. // CHECK:STDOUT: return %.loc7_53
  146. // CHECK:STDOUT: }
  147. // CHECK:STDOUT:
  148. // CHECK:STDOUT: fn @Op.2[%self: Self](%other: Self) -> Self;
  149. // CHECK:STDOUT:
  150. // CHECK:STDOUT: fn @F(%x: (), %y: ()) -> () {
  151. // CHECK:STDOUT: !entry:
  152. // CHECK:STDOUT: %x.ref: () = name_ref x, %x
  153. // CHECK:STDOUT: %Add.ref: type = name_ref Add, file.%import_ref.1 [template = constants.%.2]
  154. // CHECK:STDOUT: %Op.ref: <associated Op in Add> = name_ref Op, file.%import_ref.2 [template = constants.%.5]
  155. // CHECK:STDOUT: %.1: Op = interface_witness_access @impl.%.1, element0 [template = constants.%struct.1]
  156. // CHECK:STDOUT: %.loc11_11: <bound method> = bound_method %x.ref, %.1
  157. // CHECK:STDOUT: %y.ref: () = name_ref y, %y
  158. // CHECK:STDOUT: %Op.call: init () = call %.loc11_11(%x.ref, %y.ref)
  159. // CHECK:STDOUT: %.loc11_20.1: ref () = temporary_storage
  160. // CHECK:STDOUT: %.loc11_20.2: ref () = temporary %.loc11_20.1, %Op.call
  161. // CHECK:STDOUT: %tuple: () = tuple_value () [template = constants.%tuple]
  162. // CHECK:STDOUT: %.loc11_23: () = converted %Op.call, %tuple [template = constants.%tuple]
  163. // CHECK:STDOUT: return %.loc11_23
  164. // CHECK:STDOUT: }
  165. // CHECK:STDOUT: