left_shift.carbon 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 [concrete]
  31. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  32. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  33. // CHECK:STDOUT: %LeftShift.type: type = facet_type <@LeftShift> [concrete]
  34. // CHECK:STDOUT: %Op.type.789: type = fn_type @Op.1 [concrete]
  35. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  36. // CHECK:STDOUT: %LeftShift.impl_witness: <witness> = impl_witness file.%LeftShift.impl_witness_table [concrete]
  37. // CHECK:STDOUT: %Op.type.de2: type = fn_type @Op.2 [concrete]
  38. // CHECK:STDOUT: %Op.df9: %Op.type.de2 = struct_value () [concrete]
  39. // CHECK:STDOUT: %LeftShift.facet: %LeftShift.type = facet_value %C, (%LeftShift.impl_witness) [concrete]
  40. // CHECK:STDOUT: %C.val: %C = struct_value () [concrete]
  41. // CHECK:STDOUT: %LeftShiftAssign.type: type = facet_type <@LeftShiftAssign> [concrete]
  42. // CHECK:STDOUT: %Op.type.1de: type = fn_type @Op.3 [concrete]
  43. // CHECK:STDOUT: %LeftShiftAssign.impl_witness: <witness> = impl_witness file.%LeftShiftAssign.impl_witness_table [concrete]
  44. // CHECK:STDOUT: %ptr.019: type = ptr_type %C [concrete]
  45. // CHECK:STDOUT: %Op.type.386: type = fn_type @Op.4 [concrete]
  46. // CHECK:STDOUT: %Op.8fc: %Op.type.386 = struct_value () [concrete]
  47. // CHECK:STDOUT: %LeftShiftAssign.facet: %LeftShiftAssign.type = facet_value %C, (%LeftShiftAssign.impl_witness) [concrete]
  48. // CHECK:STDOUT: %TestOp.type: type = fn_type @TestOp [concrete]
  49. // CHECK:STDOUT: %TestOp: %TestOp.type = struct_value () [concrete]
  50. // CHECK:STDOUT: %.8a4: type = fn_type_with_self_type %Op.type.789, %LeftShift.facet [concrete]
  51. // CHECK:STDOUT: %TestAssign.type: type = fn_type @TestAssign [concrete]
  52. // CHECK:STDOUT: %TestAssign: %TestAssign.type = struct_value () [concrete]
  53. // CHECK:STDOUT: %.ac9: type = fn_type_with_self_type %Op.type.1de, %LeftShiftAssign.facet [concrete]
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: imports {
  57. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  58. // CHECK:STDOUT: .LeftShift = %Core.LeftShift
  59. // CHECK:STDOUT: .LeftShiftAssign = %Core.LeftShiftAssign
  60. // CHECK:STDOUT: import Core//prelude
  61. // CHECK:STDOUT: import Core//prelude/...
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT: %Core.LeftShift: type = import_ref Core//prelude/operators/bitwise, LeftShift, loaded [concrete = constants.%LeftShift.type]
  64. // CHECK:STDOUT: %Core.LeftShiftAssign: type = import_ref Core//prelude/operators/bitwise, LeftShiftAssign, loaded [concrete = constants.%LeftShiftAssign.type]
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: file {
  68. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  69. // CHECK:STDOUT: .Core = imports.%Core
  70. // CHECK:STDOUT: .C = %C.decl
  71. // CHECK:STDOUT: .TestOp = %TestOp.decl
  72. // CHECK:STDOUT: .TestAssign = %TestAssign.decl
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT: %Core.import = import Core
  75. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  76. // CHECK:STDOUT: impl_decl @impl.c6e [concrete] {} {
  77. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  78. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, imports.%Core [concrete = imports.%Core]
  79. // CHECK:STDOUT: %LeftShift.ref: type = name_ref LeftShift, imports.%Core.LeftShift [concrete = constants.%LeftShift.type]
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT: %LeftShift.impl_witness_table = impl_witness_table (@impl.c6e.%Op.decl), @impl.c6e [concrete]
  82. // CHECK:STDOUT: %LeftShift.impl_witness: <witness> = impl_witness %LeftShift.impl_witness_table [concrete = constants.%LeftShift.impl_witness]
  83. // CHECK:STDOUT: impl_decl @impl.29d [concrete] {} {
  84. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  85. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, imports.%Core [concrete = imports.%Core]
  86. // CHECK:STDOUT: %LeftShiftAssign.ref: type = name_ref LeftShiftAssign, imports.%Core.LeftShiftAssign [concrete = constants.%LeftShiftAssign.type]
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT: %LeftShiftAssign.impl_witness_table = impl_witness_table (@impl.29d.%Op.decl), @impl.29d [concrete]
  89. // CHECK:STDOUT: %LeftShiftAssign.impl_witness: <witness> = impl_witness %LeftShiftAssign.impl_witness_table [concrete = constants.%LeftShiftAssign.impl_witness]
  90. // CHECK:STDOUT: %TestOp.decl: %TestOp.type = fn_decl @TestOp [concrete = constants.%TestOp] {
  91. // CHECK:STDOUT: %a.patt: %C = binding_pattern a
  92. // CHECK:STDOUT: %a.param_patt: %C = value_param_pattern %a.patt, call_param0
  93. // CHECK:STDOUT: %b.patt: %C = binding_pattern b
  94. // CHECK:STDOUT: %b.param_patt: %C = value_param_pattern %b.patt, call_param1
  95. // CHECK:STDOUT: %return.patt: %C = return_slot_pattern
  96. // CHECK:STDOUT: %return.param_patt: %C = out_param_pattern %return.patt, call_param2
  97. // CHECK:STDOUT: } {
  98. // CHECK:STDOUT: %C.ref.loc26_26: type = name_ref C, file.%C.decl [concrete = constants.%C]
  99. // CHECK:STDOUT: %a.param: %C = value_param call_param0
  100. // CHECK:STDOUT: %C.ref.loc26_14: type = name_ref C, file.%C.decl [concrete = constants.%C]
  101. // CHECK:STDOUT: %a: %C = bind_name a, %a.param
  102. // CHECK:STDOUT: %b.param: %C = value_param call_param1
  103. // CHECK:STDOUT: %C.ref.loc26_20: type = name_ref C, file.%C.decl [concrete = constants.%C]
  104. // CHECK:STDOUT: %b: %C = bind_name b, %b.param
  105. // CHECK:STDOUT: %return.param: ref %C = out_param call_param2
  106. // CHECK:STDOUT: %return: ref %C = return_slot %return.param
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT: %TestAssign.decl: %TestAssign.type = fn_decl @TestAssign [concrete = constants.%TestAssign] {
  109. // CHECK:STDOUT: %a.patt: %ptr.019 = binding_pattern a
  110. // CHECK:STDOUT: %a.param_patt: %ptr.019 = value_param_pattern %a.patt, call_param0
  111. // CHECK:STDOUT: %b.patt: %C = binding_pattern b
  112. // CHECK:STDOUT: %b.param_patt: %C = value_param_pattern %b.patt, call_param1
  113. // CHECK:STDOUT: } {
  114. // CHECK:STDOUT: %a.param: %ptr.019 = value_param call_param0
  115. // CHECK:STDOUT: %.loc30: type = splice_block %ptr [concrete = constants.%ptr.019] {
  116. // CHECK:STDOUT: %C.ref.loc30_18: type = name_ref C, file.%C.decl [concrete = constants.%C]
  117. // CHECK:STDOUT: %ptr: type = ptr_type %C.ref.loc30_18 [concrete = constants.%ptr.019]
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT: %a: %ptr.019 = bind_name a, %a.param
  120. // CHECK:STDOUT: %b.param: %C = value_param call_param1
  121. // CHECK:STDOUT: %C.ref.loc30_25: type = name_ref C, file.%C.decl [concrete = constants.%C]
  122. // CHECK:STDOUT: %b: %C = bind_name b, %b.param
  123. // CHECK:STDOUT: }
  124. // CHECK:STDOUT: }
  125. // CHECK:STDOUT:
  126. // CHECK:STDOUT: impl @impl.c6e: %C.ref as %LeftShift.ref {
  127. // CHECK:STDOUT: %Op.decl: %Op.type.de2 = fn_decl @Op.2 [concrete = constants.%Op.df9] {
  128. // CHECK:STDOUT: %self.patt: %C = binding_pattern self
  129. // CHECK:STDOUT: %self.param_patt: %C = value_param_pattern %self.patt, call_param0
  130. // CHECK:STDOUT: %other.patt: %C = binding_pattern other
  131. // CHECK:STDOUT: %other.param_patt: %C = value_param_pattern %other.patt, call_param1
  132. // CHECK:STDOUT: %return.patt: %C = return_slot_pattern
  133. // CHECK:STDOUT: %return.param_patt: %C = out_param_pattern %return.patt, call_param2
  134. // CHECK:STDOUT: } {
  135. // CHECK:STDOUT: %C.ref.loc18_31: type = name_ref C, file.%C.decl [concrete = constants.%C]
  136. // CHECK:STDOUT: %self.param: %C = value_param call_param0
  137. // CHECK:STDOUT: %C.ref.loc18_15: type = name_ref C, file.%C.decl [concrete = constants.%C]
  138. // CHECK:STDOUT: %self: %C = bind_name self, %self.param
  139. // CHECK:STDOUT: %other.param: %C = value_param call_param1
  140. // CHECK:STDOUT: %C.ref.loc18_25: type = name_ref C, file.%C.decl [concrete = constants.%C]
  141. // CHECK:STDOUT: %other: %C = bind_name other, %other.param
  142. // CHECK:STDOUT: %return.param: ref %C = out_param call_param2
  143. // CHECK:STDOUT: %return: ref %C = return_slot %return.param
  144. // CHECK:STDOUT: }
  145. // CHECK:STDOUT:
  146. // CHECK:STDOUT: !members:
  147. // CHECK:STDOUT: .C = <poisoned>
  148. // CHECK:STDOUT: .Op = %Op.decl
  149. // CHECK:STDOUT: witness = file.%LeftShift.impl_witness
  150. // CHECK:STDOUT: }
  151. // CHECK:STDOUT:
  152. // CHECK:STDOUT: impl @impl.29d: %C.ref as %LeftShiftAssign.ref {
  153. // CHECK:STDOUT: %Op.decl: %Op.type.386 = fn_decl @Op.4 [concrete = constants.%Op.8fc] {
  154. // CHECK:STDOUT: %self.patt: %ptr.019 = binding_pattern self
  155. // CHECK:STDOUT: %self.param_patt: %ptr.019 = value_param_pattern %self.patt, call_param0
  156. // CHECK:STDOUT: %.loc23_9: auto = addr_pattern %self.param_patt
  157. // CHECK:STDOUT: %other.patt: %C = binding_pattern other
  158. // CHECK:STDOUT: %other.param_patt: %C = value_param_pattern %other.patt, call_param1
  159. // CHECK:STDOUT: } {
  160. // CHECK:STDOUT: %self.param: %ptr.019 = value_param call_param0
  161. // CHECK:STDOUT: %.loc23_21: type = splice_block %ptr [concrete = constants.%ptr.019] {
  162. // CHECK:STDOUT: %C.ref.loc23_20: type = name_ref C, file.%C.decl [concrete = constants.%C]
  163. // CHECK:STDOUT: %ptr: type = ptr_type %C.ref.loc23_20 [concrete = constants.%ptr.019]
  164. // CHECK:STDOUT: }
  165. // CHECK:STDOUT: %self: %ptr.019 = bind_name self, %self.param
  166. // CHECK:STDOUT: %other.param: %C = value_param call_param1
  167. // CHECK:STDOUT: %C.ref.loc23_31: type = name_ref C, file.%C.decl [concrete = constants.%C]
  168. // CHECK:STDOUT: %other: %C = bind_name other, %other.param
  169. // CHECK:STDOUT: }
  170. // CHECK:STDOUT:
  171. // CHECK:STDOUT: !members:
  172. // CHECK:STDOUT: .C = <poisoned>
  173. // CHECK:STDOUT: .Op = %Op.decl
  174. // CHECK:STDOUT: witness = file.%LeftShiftAssign.impl_witness
  175. // CHECK:STDOUT: }
  176. // CHECK:STDOUT:
  177. // CHECK:STDOUT: class @C {
  178. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  179. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
  180. // CHECK:STDOUT: complete_type_witness = %complete_type
  181. // CHECK:STDOUT:
  182. // CHECK:STDOUT: !members:
  183. // CHECK:STDOUT: .Self = constants.%C
  184. // CHECK:STDOUT: }
  185. // CHECK:STDOUT:
  186. // CHECK:STDOUT: fn @Op.2[%self.param_patt: %C](%other.param_patt: %C) -> %return.param_patt: %C {
  187. // CHECK:STDOUT: !entry:
  188. // CHECK:STDOUT: %.loc19_13.1: %empty_struct_type = struct_literal ()
  189. // CHECK:STDOUT: %.loc19_13.2: init %C = class_init (), %return [concrete = constants.%C.val]
  190. // CHECK:STDOUT: %.loc19_14: init %C = converted %.loc19_13.1, %.loc19_13.2 [concrete = constants.%C.val]
  191. // CHECK:STDOUT: return %.loc19_14 to %return
  192. // CHECK:STDOUT: }
  193. // CHECK:STDOUT:
  194. // CHECK:STDOUT: fn @Op.4[addr %self.param_patt: %ptr.019](%other.param_patt: %C) {
  195. // CHECK:STDOUT: !entry:
  196. // CHECK:STDOUT: return
  197. // CHECK:STDOUT: }
  198. // CHECK:STDOUT:
  199. // CHECK:STDOUT: fn @TestOp(%a.param_patt: %C, %b.param_patt: %C) -> %return.param_patt: %C {
  200. // CHECK:STDOUT: !entry:
  201. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  202. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  203. // CHECK:STDOUT: %impl.elem0: %.8a4 = impl_witness_access constants.%LeftShift.impl_witness, element0 [concrete = constants.%Op.df9]
  204. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %a.ref, %impl.elem0
  205. // CHECK:STDOUT: %.loc26: ref %C = splice_block %return {}
  206. // CHECK:STDOUT: %Op.call: init %C = call %bound_method(%a.ref, %b.ref) to %.loc26
  207. // CHECK:STDOUT: return %Op.call to %return
  208. // CHECK:STDOUT: }
  209. // CHECK:STDOUT:
  210. // CHECK:STDOUT: fn @TestAssign(%a.param_patt: %ptr.019, %b.param_patt: %C) {
  211. // CHECK:STDOUT: !entry:
  212. // CHECK:STDOUT: %a.ref: %ptr.019 = name_ref a, %a
  213. // CHECK:STDOUT: %.loc31: ref %C = deref %a.ref
  214. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  215. // CHECK:STDOUT: %impl.elem0: %.ac9 = impl_witness_access constants.%LeftShiftAssign.impl_witness, element0 [concrete = constants.%Op.8fc]
  216. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %.loc31, %impl.elem0
  217. // CHECK:STDOUT: %addr: %ptr.019 = addr_of %.loc31
  218. // CHECK:STDOUT: %Op.call: init %empty_tuple.type = call %bound_method(%addr, %b.ref)
  219. // CHECK:STDOUT: return
  220. // CHECK:STDOUT: }
  221. // CHECK:STDOUT: