left_shift.carbon 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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/operators/overloaded/left_shift.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/operators/overloaded/left_shift.carbon
  10. // This file was generated from binary_op.carbon.tmpl. Run make_tests.sh to regenerate.
  11. package User;
  12. class C {};
  13. impl C as Core.LeftShift {
  14. fn Op[self: C](other: C) -> C {
  15. return {};
  16. }
  17. }
  18. impl C as Core.LeftShiftAssign {
  19. fn Op[addr self: C*](other: C) {}
  20. }
  21. fn TestOp(a: C, b: C) -> C {
  22. return a << b;
  23. }
  24. fn TestAssign(a: C*, b: C) {
  25. *a <<= b;
  26. }
  27. // CHECK:STDOUT: --- left_shift.carbon
  28. // CHECK:STDOUT:
  29. // CHECK:STDOUT: constants {
  30. // CHECK:STDOUT: %C: type = class_type @C [template]
  31. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  32. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  33. // CHECK:STDOUT: %.3: type = interface_type @LeftShift [template]
  34. // CHECK:STDOUT: %Self.1: %.3 = bind_symbolic_name Self, 0 [symbolic]
  35. // CHECK:STDOUT: %Op.type.1: type = fn_type @Op.1 [template]
  36. // CHECK:STDOUT: %.4: type = tuple_type () [template]
  37. // CHECK:STDOUT: %Op.1: %Op.type.1 = struct_value () [template]
  38. // CHECK:STDOUT: %Op.type.2: type = fn_type @Op.2 [template]
  39. // CHECK:STDOUT: %Op.2: %Op.type.2 = struct_value () [template]
  40. // CHECK:STDOUT: %.5: <witness> = interface_witness (%Op.1) [template]
  41. // CHECK:STDOUT: %.6: type = ptr_type %.1 [template]
  42. // CHECK:STDOUT: %struct: %C = struct_value () [template]
  43. // CHECK:STDOUT: %.7: type = interface_type @LeftShiftAssign [template]
  44. // CHECK:STDOUT: %Self.2: %.7 = bind_symbolic_name Self, 0 [symbolic]
  45. // CHECK:STDOUT: %.8: type = ptr_type %C [template]
  46. // CHECK:STDOUT: %Op.type.3: type = fn_type @Op.3 [template]
  47. // CHECK:STDOUT: %Op.3: %Op.type.3 = struct_value () [template]
  48. // CHECK:STDOUT: %Op.type.4: type = fn_type @Op.4 [template]
  49. // CHECK:STDOUT: %Op.4: %Op.type.4 = struct_value () [template]
  50. // CHECK:STDOUT: %.9: type = ptr_type %Self.2 [symbolic]
  51. // CHECK:STDOUT: %.10: <witness> = interface_witness (%Op.3) [template]
  52. // CHECK:STDOUT: %TestOp.type: type = fn_type @TestOp [template]
  53. // CHECK:STDOUT: %TestOp: %TestOp.type = struct_value () [template]
  54. // CHECK:STDOUT: %.11: type = assoc_entity_type %.3, %Op.type.2 [template]
  55. // CHECK:STDOUT: %.12: %.11 = assoc_entity element0, imports.%import_ref.9 [template]
  56. // CHECK:STDOUT: %TestAssign.type: type = fn_type @TestAssign [template]
  57. // CHECK:STDOUT: %TestAssign: %TestAssign.type = struct_value () [template]
  58. // CHECK:STDOUT: %.13: type = assoc_entity_type %.7, %Op.type.4 [template]
  59. // CHECK:STDOUT: %.14: %.13 = assoc_entity element0, imports.%import_ref.10 [template]
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: imports {
  63. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  64. // CHECK:STDOUT: .LeftShift = %import_ref.1
  65. // CHECK:STDOUT: .LeftShiftAssign = %import_ref.5
  66. // CHECK:STDOUT: import Core//prelude
  67. // CHECK:STDOUT: import Core//prelude/operators
  68. // CHECK:STDOUT: import Core//prelude/types
  69. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  70. // CHECK:STDOUT: import Core//prelude/operators/as
  71. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  72. // CHECK:STDOUT: import Core//prelude/operators/comparison
  73. // CHECK:STDOUT: import Core//prelude/types/bool
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT: %import_ref.1: type = import_ref Core//prelude/operators/bitwise, inst+185, loaded [template = constants.%.3]
  76. // CHECK:STDOUT: %import_ref.2 = import_ref Core//prelude/operators/bitwise, inst+187, unloaded
  77. // CHECK:STDOUT: %import_ref.3: %.11 = import_ref Core//prelude/operators/bitwise, inst+210, loaded [template = constants.%.12]
  78. // CHECK:STDOUT: %import_ref.4: %Op.type.2 = import_ref Core//prelude/operators/bitwise, inst+205, loaded [template = constants.%Op.2]
  79. // CHECK:STDOUT: %import_ref.5: type = import_ref Core//prelude/operators/bitwise, inst+212, loaded [template = constants.%.7]
  80. // CHECK:STDOUT: %import_ref.6 = import_ref Core//prelude/operators/bitwise, inst+214, unloaded
  81. // CHECK:STDOUT: %import_ref.7: %.13 = import_ref Core//prelude/operators/bitwise, inst+237, loaded [template = constants.%.14]
  82. // CHECK:STDOUT: %import_ref.8: %Op.type.4 = import_ref Core//prelude/operators/bitwise, inst+231, loaded [template = constants.%Op.4]
  83. // CHECK:STDOUT: %import_ref.9 = import_ref Core//prelude/operators/bitwise, inst+205, unloaded
  84. // CHECK:STDOUT: %import_ref.10 = import_ref Core//prelude/operators/bitwise, inst+231, unloaded
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: file {
  88. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  89. // CHECK:STDOUT: .Core = imports.%Core
  90. // CHECK:STDOUT: .C = %C.decl
  91. // CHECK:STDOUT: .TestOp = %TestOp.decl
  92. // CHECK:STDOUT: .TestAssign = %TestAssign.decl
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT: %Core.import = import Core
  95. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  96. // CHECK:STDOUT: impl_decl @impl.1 [template] {} {
  97. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  98. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, imports.%Core [template = imports.%Core]
  99. // CHECK:STDOUT: %LeftShift.ref: type = name_ref LeftShift, imports.%import_ref.1 [template = constants.%.3]
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT: impl_decl @impl.2 [template] {} {
  102. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  103. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, imports.%Core [template = imports.%Core]
  104. // CHECK:STDOUT: %LeftShiftAssign.ref: type = name_ref LeftShiftAssign, imports.%import_ref.5 [template = constants.%.7]
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT: %TestOp.decl: %TestOp.type = fn_decl @TestOp [template = constants.%TestOp] {
  107. // CHECK:STDOUT: %a.patt: %C = binding_pattern a
  108. // CHECK:STDOUT: %b.patt: %C = binding_pattern b
  109. // CHECK:STDOUT: } {
  110. // CHECK:STDOUT: %C.ref.loc26_14: type = name_ref C, file.%C.decl [template = constants.%C]
  111. // CHECK:STDOUT: %a.param: %C = param a, runtime_param0
  112. // CHECK:STDOUT: %a: %C = bind_name a, %a.param
  113. // CHECK:STDOUT: %C.ref.loc26_20: type = name_ref C, file.%C.decl [template = constants.%C]
  114. // CHECK:STDOUT: %b.param: %C = param b, runtime_param1
  115. // CHECK:STDOUT: %b: %C = bind_name b, %b.param
  116. // CHECK:STDOUT: %C.ref.loc26_26: type = name_ref C, file.%C.decl [template = constants.%C]
  117. // CHECK:STDOUT: %return: ref %C = var <return slot>
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT: %TestAssign.decl: %TestAssign.type = fn_decl @TestAssign [template = constants.%TestAssign] {
  120. // CHECK:STDOUT: %a.patt: %.8 = binding_pattern a
  121. // CHECK:STDOUT: %b.patt: %C = binding_pattern b
  122. // CHECK:STDOUT: } {
  123. // CHECK:STDOUT: %C.ref.loc30_18: type = name_ref C, file.%C.decl [template = constants.%C]
  124. // CHECK:STDOUT: %.loc30: type = ptr_type %C [template = constants.%.8]
  125. // CHECK:STDOUT: %a.param: %.8 = param a, runtime_param0
  126. // CHECK:STDOUT: %a: %.8 = bind_name a, %a.param
  127. // CHECK:STDOUT: %C.ref.loc30_25: type = name_ref C, file.%C.decl [template = constants.%C]
  128. // CHECK:STDOUT: %b.param: %C = param b, runtime_param1
  129. // CHECK:STDOUT: %b: %C = bind_name b, %b.param
  130. // CHECK:STDOUT: }
  131. // CHECK:STDOUT: }
  132. // CHECK:STDOUT:
  133. // CHECK:STDOUT: interface @LeftShift {
  134. // CHECK:STDOUT: !members:
  135. // CHECK:STDOUT: .Self = imports.%import_ref.2
  136. // CHECK:STDOUT: .Op = imports.%import_ref.3
  137. // CHECK:STDOUT: witness = (imports.%import_ref.4)
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT:
  140. // CHECK:STDOUT: interface @LeftShiftAssign {
  141. // CHECK:STDOUT: !members:
  142. // CHECK:STDOUT: .Self = imports.%import_ref.6
  143. // CHECK:STDOUT: .Op = imports.%import_ref.7
  144. // CHECK:STDOUT: witness = (imports.%import_ref.8)
  145. // CHECK:STDOUT: }
  146. // CHECK:STDOUT:
  147. // CHECK:STDOUT: impl @impl.1: %C.ref as %LeftShift.ref {
  148. // CHECK:STDOUT: %Op.decl: %Op.type.1 = fn_decl @Op.1 [template = constants.%Op.1] {
  149. // CHECK:STDOUT: %self.patt: %C = binding_pattern self
  150. // CHECK:STDOUT: %other.patt: %C = binding_pattern other
  151. // CHECK:STDOUT: } {
  152. // CHECK:STDOUT: %C.ref.loc18_15: type = name_ref C, file.%C.decl [template = constants.%C]
  153. // CHECK:STDOUT: %self.param: %C = param self, runtime_param0
  154. // CHECK:STDOUT: %self: %C = bind_name self, %self.param
  155. // CHECK:STDOUT: %C.ref.loc18_25: type = name_ref C, file.%C.decl [template = constants.%C]
  156. // CHECK:STDOUT: %other.param: %C = param other, runtime_param1
  157. // CHECK:STDOUT: %other: %C = bind_name other, %other.param
  158. // CHECK:STDOUT: %C.ref.loc18_31: type = name_ref C, file.%C.decl [template = constants.%C]
  159. // CHECK:STDOUT: %return: ref %C = var <return slot>
  160. // CHECK:STDOUT: }
  161. // CHECK:STDOUT: %.loc17: <witness> = interface_witness (%Op.decl) [template = constants.%.5]
  162. // CHECK:STDOUT:
  163. // CHECK:STDOUT: !members:
  164. // CHECK:STDOUT: .Op = %Op.decl
  165. // CHECK:STDOUT: witness = %.loc17
  166. // CHECK:STDOUT: }
  167. // CHECK:STDOUT:
  168. // CHECK:STDOUT: impl @impl.2: %C.ref as %LeftShiftAssign.ref {
  169. // CHECK:STDOUT: %Op.decl: %Op.type.3 = fn_decl @Op.3 [template = constants.%Op.3] {
  170. // CHECK:STDOUT: %self.patt: %.8 = binding_pattern self
  171. // CHECK:STDOUT: %other.patt: %C = binding_pattern other
  172. // CHECK:STDOUT: } {
  173. // CHECK:STDOUT: %C.ref.loc23_20: type = name_ref C, file.%C.decl [template = constants.%C]
  174. // CHECK:STDOUT: %.loc23_21: type = ptr_type %C [template = constants.%.8]
  175. // CHECK:STDOUT: %self.param: %.8 = param self, runtime_param0
  176. // CHECK:STDOUT: %self: %.8 = bind_name self, %self.param
  177. // CHECK:STDOUT: %.loc23_9: %.8 = addr_pattern %self
  178. // CHECK:STDOUT: %C.ref.loc23_31: type = name_ref C, file.%C.decl [template = constants.%C]
  179. // CHECK:STDOUT: %other.param: %C = param other, runtime_param1
  180. // CHECK:STDOUT: %other: %C = bind_name other, %other.param
  181. // CHECK:STDOUT: }
  182. // CHECK:STDOUT: %.loc22: <witness> = interface_witness (%Op.decl) [template = constants.%.10]
  183. // CHECK:STDOUT:
  184. // CHECK:STDOUT: !members:
  185. // CHECK:STDOUT: .Op = %Op.decl
  186. // CHECK:STDOUT: witness = %.loc22
  187. // CHECK:STDOUT: }
  188. // CHECK:STDOUT:
  189. // CHECK:STDOUT: class @C {
  190. // CHECK:STDOUT: %.loc15: <witness> = complete_type_witness %.1 [template = constants.%.2]
  191. // CHECK:STDOUT:
  192. // CHECK:STDOUT: !members:
  193. // CHECK:STDOUT: .Self = constants.%C
  194. // CHECK:STDOUT: }
  195. // CHECK:STDOUT:
  196. // CHECK:STDOUT: fn @Op.1[%self: %C](%other: %C) -> %return: %C {
  197. // CHECK:STDOUT: !entry:
  198. // CHECK:STDOUT: %.loc19_13.1: %.1 = struct_literal ()
  199. // CHECK:STDOUT: %.loc19_13.2: init %C = class_init (), %return [template = constants.%struct]
  200. // CHECK:STDOUT: %.loc19_14: init %C = converted %.loc19_13.1, %.loc19_13.2 [template = constants.%struct]
  201. // CHECK:STDOUT: return %.loc19_14 to %return
  202. // CHECK:STDOUT: }
  203. // CHECK:STDOUT:
  204. // CHECK:STDOUT: generic fn @Op.2(constants.%Self.1: %.3) {
  205. // CHECK:STDOUT: %Self: %.3 = bind_symbolic_name Self, 0 [symbolic = %Self (constants.%Self.1)]
  206. // CHECK:STDOUT:
  207. // CHECK:STDOUT: fn[%self: @Op.2.%Self (%Self.1)](%other: @Op.2.%Self (%Self.1)) -> @Op.2.%Self (%Self.1);
  208. // CHECK:STDOUT: }
  209. // CHECK:STDOUT:
  210. // CHECK:STDOUT: fn @Op.3[addr %self: %.8](%other: %C) {
  211. // CHECK:STDOUT: !entry:
  212. // CHECK:STDOUT: return
  213. // CHECK:STDOUT: }
  214. // CHECK:STDOUT:
  215. // CHECK:STDOUT: generic fn @Op.4(constants.%Self.2: %.7) {
  216. // CHECK:STDOUT: %Self: %.7 = bind_symbolic_name Self, 0 [symbolic = %Self (constants.%Self.2)]
  217. // CHECK:STDOUT: %.2: type = ptr_type @Op.4.%Self (%Self.2) [symbolic = %.2 (constants.%.9)]
  218. // CHECK:STDOUT:
  219. // CHECK:STDOUT: fn[addr %self: @Op.4.%.2 (%.9)](%other: @Op.4.%Self (%Self.2));
  220. // CHECK:STDOUT: }
  221. // CHECK:STDOUT:
  222. // CHECK:STDOUT: fn @TestOp(%a: %C, %b: %C) -> %return: %C {
  223. // CHECK:STDOUT: !entry:
  224. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  225. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  226. // CHECK:STDOUT: %Op.ref: %.11 = name_ref Op, imports.%import_ref.3 [template = constants.%.12]
  227. // CHECK:STDOUT: %.loc27_12.1: %Op.type.2 = interface_witness_access constants.%.5, element0 [template = constants.%Op.1]
  228. // CHECK:STDOUT: %.loc27_12.2: <bound method> = bound_method %a.ref, %.loc27_12.1
  229. // CHECK:STDOUT: %.loc26: ref %C = splice_block %return {}
  230. // CHECK:STDOUT: %Op.call: init %C = call %.loc27_12.2(%a.ref, %b.ref) to %.loc26
  231. // CHECK:STDOUT: return %Op.call to %return
  232. // CHECK:STDOUT: }
  233. // CHECK:STDOUT:
  234. // CHECK:STDOUT: fn @TestAssign(%a: %.8, %b: %C) {
  235. // CHECK:STDOUT: !entry:
  236. // CHECK:STDOUT: %a.ref: %.8 = name_ref a, %a
  237. // CHECK:STDOUT: %.loc31_3.1: ref %C = deref %a.ref
  238. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  239. // CHECK:STDOUT: %Op.ref: %.13 = name_ref Op, imports.%import_ref.7 [template = constants.%.14]
  240. // CHECK:STDOUT: %.loc31_6.1: %Op.type.4 = interface_witness_access constants.%.10, element0 [template = constants.%Op.3]
  241. // CHECK:STDOUT: %.loc31_6.2: <bound method> = bound_method %.loc31_3.1, %.loc31_6.1
  242. // CHECK:STDOUT: %.loc31_3.2: %.8 = addr_of %.loc31_3.1
  243. // CHECK:STDOUT: %Op.call: init %.4 = call %.loc31_6.2(%.loc31_3.2, %b.ref)
  244. // CHECK:STDOUT: return
  245. // CHECK:STDOUT: }
  246. // CHECK:STDOUT:
  247. // CHECK:STDOUT: specific @Op.2(constants.%Self.1) {
  248. // CHECK:STDOUT: %Self => constants.%Self.1
  249. // CHECK:STDOUT: }
  250. // CHECK:STDOUT:
  251. // CHECK:STDOUT: specific @Op.2(constants.%C) {
  252. // CHECK:STDOUT: %Self => constants.%C
  253. // CHECK:STDOUT: }
  254. // CHECK:STDOUT:
  255. // CHECK:STDOUT: specific @Op.4(constants.%Self.2) {
  256. // CHECK:STDOUT: %Self => constants.%Self.2
  257. // CHECK:STDOUT: %.2 => constants.%.9
  258. // CHECK:STDOUT: }
  259. // CHECK:STDOUT:
  260. // CHECK:STDOUT: specific @Op.4(constants.%C) {
  261. // CHECK:STDOUT: %Self => constants.%C
  262. // CHECK:STDOUT: %.2 => constants.%.8
  263. // CHECK:STDOUT: }
  264. // CHECK:STDOUT: