ordered.carbon 29 KB

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