ordered.carbon 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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/ordered.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/operators/overloaded/ordered.carbon
  10. // --- user.carbon
  11. package User;
  12. class C {};
  13. impl C as Core.Ordered {
  14. fn Less[self: C](other: C) -> bool;
  15. fn LessOrEquivalent[self: C](other: C) -> bool;
  16. fn Greater[self: C](other: C) -> bool;
  17. fn GreaterOrEquivalent[self: C](other: C) -> bool;
  18. }
  19. fn TestLess(a: C, b: C) -> bool {
  20. return a < b;
  21. }
  22. fn TestLessEqual(a: C, b: C) -> bool {
  23. return a <= b;
  24. }
  25. fn TestGreater(a: C, b: C) -> bool {
  26. return a > b;
  27. }
  28. fn TestGreaterEqual(a: C, b: C) -> bool {
  29. return a >= b;
  30. }
  31. // --- fail_no_impl.carbon
  32. package FailNoImpl;
  33. class D {};
  34. fn TestLess(a: D, b: D) -> bool {
  35. // CHECK:STDERR: fail_no_impl.carbon:[[@LINE+4]]:10: error: cannot access member of interface `Core.Ordered` in type `D` that does not implement that interface [MissingImplInMemberAccess]
  36. // CHECK:STDERR: return a < b;
  37. // CHECK:STDERR: ^~~~~
  38. // CHECK:STDERR:
  39. return a < b;
  40. }
  41. fn TestLessEqual(a: D, b: D) -> bool {
  42. // CHECK:STDERR: fail_no_impl.carbon:[[@LINE+4]]:10: error: cannot access member of interface `Core.Ordered` in type `D` that does not implement that interface [MissingImplInMemberAccess]
  43. // CHECK:STDERR: return a <= b;
  44. // CHECK:STDERR: ^~~~~~
  45. // CHECK:STDERR:
  46. return a <= b;
  47. }
  48. fn TestGreater(a: D, b: D) -> bool {
  49. // CHECK:STDERR: fail_no_impl.carbon:[[@LINE+4]]:10: error: cannot access member of interface `Core.Ordered` in type `D` that does not implement that interface [MissingImplInMemberAccess]
  50. // CHECK:STDERR: return a > b;
  51. // CHECK:STDERR: ^~~~~
  52. // CHECK:STDERR:
  53. return a > b;
  54. }
  55. fn TestGreaterEqual(a: D, b: D) -> bool {
  56. // CHECK:STDERR: fail_no_impl.carbon:[[@LINE+4]]:10: error: cannot access member of interface `Core.Ordered` in type `D` that does not implement that interface [MissingImplInMemberAccess]
  57. // CHECK:STDERR: return a >= b;
  58. // CHECK:STDERR: ^~~~~~
  59. // CHECK:STDERR:
  60. return a >= b;
  61. }
  62. // CHECK:STDOUT: --- user.carbon
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: constants {
  65. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  66. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  67. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  68. // CHECK:STDOUT: %Ordered.type: type = facet_type <@Ordered> [concrete]
  69. // CHECK:STDOUT: %Less.type.341: type = fn_type @Less.1 [concrete]
  70. // CHECK:STDOUT: %pattern_type.831: type = pattern_type bool [concrete]
  71. // CHECK:STDOUT: %LessOrEquivalent.type.859: type = fn_type @LessOrEquivalent.1 [concrete]
  72. // CHECK:STDOUT: %Greater.type.270: type = fn_type @Greater.1 [concrete]
  73. // CHECK:STDOUT: %GreaterOrEquivalent.type.8af: type = fn_type @GreaterOrEquivalent.1 [concrete]
  74. // CHECK:STDOUT: %Ordered.impl_witness: <witness> = impl_witness file.%Ordered.impl_witness_table [concrete]
  75. // CHECK:STDOUT: %pattern_type.c48: type = pattern_type %C [concrete]
  76. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [concrete]
  77. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [concrete]
  78. // CHECK:STDOUT: %Less.type.25a: type = fn_type @Less.2 [concrete]
  79. // CHECK:STDOUT: %Less.738: %Less.type.25a = struct_value () [concrete]
  80. // CHECK:STDOUT: %LessOrEquivalent.type.478: type = fn_type @LessOrEquivalent.2 [concrete]
  81. // CHECK:STDOUT: %LessOrEquivalent.010: %LessOrEquivalent.type.478 = struct_value () [concrete]
  82. // CHECK:STDOUT: %Greater.type.0a1: type = fn_type @Greater.2 [concrete]
  83. // CHECK:STDOUT: %Greater.afe: %Greater.type.0a1 = struct_value () [concrete]
  84. // CHECK:STDOUT: %GreaterOrEquivalent.type.caf: type = fn_type @GreaterOrEquivalent.2 [concrete]
  85. // CHECK:STDOUT: %GreaterOrEquivalent.03b: %GreaterOrEquivalent.type.caf = struct_value () [concrete]
  86. // CHECK:STDOUT: %Ordered.facet: %Ordered.type = facet_value %C, (%Ordered.impl_witness) [concrete]
  87. // CHECK:STDOUT: %TestLess.type: type = fn_type @TestLess [concrete]
  88. // CHECK:STDOUT: %TestLess: %TestLess.type = struct_value () [concrete]
  89. // CHECK:STDOUT: %.d60: type = fn_type_with_self_type %Less.type.341, %Ordered.facet [concrete]
  90. // CHECK:STDOUT: %TestLessEqual.type: type = fn_type @TestLessEqual [concrete]
  91. // CHECK:STDOUT: %TestLessEqual: %TestLessEqual.type = struct_value () [concrete]
  92. // CHECK:STDOUT: %.6b1: type = fn_type_with_self_type %LessOrEquivalent.type.859, %Ordered.facet [concrete]
  93. // CHECK:STDOUT: %TestGreater.type: type = fn_type @TestGreater [concrete]
  94. // CHECK:STDOUT: %TestGreater: %TestGreater.type = struct_value () [concrete]
  95. // CHECK:STDOUT: %.5ae: type = fn_type_with_self_type %Greater.type.270, %Ordered.facet [concrete]
  96. // CHECK:STDOUT: %TestGreaterEqual.type: type = fn_type @TestGreaterEqual [concrete]
  97. // CHECK:STDOUT: %TestGreaterEqual: %TestGreaterEqual.type = struct_value () [concrete]
  98. // CHECK:STDOUT: %.0c4: type = fn_type_with_self_type %GreaterOrEquivalent.type.8af, %Ordered.facet [concrete]
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: imports {
  102. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  103. // CHECK:STDOUT: .Ordered = %Core.Ordered
  104. // CHECK:STDOUT: .Bool = %Core.Bool
  105. // CHECK:STDOUT: import Core//prelude
  106. // CHECK:STDOUT: import Core//prelude/...
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT: %Core.Ordered: type = import_ref Core//prelude/operators/comparison, Ordered, loaded [concrete = constants.%Ordered.type]
  109. // CHECK:STDOUT: %Core.Bool: %Bool.type = import_ref Core//prelude/types/bool, Bool, loaded [concrete = constants.%Bool]
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT:
  112. // CHECK:STDOUT: file {
  113. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  114. // CHECK:STDOUT: .Core = imports.%Core
  115. // CHECK:STDOUT: .C = %C.decl
  116. // CHECK:STDOUT: .TestLess = %TestLess.decl
  117. // CHECK:STDOUT: .TestLessEqual = %TestLessEqual.decl
  118. // CHECK:STDOUT: .TestGreater = %TestGreater.decl
  119. // CHECK:STDOUT: .TestGreaterEqual = %TestGreaterEqual.decl
  120. // CHECK:STDOUT: }
  121. // CHECK:STDOUT: %Core.import = import Core
  122. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  123. // CHECK:STDOUT: impl_decl @impl.d54 [concrete] {} {
  124. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  125. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, imports.%Core [concrete = imports.%Core]
  126. // CHECK:STDOUT: %Ordered.ref: type = name_ref Ordered, imports.%Core.Ordered [concrete = constants.%Ordered.type]
  127. // CHECK:STDOUT: }
  128. // CHECK:STDOUT: %Ordered.impl_witness_table = impl_witness_table (@impl.d54.%Less.decl, @impl.d54.%LessOrEquivalent.decl, @impl.d54.%Greater.decl, @impl.d54.%GreaterOrEquivalent.decl), @impl.d54 [concrete]
  129. // CHECK:STDOUT: %Ordered.impl_witness: <witness> = impl_witness %Ordered.impl_witness_table [concrete = constants.%Ordered.impl_witness]
  130. // CHECK:STDOUT: %TestLess.decl: %TestLess.type = fn_decl @TestLess [concrete = constants.%TestLess] {
  131. // CHECK:STDOUT: %a.patt: %pattern_type.c48 = binding_pattern a [concrete]
  132. // CHECK:STDOUT: %a.param_patt: %pattern_type.c48 = value_param_pattern %a.patt, call_param0 [concrete]
  133. // CHECK:STDOUT: %b.patt: %pattern_type.c48 = binding_pattern b [concrete]
  134. // CHECK:STDOUT: %b.param_patt: %pattern_type.c48 = value_param_pattern %b.patt, call_param1 [concrete]
  135. // CHECK:STDOUT: %return.patt: %pattern_type.831 = return_slot_pattern [concrete]
  136. // CHECK:STDOUT: %return.param_patt: %pattern_type.831 = out_param_pattern %return.patt, call_param2 [concrete]
  137. // CHECK:STDOUT: } {
  138. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [concrete = bool]
  139. // CHECK:STDOUT: %.loc13_28.1: type = value_of_initializer %bool.make_type [concrete = bool]
  140. // CHECK:STDOUT: %.loc13_28.2: type = converted %bool.make_type, %.loc13_28.1 [concrete = bool]
  141. // CHECK:STDOUT: %a.param: %C = value_param call_param0
  142. // CHECK:STDOUT: %C.ref.loc13_16: type = name_ref C, file.%C.decl [concrete = constants.%C]
  143. // CHECK:STDOUT: %a: %C = bind_name a, %a.param
  144. // CHECK:STDOUT: %b.param: %C = value_param call_param1
  145. // CHECK:STDOUT: %C.ref.loc13_22: type = name_ref C, file.%C.decl [concrete = constants.%C]
  146. // CHECK:STDOUT: %b: %C = bind_name b, %b.param
  147. // CHECK:STDOUT: %return.param: ref bool = out_param call_param2
  148. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  149. // CHECK:STDOUT: }
  150. // CHECK:STDOUT: %TestLessEqual.decl: %TestLessEqual.type = fn_decl @TestLessEqual [concrete = constants.%TestLessEqual] {
  151. // CHECK:STDOUT: %a.patt: %pattern_type.c48 = binding_pattern a [concrete]
  152. // CHECK:STDOUT: %a.param_patt: %pattern_type.c48 = value_param_pattern %a.patt, call_param0 [concrete]
  153. // CHECK:STDOUT: %b.patt: %pattern_type.c48 = binding_pattern b [concrete]
  154. // CHECK:STDOUT: %b.param_patt: %pattern_type.c48 = value_param_pattern %b.patt, call_param1 [concrete]
  155. // CHECK:STDOUT: %return.patt: %pattern_type.831 = return_slot_pattern [concrete]
  156. // CHECK:STDOUT: %return.param_patt: %pattern_type.831 = out_param_pattern %return.patt, call_param2 [concrete]
  157. // CHECK:STDOUT: } {
  158. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [concrete = bool]
  159. // CHECK:STDOUT: %.loc17_33.1: type = value_of_initializer %bool.make_type [concrete = bool]
  160. // CHECK:STDOUT: %.loc17_33.2: type = converted %bool.make_type, %.loc17_33.1 [concrete = bool]
  161. // CHECK:STDOUT: %a.param: %C = value_param call_param0
  162. // CHECK:STDOUT: %C.ref.loc17_21: type = name_ref C, file.%C.decl [concrete = constants.%C]
  163. // CHECK:STDOUT: %a: %C = bind_name a, %a.param
  164. // CHECK:STDOUT: %b.param: %C = value_param call_param1
  165. // CHECK:STDOUT: %C.ref.loc17_27: type = name_ref C, file.%C.decl [concrete = constants.%C]
  166. // CHECK:STDOUT: %b: %C = bind_name b, %b.param
  167. // CHECK:STDOUT: %return.param: ref bool = out_param call_param2
  168. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  169. // CHECK:STDOUT: }
  170. // CHECK:STDOUT: %TestGreater.decl: %TestGreater.type = fn_decl @TestGreater [concrete = constants.%TestGreater] {
  171. // CHECK:STDOUT: %a.patt: %pattern_type.c48 = binding_pattern a [concrete]
  172. // CHECK:STDOUT: %a.param_patt: %pattern_type.c48 = value_param_pattern %a.patt, call_param0 [concrete]
  173. // CHECK:STDOUT: %b.patt: %pattern_type.c48 = binding_pattern b [concrete]
  174. // CHECK:STDOUT: %b.param_patt: %pattern_type.c48 = value_param_pattern %b.patt, call_param1 [concrete]
  175. // CHECK:STDOUT: %return.patt: %pattern_type.831 = return_slot_pattern [concrete]
  176. // CHECK:STDOUT: %return.param_patt: %pattern_type.831 = out_param_pattern %return.patt, call_param2 [concrete]
  177. // CHECK:STDOUT: } {
  178. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [concrete = bool]
  179. // CHECK:STDOUT: %.loc21_31.1: type = value_of_initializer %bool.make_type [concrete = bool]
  180. // CHECK:STDOUT: %.loc21_31.2: type = converted %bool.make_type, %.loc21_31.1 [concrete = bool]
  181. // CHECK:STDOUT: %a.param: %C = value_param call_param0
  182. // CHECK:STDOUT: %C.ref.loc21_19: type = name_ref C, file.%C.decl [concrete = constants.%C]
  183. // CHECK:STDOUT: %a: %C = bind_name a, %a.param
  184. // CHECK:STDOUT: %b.param: %C = value_param call_param1
  185. // CHECK:STDOUT: %C.ref.loc21_25: type = name_ref C, file.%C.decl [concrete = constants.%C]
  186. // CHECK:STDOUT: %b: %C = bind_name b, %b.param
  187. // CHECK:STDOUT: %return.param: ref bool = out_param call_param2
  188. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  189. // CHECK:STDOUT: }
  190. // CHECK:STDOUT: %TestGreaterEqual.decl: %TestGreaterEqual.type = fn_decl @TestGreaterEqual [concrete = constants.%TestGreaterEqual] {
  191. // CHECK:STDOUT: %a.patt: %pattern_type.c48 = binding_pattern a [concrete]
  192. // CHECK:STDOUT: %a.param_patt: %pattern_type.c48 = value_param_pattern %a.patt, call_param0 [concrete]
  193. // CHECK:STDOUT: %b.patt: %pattern_type.c48 = binding_pattern b [concrete]
  194. // CHECK:STDOUT: %b.param_patt: %pattern_type.c48 = value_param_pattern %b.patt, call_param1 [concrete]
  195. // CHECK:STDOUT: %return.patt: %pattern_type.831 = return_slot_pattern [concrete]
  196. // CHECK:STDOUT: %return.param_patt: %pattern_type.831 = out_param_pattern %return.patt, call_param2 [concrete]
  197. // CHECK:STDOUT: } {
  198. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [concrete = bool]
  199. // CHECK:STDOUT: %.loc25_36.1: type = value_of_initializer %bool.make_type [concrete = bool]
  200. // CHECK:STDOUT: %.loc25_36.2: type = converted %bool.make_type, %.loc25_36.1 [concrete = bool]
  201. // CHECK:STDOUT: %a.param: %C = value_param call_param0
  202. // CHECK:STDOUT: %C.ref.loc25_24: type = name_ref C, file.%C.decl [concrete = constants.%C]
  203. // CHECK:STDOUT: %a: %C = bind_name a, %a.param
  204. // CHECK:STDOUT: %b.param: %C = value_param call_param1
  205. // CHECK:STDOUT: %C.ref.loc25_30: type = name_ref C, file.%C.decl [concrete = constants.%C]
  206. // CHECK:STDOUT: %b: %C = bind_name b, %b.param
  207. // CHECK:STDOUT: %return.param: ref bool = out_param call_param2
  208. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  209. // CHECK:STDOUT: }
  210. // CHECK:STDOUT: }
  211. // CHECK:STDOUT:
  212. // CHECK:STDOUT: impl @impl.d54: %C.ref as %Ordered.ref {
  213. // CHECK:STDOUT: %Less.decl: %Less.type.25a = fn_decl @Less.2 [concrete = constants.%Less.738] {
  214. // CHECK:STDOUT: %self.patt: %pattern_type.c48 = binding_pattern self [concrete]
  215. // CHECK:STDOUT: %self.param_patt: %pattern_type.c48 = value_param_pattern %self.patt, call_param0 [concrete]
  216. // CHECK:STDOUT: %other.patt: %pattern_type.c48 = binding_pattern other [concrete]
  217. // CHECK:STDOUT: %other.param_patt: %pattern_type.c48 = value_param_pattern %other.patt, call_param1 [concrete]
  218. // CHECK:STDOUT: %return.patt: %pattern_type.831 = return_slot_pattern [concrete]
  219. // CHECK:STDOUT: %return.param_patt: %pattern_type.831 = out_param_pattern %return.patt, call_param2 [concrete]
  220. // CHECK:STDOUT: } {
  221. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [concrete = bool]
  222. // CHECK:STDOUT: %.loc7_33.1: type = value_of_initializer %bool.make_type [concrete = bool]
  223. // CHECK:STDOUT: %.loc7_33.2: type = converted %bool.make_type, %.loc7_33.1 [concrete = bool]
  224. // CHECK:STDOUT: %self.param: %C = value_param call_param0
  225. // CHECK:STDOUT: %C.ref.loc7_17: type = name_ref C, file.%C.decl [concrete = constants.%C]
  226. // CHECK:STDOUT: %self: %C = bind_name self, %self.param
  227. // CHECK:STDOUT: %other.param: %C = value_param call_param1
  228. // CHECK:STDOUT: %C.ref.loc7_27: type = name_ref C, file.%C.decl [concrete = constants.%C]
  229. // CHECK:STDOUT: %other: %C = bind_name other, %other.param
  230. // CHECK:STDOUT: %return.param: ref bool = out_param call_param2
  231. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  232. // CHECK:STDOUT: }
  233. // CHECK:STDOUT: %LessOrEquivalent.decl: %LessOrEquivalent.type.478 = fn_decl @LessOrEquivalent.2 [concrete = constants.%LessOrEquivalent.010] {
  234. // CHECK:STDOUT: %self.patt: %pattern_type.c48 = binding_pattern self [concrete]
  235. // CHECK:STDOUT: %self.param_patt: %pattern_type.c48 = value_param_pattern %self.patt, call_param0 [concrete]
  236. // CHECK:STDOUT: %other.patt: %pattern_type.c48 = binding_pattern other [concrete]
  237. // CHECK:STDOUT: %other.param_patt: %pattern_type.c48 = value_param_pattern %other.patt, call_param1 [concrete]
  238. // CHECK:STDOUT: %return.patt: %pattern_type.831 = return_slot_pattern [concrete]
  239. // CHECK:STDOUT: %return.param_patt: %pattern_type.831 = out_param_pattern %return.patt, call_param2 [concrete]
  240. // CHECK:STDOUT: } {
  241. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [concrete = bool]
  242. // CHECK:STDOUT: %.loc8_45.1: type = value_of_initializer %bool.make_type [concrete = bool]
  243. // CHECK:STDOUT: %.loc8_45.2: type = converted %bool.make_type, %.loc8_45.1 [concrete = bool]
  244. // CHECK:STDOUT: %self.param: %C = value_param call_param0
  245. // CHECK:STDOUT: %C.ref.loc8_29: type = name_ref C, file.%C.decl [concrete = constants.%C]
  246. // CHECK:STDOUT: %self: %C = bind_name self, %self.param
  247. // CHECK:STDOUT: %other.param: %C = value_param call_param1
  248. // CHECK:STDOUT: %C.ref.loc8_39: type = name_ref C, file.%C.decl [concrete = constants.%C]
  249. // CHECK:STDOUT: %other: %C = bind_name other, %other.param
  250. // CHECK:STDOUT: %return.param: ref bool = out_param call_param2
  251. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  252. // CHECK:STDOUT: }
  253. // CHECK:STDOUT: %Greater.decl: %Greater.type.0a1 = fn_decl @Greater.2 [concrete = constants.%Greater.afe] {
  254. // CHECK:STDOUT: %self.patt: %pattern_type.c48 = binding_pattern self [concrete]
  255. // CHECK:STDOUT: %self.param_patt: %pattern_type.c48 = value_param_pattern %self.patt, call_param0 [concrete]
  256. // CHECK:STDOUT: %other.patt: %pattern_type.c48 = binding_pattern other [concrete]
  257. // CHECK:STDOUT: %other.param_patt: %pattern_type.c48 = value_param_pattern %other.patt, call_param1 [concrete]
  258. // CHECK:STDOUT: %return.patt: %pattern_type.831 = return_slot_pattern [concrete]
  259. // CHECK:STDOUT: %return.param_patt: %pattern_type.831 = out_param_pattern %return.patt, call_param2 [concrete]
  260. // CHECK:STDOUT: } {
  261. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [concrete = bool]
  262. // CHECK:STDOUT: %.loc9_36.1: type = value_of_initializer %bool.make_type [concrete = bool]
  263. // CHECK:STDOUT: %.loc9_36.2: type = converted %bool.make_type, %.loc9_36.1 [concrete = bool]
  264. // CHECK:STDOUT: %self.param: %C = value_param call_param0
  265. // CHECK:STDOUT: %C.ref.loc9_20: type = name_ref C, file.%C.decl [concrete = constants.%C]
  266. // CHECK:STDOUT: %self: %C = bind_name self, %self.param
  267. // CHECK:STDOUT: %other.param: %C = value_param call_param1
  268. // CHECK:STDOUT: %C.ref.loc9_30: type = name_ref C, file.%C.decl [concrete = constants.%C]
  269. // CHECK:STDOUT: %other: %C = bind_name other, %other.param
  270. // CHECK:STDOUT: %return.param: ref bool = out_param call_param2
  271. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  272. // CHECK:STDOUT: }
  273. // CHECK:STDOUT: %GreaterOrEquivalent.decl: %GreaterOrEquivalent.type.caf = fn_decl @GreaterOrEquivalent.2 [concrete = constants.%GreaterOrEquivalent.03b] {
  274. // CHECK:STDOUT: %self.patt: %pattern_type.c48 = binding_pattern self [concrete]
  275. // CHECK:STDOUT: %self.param_patt: %pattern_type.c48 = value_param_pattern %self.patt, call_param0 [concrete]
  276. // CHECK:STDOUT: %other.patt: %pattern_type.c48 = binding_pattern other [concrete]
  277. // CHECK:STDOUT: %other.param_patt: %pattern_type.c48 = value_param_pattern %other.patt, call_param1 [concrete]
  278. // CHECK:STDOUT: %return.patt: %pattern_type.831 = return_slot_pattern [concrete]
  279. // CHECK:STDOUT: %return.param_patt: %pattern_type.831 = out_param_pattern %return.patt, call_param2 [concrete]
  280. // CHECK:STDOUT: } {
  281. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [concrete = bool]
  282. // CHECK:STDOUT: %.loc10_48.1: type = value_of_initializer %bool.make_type [concrete = bool]
  283. // CHECK:STDOUT: %.loc10_48.2: type = converted %bool.make_type, %.loc10_48.1 [concrete = bool]
  284. // CHECK:STDOUT: %self.param: %C = value_param call_param0
  285. // CHECK:STDOUT: %C.ref.loc10_32: type = name_ref C, file.%C.decl [concrete = constants.%C]
  286. // CHECK:STDOUT: %self: %C = bind_name self, %self.param
  287. // CHECK:STDOUT: %other.param: %C = value_param call_param1
  288. // CHECK:STDOUT: %C.ref.loc10_42: type = name_ref C, file.%C.decl [concrete = constants.%C]
  289. // CHECK:STDOUT: %other: %C = bind_name other, %other.param
  290. // CHECK:STDOUT: %return.param: ref bool = out_param call_param2
  291. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  292. // CHECK:STDOUT: }
  293. // CHECK:STDOUT:
  294. // CHECK:STDOUT: !members:
  295. // CHECK:STDOUT: .C = <poisoned>
  296. // CHECK:STDOUT: .Less = %Less.decl
  297. // CHECK:STDOUT: .LessOrEquivalent = %LessOrEquivalent.decl
  298. // CHECK:STDOUT: .Greater = %Greater.decl
  299. // CHECK:STDOUT: .GreaterOrEquivalent = %GreaterOrEquivalent.decl
  300. // CHECK:STDOUT: witness = file.%Ordered.impl_witness
  301. // CHECK:STDOUT: }
  302. // CHECK:STDOUT:
  303. // CHECK:STDOUT: class @C {
  304. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  305. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
  306. // CHECK:STDOUT: complete_type_witness = %complete_type
  307. // CHECK:STDOUT:
  308. // CHECK:STDOUT: !members:
  309. // CHECK:STDOUT: .Self = constants.%C
  310. // CHECK:STDOUT: }
  311. // CHECK:STDOUT:
  312. // CHECK:STDOUT: fn @Less.2(%self.param: %C, %other.param: %C) -> bool;
  313. // CHECK:STDOUT:
  314. // CHECK:STDOUT: fn @LessOrEquivalent.2(%self.param: %C, %other.param: %C) -> bool;
  315. // CHECK:STDOUT:
  316. // CHECK:STDOUT: fn @Greater.2(%self.param: %C, %other.param: %C) -> bool;
  317. // CHECK:STDOUT:
  318. // CHECK:STDOUT: fn @GreaterOrEquivalent.2(%self.param: %C, %other.param: %C) -> bool;
  319. // CHECK:STDOUT:
  320. // CHECK:STDOUT: fn @TestLess(%a.param: %C, %b.param: %C) -> bool {
  321. // CHECK:STDOUT: !entry:
  322. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  323. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  324. // CHECK:STDOUT: %impl.elem0: %.d60 = impl_witness_access constants.%Ordered.impl_witness, element0 [concrete = constants.%Less.738]
  325. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %a.ref, %impl.elem0
  326. // CHECK:STDOUT: %Less.call: init bool = call %bound_method(%a.ref, %b.ref)
  327. // CHECK:STDOUT: %.loc14_15.1: bool = value_of_initializer %Less.call
  328. // CHECK:STDOUT: %.loc14_15.2: bool = converted %Less.call, %.loc14_15.1
  329. // CHECK:STDOUT: return %.loc14_15.2
  330. // CHECK:STDOUT: }
  331. // CHECK:STDOUT:
  332. // CHECK:STDOUT: fn @TestLessEqual(%a.param: %C, %b.param: %C) -> bool {
  333. // CHECK:STDOUT: !entry:
  334. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  335. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  336. // CHECK:STDOUT: %impl.elem1: %.6b1 = impl_witness_access constants.%Ordered.impl_witness, element1 [concrete = constants.%LessOrEquivalent.010]
  337. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %a.ref, %impl.elem1
  338. // CHECK:STDOUT: %LessOrEquivalent.call: init bool = call %bound_method(%a.ref, %b.ref)
  339. // CHECK:STDOUT: %.loc18_16.1: bool = value_of_initializer %LessOrEquivalent.call
  340. // CHECK:STDOUT: %.loc18_16.2: bool = converted %LessOrEquivalent.call, %.loc18_16.1
  341. // CHECK:STDOUT: return %.loc18_16.2
  342. // CHECK:STDOUT: }
  343. // CHECK:STDOUT:
  344. // CHECK:STDOUT: fn @TestGreater(%a.param: %C, %b.param: %C) -> bool {
  345. // CHECK:STDOUT: !entry:
  346. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  347. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  348. // CHECK:STDOUT: %impl.elem2: %.5ae = impl_witness_access constants.%Ordered.impl_witness, element2 [concrete = constants.%Greater.afe]
  349. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %a.ref, %impl.elem2
  350. // CHECK:STDOUT: %Greater.call: init bool = call %bound_method(%a.ref, %b.ref)
  351. // CHECK:STDOUT: %.loc22_15.1: bool = value_of_initializer %Greater.call
  352. // CHECK:STDOUT: %.loc22_15.2: bool = converted %Greater.call, %.loc22_15.1
  353. // CHECK:STDOUT: return %.loc22_15.2
  354. // CHECK:STDOUT: }
  355. // CHECK:STDOUT:
  356. // CHECK:STDOUT: fn @TestGreaterEqual(%a.param: %C, %b.param: %C) -> bool {
  357. // CHECK:STDOUT: !entry:
  358. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  359. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  360. // CHECK:STDOUT: %impl.elem3: %.0c4 = impl_witness_access constants.%Ordered.impl_witness, element3 [concrete = constants.%GreaterOrEquivalent.03b]
  361. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %a.ref, %impl.elem3
  362. // CHECK:STDOUT: %GreaterOrEquivalent.call: init bool = call %bound_method(%a.ref, %b.ref)
  363. // CHECK:STDOUT: %.loc26_16.1: bool = value_of_initializer %GreaterOrEquivalent.call
  364. // CHECK:STDOUT: %.loc26_16.2: bool = converted %GreaterOrEquivalent.call, %.loc26_16.1
  365. // CHECK:STDOUT: return %.loc26_16.2
  366. // CHECK:STDOUT: }
  367. // CHECK:STDOUT:
  368. // CHECK:STDOUT: --- fail_no_impl.carbon
  369. // CHECK:STDOUT:
  370. // CHECK:STDOUT: constants {
  371. // CHECK:STDOUT: %D: type = class_type @D [concrete]
  372. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  373. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  374. // CHECK:STDOUT: %pattern_type.510: type = pattern_type %D [concrete]
  375. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [concrete]
  376. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [concrete]
  377. // CHECK:STDOUT: %pattern_type.831: type = pattern_type bool [concrete]
  378. // CHECK:STDOUT: %TestLess.type: type = fn_type @TestLess [concrete]
  379. // CHECK:STDOUT: %TestLess: %TestLess.type = struct_value () [concrete]
  380. // CHECK:STDOUT: %Ordered.type: type = facet_type <@Ordered> [concrete]
  381. // CHECK:STDOUT: %TestLessEqual.type: type = fn_type @TestLessEqual [concrete]
  382. // CHECK:STDOUT: %TestLessEqual: %TestLessEqual.type = struct_value () [concrete]
  383. // CHECK:STDOUT: %TestGreater.type: type = fn_type @TestGreater [concrete]
  384. // CHECK:STDOUT: %TestGreater: %TestGreater.type = struct_value () [concrete]
  385. // CHECK:STDOUT: %TestGreaterEqual.type: type = fn_type @TestGreaterEqual [concrete]
  386. // CHECK:STDOUT: %TestGreaterEqual: %TestGreaterEqual.type = struct_value () [concrete]
  387. // CHECK:STDOUT: }
  388. // CHECK:STDOUT:
  389. // CHECK:STDOUT: imports {
  390. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  391. // CHECK:STDOUT: .Bool = %Core.Bool
  392. // CHECK:STDOUT: .Ordered = %Core.Ordered
  393. // CHECK:STDOUT: import Core//prelude
  394. // CHECK:STDOUT: import Core//prelude/...
  395. // CHECK:STDOUT: }
  396. // CHECK:STDOUT: %Core.Bool: %Bool.type = import_ref Core//prelude/types/bool, Bool, loaded [concrete = constants.%Bool]
  397. // CHECK:STDOUT: %Core.Ordered: type = import_ref Core//prelude/operators/comparison, Ordered, loaded [concrete = constants.%Ordered.type]
  398. // CHECK:STDOUT: }
  399. // CHECK:STDOUT:
  400. // CHECK:STDOUT: file {
  401. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  402. // CHECK:STDOUT: .Core = imports.%Core
  403. // CHECK:STDOUT: .D = %D.decl
  404. // CHECK:STDOUT: .TestLess = %TestLess.decl
  405. // CHECK:STDOUT: .TestLessEqual = %TestLessEqual.decl
  406. // CHECK:STDOUT: .TestGreater = %TestGreater.decl
  407. // CHECK:STDOUT: .TestGreaterEqual = %TestGreaterEqual.decl
  408. // CHECK:STDOUT: }
  409. // CHECK:STDOUT: %Core.import = import Core
  410. // CHECK:STDOUT: %D.decl: type = class_decl @D [concrete = constants.%D] {} {}
  411. // CHECK:STDOUT: %TestLess.decl: %TestLess.type = fn_decl @TestLess [concrete = constants.%TestLess] {
  412. // CHECK:STDOUT: %a.patt: %pattern_type.510 = binding_pattern a [concrete]
  413. // CHECK:STDOUT: %a.param_patt: %pattern_type.510 = value_param_pattern %a.patt, call_param0 [concrete]
  414. // CHECK:STDOUT: %b.patt: %pattern_type.510 = binding_pattern b [concrete]
  415. // CHECK:STDOUT: %b.param_patt: %pattern_type.510 = value_param_pattern %b.patt, call_param1 [concrete]
  416. // CHECK:STDOUT: %return.patt: %pattern_type.831 = return_slot_pattern [concrete]
  417. // CHECK:STDOUT: %return.param_patt: %pattern_type.831 = out_param_pattern %return.patt, call_param2 [concrete]
  418. // CHECK:STDOUT: } {
  419. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [concrete = bool]
  420. // CHECK:STDOUT: %.loc6_28.1: type = value_of_initializer %bool.make_type [concrete = bool]
  421. // CHECK:STDOUT: %.loc6_28.2: type = converted %bool.make_type, %.loc6_28.1 [concrete = bool]
  422. // CHECK:STDOUT: %a.param: %D = value_param call_param0
  423. // CHECK:STDOUT: %D.ref.loc6_16: type = name_ref D, file.%D.decl [concrete = constants.%D]
  424. // CHECK:STDOUT: %a: %D = bind_name a, %a.param
  425. // CHECK:STDOUT: %b.param: %D = value_param call_param1
  426. // CHECK:STDOUT: %D.ref.loc6_22: type = name_ref D, file.%D.decl [concrete = constants.%D]
  427. // CHECK:STDOUT: %b: %D = bind_name b, %b.param
  428. // CHECK:STDOUT: %return.param: ref bool = out_param call_param2
  429. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  430. // CHECK:STDOUT: }
  431. // CHECK:STDOUT: %TestLessEqual.decl: %TestLessEqual.type = fn_decl @TestLessEqual [concrete = constants.%TestLessEqual] {
  432. // CHECK:STDOUT: %a.patt: %pattern_type.510 = binding_pattern a [concrete]
  433. // CHECK:STDOUT: %a.param_patt: %pattern_type.510 = value_param_pattern %a.patt, call_param0 [concrete]
  434. // CHECK:STDOUT: %b.patt: %pattern_type.510 = binding_pattern b [concrete]
  435. // CHECK:STDOUT: %b.param_patt: %pattern_type.510 = value_param_pattern %b.patt, call_param1 [concrete]
  436. // CHECK:STDOUT: %return.patt: %pattern_type.831 = return_slot_pattern [concrete]
  437. // CHECK:STDOUT: %return.param_patt: %pattern_type.831 = out_param_pattern %return.patt, call_param2 [concrete]
  438. // CHECK:STDOUT: } {
  439. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [concrete = bool]
  440. // CHECK:STDOUT: %.loc14_33.1: type = value_of_initializer %bool.make_type [concrete = bool]
  441. // CHECK:STDOUT: %.loc14_33.2: type = converted %bool.make_type, %.loc14_33.1 [concrete = bool]
  442. // CHECK:STDOUT: %a.param: %D = value_param call_param0
  443. // CHECK:STDOUT: %D.ref.loc14_21: type = name_ref D, file.%D.decl [concrete = constants.%D]
  444. // CHECK:STDOUT: %a: %D = bind_name a, %a.param
  445. // CHECK:STDOUT: %b.param: %D = value_param call_param1
  446. // CHECK:STDOUT: %D.ref.loc14_27: type = name_ref D, file.%D.decl [concrete = constants.%D]
  447. // CHECK:STDOUT: %b: %D = bind_name b, %b.param
  448. // CHECK:STDOUT: %return.param: ref bool = out_param call_param2
  449. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  450. // CHECK:STDOUT: }
  451. // CHECK:STDOUT: %TestGreater.decl: %TestGreater.type = fn_decl @TestGreater [concrete = constants.%TestGreater] {
  452. // CHECK:STDOUT: %a.patt: %pattern_type.510 = binding_pattern a [concrete]
  453. // CHECK:STDOUT: %a.param_patt: %pattern_type.510 = value_param_pattern %a.patt, call_param0 [concrete]
  454. // CHECK:STDOUT: %b.patt: %pattern_type.510 = binding_pattern b [concrete]
  455. // CHECK:STDOUT: %b.param_patt: %pattern_type.510 = value_param_pattern %b.patt, call_param1 [concrete]
  456. // CHECK:STDOUT: %return.patt: %pattern_type.831 = return_slot_pattern [concrete]
  457. // CHECK:STDOUT: %return.param_patt: %pattern_type.831 = out_param_pattern %return.patt, call_param2 [concrete]
  458. // CHECK:STDOUT: } {
  459. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [concrete = bool]
  460. // CHECK:STDOUT: %.loc22_31.1: type = value_of_initializer %bool.make_type [concrete = bool]
  461. // CHECK:STDOUT: %.loc22_31.2: type = converted %bool.make_type, %.loc22_31.1 [concrete = bool]
  462. // CHECK:STDOUT: %a.param: %D = value_param call_param0
  463. // CHECK:STDOUT: %D.ref.loc22_19: type = name_ref D, file.%D.decl [concrete = constants.%D]
  464. // CHECK:STDOUT: %a: %D = bind_name a, %a.param
  465. // CHECK:STDOUT: %b.param: %D = value_param call_param1
  466. // CHECK:STDOUT: %D.ref.loc22_25: type = name_ref D, file.%D.decl [concrete = constants.%D]
  467. // CHECK:STDOUT: %b: %D = bind_name b, %b.param
  468. // CHECK:STDOUT: %return.param: ref bool = out_param call_param2
  469. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  470. // CHECK:STDOUT: }
  471. // CHECK:STDOUT: %TestGreaterEqual.decl: %TestGreaterEqual.type = fn_decl @TestGreaterEqual [concrete = constants.%TestGreaterEqual] {
  472. // CHECK:STDOUT: %a.patt: %pattern_type.510 = binding_pattern a [concrete]
  473. // CHECK:STDOUT: %a.param_patt: %pattern_type.510 = value_param_pattern %a.patt, call_param0 [concrete]
  474. // CHECK:STDOUT: %b.patt: %pattern_type.510 = binding_pattern b [concrete]
  475. // CHECK:STDOUT: %b.param_patt: %pattern_type.510 = value_param_pattern %b.patt, call_param1 [concrete]
  476. // CHECK:STDOUT: %return.patt: %pattern_type.831 = return_slot_pattern [concrete]
  477. // CHECK:STDOUT: %return.param_patt: %pattern_type.831 = out_param_pattern %return.patt, call_param2 [concrete]
  478. // CHECK:STDOUT: } {
  479. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [concrete = bool]
  480. // CHECK:STDOUT: %.loc30_36.1: type = value_of_initializer %bool.make_type [concrete = bool]
  481. // CHECK:STDOUT: %.loc30_36.2: type = converted %bool.make_type, %.loc30_36.1 [concrete = bool]
  482. // CHECK:STDOUT: %a.param: %D = value_param call_param0
  483. // CHECK:STDOUT: %D.ref.loc30_24: type = name_ref D, file.%D.decl [concrete = constants.%D]
  484. // CHECK:STDOUT: %a: %D = bind_name a, %a.param
  485. // CHECK:STDOUT: %b.param: %D = value_param call_param1
  486. // CHECK:STDOUT: %D.ref.loc30_30: type = name_ref D, file.%D.decl [concrete = constants.%D]
  487. // CHECK:STDOUT: %b: %D = bind_name b, %b.param
  488. // CHECK:STDOUT: %return.param: ref bool = out_param call_param2
  489. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  490. // CHECK:STDOUT: }
  491. // CHECK:STDOUT: }
  492. // CHECK:STDOUT:
  493. // CHECK:STDOUT: class @D {
  494. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  495. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
  496. // CHECK:STDOUT: complete_type_witness = %complete_type
  497. // CHECK:STDOUT:
  498. // CHECK:STDOUT: !members:
  499. // CHECK:STDOUT: .Self = constants.%D
  500. // CHECK:STDOUT: }
  501. // CHECK:STDOUT:
  502. // CHECK:STDOUT: fn @TestLess(%a.param: %D, %b.param: %D) -> bool {
  503. // CHECK:STDOUT: !entry:
  504. // CHECK:STDOUT: %a.ref: %D = name_ref a, %a
  505. // CHECK:STDOUT: %b.ref: %D = name_ref b, %b
  506. // CHECK:STDOUT: return <error>
  507. // CHECK:STDOUT: }
  508. // CHECK:STDOUT:
  509. // CHECK:STDOUT: fn @TestLessEqual(%a.param: %D, %b.param: %D) -> bool {
  510. // CHECK:STDOUT: !entry:
  511. // CHECK:STDOUT: %a.ref: %D = name_ref a, %a
  512. // CHECK:STDOUT: %b.ref: %D = name_ref b, %b
  513. // CHECK:STDOUT: return <error>
  514. // CHECK:STDOUT: }
  515. // CHECK:STDOUT:
  516. // CHECK:STDOUT: fn @TestGreater(%a.param: %D, %b.param: %D) -> bool {
  517. // CHECK:STDOUT: !entry:
  518. // CHECK:STDOUT: %a.ref: %D = name_ref a, %a
  519. // CHECK:STDOUT: %b.ref: %D = name_ref b, %b
  520. // CHECK:STDOUT: return <error>
  521. // CHECK:STDOUT: }
  522. // CHECK:STDOUT:
  523. // CHECK:STDOUT: fn @TestGreaterEqual(%a.param: %D, %b.param: %D) -> bool {
  524. // CHECK:STDOUT: !entry:
  525. // CHECK:STDOUT: %a.ref: %D = name_ref a, %a
  526. // CHECK:STDOUT: %b.ref: %D = name_ref b, %b
  527. // CHECK:STDOUT: return <error>
  528. // CHECK:STDOUT: }
  529. // CHECK:STDOUT: