ordered.carbon 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  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 Ordered in type D that does not implement that interface.
  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 Ordered in type D that does not implement that interface.
  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 Ordered in type D that does not implement that interface.
  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+3]]:10: ERROR: Cannot access member of interface Ordered in type D that does not implement that interface.
  57. // CHECK:STDERR: return a >= b;
  58. // CHECK:STDERR: ^~~~~~
  59. return a >= b;
  60. }
  61. // CHECK:STDOUT: --- user.carbon
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: constants {
  64. // CHECK:STDOUT: %C: type = class_type @C [template]
  65. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  66. // CHECK:STDOUT: %.2: type = interface_type @Ordered [template]
  67. // CHECK:STDOUT: %Self: %.2 = bind_symbolic_name Self 0 [symbolic]
  68. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [template]
  69. // CHECK:STDOUT: %.3: type = tuple_type () [template]
  70. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [template]
  71. // CHECK:STDOUT: %Less.type.1: type = fn_type @Less.1 [template]
  72. // CHECK:STDOUT: %Less.1: %Less.type.1 = struct_value () [template]
  73. // CHECK:STDOUT: %LessOrEquivalent.type.1: type = fn_type @LessOrEquivalent.1 [template]
  74. // CHECK:STDOUT: %LessOrEquivalent.1: %LessOrEquivalent.type.1 = struct_value () [template]
  75. // CHECK:STDOUT: %Greater.type.1: type = fn_type @Greater.1 [template]
  76. // CHECK:STDOUT: %Greater.1: %Greater.type.1 = struct_value () [template]
  77. // CHECK:STDOUT: %GreaterOrEquivalent.type.1: type = fn_type @GreaterOrEquivalent.1 [template]
  78. // CHECK:STDOUT: %GreaterOrEquivalent.1: %GreaterOrEquivalent.type.1 = struct_value () [template]
  79. // CHECK:STDOUT: %Less.type.2: type = fn_type @Less.2 [template]
  80. // CHECK:STDOUT: %Less.2: %Less.type.2 = struct_value () [template]
  81. // CHECK:STDOUT: %LessOrEquivalent.type.2: type = fn_type @LessOrEquivalent.2 [template]
  82. // CHECK:STDOUT: %LessOrEquivalent.2: %LessOrEquivalent.type.2 = struct_value () [template]
  83. // CHECK:STDOUT: %Greater.type.2: type = fn_type @Greater.2 [template]
  84. // CHECK:STDOUT: %Greater.2: %Greater.type.2 = struct_value () [template]
  85. // CHECK:STDOUT: %GreaterOrEquivalent.type.2: type = fn_type @GreaterOrEquivalent.2 [template]
  86. // CHECK:STDOUT: %GreaterOrEquivalent.2: %GreaterOrEquivalent.type.2 = struct_value () [template]
  87. // CHECK:STDOUT: %.4: <witness> = interface_witness (%Less.1, %LessOrEquivalent.1, %Greater.1, %GreaterOrEquivalent.1) [template]
  88. // CHECK:STDOUT: %TestLess.type: type = fn_type @TestLess [template]
  89. // CHECK:STDOUT: %TestLess: %TestLess.type = struct_value () [template]
  90. // CHECK:STDOUT: %.5: type = ptr_type %.1 [template]
  91. // CHECK:STDOUT: %.6: type = assoc_entity_type @Ordered, %Less.type.2 [template]
  92. // CHECK:STDOUT: %.7: %.6 = assoc_entity element0, file.%import_ref.17 [template]
  93. // CHECK:STDOUT: %TestLessEqual.type: type = fn_type @TestLessEqual [template]
  94. // CHECK:STDOUT: %TestLessEqual: %TestLessEqual.type = struct_value () [template]
  95. // CHECK:STDOUT: %.8: type = assoc_entity_type @Ordered, %LessOrEquivalent.type.2 [template]
  96. // CHECK:STDOUT: %.9: %.8 = assoc_entity element1, file.%import_ref.20 [template]
  97. // CHECK:STDOUT: %TestGreater.type: type = fn_type @TestGreater [template]
  98. // CHECK:STDOUT: %TestGreater: %TestGreater.type = struct_value () [template]
  99. // CHECK:STDOUT: %.10: type = assoc_entity_type @Ordered, %Greater.type.2 [template]
  100. // CHECK:STDOUT: %.11: %.10 = assoc_entity element2, file.%import_ref.23 [template]
  101. // CHECK:STDOUT: %TestGreaterEqual.type: type = fn_type @TestGreaterEqual [template]
  102. // CHECK:STDOUT: %TestGreaterEqual: %TestGreaterEqual.type = struct_value () [template]
  103. // CHECK:STDOUT: %.12: type = assoc_entity_type @Ordered, %GreaterOrEquivalent.type.2 [template]
  104. // CHECK:STDOUT: %.13: %.12 = assoc_entity element3, file.%import_ref.26 [template]
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: file {
  108. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  109. // CHECK:STDOUT: .Core = %Core
  110. // CHECK:STDOUT: .C = %C.decl
  111. // CHECK:STDOUT: .TestLess = %TestLess.decl
  112. // CHECK:STDOUT: .TestLessEqual = %TestLessEqual.decl
  113. // CHECK:STDOUT: .TestGreater = %TestGreater.decl
  114. // CHECK:STDOUT: .TestGreaterEqual = %TestGreaterEqual.decl
  115. // CHECK:STDOUT: }
  116. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  117. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  118. // CHECK:STDOUT: %import_ref.1: type = import_ref ir6, inst+51, loaded [template = constants.%.2]
  119. // CHECK:STDOUT: %import_ref.2 = import_ref ir6, inst+53, unloaded
  120. // CHECK:STDOUT: %import_ref.3: %.6 = import_ref ir6, inst+73, loaded [template = constants.%.7]
  121. // CHECK:STDOUT: %import_ref.4: %.8 = import_ref ir6, inst+93, loaded [template = constants.%.9]
  122. // CHECK:STDOUT: %import_ref.5: %.10 = import_ref ir6, inst+113, loaded [template = constants.%.11]
  123. // CHECK:STDOUT: %import_ref.6: %.12 = import_ref ir6, inst+133, loaded [template = constants.%.13]
  124. // CHECK:STDOUT: %import_ref.7: %Less.type.2 = import_ref ir6, inst+69, loaded [template = constants.%Less.2]
  125. // CHECK:STDOUT: %import_ref.8: %LessOrEquivalent.type.2 = import_ref ir6, inst+89, loaded [template = constants.%LessOrEquivalent.2]
  126. // CHECK:STDOUT: %import_ref.9: %Greater.type.2 = import_ref ir6, inst+109, loaded [template = constants.%Greater.2]
  127. // CHECK:STDOUT: %import_ref.10: %GreaterOrEquivalent.type.2 = import_ref ir6, inst+129, loaded [template = constants.%GreaterOrEquivalent.2]
  128. // CHECK:STDOUT: impl_decl @impl {
  129. // CHECK:STDOUT: %C.ref.loc6: type = name_ref C, %C.decl [template = constants.%C]
  130. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, %Core [template = %Core]
  131. // CHECK:STDOUT: %Ordered.ref: type = name_ref Ordered, %import_ref.1 [template = constants.%.2]
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT: %import_ref.11: %Bool.type = import_ref ir7, inst+2, loaded [template = constants.%Bool]
  134. // CHECK:STDOUT: %import_ref.12: %Bool.type = import_ref ir7, inst+2, loaded [template = constants.%Bool]
  135. // CHECK:STDOUT: %import_ref.13: %Bool.type = import_ref ir7, inst+2, loaded [template = constants.%Bool]
  136. // CHECK:STDOUT: %import_ref.14: %Bool.type = import_ref ir7, inst+2, loaded [template = constants.%Bool]
  137. // CHECK:STDOUT: %import_ref.15: %Bool.type = import_ref ir7, inst+2, loaded [template = constants.%Bool]
  138. // CHECK:STDOUT: %TestLess.decl: %TestLess.type = fn_decl @TestLess [template = constants.%TestLess] {
  139. // CHECK:STDOUT: %C.ref.loc13_16: type = name_ref C, %C.decl [template = constants.%C]
  140. // CHECK:STDOUT: %a.loc13_13.1: %C = param a
  141. // CHECK:STDOUT: @TestLess.%a: %C = bind_name a, %a.loc13_13.1
  142. // CHECK:STDOUT: %C.ref.loc13_22: type = name_ref C, %C.decl [template = constants.%C]
  143. // CHECK:STDOUT: %b.loc13_19.1: %C = param b
  144. // CHECK:STDOUT: @TestLess.%b: %C = bind_name b, %b.loc13_19.1
  145. // CHECK:STDOUT: %bool.make_type.loc13: init type = call constants.%Bool() [template = bool]
  146. // CHECK:STDOUT: %.loc13_28.1: type = value_of_initializer %bool.make_type.loc13 [template = bool]
  147. // CHECK:STDOUT: %.loc13_28.2: type = converted %bool.make_type.loc13, %.loc13_28.1 [template = bool]
  148. // CHECK:STDOUT: @TestLess.%return: ref bool = var <return slot>
  149. // CHECK:STDOUT: }
  150. // CHECK:STDOUT: %import_ref.16: type = import_ref ir6, inst+51, loaded [template = constants.%.2]
  151. // CHECK:STDOUT: %import_ref.17 = import_ref ir6, inst+69, unloaded
  152. // CHECK:STDOUT: %import_ref.18: %Bool.type = import_ref ir7, inst+2, loaded [template = constants.%Bool]
  153. // CHECK:STDOUT: %TestLessEqual.decl: %TestLessEqual.type = fn_decl @TestLessEqual [template = constants.%TestLessEqual] {
  154. // CHECK:STDOUT: %C.ref.loc17_21: type = name_ref C, %C.decl [template = constants.%C]
  155. // CHECK:STDOUT: %a.loc17_18.1: %C = param a
  156. // CHECK:STDOUT: @TestLessEqual.%a: %C = bind_name a, %a.loc17_18.1
  157. // CHECK:STDOUT: %C.ref.loc17_27: type = name_ref C, %C.decl [template = constants.%C]
  158. // CHECK:STDOUT: %b.loc17_24.1: %C = param b
  159. // CHECK:STDOUT: @TestLessEqual.%b: %C = bind_name b, %b.loc17_24.1
  160. // CHECK:STDOUT: %bool.make_type.loc17: init type = call constants.%Bool() [template = bool]
  161. // CHECK:STDOUT: %.loc17_33.1: type = value_of_initializer %bool.make_type.loc17 [template = bool]
  162. // CHECK:STDOUT: %.loc17_33.2: type = converted %bool.make_type.loc17, %.loc17_33.1 [template = bool]
  163. // CHECK:STDOUT: @TestLessEqual.%return: ref bool = var <return slot>
  164. // CHECK:STDOUT: }
  165. // CHECK:STDOUT: %import_ref.19: type = import_ref ir6, inst+51, loaded [template = constants.%.2]
  166. // CHECK:STDOUT: %import_ref.20 = import_ref ir6, inst+89, unloaded
  167. // CHECK:STDOUT: %import_ref.21: %Bool.type = import_ref ir7, inst+2, loaded [template = constants.%Bool]
  168. // CHECK:STDOUT: %TestGreater.decl: %TestGreater.type = fn_decl @TestGreater [template = constants.%TestGreater] {
  169. // CHECK:STDOUT: %C.ref.loc21_19: type = name_ref C, %C.decl [template = constants.%C]
  170. // CHECK:STDOUT: %a.loc21_16.1: %C = param a
  171. // CHECK:STDOUT: @TestGreater.%a: %C = bind_name a, %a.loc21_16.1
  172. // CHECK:STDOUT: %C.ref.loc21_25: type = name_ref C, %C.decl [template = constants.%C]
  173. // CHECK:STDOUT: %b.loc21_22.1: %C = param b
  174. // CHECK:STDOUT: @TestGreater.%b: %C = bind_name b, %b.loc21_22.1
  175. // CHECK:STDOUT: %bool.make_type.loc21: init type = call constants.%Bool() [template = bool]
  176. // CHECK:STDOUT: %.loc21_31.1: type = value_of_initializer %bool.make_type.loc21 [template = bool]
  177. // CHECK:STDOUT: %.loc21_31.2: type = converted %bool.make_type.loc21, %.loc21_31.1 [template = bool]
  178. // CHECK:STDOUT: @TestGreater.%return: ref bool = var <return slot>
  179. // CHECK:STDOUT: }
  180. // CHECK:STDOUT: %import_ref.22: type = import_ref ir6, inst+51, loaded [template = constants.%.2]
  181. // CHECK:STDOUT: %import_ref.23 = import_ref ir6, inst+109, unloaded
  182. // CHECK:STDOUT: %import_ref.24: %Bool.type = import_ref ir7, inst+2, loaded [template = constants.%Bool]
  183. // CHECK:STDOUT: %TestGreaterEqual.decl: %TestGreaterEqual.type = fn_decl @TestGreaterEqual [template = constants.%TestGreaterEqual] {
  184. // CHECK:STDOUT: %C.ref.loc25_24: type = name_ref C, %C.decl [template = constants.%C]
  185. // CHECK:STDOUT: %a.loc25_21.1: %C = param a
  186. // CHECK:STDOUT: @TestGreaterEqual.%a: %C = bind_name a, %a.loc25_21.1
  187. // CHECK:STDOUT: %C.ref.loc25_30: type = name_ref C, %C.decl [template = constants.%C]
  188. // CHECK:STDOUT: %b.loc25_27.1: %C = param b
  189. // CHECK:STDOUT: @TestGreaterEqual.%b: %C = bind_name b, %b.loc25_27.1
  190. // CHECK:STDOUT: %bool.make_type.loc25: init type = call constants.%Bool() [template = bool]
  191. // CHECK:STDOUT: %.loc25_36.1: type = value_of_initializer %bool.make_type.loc25 [template = bool]
  192. // CHECK:STDOUT: %.loc25_36.2: type = converted %bool.make_type.loc25, %.loc25_36.1 [template = bool]
  193. // CHECK:STDOUT: @TestGreaterEqual.%return: ref bool = var <return slot>
  194. // CHECK:STDOUT: }
  195. // CHECK:STDOUT: %import_ref.25: type = import_ref ir6, inst+51, loaded [template = constants.%.2]
  196. // CHECK:STDOUT: %import_ref.26 = import_ref ir6, inst+129, unloaded
  197. // CHECK:STDOUT: }
  198. // CHECK:STDOUT:
  199. // CHECK:STDOUT: interface @Ordered {
  200. // CHECK:STDOUT: !members:
  201. // CHECK:STDOUT: .Self = file.%import_ref.2
  202. // CHECK:STDOUT: .Less = file.%import_ref.3
  203. // CHECK:STDOUT: .LessOrEquivalent = file.%import_ref.4
  204. // CHECK:STDOUT: .Greater = file.%import_ref.5
  205. // CHECK:STDOUT: .GreaterOrEquivalent = file.%import_ref.6
  206. // CHECK:STDOUT: witness = (file.%import_ref.7, file.%import_ref.8, file.%import_ref.9, file.%import_ref.10)
  207. // CHECK:STDOUT: }
  208. // CHECK:STDOUT:
  209. // CHECK:STDOUT: impl @impl: %C as %.2 {
  210. // CHECK:STDOUT: %Less.decl: %Less.type.1 = fn_decl @Less.1 [template = constants.%Less.1] {
  211. // CHECK:STDOUT: %C.ref.loc7_17: type = name_ref C, file.%C.decl [template = constants.%C]
  212. // CHECK:STDOUT: %self.loc7_11.1: %C = param self
  213. // CHECK:STDOUT: %self.loc7_11.2: %C = bind_name self, %self.loc7_11.1
  214. // CHECK:STDOUT: %C.ref.loc7_27: type = name_ref C, file.%C.decl [template = constants.%C]
  215. // CHECK:STDOUT: %other.loc7_20.1: %C = param other
  216. // CHECK:STDOUT: %other.loc7_20.2: %C = bind_name other, %other.loc7_20.1
  217. // CHECK:STDOUT: %bool.make_type.loc7: init type = call constants.%Bool() [template = bool]
  218. // CHECK:STDOUT: %.loc7_33.1: type = value_of_initializer %bool.make_type.loc7 [template = bool]
  219. // CHECK:STDOUT: %.loc7_33.2: type = converted %bool.make_type.loc7, %.loc7_33.1 [template = bool]
  220. // CHECK:STDOUT: %return.var.loc7: ref bool = var <return slot>
  221. // CHECK:STDOUT: }
  222. // CHECK:STDOUT: %LessOrEquivalent.decl: %LessOrEquivalent.type.1 = fn_decl @LessOrEquivalent.1 [template = constants.%LessOrEquivalent.1] {
  223. // CHECK:STDOUT: %C.ref.loc8_29: type = name_ref C, file.%C.decl [template = constants.%C]
  224. // CHECK:STDOUT: %self.loc8_23.1: %C = param self
  225. // CHECK:STDOUT: %self.loc8_23.2: %C = bind_name self, %self.loc8_23.1
  226. // CHECK:STDOUT: %C.ref.loc8_39: type = name_ref C, file.%C.decl [template = constants.%C]
  227. // CHECK:STDOUT: %other.loc8_32.1: %C = param other
  228. // CHECK:STDOUT: %other.loc8_32.2: %C = bind_name other, %other.loc8_32.1
  229. // CHECK:STDOUT: %bool.make_type.loc8: init type = call constants.%Bool() [template = bool]
  230. // CHECK:STDOUT: %.loc8_45.1: type = value_of_initializer %bool.make_type.loc8 [template = bool]
  231. // CHECK:STDOUT: %.loc8_45.2: type = converted %bool.make_type.loc8, %.loc8_45.1 [template = bool]
  232. // CHECK:STDOUT: %return.var.loc8: ref bool = var <return slot>
  233. // CHECK:STDOUT: }
  234. // CHECK:STDOUT: %Greater.decl: %Greater.type.1 = fn_decl @Greater.1 [template = constants.%Greater.1] {
  235. // CHECK:STDOUT: %C.ref.loc9_20: type = name_ref C, file.%C.decl [template = constants.%C]
  236. // CHECK:STDOUT: %self.loc9_14.1: %C = param self
  237. // CHECK:STDOUT: %self.loc9_14.2: %C = bind_name self, %self.loc9_14.1
  238. // CHECK:STDOUT: %C.ref.loc9_30: type = name_ref C, file.%C.decl [template = constants.%C]
  239. // CHECK:STDOUT: %other.loc9_23.1: %C = param other
  240. // CHECK:STDOUT: %other.loc9_23.2: %C = bind_name other, %other.loc9_23.1
  241. // CHECK:STDOUT: %bool.make_type.loc9: init type = call constants.%Bool() [template = bool]
  242. // CHECK:STDOUT: %.loc9_36.1: type = value_of_initializer %bool.make_type.loc9 [template = bool]
  243. // CHECK:STDOUT: %.loc9_36.2: type = converted %bool.make_type.loc9, %.loc9_36.1 [template = bool]
  244. // CHECK:STDOUT: %return.var.loc9: ref bool = var <return slot>
  245. // CHECK:STDOUT: }
  246. // CHECK:STDOUT: %GreaterOrEquivalent.decl: %GreaterOrEquivalent.type.1 = fn_decl @GreaterOrEquivalent.1 [template = constants.%GreaterOrEquivalent.1] {
  247. // CHECK:STDOUT: %C.ref.loc10_32: type = name_ref C, file.%C.decl [template = constants.%C]
  248. // CHECK:STDOUT: %self.loc10_26.1: %C = param self
  249. // CHECK:STDOUT: %self.loc10_26.2: %C = bind_name self, %self.loc10_26.1
  250. // CHECK:STDOUT: %C.ref.loc10_42: type = name_ref C, file.%C.decl [template = constants.%C]
  251. // CHECK:STDOUT: %other.loc10_35.1: %C = param other
  252. // CHECK:STDOUT: %other.loc10_35.2: %C = bind_name other, %other.loc10_35.1
  253. // CHECK:STDOUT: %bool.make_type.loc10: init type = call constants.%Bool() [template = bool]
  254. // CHECK:STDOUT: %.loc10_48.1: type = value_of_initializer %bool.make_type.loc10 [template = bool]
  255. // CHECK:STDOUT: %.loc10_48.2: type = converted %bool.make_type.loc10, %.loc10_48.1 [template = bool]
  256. // CHECK:STDOUT: %return.var.loc10: ref bool = var <return slot>
  257. // CHECK:STDOUT: }
  258. // CHECK:STDOUT: %.1: <witness> = interface_witness (%Less.decl, %LessOrEquivalent.decl, %Greater.decl, %GreaterOrEquivalent.decl) [template = constants.%.4]
  259. // CHECK:STDOUT:
  260. // CHECK:STDOUT: !members:
  261. // CHECK:STDOUT: .Less = %Less.decl
  262. // CHECK:STDOUT: .LessOrEquivalent = %LessOrEquivalent.decl
  263. // CHECK:STDOUT: .Greater = %Greater.decl
  264. // CHECK:STDOUT: .GreaterOrEquivalent = %GreaterOrEquivalent.decl
  265. // CHECK:STDOUT: witness = %.1
  266. // CHECK:STDOUT: }
  267. // CHECK:STDOUT:
  268. // CHECK:STDOUT: class @C {
  269. // CHECK:STDOUT: !members:
  270. // CHECK:STDOUT: .Self = constants.%C
  271. // CHECK:STDOUT: }
  272. // CHECK:STDOUT:
  273. // CHECK:STDOUT: fn @Bool() -> type = "bool.make_type";
  274. // CHECK:STDOUT:
  275. // CHECK:STDOUT: fn @Less.1[@impl.%self.loc7_11.2: %C](@impl.%other.loc7_20.2: %C) -> bool;
  276. // CHECK:STDOUT:
  277. // CHECK:STDOUT: fn @LessOrEquivalent.1[@impl.%self.loc8_23.2: %C](@impl.%other.loc8_32.2: %C) -> bool;
  278. // CHECK:STDOUT:
  279. // CHECK:STDOUT: fn @Greater.1[@impl.%self.loc9_14.2: %C](@impl.%other.loc9_23.2: %C) -> bool;
  280. // CHECK:STDOUT:
  281. // CHECK:STDOUT: fn @GreaterOrEquivalent.1[@impl.%self.loc10_26.2: %C](@impl.%other.loc10_35.2: %C) -> bool;
  282. // CHECK:STDOUT:
  283. // CHECK:STDOUT: fn @Less.2[%self: %Self](%other: %Self) -> bool;
  284. // CHECK:STDOUT:
  285. // CHECK:STDOUT: fn @LessOrEquivalent.2[%self: %Self](%other: %Self) -> bool;
  286. // CHECK:STDOUT:
  287. // CHECK:STDOUT: fn @Greater.2[%self: %Self](%other: %Self) -> bool;
  288. // CHECK:STDOUT:
  289. // CHECK:STDOUT: fn @GreaterOrEquivalent.2[%self: %Self](%other: %Self) -> bool;
  290. // CHECK:STDOUT:
  291. // CHECK:STDOUT: fn @TestLess(%a: %C, %b: %C) -> bool {
  292. // CHECK:STDOUT: !entry:
  293. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  294. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  295. // CHECK:STDOUT: %.1: %Less.type.2 = interface_witness_access @impl.%.1, element0 [template = constants.%Less.1]
  296. // CHECK:STDOUT: %.loc14_12: <bound method> = bound_method %a.ref, %.1
  297. // CHECK:STDOUT: %Less.call: init bool = call %.loc14_12(%a.ref, %b.ref)
  298. // CHECK:STDOUT: %.loc14_15.1: bool = value_of_initializer %Less.call
  299. // CHECK:STDOUT: %.loc14_15.2: bool = converted %Less.call, %.loc14_15.1
  300. // CHECK:STDOUT: return %.loc14_15.2
  301. // CHECK:STDOUT: }
  302. // CHECK:STDOUT:
  303. // CHECK:STDOUT: fn @TestLessEqual(%a: %C, %b: %C) -> bool {
  304. // CHECK:STDOUT: !entry:
  305. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  306. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  307. // CHECK:STDOUT: %.1: %LessOrEquivalent.type.2 = interface_witness_access @impl.%.1, element1 [template = constants.%LessOrEquivalent.1]
  308. // CHECK:STDOUT: %.loc18_12: <bound method> = bound_method %a.ref, %.1
  309. // CHECK:STDOUT: %LessOrEquivalent.call: init bool = call %.loc18_12(%a.ref, %b.ref)
  310. // CHECK:STDOUT: %.loc18_16.1: bool = value_of_initializer %LessOrEquivalent.call
  311. // CHECK:STDOUT: %.loc18_16.2: bool = converted %LessOrEquivalent.call, %.loc18_16.1
  312. // CHECK:STDOUT: return %.loc18_16.2
  313. // CHECK:STDOUT: }
  314. // CHECK:STDOUT:
  315. // CHECK:STDOUT: fn @TestGreater(%a: %C, %b: %C) -> bool {
  316. // CHECK:STDOUT: !entry:
  317. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  318. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  319. // CHECK:STDOUT: %.1: %Greater.type.2 = interface_witness_access @impl.%.1, element2 [template = constants.%Greater.1]
  320. // CHECK:STDOUT: %.loc22_12: <bound method> = bound_method %a.ref, %.1
  321. // CHECK:STDOUT: %Greater.call: init bool = call %.loc22_12(%a.ref, %b.ref)
  322. // CHECK:STDOUT: %.loc22_15.1: bool = value_of_initializer %Greater.call
  323. // CHECK:STDOUT: %.loc22_15.2: bool = converted %Greater.call, %.loc22_15.1
  324. // CHECK:STDOUT: return %.loc22_15.2
  325. // CHECK:STDOUT: }
  326. // CHECK:STDOUT:
  327. // CHECK:STDOUT: fn @TestGreaterEqual(%a: %C, %b: %C) -> bool {
  328. // CHECK:STDOUT: !entry:
  329. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  330. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  331. // CHECK:STDOUT: %.1: %GreaterOrEquivalent.type.2 = interface_witness_access @impl.%.1, element3 [template = constants.%GreaterOrEquivalent.1]
  332. // CHECK:STDOUT: %.loc26_12: <bound method> = bound_method %a.ref, %.1
  333. // CHECK:STDOUT: %GreaterOrEquivalent.call: init bool = call %.loc26_12(%a.ref, %b.ref)
  334. // CHECK:STDOUT: %.loc26_16.1: bool = value_of_initializer %GreaterOrEquivalent.call
  335. // CHECK:STDOUT: %.loc26_16.2: bool = converted %GreaterOrEquivalent.call, %.loc26_16.1
  336. // CHECK:STDOUT: return %.loc26_16.2
  337. // CHECK:STDOUT: }
  338. // CHECK:STDOUT:
  339. // CHECK:STDOUT: --- fail_no_impl.carbon
  340. // CHECK:STDOUT:
  341. // CHECK:STDOUT: constants {
  342. // CHECK:STDOUT: %D: type = class_type @D [template]
  343. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  344. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [template]
  345. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  346. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [template]
  347. // CHECK:STDOUT: %TestLess.type: type = fn_type @TestLess [template]
  348. // CHECK:STDOUT: %TestLess: %TestLess.type = struct_value () [template]
  349. // CHECK:STDOUT: %.3: type = ptr_type %.1 [template]
  350. // CHECK:STDOUT: %.4: type = interface_type @Ordered [template]
  351. // CHECK:STDOUT: %Self: %.4 = bind_symbolic_name Self 0 [symbolic]
  352. // CHECK:STDOUT: %Less.type: type = fn_type @Less [template]
  353. // CHECK:STDOUT: %Less: %Less.type = struct_value () [template]
  354. // CHECK:STDOUT: %.5: type = assoc_entity_type @Ordered, %Less.type [template]
  355. // CHECK:STDOUT: %.6: %.5 = assoc_entity element0, file.%import_ref.12 [template]
  356. // CHECK:STDOUT: %TestLessEqual.type: type = fn_type @TestLessEqual [template]
  357. // CHECK:STDOUT: %TestLessEqual: %TestLessEqual.type = struct_value () [template]
  358. // CHECK:STDOUT: %LessOrEquivalent.type: type = fn_type @LessOrEquivalent [template]
  359. // CHECK:STDOUT: %LessOrEquivalent: %LessOrEquivalent.type = struct_value () [template]
  360. // CHECK:STDOUT: %.7: type = assoc_entity_type @Ordered, %LessOrEquivalent.type [template]
  361. // CHECK:STDOUT: %.8: %.7 = assoc_entity element1, file.%import_ref.15 [template]
  362. // CHECK:STDOUT: %TestGreater.type: type = fn_type @TestGreater [template]
  363. // CHECK:STDOUT: %TestGreater: %TestGreater.type = struct_value () [template]
  364. // CHECK:STDOUT: %Greater.type: type = fn_type @Greater [template]
  365. // CHECK:STDOUT: %Greater: %Greater.type = struct_value () [template]
  366. // CHECK:STDOUT: %.9: type = assoc_entity_type @Ordered, %Greater.type [template]
  367. // CHECK:STDOUT: %.10: %.9 = assoc_entity element2, file.%import_ref.18 [template]
  368. // CHECK:STDOUT: %TestGreaterEqual.type: type = fn_type @TestGreaterEqual [template]
  369. // CHECK:STDOUT: %TestGreaterEqual: %TestGreaterEqual.type = struct_value () [template]
  370. // CHECK:STDOUT: %GreaterOrEquivalent.type: type = fn_type @GreaterOrEquivalent [template]
  371. // CHECK:STDOUT: %GreaterOrEquivalent: %GreaterOrEquivalent.type = struct_value () [template]
  372. // CHECK:STDOUT: %.11: type = assoc_entity_type @Ordered, %GreaterOrEquivalent.type [template]
  373. // CHECK:STDOUT: %.12: %.11 = assoc_entity element3, file.%import_ref.21 [template]
  374. // CHECK:STDOUT: }
  375. // CHECK:STDOUT:
  376. // CHECK:STDOUT: file {
  377. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  378. // CHECK:STDOUT: .Core = %Core
  379. // CHECK:STDOUT: .D = %D.decl
  380. // CHECK:STDOUT: .TestLess = %TestLess.decl
  381. // CHECK:STDOUT: .TestLessEqual = %TestLessEqual.decl
  382. // CHECK:STDOUT: .TestGreater = %TestGreater.decl
  383. // CHECK:STDOUT: .TestGreaterEqual = %TestGreaterEqual.decl
  384. // CHECK:STDOUT: }
  385. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  386. // CHECK:STDOUT: %D.decl: type = class_decl @D [template = constants.%D] {}
  387. // CHECK:STDOUT: %import_ref.1: %Bool.type = import_ref ir7, inst+2, loaded [template = constants.%Bool]
  388. // CHECK:STDOUT: %TestLess.decl: %TestLess.type = fn_decl @TestLess [template = constants.%TestLess] {
  389. // CHECK:STDOUT: %D.ref.loc6_16: type = name_ref D, %D.decl [template = constants.%D]
  390. // CHECK:STDOUT: %a.loc6_13.1: %D = param a
  391. // CHECK:STDOUT: @TestLess.%a: %D = bind_name a, %a.loc6_13.1
  392. // CHECK:STDOUT: %D.ref.loc6_22: type = name_ref D, %D.decl [template = constants.%D]
  393. // CHECK:STDOUT: %b.loc6_19.1: %D = param b
  394. // CHECK:STDOUT: @TestLess.%b: %D = bind_name b, %b.loc6_19.1
  395. // CHECK:STDOUT: %bool.make_type.loc6: init type = call constants.%Bool() [template = bool]
  396. // CHECK:STDOUT: %.loc6_28.1: type = value_of_initializer %bool.make_type.loc6 [template = bool]
  397. // CHECK:STDOUT: %.loc6_28.2: type = converted %bool.make_type.loc6, %.loc6_28.1 [template = bool]
  398. // CHECK:STDOUT: @TestLess.%return: ref bool = var <return slot>
  399. // CHECK:STDOUT: }
  400. // CHECK:STDOUT: %import_ref.2: type = import_ref ir6, inst+51, loaded [template = constants.%.4]
  401. // CHECK:STDOUT: %import_ref.3 = import_ref ir6, inst+53, unloaded
  402. // CHECK:STDOUT: %import_ref.4: %.5 = import_ref ir6, inst+73, loaded [template = constants.%.6]
  403. // CHECK:STDOUT: %import_ref.5: %.7 = import_ref ir6, inst+93, loaded [template = constants.%.8]
  404. // CHECK:STDOUT: %import_ref.6: %.9 = import_ref ir6, inst+113, loaded [template = constants.%.10]
  405. // CHECK:STDOUT: %import_ref.7: %.11 = import_ref ir6, inst+133, loaded [template = constants.%.12]
  406. // CHECK:STDOUT: %import_ref.8 = import_ref ir6, inst+69, unloaded
  407. // CHECK:STDOUT: %import_ref.9 = import_ref ir6, inst+89, unloaded
  408. // CHECK:STDOUT: %import_ref.10 = import_ref ir6, inst+109, unloaded
  409. // CHECK:STDOUT: %import_ref.11 = import_ref ir6, inst+129, unloaded
  410. // CHECK:STDOUT: %import_ref.12 = import_ref ir6, inst+69, unloaded
  411. // CHECK:STDOUT: %import_ref.13: %Bool.type = import_ref ir7, inst+2, loaded [template = constants.%Bool]
  412. // CHECK:STDOUT: %TestLessEqual.decl: %TestLessEqual.type = fn_decl @TestLessEqual [template = constants.%TestLessEqual] {
  413. // CHECK:STDOUT: %D.ref.loc14_21: type = name_ref D, %D.decl [template = constants.%D]
  414. // CHECK:STDOUT: %a.loc14_18.1: %D = param a
  415. // CHECK:STDOUT: @TestLessEqual.%a: %D = bind_name a, %a.loc14_18.1
  416. // CHECK:STDOUT: %D.ref.loc14_27: type = name_ref D, %D.decl [template = constants.%D]
  417. // CHECK:STDOUT: %b.loc14_24.1: %D = param b
  418. // CHECK:STDOUT: @TestLessEqual.%b: %D = bind_name b, %b.loc14_24.1
  419. // CHECK:STDOUT: %bool.make_type.loc14: init type = call constants.%Bool() [template = bool]
  420. // CHECK:STDOUT: %.loc14_33.1: type = value_of_initializer %bool.make_type.loc14 [template = bool]
  421. // CHECK:STDOUT: %.loc14_33.2: type = converted %bool.make_type.loc14, %.loc14_33.1 [template = bool]
  422. // CHECK:STDOUT: @TestLessEqual.%return: ref bool = var <return slot>
  423. // CHECK:STDOUT: }
  424. // CHECK:STDOUT: %import_ref.14: type = import_ref ir6, inst+51, loaded [template = constants.%.4]
  425. // CHECK:STDOUT: %import_ref.15 = import_ref ir6, inst+89, unloaded
  426. // CHECK:STDOUT: %import_ref.16: %Bool.type = import_ref ir7, inst+2, loaded [template = constants.%Bool]
  427. // CHECK:STDOUT: %TestGreater.decl: %TestGreater.type = fn_decl @TestGreater [template = constants.%TestGreater] {
  428. // CHECK:STDOUT: %D.ref.loc22_19: type = name_ref D, %D.decl [template = constants.%D]
  429. // CHECK:STDOUT: %a.loc22_16.1: %D = param a
  430. // CHECK:STDOUT: @TestGreater.%a: %D = bind_name a, %a.loc22_16.1
  431. // CHECK:STDOUT: %D.ref.loc22_25: type = name_ref D, %D.decl [template = constants.%D]
  432. // CHECK:STDOUT: %b.loc22_22.1: %D = param b
  433. // CHECK:STDOUT: @TestGreater.%b: %D = bind_name b, %b.loc22_22.1
  434. // CHECK:STDOUT: %bool.make_type.loc22: init type = call constants.%Bool() [template = bool]
  435. // CHECK:STDOUT: %.loc22_31.1: type = value_of_initializer %bool.make_type.loc22 [template = bool]
  436. // CHECK:STDOUT: %.loc22_31.2: type = converted %bool.make_type.loc22, %.loc22_31.1 [template = bool]
  437. // CHECK:STDOUT: @TestGreater.%return: ref bool = var <return slot>
  438. // CHECK:STDOUT: }
  439. // CHECK:STDOUT: %import_ref.17: type = import_ref ir6, inst+51, loaded [template = constants.%.4]
  440. // CHECK:STDOUT: %import_ref.18 = import_ref ir6, inst+109, unloaded
  441. // CHECK:STDOUT: %import_ref.19: %Bool.type = import_ref ir7, inst+2, loaded [template = constants.%Bool]
  442. // CHECK:STDOUT: %TestGreaterEqual.decl: %TestGreaterEqual.type = fn_decl @TestGreaterEqual [template = constants.%TestGreaterEqual] {
  443. // CHECK:STDOUT: %D.ref.loc30_24: type = name_ref D, %D.decl [template = constants.%D]
  444. // CHECK:STDOUT: %a.loc30_21.1: %D = param a
  445. // CHECK:STDOUT: @TestGreaterEqual.%a: %D = bind_name a, %a.loc30_21.1
  446. // CHECK:STDOUT: %D.ref.loc30_30: type = name_ref D, %D.decl [template = constants.%D]
  447. // CHECK:STDOUT: %b.loc30_27.1: %D = param b
  448. // CHECK:STDOUT: @TestGreaterEqual.%b: %D = bind_name b, %b.loc30_27.1
  449. // CHECK:STDOUT: %bool.make_type.loc30: init type = call constants.%Bool() [template = bool]
  450. // CHECK:STDOUT: %.loc30_36.1: type = value_of_initializer %bool.make_type.loc30 [template = bool]
  451. // CHECK:STDOUT: %.loc30_36.2: type = converted %bool.make_type.loc30, %.loc30_36.1 [template = bool]
  452. // CHECK:STDOUT: @TestGreaterEqual.%return: ref bool = var <return slot>
  453. // CHECK:STDOUT: }
  454. // CHECK:STDOUT: %import_ref.20: type = import_ref ir6, inst+51, loaded [template = constants.%.4]
  455. // CHECK:STDOUT: %import_ref.21 = import_ref ir6, inst+129, unloaded
  456. // CHECK:STDOUT: }
  457. // CHECK:STDOUT:
  458. // CHECK:STDOUT: interface @Ordered {
  459. // CHECK:STDOUT: !members:
  460. // CHECK:STDOUT: .Self = file.%import_ref.3
  461. // CHECK:STDOUT: .Less = file.%import_ref.4
  462. // CHECK:STDOUT: .LessOrEquivalent = file.%import_ref.5
  463. // CHECK:STDOUT: .Greater = file.%import_ref.6
  464. // CHECK:STDOUT: .GreaterOrEquivalent = file.%import_ref.7
  465. // CHECK:STDOUT: witness = (file.%import_ref.8, file.%import_ref.9, file.%import_ref.10, file.%import_ref.11)
  466. // CHECK:STDOUT: }
  467. // CHECK:STDOUT:
  468. // CHECK:STDOUT: class @D {
  469. // CHECK:STDOUT: !members:
  470. // CHECK:STDOUT: .Self = constants.%D
  471. // CHECK:STDOUT: }
  472. // CHECK:STDOUT:
  473. // CHECK:STDOUT: fn @Bool() -> type = "bool.make_type";
  474. // CHECK:STDOUT:
  475. // CHECK:STDOUT: fn @TestLess(%a: %D, %b: %D) -> bool {
  476. // CHECK:STDOUT: !entry:
  477. // CHECK:STDOUT: %a.ref: %D = name_ref a, %a
  478. // CHECK:STDOUT: %b.ref: %D = name_ref b, %b
  479. // CHECK:STDOUT: return <error>
  480. // CHECK:STDOUT: }
  481. // CHECK:STDOUT:
  482. // CHECK:STDOUT: fn @Less[%self: %Self](%other: %Self) -> bool;
  483. // CHECK:STDOUT:
  484. // CHECK:STDOUT: fn @TestLessEqual(%a: %D, %b: %D) -> bool {
  485. // CHECK:STDOUT: !entry:
  486. // CHECK:STDOUT: %a.ref: %D = name_ref a, %a
  487. // CHECK:STDOUT: %b.ref: %D = name_ref b, %b
  488. // CHECK:STDOUT: return <error>
  489. // CHECK:STDOUT: }
  490. // CHECK:STDOUT:
  491. // CHECK:STDOUT: fn @LessOrEquivalent[%self: %Self](%other: %Self) -> bool;
  492. // CHECK:STDOUT:
  493. // CHECK:STDOUT: fn @TestGreater(%a: %D, %b: %D) -> bool {
  494. // CHECK:STDOUT: !entry:
  495. // CHECK:STDOUT: %a.ref: %D = name_ref a, %a
  496. // CHECK:STDOUT: %b.ref: %D = name_ref b, %b
  497. // CHECK:STDOUT: return <error>
  498. // CHECK:STDOUT: }
  499. // CHECK:STDOUT:
  500. // CHECK:STDOUT: fn @Greater[%self: %Self](%other: %Self) -> bool;
  501. // CHECK:STDOUT:
  502. // CHECK:STDOUT: fn @TestGreaterEqual(%a: %D, %b: %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 @GreaterOrEquivalent[%self: %Self](%other: %Self) -> bool;
  510. // CHECK:STDOUT: