ordered.carbon 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  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. // --- prelude.carbon
  7. package Core api;
  8. import library "prelude";
  9. interface Ordered {
  10. // TODO: fn Compare
  11. fn Less[self: Self](other: Self) -> bool;
  12. fn LessOrEquivalent[self: Self](other: Self) -> bool;
  13. fn Greater[self: Self](other: Self) -> bool;
  14. fn GreaterOrEquivalent[self: Self](other: Self) -> bool;
  15. }
  16. // --- user.carbon
  17. package User api;
  18. import Core;
  19. class C {};
  20. impl C as Core.Ordered {
  21. fn Less[self: C](other: C) -> bool;
  22. fn LessOrEquivalent[self: C](other: C) -> bool;
  23. fn Greater[self: C](other: C) -> bool;
  24. fn GreaterOrEquivalent[self: C](other: C) -> bool;
  25. }
  26. fn TestLess(a: C, b: C) -> bool {
  27. return a < b;
  28. }
  29. fn TestLessEqual(a: C, b: C) -> bool {
  30. return a <= b;
  31. }
  32. fn TestGreater(a: C, b: C) -> bool {
  33. return a > b;
  34. }
  35. fn TestGreaterEqual(a: C, b: C) -> bool {
  36. return a >= b;
  37. }
  38. // --- fail_no_impl.carbon
  39. package FailNoImpl api;
  40. import Core;
  41. class D {};
  42. fn TestLess(a: D, b: D) -> bool {
  43. // 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.
  44. // CHECK:STDERR: return a < b;
  45. // CHECK:STDERR: ^~~~~
  46. // CHECK:STDERR:
  47. return a < b;
  48. }
  49. fn TestLessEqual(a: D, b: D) -> bool {
  50. // 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.
  51. // CHECK:STDERR: return a <= b;
  52. // CHECK:STDERR: ^~~~~~
  53. // CHECK:STDERR:
  54. return a <= b;
  55. }
  56. fn TestGreater(a: D, b: D) -> bool {
  57. // 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.
  58. // CHECK:STDERR: return a > b;
  59. // CHECK:STDERR: ^~~~~
  60. // CHECK:STDERR:
  61. return a > b;
  62. }
  63. fn TestGreaterEqual(a: D, b: D) -> bool {
  64. // 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.
  65. // CHECK:STDERR: return a >= b;
  66. // CHECK:STDERR: ^~~~~~
  67. return a >= b;
  68. }
  69. // CHECK:STDOUT: --- prelude.carbon
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: constants {
  72. // CHECK:STDOUT: %.1: type = interface_type @Ordered [template]
  73. // CHECK:STDOUT: %.2: type = assoc_entity_type @Ordered, <function> [template]
  74. // CHECK:STDOUT: %.3: <associated <function> in Ordered> = assoc_entity element0, @Ordered.%Less [template]
  75. // CHECK:STDOUT: %.4: <associated <function> in Ordered> = assoc_entity element1, @Ordered.%LessOrEquivalent [template]
  76. // CHECK:STDOUT: %.5: <associated <function> in Ordered> = assoc_entity element2, @Ordered.%Greater [template]
  77. // CHECK:STDOUT: %.6: <associated <function> in Ordered> = assoc_entity element3, @Ordered.%GreaterOrEquivalent [template]
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: file {
  81. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  82. // CHECK:STDOUT: .Ordered = %Ordered.decl
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT: %Ordered.decl: type = interface_decl @Ordered [template = constants.%.1] {}
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: interface @Ordered {
  88. // CHECK:STDOUT: %Self: Ordered = bind_symbolic_name Self [symbolic]
  89. // CHECK:STDOUT: %Less: <function> = fn_decl @Less [template] {
  90. // CHECK:STDOUT: %Self.ref.loc8_17: Ordered = name_ref Self, %Self [symbolic = %Self]
  91. // CHECK:STDOUT: %.loc8_17.1: type = facet_type_access %Self.ref.loc8_17 [symbolic = %Self]
  92. // CHECK:STDOUT: %.loc8_17.2: type = converted %Self.ref.loc8_17, %.loc8_17.1 [symbolic = %Self]
  93. // CHECK:STDOUT: %self.loc8_11.1: Self = param self
  94. // CHECK:STDOUT: %self.loc8_11.2: Self = bind_name self, %self.loc8_11.1
  95. // CHECK:STDOUT: %Self.ref.loc8_30: Ordered = name_ref Self, %Self [symbolic = %Self]
  96. // CHECK:STDOUT: %.loc8_30.1: type = facet_type_access %Self.ref.loc8_30 [symbolic = %Self]
  97. // CHECK:STDOUT: %.loc8_30.2: type = converted %Self.ref.loc8_30, %.loc8_30.1 [symbolic = %Self]
  98. // CHECK:STDOUT: %other.loc8_23.1: Self = param other
  99. // CHECK:STDOUT: %other.loc8_23.2: Self = bind_name other, %other.loc8_23.1
  100. // CHECK:STDOUT: %return.var.loc8: ref bool = var <return slot>
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT: %.loc8_43: <associated <function> in Ordered> = assoc_entity element0, %Less [template = constants.%.3]
  103. // CHECK:STDOUT: %LessOrEquivalent: <function> = fn_decl @LessOrEquivalent [template] {
  104. // CHECK:STDOUT: %Self.ref.loc9_29: Ordered = name_ref Self, %Self [symbolic = %Self]
  105. // CHECK:STDOUT: %.loc9_29.1: type = facet_type_access %Self.ref.loc9_29 [symbolic = %Self]
  106. // CHECK:STDOUT: %.loc9_29.2: type = converted %Self.ref.loc9_29, %.loc9_29.1 [symbolic = %Self]
  107. // CHECK:STDOUT: %self.loc9_23.1: Self = param self
  108. // CHECK:STDOUT: %self.loc9_23.2: Self = bind_name self, %self.loc9_23.1
  109. // CHECK:STDOUT: %Self.ref.loc9_42: Ordered = name_ref Self, %Self [symbolic = %Self]
  110. // CHECK:STDOUT: %.loc9_42.1: type = facet_type_access %Self.ref.loc9_42 [symbolic = %Self]
  111. // CHECK:STDOUT: %.loc9_42.2: type = converted %Self.ref.loc9_42, %.loc9_42.1 [symbolic = %Self]
  112. // CHECK:STDOUT: %other.loc9_35.1: Self = param other
  113. // CHECK:STDOUT: %other.loc9_35.2: Self = bind_name other, %other.loc9_35.1
  114. // CHECK:STDOUT: %return.var.loc9: ref bool = var <return slot>
  115. // CHECK:STDOUT: }
  116. // CHECK:STDOUT: %.loc9_55: <associated <function> in Ordered> = assoc_entity element1, %LessOrEquivalent [template = constants.%.4]
  117. // CHECK:STDOUT: %Greater: <function> = fn_decl @Greater [template] {
  118. // CHECK:STDOUT: %Self.ref.loc10_20: Ordered = name_ref Self, %Self [symbolic = %Self]
  119. // CHECK:STDOUT: %.loc10_20.1: type = facet_type_access %Self.ref.loc10_20 [symbolic = %Self]
  120. // CHECK:STDOUT: %.loc10_20.2: type = converted %Self.ref.loc10_20, %.loc10_20.1 [symbolic = %Self]
  121. // CHECK:STDOUT: %self.loc10_14.1: Self = param self
  122. // CHECK:STDOUT: %self.loc10_14.2: Self = bind_name self, %self.loc10_14.1
  123. // CHECK:STDOUT: %Self.ref.loc10_33: Ordered = name_ref Self, %Self [symbolic = %Self]
  124. // CHECK:STDOUT: %.loc10_33.1: type = facet_type_access %Self.ref.loc10_33 [symbolic = %Self]
  125. // CHECK:STDOUT: %.loc10_33.2: type = converted %Self.ref.loc10_33, %.loc10_33.1 [symbolic = %Self]
  126. // CHECK:STDOUT: %other.loc10_26.1: Self = param other
  127. // CHECK:STDOUT: %other.loc10_26.2: Self = bind_name other, %other.loc10_26.1
  128. // CHECK:STDOUT: %return.var.loc10: ref bool = var <return slot>
  129. // CHECK:STDOUT: }
  130. // CHECK:STDOUT: %.loc10_46: <associated <function> in Ordered> = assoc_entity element2, %Greater [template = constants.%.5]
  131. // CHECK:STDOUT: %GreaterOrEquivalent: <function> = fn_decl @GreaterOrEquivalent [template] {
  132. // CHECK:STDOUT: %Self.ref.loc11_32: Ordered = name_ref Self, %Self [symbolic = %Self]
  133. // CHECK:STDOUT: %.loc11_32.1: type = facet_type_access %Self.ref.loc11_32 [symbolic = %Self]
  134. // CHECK:STDOUT: %.loc11_32.2: type = converted %Self.ref.loc11_32, %.loc11_32.1 [symbolic = %Self]
  135. // CHECK:STDOUT: %self.loc11_26.1: Self = param self
  136. // CHECK:STDOUT: %self.loc11_26.2: Self = bind_name self, %self.loc11_26.1
  137. // CHECK:STDOUT: %Self.ref.loc11_45: Ordered = name_ref Self, %Self [symbolic = %Self]
  138. // CHECK:STDOUT: %.loc11_45.1: type = facet_type_access %Self.ref.loc11_45 [symbolic = %Self]
  139. // CHECK:STDOUT: %.loc11_45.2: type = converted %Self.ref.loc11_45, %.loc11_45.1 [symbolic = %Self]
  140. // CHECK:STDOUT: %other.loc11_38.1: Self = param other
  141. // CHECK:STDOUT: %other.loc11_38.2: Self = bind_name other, %other.loc11_38.1
  142. // CHECK:STDOUT: %return.var.loc11: ref bool = var <return slot>
  143. // CHECK:STDOUT: }
  144. // CHECK:STDOUT: %.loc11_58: <associated <function> in Ordered> = assoc_entity element3, %GreaterOrEquivalent [template = constants.%.6]
  145. // CHECK:STDOUT:
  146. // CHECK:STDOUT: !members:
  147. // CHECK:STDOUT: .Self = %Self
  148. // CHECK:STDOUT: .Less = %.loc8_43
  149. // CHECK:STDOUT: .LessOrEquivalent = %.loc9_55
  150. // CHECK:STDOUT: .Greater = %.loc10_46
  151. // CHECK:STDOUT: .GreaterOrEquivalent = %.loc11_58
  152. // CHECK:STDOUT: witness = (%Less, %LessOrEquivalent, %Greater, %GreaterOrEquivalent)
  153. // CHECK:STDOUT: }
  154. // CHECK:STDOUT:
  155. // CHECK:STDOUT: fn @Less[@Ordered.%self.loc8_11.2: Self](@Ordered.%other.loc8_23.2: Self) -> bool;
  156. // CHECK:STDOUT:
  157. // CHECK:STDOUT: fn @LessOrEquivalent[@Ordered.%self.loc9_23.2: Self](@Ordered.%other.loc9_35.2: Self) -> bool;
  158. // CHECK:STDOUT:
  159. // CHECK:STDOUT: fn @Greater[@Ordered.%self.loc10_14.2: Self](@Ordered.%other.loc10_26.2: Self) -> bool;
  160. // CHECK:STDOUT:
  161. // CHECK:STDOUT: fn @GreaterOrEquivalent[@Ordered.%self.loc11_26.2: Self](@Ordered.%other.loc11_38.2: Self) -> bool;
  162. // CHECK:STDOUT:
  163. // CHECK:STDOUT: --- user.carbon
  164. // CHECK:STDOUT:
  165. // CHECK:STDOUT: constants {
  166. // CHECK:STDOUT: %C: type = class_type @C [template]
  167. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  168. // CHECK:STDOUT: %.2: type = interface_type @Ordered [template]
  169. // CHECK:STDOUT: %.3: <witness> = interface_witness (@impl.%Less, @impl.%LessOrEquivalent, @impl.%Greater, @impl.%GreaterOrEquivalent) [template]
  170. // CHECK:STDOUT: %.4: type = tuple_type () [template]
  171. // CHECK:STDOUT: %.5: type = ptr_type {} [template]
  172. // CHECK:STDOUT: %.6: type = assoc_entity_type @Ordered, <function> [template]
  173. // CHECK:STDOUT: %.7: <associated <function> in Ordered> = assoc_entity element0, file.%import_ref.12 [template]
  174. // CHECK:STDOUT: %.8: <associated <function> in Ordered> = assoc_entity element1, file.%import_ref.14 [template]
  175. // CHECK:STDOUT: %.9: <associated <function> in Ordered> = assoc_entity element2, file.%import_ref.16 [template]
  176. // CHECK:STDOUT: %.10: <associated <function> in Ordered> = assoc_entity element3, file.%import_ref.18 [template]
  177. // CHECK:STDOUT: }
  178. // CHECK:STDOUT:
  179. // CHECK:STDOUT: file {
  180. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  181. // CHECK:STDOUT: .Core = %Core
  182. // CHECK:STDOUT: .C = %C.decl
  183. // CHECK:STDOUT: .TestLess = %TestLess
  184. // CHECK:STDOUT: .TestLessEqual = %TestLessEqual
  185. // CHECK:STDOUT: .TestGreater = %TestGreater
  186. // CHECK:STDOUT: .TestGreaterEqual = %TestGreaterEqual
  187. // CHECK:STDOUT: }
  188. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  189. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  190. // CHECK:STDOUT: %import_ref.1: type = import_ref ir3, inst+1, loc_18 [template = constants.%.2]
  191. // CHECK:STDOUT: %import_ref.2: <associated <function> in Ordered> = import_ref ir3, inst+59, loc_158 [template = constants.%.10]
  192. // CHECK:STDOUT: %import_ref.3 = import_ref ir3, inst+3, unloaded
  193. // CHECK:STDOUT: %import_ref.4: <associated <function> in Ordered> = import_ref ir3, inst+45, loc_138 [template = constants.%.9]
  194. // CHECK:STDOUT: %import_ref.5: <associated <function> in Ordered> = import_ref ir3, inst+17, loc_98 [template = constants.%.7]
  195. // CHECK:STDOUT: %import_ref.6: <associated <function> in Ordered> = import_ref ir3, inst+31, loc_118 [template = constants.%.8]
  196. // CHECK:STDOUT: %import_ref.7: <function> = import_ref ir3, inst+15, loc_19 [template = imports.%Less]
  197. // CHECK:STDOUT: %import_ref.8: <function> = import_ref ir3, inst+30, loc_19 [template = imports.%LessOrEquivalent]
  198. // CHECK:STDOUT: %import_ref.9: <function> = import_ref ir3, inst+44, loc_19 [template = imports.%Greater]
  199. // CHECK:STDOUT: %import_ref.10: <function> = import_ref ir3, inst+58, loc_19 [template = imports.%GreaterOrEquivalent]
  200. // CHECK:STDOUT: impl_decl @impl {
  201. // CHECK:STDOUT: %C.ref.loc8: type = name_ref C, %C.decl [template = constants.%C]
  202. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, %Core [template = %Core]
  203. // CHECK:STDOUT: %Ordered.decl: invalid = interface_decl @Ordered [template = constants.%.2] {}
  204. // CHECK:STDOUT: %Ordered.ref: type = name_ref Ordered, %import_ref.1 [template = constants.%.2]
  205. // CHECK:STDOUT: }
  206. // CHECK:STDOUT: %TestLess: <function> = fn_decl @TestLess [template] {
  207. // CHECK:STDOUT: %C.ref.loc15_16: type = name_ref C, %C.decl [template = constants.%C]
  208. // CHECK:STDOUT: %a.loc15_13.1: C = param a
  209. // CHECK:STDOUT: @TestLess.%a: C = bind_name a, %a.loc15_13.1
  210. // CHECK:STDOUT: %C.ref.loc15_22: type = name_ref C, %C.decl [template = constants.%C]
  211. // CHECK:STDOUT: %b.loc15_19.1: C = param b
  212. // CHECK:STDOUT: @TestLess.%b: C = bind_name b, %b.loc15_19.1
  213. // CHECK:STDOUT: %return.var.loc15: ref bool = var <return slot>
  214. // CHECK:STDOUT: }
  215. // CHECK:STDOUT: %import_ref.11: type = import_ref ir3, inst+1, loc_98 [template = constants.%.2]
  216. // CHECK:STDOUT: %import_ref.12 = import_ref ir3, inst+15, unloaded
  217. // CHECK:STDOUT: %TestLessEqual: <function> = fn_decl @TestLessEqual [template] {
  218. // CHECK:STDOUT: %C.ref.loc19_21: type = name_ref C, %C.decl [template = constants.%C]
  219. // CHECK:STDOUT: %a.loc19_18.1: C = param a
  220. // CHECK:STDOUT: @TestLessEqual.%a: C = bind_name a, %a.loc19_18.1
  221. // CHECK:STDOUT: %C.ref.loc19_27: type = name_ref C, %C.decl [template = constants.%C]
  222. // CHECK:STDOUT: %b.loc19_24.1: C = param b
  223. // CHECK:STDOUT: @TestLessEqual.%b: C = bind_name b, %b.loc19_24.1
  224. // CHECK:STDOUT: %return.var.loc19: ref bool = var <return slot>
  225. // CHECK:STDOUT: }
  226. // CHECK:STDOUT: %import_ref.13: type = import_ref ir3, inst+1, loc_118 [template = constants.%.2]
  227. // CHECK:STDOUT: %import_ref.14 = import_ref ir3, inst+30, unloaded
  228. // CHECK:STDOUT: %TestGreater: <function> = fn_decl @TestGreater [template] {
  229. // CHECK:STDOUT: %C.ref.loc23_19: type = name_ref C, %C.decl [template = constants.%C]
  230. // CHECK:STDOUT: %a.loc23_16.1: C = param a
  231. // CHECK:STDOUT: @TestGreater.%a: C = bind_name a, %a.loc23_16.1
  232. // CHECK:STDOUT: %C.ref.loc23_25: type = name_ref C, %C.decl [template = constants.%C]
  233. // CHECK:STDOUT: %b.loc23_22.1: C = param b
  234. // CHECK:STDOUT: @TestGreater.%b: C = bind_name b, %b.loc23_22.1
  235. // CHECK:STDOUT: %return.var.loc23: ref bool = var <return slot>
  236. // CHECK:STDOUT: }
  237. // CHECK:STDOUT: %import_ref.15: type = import_ref ir3, inst+1, loc_138 [template = constants.%.2]
  238. // CHECK:STDOUT: %import_ref.16 = import_ref ir3, inst+44, unloaded
  239. // CHECK:STDOUT: %TestGreaterEqual: <function> = fn_decl @TestGreaterEqual [template] {
  240. // CHECK:STDOUT: %C.ref.loc27_24: type = name_ref C, %C.decl [template = constants.%C]
  241. // CHECK:STDOUT: %a.loc27_21.1: C = param a
  242. // CHECK:STDOUT: @TestGreaterEqual.%a: C = bind_name a, %a.loc27_21.1
  243. // CHECK:STDOUT: %C.ref.loc27_30: type = name_ref C, %C.decl [template = constants.%C]
  244. // CHECK:STDOUT: %b.loc27_27.1: C = param b
  245. // CHECK:STDOUT: @TestGreaterEqual.%b: C = bind_name b, %b.loc27_27.1
  246. // CHECK:STDOUT: %return.var.loc27: ref bool = var <return slot>
  247. // CHECK:STDOUT: }
  248. // CHECK:STDOUT: %import_ref.17: type = import_ref ir3, inst+1, loc_158 [template = constants.%.2]
  249. // CHECK:STDOUT: %import_ref.18 = import_ref ir3, inst+58, unloaded
  250. // CHECK:STDOUT: }
  251. // CHECK:STDOUT:
  252. // CHECK:STDOUT: interface @Ordered {
  253. // CHECK:STDOUT: !members:
  254. // CHECK:STDOUT: .GreaterOrEquivalent = file.%import_ref.2
  255. // CHECK:STDOUT: .Self = file.%import_ref.3
  256. // CHECK:STDOUT: .Greater = file.%import_ref.4
  257. // CHECK:STDOUT: .Less = file.%import_ref.5
  258. // CHECK:STDOUT: .LessOrEquivalent = file.%import_ref.6
  259. // CHECK:STDOUT: witness = (file.%import_ref.7, file.%import_ref.8, file.%import_ref.9, file.%import_ref.10)
  260. // CHECK:STDOUT: }
  261. // CHECK:STDOUT:
  262. // CHECK:STDOUT: impl @impl: C as Ordered {
  263. // CHECK:STDOUT: %Less: <function> = fn_decl @Less.1 [template] {
  264. // CHECK:STDOUT: %C.ref.loc9_17: type = name_ref C, file.%C.decl [template = constants.%C]
  265. // CHECK:STDOUT: %self.loc9_11.1: C = param self
  266. // CHECK:STDOUT: %self.loc9_11.2: C = bind_name self, %self.loc9_11.1
  267. // CHECK:STDOUT: %C.ref.loc9_27: type = name_ref C, file.%C.decl [template = constants.%C]
  268. // CHECK:STDOUT: %other.loc9_20.1: C = param other
  269. // CHECK:STDOUT: %other.loc9_20.2: C = bind_name other, %other.loc9_20.1
  270. // CHECK:STDOUT: %return.var.loc9: ref bool = var <return slot>
  271. // CHECK:STDOUT: }
  272. // CHECK:STDOUT: %LessOrEquivalent: <function> = fn_decl @LessOrEquivalent.1 [template] {
  273. // CHECK:STDOUT: %C.ref.loc10_29: type = name_ref C, file.%C.decl [template = constants.%C]
  274. // CHECK:STDOUT: %self.loc10_23.1: C = param self
  275. // CHECK:STDOUT: %self.loc10_23.2: C = bind_name self, %self.loc10_23.1
  276. // CHECK:STDOUT: %C.ref.loc10_39: type = name_ref C, file.%C.decl [template = constants.%C]
  277. // CHECK:STDOUT: %other.loc10_32.1: C = param other
  278. // CHECK:STDOUT: %other.loc10_32.2: C = bind_name other, %other.loc10_32.1
  279. // CHECK:STDOUT: %return.var.loc10: ref bool = var <return slot>
  280. // CHECK:STDOUT: }
  281. // CHECK:STDOUT: %Greater: <function> = fn_decl @Greater.1 [template] {
  282. // CHECK:STDOUT: %C.ref.loc11_20: type = name_ref C, file.%C.decl [template = constants.%C]
  283. // CHECK:STDOUT: %self.loc11_14.1: C = param self
  284. // CHECK:STDOUT: %self.loc11_14.2: C = bind_name self, %self.loc11_14.1
  285. // CHECK:STDOUT: %C.ref.loc11_30: type = name_ref C, file.%C.decl [template = constants.%C]
  286. // CHECK:STDOUT: %other.loc11_23.1: C = param other
  287. // CHECK:STDOUT: %other.loc11_23.2: C = bind_name other, %other.loc11_23.1
  288. // CHECK:STDOUT: %return.var.loc11: ref bool = var <return slot>
  289. // CHECK:STDOUT: }
  290. // CHECK:STDOUT: %GreaterOrEquivalent: <function> = fn_decl @GreaterOrEquivalent.1 [template] {
  291. // CHECK:STDOUT: %C.ref.loc12_32: type = name_ref C, file.%C.decl [template = constants.%C]
  292. // CHECK:STDOUT: %self.loc12_26.1: C = param self
  293. // CHECK:STDOUT: %self.loc12_26.2: C = bind_name self, %self.loc12_26.1
  294. // CHECK:STDOUT: %C.ref.loc12_42: type = name_ref C, file.%C.decl [template = constants.%C]
  295. // CHECK:STDOUT: %other.loc12_35.1: C = param other
  296. // CHECK:STDOUT: %other.loc12_35.2: C = bind_name other, %other.loc12_35.1
  297. // CHECK:STDOUT: %return.var.loc12: ref bool = var <return slot>
  298. // CHECK:STDOUT: }
  299. // CHECK:STDOUT: %.1: <witness> = interface_witness (%Less, %LessOrEquivalent, %Greater, %GreaterOrEquivalent) [template = constants.%.3]
  300. // CHECK:STDOUT:
  301. // CHECK:STDOUT: !members:
  302. // CHECK:STDOUT: .Less = %Less
  303. // CHECK:STDOUT: .LessOrEquivalent = %LessOrEquivalent
  304. // CHECK:STDOUT: .Greater = %Greater
  305. // CHECK:STDOUT: .GreaterOrEquivalent = %GreaterOrEquivalent
  306. // CHECK:STDOUT: witness = %.1
  307. // CHECK:STDOUT: }
  308. // CHECK:STDOUT:
  309. // CHECK:STDOUT: class @C {
  310. // CHECK:STDOUT: !members:
  311. // CHECK:STDOUT: .Self = constants.%C
  312. // CHECK:STDOUT: }
  313. // CHECK:STDOUT:
  314. // CHECK:STDOUT: fn @Less.1[@impl.%self.loc9_11.2: C](@impl.%other.loc9_20.2: C) -> bool;
  315. // CHECK:STDOUT:
  316. // CHECK:STDOUT: fn @LessOrEquivalent.1[@impl.%self.loc10_23.2: C](@impl.%other.loc10_32.2: C) -> bool;
  317. // CHECK:STDOUT:
  318. // CHECK:STDOUT: fn @Greater.1[@impl.%self.loc11_14.2: C](@impl.%other.loc11_23.2: C) -> bool;
  319. // CHECK:STDOUT:
  320. // CHECK:STDOUT: fn @GreaterOrEquivalent.1[@impl.%self.loc12_26.2: C](@impl.%other.loc12_35.2: C) -> bool;
  321. // CHECK:STDOUT:
  322. // CHECK:STDOUT: fn @Less.2[%self: Self](%other: Self) -> bool;
  323. // CHECK:STDOUT:
  324. // CHECK:STDOUT: fn @LessOrEquivalent.2[%self: Self](%other: Self) -> bool;
  325. // CHECK:STDOUT:
  326. // CHECK:STDOUT: fn @Greater.2[%self: Self](%other: Self) -> bool;
  327. // CHECK:STDOUT:
  328. // CHECK:STDOUT: fn @GreaterOrEquivalent.2[%self: Self](%other: Self) -> bool;
  329. // CHECK:STDOUT:
  330. // CHECK:STDOUT: fn @TestLess(%a: C, %b: C) -> bool {
  331. // CHECK:STDOUT: !entry:
  332. // CHECK:STDOUT: %a.ref: C = name_ref a, %a
  333. // CHECK:STDOUT: %b.ref: C = name_ref b, %b
  334. // CHECK:STDOUT: %.1: <function> = interface_witness_access @impl.%.1, element0 [template = @impl.%Less]
  335. // CHECK:STDOUT: %.loc16_12.1: <bound method> = bound_method %a.ref, %.1
  336. // CHECK:STDOUT: %.loc16_12.2: init bool = call %.loc16_12.1(%a.ref, %b.ref)
  337. // CHECK:STDOUT: %.loc16_15: bool = value_of_initializer %.loc16_12.2
  338. // CHECK:STDOUT: %.loc16_12.3: bool = converted %.loc16_12.2, %.loc16_15
  339. // CHECK:STDOUT: return %.loc16_12.3
  340. // CHECK:STDOUT: }
  341. // CHECK:STDOUT:
  342. // CHECK:STDOUT: fn @TestLessEqual(%a: C, %b: C) -> bool {
  343. // CHECK:STDOUT: !entry:
  344. // CHECK:STDOUT: %a.ref: C = name_ref a, %a
  345. // CHECK:STDOUT: %b.ref: C = name_ref b, %b
  346. // CHECK:STDOUT: %.1: <function> = interface_witness_access @impl.%.1, element1 [template = @impl.%LessOrEquivalent]
  347. // CHECK:STDOUT: %.loc20_12.1: <bound method> = bound_method %a.ref, %.1
  348. // CHECK:STDOUT: %.loc20_12.2: init bool = call %.loc20_12.1(%a.ref, %b.ref)
  349. // CHECK:STDOUT: %.loc20_16: bool = value_of_initializer %.loc20_12.2
  350. // CHECK:STDOUT: %.loc20_12.3: bool = converted %.loc20_12.2, %.loc20_16
  351. // CHECK:STDOUT: return %.loc20_12.3
  352. // CHECK:STDOUT: }
  353. // CHECK:STDOUT:
  354. // CHECK:STDOUT: fn @TestGreater(%a: C, %b: C) -> bool {
  355. // CHECK:STDOUT: !entry:
  356. // CHECK:STDOUT: %a.ref: C = name_ref a, %a
  357. // CHECK:STDOUT: %b.ref: C = name_ref b, %b
  358. // CHECK:STDOUT: %.1: <function> = interface_witness_access @impl.%.1, element2 [template = @impl.%Greater]
  359. // CHECK:STDOUT: %.loc24_12.1: <bound method> = bound_method %a.ref, %.1
  360. // CHECK:STDOUT: %.loc24_12.2: init bool = call %.loc24_12.1(%a.ref, %b.ref)
  361. // CHECK:STDOUT: %.loc24_15: bool = value_of_initializer %.loc24_12.2
  362. // CHECK:STDOUT: %.loc24_12.3: bool = converted %.loc24_12.2, %.loc24_15
  363. // CHECK:STDOUT: return %.loc24_12.3
  364. // CHECK:STDOUT: }
  365. // CHECK:STDOUT:
  366. // CHECK:STDOUT: fn @TestGreaterEqual(%a: C, %b: C) -> bool {
  367. // CHECK:STDOUT: !entry:
  368. // CHECK:STDOUT: %a.ref: C = name_ref a, %a
  369. // CHECK:STDOUT: %b.ref: C = name_ref b, %b
  370. // CHECK:STDOUT: %.1: <function> = interface_witness_access @impl.%.1, element3 [template = @impl.%GreaterOrEquivalent]
  371. // CHECK:STDOUT: %.loc28_12.1: <bound method> = bound_method %a.ref, %.1
  372. // CHECK:STDOUT: %.loc28_12.2: init bool = call %.loc28_12.1(%a.ref, %b.ref)
  373. // CHECK:STDOUT: %.loc28_16: bool = value_of_initializer %.loc28_12.2
  374. // CHECK:STDOUT: %.loc28_12.3: bool = converted %.loc28_12.2, %.loc28_16
  375. // CHECK:STDOUT: return %.loc28_12.3
  376. // CHECK:STDOUT: }
  377. // CHECK:STDOUT:
  378. // CHECK:STDOUT: --- fail_no_impl.carbon
  379. // CHECK:STDOUT:
  380. // CHECK:STDOUT: constants {
  381. // CHECK:STDOUT: %D: type = class_type @D [template]
  382. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  383. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  384. // CHECK:STDOUT: %.3: type = ptr_type {} [template]
  385. // CHECK:STDOUT: %.4: type = interface_type @Ordered [template]
  386. // CHECK:STDOUT: %.5: type = assoc_entity_type @Ordered, <function> [template]
  387. // CHECK:STDOUT: %.6: <associated <function> in Ordered> = assoc_entity element0, file.%import_ref.11 [template]
  388. // CHECK:STDOUT: %.7: <associated <function> in Ordered> = assoc_entity element1, file.%import_ref.13 [template]
  389. // CHECK:STDOUT: %.8: <associated <function> in Ordered> = assoc_entity element2, file.%import_ref.15 [template]
  390. // CHECK:STDOUT: %.9: <associated <function> in Ordered> = assoc_entity element3, file.%import_ref.17 [template]
  391. // CHECK:STDOUT: }
  392. // CHECK:STDOUT:
  393. // CHECK:STDOUT: file {
  394. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  395. // CHECK:STDOUT: .Core = %Core
  396. // CHECK:STDOUT: .D = %D.decl
  397. // CHECK:STDOUT: .TestLess = %TestLess
  398. // CHECK:STDOUT: .TestLessEqual = %TestLessEqual
  399. // CHECK:STDOUT: .TestGreater = %TestGreater
  400. // CHECK:STDOUT: .TestGreaterEqual = %TestGreaterEqual
  401. // CHECK:STDOUT: }
  402. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  403. // CHECK:STDOUT: %D.decl: type = class_decl @D [template = constants.%D] {}
  404. // CHECK:STDOUT: %TestLess: <function> = fn_decl @TestLess [template] {
  405. // CHECK:STDOUT: %D.ref.loc8_16: type = name_ref D, %D.decl [template = constants.%D]
  406. // CHECK:STDOUT: %a.loc8_13.1: D = param a
  407. // CHECK:STDOUT: @TestLess.%a: D = bind_name a, %a.loc8_13.1
  408. // CHECK:STDOUT: %D.ref.loc8_22: type = name_ref D, %D.decl [template = constants.%D]
  409. // CHECK:STDOUT: %b.loc8_19.1: D = param b
  410. // CHECK:STDOUT: @TestLess.%b: D = bind_name b, %b.loc8_19.1
  411. // CHECK:STDOUT: %return.var.loc8: ref bool = var <return slot>
  412. // CHECK:STDOUT: }
  413. // CHECK:STDOUT: %import_ref.1: type = import_ref ir3, inst+1, loc_30 [template = constants.%.4]
  414. // CHECK:STDOUT: %import_ref.2: <associated <function> in Ordered> = import_ref ir3, inst+59, loc_90 [template = constants.%.9]
  415. // CHECK:STDOUT: %import_ref.3 = import_ref ir3, inst+3, unloaded
  416. // CHECK:STDOUT: %import_ref.4: <associated <function> in Ordered> = import_ref ir3, inst+45, loc_70 [template = constants.%.8]
  417. // CHECK:STDOUT: %import_ref.5: <associated <function> in Ordered> = import_ref ir3, inst+17, loc_30 [template = constants.%.6]
  418. // CHECK:STDOUT: %import_ref.6: <associated <function> in Ordered> = import_ref ir3, inst+31, loc_50 [template = constants.%.7]
  419. // CHECK:STDOUT: %import_ref.7 = import_ref ir3, inst+15, unloaded
  420. // CHECK:STDOUT: %import_ref.8 = import_ref ir3, inst+30, unloaded
  421. // CHECK:STDOUT: %import_ref.9 = import_ref ir3, inst+44, unloaded
  422. // CHECK:STDOUT: %import_ref.10 = import_ref ir3, inst+58, unloaded
  423. // CHECK:STDOUT: %import_ref.11 = import_ref ir3, inst+15, unloaded
  424. // CHECK:STDOUT: %TestLessEqual: <function> = fn_decl @TestLessEqual [template] {
  425. // CHECK:STDOUT: %D.ref.loc16_21: type = name_ref D, %D.decl [template = constants.%D]
  426. // CHECK:STDOUT: %a.loc16_18.1: D = param a
  427. // CHECK:STDOUT: @TestLessEqual.%a: D = bind_name a, %a.loc16_18.1
  428. // CHECK:STDOUT: %D.ref.loc16_27: type = name_ref D, %D.decl [template = constants.%D]
  429. // CHECK:STDOUT: %b.loc16_24.1: D = param b
  430. // CHECK:STDOUT: @TestLessEqual.%b: D = bind_name b, %b.loc16_24.1
  431. // CHECK:STDOUT: %return.var.loc16: ref bool = var <return slot>
  432. // CHECK:STDOUT: }
  433. // CHECK:STDOUT: %import_ref.12: type = import_ref ir3, inst+1, loc_50 [template = constants.%.4]
  434. // CHECK:STDOUT: %import_ref.13 = import_ref ir3, inst+30, unloaded
  435. // CHECK:STDOUT: %TestGreater: <function> = fn_decl @TestGreater [template] {
  436. // CHECK:STDOUT: %D.ref.loc24_19: type = name_ref D, %D.decl [template = constants.%D]
  437. // CHECK:STDOUT: %a.loc24_16.1: D = param a
  438. // CHECK:STDOUT: @TestGreater.%a: D = bind_name a, %a.loc24_16.1
  439. // CHECK:STDOUT: %D.ref.loc24_25: type = name_ref D, %D.decl [template = constants.%D]
  440. // CHECK:STDOUT: %b.loc24_22.1: D = param b
  441. // CHECK:STDOUT: @TestGreater.%b: D = bind_name b, %b.loc24_22.1
  442. // CHECK:STDOUT: %return.var.loc24: ref bool = var <return slot>
  443. // CHECK:STDOUT: }
  444. // CHECK:STDOUT: %import_ref.14: type = import_ref ir3, inst+1, loc_70 [template = constants.%.4]
  445. // CHECK:STDOUT: %import_ref.15 = import_ref ir3, inst+44, unloaded
  446. // CHECK:STDOUT: %TestGreaterEqual: <function> = fn_decl @TestGreaterEqual [template] {
  447. // CHECK:STDOUT: %D.ref.loc32_24: type = name_ref D, %D.decl [template = constants.%D]
  448. // CHECK:STDOUT: %a.loc32_21.1: D = param a
  449. // CHECK:STDOUT: @TestGreaterEqual.%a: D = bind_name a, %a.loc32_21.1
  450. // CHECK:STDOUT: %D.ref.loc32_30: type = name_ref D, %D.decl [template = constants.%D]
  451. // CHECK:STDOUT: %b.loc32_27.1: D = param b
  452. // CHECK:STDOUT: @TestGreaterEqual.%b: D = bind_name b, %b.loc32_27.1
  453. // CHECK:STDOUT: %return.var.loc32: ref bool = var <return slot>
  454. // CHECK:STDOUT: }
  455. // CHECK:STDOUT: %import_ref.16: type = import_ref ir3, inst+1, loc_90 [template = constants.%.4]
  456. // CHECK:STDOUT: %import_ref.17 = import_ref ir3, inst+58, unloaded
  457. // CHECK:STDOUT: }
  458. // CHECK:STDOUT:
  459. // CHECK:STDOUT: interface @Ordered {
  460. // CHECK:STDOUT: !members:
  461. // CHECK:STDOUT: .GreaterOrEquivalent = file.%import_ref.2
  462. // CHECK:STDOUT: .Self = file.%import_ref.3
  463. // CHECK:STDOUT: .Greater = file.%import_ref.4
  464. // CHECK:STDOUT: .Less = file.%import_ref.5
  465. // CHECK:STDOUT: .LessOrEquivalent = file.%import_ref.6
  466. // CHECK:STDOUT: witness = (file.%import_ref.7, file.%import_ref.8, file.%import_ref.9, file.%import_ref.10)
  467. // CHECK:STDOUT: }
  468. // CHECK:STDOUT:
  469. // CHECK:STDOUT: class @D {
  470. // CHECK:STDOUT: !members:
  471. // CHECK:STDOUT: .Self = constants.%D
  472. // CHECK:STDOUT: }
  473. // CHECK:STDOUT:
  474. // CHECK:STDOUT: fn @TestLess(%a: D, %b: D) -> bool {
  475. // CHECK:STDOUT: !entry:
  476. // CHECK:STDOUT: %a.ref: D = name_ref a, %a
  477. // CHECK:STDOUT: %b.ref: D = name_ref b, %b
  478. // CHECK:STDOUT: %Ordered.decl: invalid = interface_decl @Ordered [template = constants.%.4] {}
  479. // CHECK:STDOUT: return <error>
  480. // CHECK:STDOUT: }
  481. // CHECK:STDOUT:
  482. // CHECK:STDOUT: fn @TestLessEqual(%a: D, %b: D) -> bool {
  483. // CHECK:STDOUT: !entry:
  484. // CHECK:STDOUT: %a.ref: D = name_ref a, %a
  485. // CHECK:STDOUT: %b.ref: D = name_ref b, %b
  486. // CHECK:STDOUT: return <error>
  487. // CHECK:STDOUT: }
  488. // CHECK:STDOUT:
  489. // CHECK:STDOUT: fn @TestGreater(%a: D, %b: D) -> bool {
  490. // CHECK:STDOUT: !entry:
  491. // CHECK:STDOUT: %a.ref: D = name_ref a, %a
  492. // CHECK:STDOUT: %b.ref: D = name_ref b, %b
  493. // CHECK:STDOUT: return <error>
  494. // CHECK:STDOUT: }
  495. // CHECK:STDOUT:
  496. // CHECK:STDOUT: fn @TestGreaterEqual(%a: D, %b: D) -> bool {
  497. // CHECK:STDOUT: !entry:
  498. // CHECK:STDOUT: %a.ref: D = name_ref a, %a
  499. // CHECK:STDOUT: %b.ref: D = name_ref b, %b
  500. // CHECK:STDOUT: return <error>
  501. // CHECK:STDOUT: }
  502. // CHECK:STDOUT: