right_shift.carbon 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. // This file was generated from binary_op.carbon.tmpl. Run make_tests.sh to regenerate.
  7. // --- prelude.carbon
  8. package Core api;
  9. interface RightShift {
  10. fn Op[self: Self](other: Self) -> Self;
  11. }
  12. interface RightShiftAssign {
  13. fn Op[addr self: Self*](other: Self);
  14. }
  15. // --- user.carbon
  16. package User api;
  17. import Core;
  18. class C {};
  19. impl C as Core.RightShift {
  20. fn Op[self: C](other: C) -> C {
  21. return {};
  22. }
  23. }
  24. impl C as Core.RightShiftAssign {
  25. fn Op[addr self: C*](other: C) {}
  26. }
  27. fn TestOp(a: C, b: C) -> C {
  28. return a >> b;
  29. }
  30. fn TestAssign(a: C*, b: C) {
  31. *a >>= b;
  32. }
  33. // CHECK:STDOUT: --- prelude.carbon
  34. // CHECK:STDOUT:
  35. // CHECK:STDOUT: constants {
  36. // CHECK:STDOUT: %.1: type = interface_type @RightShift [template]
  37. // CHECK:STDOUT: %.2: type = assoc_entity_type @RightShift, <function> [template]
  38. // CHECK:STDOUT: %.3: <associated <function> in RightShift> = assoc_entity element0, @RightShift.%Op [template]
  39. // CHECK:STDOUT: %.4: type = interface_type @RightShiftAssign [template]
  40. // CHECK:STDOUT: %.5: type = ptr_type Self [symbolic]
  41. // CHECK:STDOUT: %.6: type = assoc_entity_type @RightShiftAssign, <function> [template]
  42. // CHECK:STDOUT: %.7: <associated <function> in RightShiftAssign> = assoc_entity element0, @RightShiftAssign.%Op [template]
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: file {
  46. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  47. // CHECK:STDOUT: .RightShift = %RightShift.decl
  48. // CHECK:STDOUT: .RightShiftAssign = %RightShiftAssign.decl
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT: %RightShift.decl: type = interface_decl @RightShift [template = constants.%.1] {}
  51. // CHECK:STDOUT: %RightShiftAssign.decl: type = interface_decl @RightShiftAssign [template = constants.%.4] {}
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: interface @RightShift {
  55. // CHECK:STDOUT: %Self: RightShift = bind_symbolic_name Self [symbolic]
  56. // CHECK:STDOUT: %Op: <function> = fn_decl @Op.1 [template] {
  57. // CHECK:STDOUT: %Self.ref.loc5_15: RightShift = name_ref Self, %Self [symbolic = %Self]
  58. // CHECK:STDOUT: %.loc5_15.1: type = facet_type_access %Self.ref.loc5_15 [symbolic = %Self]
  59. // CHECK:STDOUT: %.loc5_15.2: type = converted %Self.ref.loc5_15, %.loc5_15.1 [symbolic = %Self]
  60. // CHECK:STDOUT: %self.loc5_9.1: Self = param self
  61. // CHECK:STDOUT: %self.loc5_9.2: Self = bind_name self, %self.loc5_9.1
  62. // CHECK:STDOUT: %Self.ref.loc5_28: RightShift = name_ref Self, %Self [symbolic = %Self]
  63. // CHECK:STDOUT: %.loc5_28.1: type = facet_type_access %Self.ref.loc5_28 [symbolic = %Self]
  64. // CHECK:STDOUT: %.loc5_28.2: type = converted %Self.ref.loc5_28, %.loc5_28.1 [symbolic = %Self]
  65. // CHECK:STDOUT: %other.loc5_21.1: Self = param other
  66. // CHECK:STDOUT: %other.loc5_21.2: Self = bind_name other, %other.loc5_21.1
  67. // CHECK:STDOUT: %Self.ref.loc5_37: RightShift = name_ref Self, %Self [symbolic = %Self]
  68. // CHECK:STDOUT: %.loc5_37.1: type = facet_type_access %Self.ref.loc5_37 [symbolic = %Self]
  69. // CHECK:STDOUT: %.loc5_37.2: type = converted %Self.ref.loc5_37, %.loc5_37.1 [symbolic = %Self]
  70. // CHECK:STDOUT: %return.var: ref Self = var <return slot>
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT: %.loc5_41: <associated <function> in RightShift> = assoc_entity element0, %Op [template = constants.%.3]
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: !members:
  75. // CHECK:STDOUT: .Self = %Self
  76. // CHECK:STDOUT: .Op = %.loc5_41
  77. // CHECK:STDOUT: witness = (%Op)
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: interface @RightShiftAssign {
  81. // CHECK:STDOUT: %Self: RightShiftAssign = bind_symbolic_name Self [symbolic]
  82. // CHECK:STDOUT: %Op: <function> = fn_decl @Op.2 [template] {
  83. // CHECK:STDOUT: %Self.ref.loc8_20: RightShiftAssign = name_ref Self, %Self [symbolic = %Self]
  84. // CHECK:STDOUT: %.loc8_24.1: type = facet_type_access %Self.ref.loc8_20 [symbolic = %Self]
  85. // CHECK:STDOUT: %.loc8_20: type = converted %Self.ref.loc8_20, %.loc8_24.1 [symbolic = %Self]
  86. // CHECK:STDOUT: %.loc8_24.2: type = ptr_type Self [symbolic = constants.%.5]
  87. // CHECK:STDOUT: %self.loc8_14.1: Self* = param self
  88. // CHECK:STDOUT: %self.loc8_14.3: Self* = bind_name self, %self.loc8_14.1
  89. // CHECK:STDOUT: %.loc8_9: Self* = addr_pattern %self.loc8_14.3
  90. // CHECK:STDOUT: %Self.ref.loc8_34: RightShiftAssign = name_ref Self, %Self [symbolic = %Self]
  91. // CHECK:STDOUT: %.loc8_34.1: type = facet_type_access %Self.ref.loc8_34 [symbolic = %Self]
  92. // CHECK:STDOUT: %.loc8_34.2: type = converted %Self.ref.loc8_34, %.loc8_34.1 [symbolic = %Self]
  93. // CHECK:STDOUT: %other.loc8_27.1: Self = param other
  94. // CHECK:STDOUT: %other.loc8_27.2: Self = bind_name other, %other.loc8_27.1
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT: %.loc8_39: <associated <function> in RightShiftAssign> = assoc_entity element0, %Op [template = constants.%.7]
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: !members:
  99. // CHECK:STDOUT: .Self = %Self
  100. // CHECK:STDOUT: .Op = %.loc8_39
  101. // CHECK:STDOUT: witness = (%Op)
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: fn @Op.1[@RightShift.%self.loc5_9.2: Self](@RightShift.%other.loc5_21.2: Self) -> Self;
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: fn @Op.2[addr @RightShiftAssign.%self.loc8_14.3: Self*](@RightShiftAssign.%other.loc8_27.2: Self);
  107. // CHECK:STDOUT:
  108. // CHECK:STDOUT: --- user.carbon
  109. // CHECK:STDOUT:
  110. // CHECK:STDOUT: constants {
  111. // CHECK:STDOUT: %C: type = class_type @C [template]
  112. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  113. // CHECK:STDOUT: %.2: type = interface_type @RightShift [template]
  114. // CHECK:STDOUT: %.3: type = tuple_type () [template]
  115. // CHECK:STDOUT: %.4: type = ptr_type {} [template]
  116. // CHECK:STDOUT: %.5: C = struct_value () [template]
  117. // CHECK:STDOUT: %.6: <witness> = interface_witness (@impl.1.%Op) [template]
  118. // CHECK:STDOUT: %.7: type = interface_type @RightShiftAssign [template]
  119. // CHECK:STDOUT: %.8: type = ptr_type C [template]
  120. // CHECK:STDOUT: %.9: type = ptr_type Self [symbolic]
  121. // CHECK:STDOUT: %.10: <witness> = interface_witness (@impl.2.%Op) [template]
  122. // CHECK:STDOUT: %.11: type = assoc_entity_type @RightShift, <function> [template]
  123. // CHECK:STDOUT: %.12: <associated <function> in RightShift> = assoc_entity element0, file.%import_ref.10 [template]
  124. // CHECK:STDOUT: %.13: type = assoc_entity_type @RightShiftAssign, <function> [template]
  125. // CHECK:STDOUT: %.14: <associated <function> in RightShiftAssign> = assoc_entity element0, file.%import_ref.12 [template]
  126. // CHECK:STDOUT: }
  127. // CHECK:STDOUT:
  128. // CHECK:STDOUT: file {
  129. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  130. // CHECK:STDOUT: .Core = %Core
  131. // CHECK:STDOUT: .C = %C.decl
  132. // CHECK:STDOUT: .TestOp = %TestOp
  133. // CHECK:STDOUT: .TestAssign = %TestAssign
  134. // CHECK:STDOUT: }
  135. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  136. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  137. // CHECK:STDOUT: %import_ref.1: type = import_ref ir1, inst+1, used [template = constants.%.2]
  138. // CHECK:STDOUT: %import_ref.2: <associated <function> in RightShift> = import_ref ir1, inst+20, used [template = constants.%.12]
  139. // CHECK:STDOUT: %import_ref.3 = import_ref ir1, inst+3, unused
  140. // CHECK:STDOUT: %import_ref.4: <function> = import_ref ir1, inst+18, used [template = imports.%Op.1]
  141. // CHECK:STDOUT: impl_decl @impl.1 {
  142. // CHECK:STDOUT: %C.ref.loc8: type = name_ref C, %C.decl [template = constants.%C]
  143. // CHECK:STDOUT: %Core.ref.loc8: <namespace> = name_ref Core, %Core [template = %Core]
  144. // CHECK:STDOUT: %RightShift.decl: invalid = interface_decl @RightShift [template = constants.%.2] {}
  145. // CHECK:STDOUT: %RightShift.ref: type = name_ref RightShift, %import_ref.1 [template = constants.%.2]
  146. // CHECK:STDOUT: }
  147. // CHECK:STDOUT: %import_ref.5: type = import_ref ir1, inst+22, used [template = constants.%.7]
  148. // CHECK:STDOUT: %import_ref.6: <associated <function> in RightShiftAssign> = import_ref ir1, inst+40, used [template = constants.%.14]
  149. // CHECK:STDOUT: %import_ref.7 = import_ref ir1, inst+24, unused
  150. // CHECK:STDOUT: %import_ref.8: <function> = import_ref ir1, inst+38, used [template = imports.%Op.2]
  151. // CHECK:STDOUT: impl_decl @impl.2 {
  152. // CHECK:STDOUT: %C.ref.loc13: type = name_ref C, %C.decl [template = constants.%C]
  153. // CHECK:STDOUT: %Core.ref.loc13: <namespace> = name_ref Core, %Core [template = %Core]
  154. // CHECK:STDOUT: %RightShiftAssign.decl: invalid = interface_decl @RightShiftAssign [template = constants.%.7] {}
  155. // CHECK:STDOUT: %RightShiftAssign.ref: type = name_ref RightShiftAssign, %import_ref.5 [template = constants.%.7]
  156. // CHECK:STDOUT: }
  157. // CHECK:STDOUT: %TestOp: <function> = fn_decl @TestOp [template] {
  158. // CHECK:STDOUT: %C.ref.loc17_14: type = name_ref C, %C.decl [template = constants.%C]
  159. // CHECK:STDOUT: %a.loc17_11.1: C = param a
  160. // CHECK:STDOUT: @TestOp.%a: C = bind_name a, %a.loc17_11.1
  161. // CHECK:STDOUT: %C.ref.loc17_20: type = name_ref C, %C.decl [template = constants.%C]
  162. // CHECK:STDOUT: %b.loc17_17.1: C = param b
  163. // CHECK:STDOUT: @TestOp.%b: C = bind_name b, %b.loc17_17.1
  164. // CHECK:STDOUT: %C.ref.loc17_26: type = name_ref C, %C.decl [template = constants.%C]
  165. // CHECK:STDOUT: @TestOp.%return: ref C = var <return slot>
  166. // CHECK:STDOUT: }
  167. // CHECK:STDOUT: %import_ref.9: type = import_ref ir1, inst+1, used [template = constants.%.2]
  168. // CHECK:STDOUT: %import_ref.10 = import_ref ir1, inst+18, unused
  169. // CHECK:STDOUT: %TestAssign: <function> = fn_decl @TestAssign [template] {
  170. // CHECK:STDOUT: %C.ref.loc21_18: type = name_ref C, %C.decl [template = constants.%C]
  171. // CHECK:STDOUT: %.loc21: type = ptr_type C [template = constants.%.8]
  172. // CHECK:STDOUT: %a.loc21_15.1: C* = param a
  173. // CHECK:STDOUT: @TestAssign.%a: C* = bind_name a, %a.loc21_15.1
  174. // CHECK:STDOUT: %C.ref.loc21_25: type = name_ref C, %C.decl [template = constants.%C]
  175. // CHECK:STDOUT: %b.loc21_22.1: C = param b
  176. // CHECK:STDOUT: @TestAssign.%b: C = bind_name b, %b.loc21_22.1
  177. // CHECK:STDOUT: }
  178. // CHECK:STDOUT: %import_ref.11: type = import_ref ir1, inst+22, used [template = constants.%.7]
  179. // CHECK:STDOUT: %import_ref.12 = import_ref ir1, inst+38, unused
  180. // CHECK:STDOUT: }
  181. // CHECK:STDOUT:
  182. // CHECK:STDOUT: interface @RightShift {
  183. // CHECK:STDOUT: !members:
  184. // CHECK:STDOUT: .Op = file.%import_ref.2
  185. // CHECK:STDOUT: .Self = file.%import_ref.3
  186. // CHECK:STDOUT: witness = (file.%import_ref.4)
  187. // CHECK:STDOUT: }
  188. // CHECK:STDOUT:
  189. // CHECK:STDOUT: interface @RightShiftAssign {
  190. // CHECK:STDOUT: !members:
  191. // CHECK:STDOUT: .Op = file.%import_ref.6
  192. // CHECK:STDOUT: .Self = file.%import_ref.7
  193. // CHECK:STDOUT: witness = (file.%import_ref.8)
  194. // CHECK:STDOUT: }
  195. // CHECK:STDOUT:
  196. // CHECK:STDOUT: impl @impl.1: C as RightShift {
  197. // CHECK:STDOUT: %Op: <function> = fn_decl @Op.1 [template] {
  198. // CHECK:STDOUT: %C.ref.loc9_15: type = name_ref C, file.%C.decl [template = constants.%C]
  199. // CHECK:STDOUT: %self.loc9_9.1: C = param self
  200. // CHECK:STDOUT: %self.loc9_9.2: C = bind_name self, %self.loc9_9.1
  201. // CHECK:STDOUT: %C.ref.loc9_25: type = name_ref C, file.%C.decl [template = constants.%C]
  202. // CHECK:STDOUT: %other.loc9_18.1: C = param other
  203. // CHECK:STDOUT: %other.loc9_18.2: C = bind_name other, %other.loc9_18.1
  204. // CHECK:STDOUT: %C.ref.loc9_31: type = name_ref C, file.%C.decl [template = constants.%C]
  205. // CHECK:STDOUT: %return.var: ref C = var <return slot>
  206. // CHECK:STDOUT: }
  207. // CHECK:STDOUT: %.1: <witness> = interface_witness (%Op) [template = constants.%.6]
  208. // CHECK:STDOUT:
  209. // CHECK:STDOUT: !members:
  210. // CHECK:STDOUT: .Op = %Op
  211. // CHECK:STDOUT: witness = %.1
  212. // CHECK:STDOUT: }
  213. // CHECK:STDOUT:
  214. // CHECK:STDOUT: impl @impl.2: C as RightShiftAssign {
  215. // CHECK:STDOUT: %Op: <function> = fn_decl @Op.3 [template] {
  216. // CHECK:STDOUT: %C.ref.loc14_20: type = name_ref C, file.%C.decl [template = constants.%C]
  217. // CHECK:STDOUT: %.loc14_21: type = ptr_type C [template = constants.%.8]
  218. // CHECK:STDOUT: %self.loc14_14.1: C* = param self
  219. // CHECK:STDOUT: %self.loc14_14.3: C* = bind_name self, %self.loc14_14.1
  220. // CHECK:STDOUT: %.loc14_9: C* = addr_pattern %self.loc14_14.3
  221. // CHECK:STDOUT: %C.ref.loc14_31: type = name_ref C, file.%C.decl [template = constants.%C]
  222. // CHECK:STDOUT: %other.loc14_24.1: C = param other
  223. // CHECK:STDOUT: %other.loc14_24.2: C = bind_name other, %other.loc14_24.1
  224. // CHECK:STDOUT: }
  225. // CHECK:STDOUT: %.1: <witness> = interface_witness (%Op) [template = constants.%.10]
  226. // CHECK:STDOUT:
  227. // CHECK:STDOUT: !members:
  228. // CHECK:STDOUT: .Op = %Op
  229. // CHECK:STDOUT: witness = %.1
  230. // CHECK:STDOUT: }
  231. // CHECK:STDOUT:
  232. // CHECK:STDOUT: class @C {
  233. // CHECK:STDOUT: !members:
  234. // CHECK:STDOUT: .Self = constants.%C
  235. // CHECK:STDOUT: }
  236. // CHECK:STDOUT:
  237. // CHECK:STDOUT: fn @Op.1[@impl.1.%self.loc9_9.2: C](@impl.1.%other.loc9_18.2: C) -> @impl.1.%return.var: C {
  238. // CHECK:STDOUT: !entry:
  239. // CHECK:STDOUT: %.loc10_13.1: {} = struct_literal ()
  240. // CHECK:STDOUT: %.loc10_13.2: init C = class_init (), @impl.1.%return.var [template = constants.%.5]
  241. // CHECK:STDOUT: %.loc10_13.3: init C = converted %.loc10_13.1, %.loc10_13.2 [template = constants.%.5]
  242. // CHECK:STDOUT: return %.loc10_13.3
  243. // CHECK:STDOUT: }
  244. // CHECK:STDOUT:
  245. // CHECK:STDOUT: fn @Op.2[%self: Self](%other: Self) -> Self;
  246. // CHECK:STDOUT:
  247. // CHECK:STDOUT: fn @Op.3[addr @impl.2.%self.loc14_14.3: C*](@impl.2.%other.loc14_24.2: C) {
  248. // CHECK:STDOUT: !entry:
  249. // CHECK:STDOUT: return
  250. // CHECK:STDOUT: }
  251. // CHECK:STDOUT:
  252. // CHECK:STDOUT: fn @Op.4[addr %self: Self*](%other: Self);
  253. // CHECK:STDOUT:
  254. // CHECK:STDOUT: fn @TestOp(%a: C, %b: C) -> %return: C {
  255. // CHECK:STDOUT: !entry:
  256. // CHECK:STDOUT: %a.ref: C = name_ref a, %a
  257. // CHECK:STDOUT: %b.ref: C = name_ref b, %b
  258. // CHECK:STDOUT: %.1: <function> = interface_witness_access @impl.1.%.1, element0 [template = @impl.1.%Op]
  259. // CHECK:STDOUT: %.loc18_12.1: <bound method> = bound_method %a.ref, %.1
  260. // CHECK:STDOUT: %.loc17: ref C = splice_block %return {}
  261. // CHECK:STDOUT: %.loc18_12.2: init C = call %.loc18_12.1(%a.ref, %b.ref) to %.loc17
  262. // CHECK:STDOUT: return %.loc18_12.2
  263. // CHECK:STDOUT: }
  264. // CHECK:STDOUT:
  265. // CHECK:STDOUT: fn @TestAssign(%a: C*, %b: C) {
  266. // CHECK:STDOUT: !entry:
  267. // CHECK:STDOUT: %a.ref: C* = name_ref a, %a
  268. // CHECK:STDOUT: %.loc22_3.1: ref C = deref %a.ref
  269. // CHECK:STDOUT: %b.ref: C = name_ref b, %b
  270. // CHECK:STDOUT: %.1: <function> = interface_witness_access @impl.2.%.1, element0 [template = @impl.2.%Op]
  271. // CHECK:STDOUT: %.loc22_6.1: <bound method> = bound_method %.loc22_3.1, %.1
  272. // CHECK:STDOUT: %.loc22_3.2: C* = addr_of %.loc22_3.1
  273. // CHECK:STDOUT: %.loc22_6.2: init () = call %.loc22_6.1(%.loc22_3.2, %b.ref)
  274. // CHECK:STDOUT: return
  275. // CHECK:STDOUT: }
  276. // CHECK:STDOUT: