equal_rewrite.carbon 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  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/where_expr/equal_rewrite.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/where_expr/equal_rewrite.carbon
  10. // --- equal_constraint.carbon
  11. library "[[@TEST_NAME]]";
  12. interface N {
  13. let P:! type;
  14. }
  15. //@dump-sem-ir-begin
  16. fn Equal(T:! N where .P = {});
  17. //@dump-sem-ir-end
  18. // --- nested_rewrites.carbon
  19. library "[[@TEST_NAME]]";
  20. interface A {
  21. let B:! type;
  22. let C:! type;
  23. }
  24. //@dump-sem-ir-begin
  25. fn NestedRewrite(D:! (A where .B = bool) where .C = ());
  26. //@dump-sem-ir-end
  27. // --- repeated_rewrite.carbon
  28. library "[[@TEST_NAME]]";
  29. interface E {
  30. let F:! type;
  31. }
  32. //@dump-sem-ir-begin
  33. fn OneRewrite(G:! E where .F = i32) {}
  34. fn RepeatedRewrite(H:! E where .F = i32 and .F = i32) {
  35. //@dump-sem-ir-end
  36. OneRewrite(H);
  37. }
  38. fn OneRewriteAgain(I:! E where .F = i32) {
  39. RepeatedRewrite(I);
  40. }
  41. // --- rewrites_reordered.carbon
  42. library "[[@TEST_NAME]]";
  43. interface J {
  44. let K:! type;
  45. let L:! type;
  46. }
  47. //@dump-sem-ir-begin
  48. fn Alphabetical(M:! J where .K = () and .L = bool) {}
  49. fn Reversed(N:! J where .L = bool and .K = ()) {
  50. //@dump-sem-ir-end
  51. Alphabetical(N);
  52. }
  53. // --- todo_fail_rewrites_mismatch_right.carbon
  54. library "[[@TEST_NAME]]";
  55. interface O {
  56. let P:! type;
  57. }
  58. fn WithInteger(Q:! O where .P = i32) {}
  59. fn WithBool(R:! O where .P = bool) {
  60. // TODO: This should fail.
  61. WithInteger(R);
  62. }
  63. // --- todo_fail_rewrites_mismatch_left.carbon
  64. library "[[@TEST_NAME]]";
  65. interface S {
  66. let T:! type;
  67. let U:! type;
  68. }
  69. fn WithT(V:! S where .T = ()) {}
  70. fn WithU(W:! S where .U = ()) {
  71. // TODO: This should fail.
  72. WithT(W);
  73. }
  74. // --- fail_import_rewrites.carbon
  75. library "[[@TEST_NAME]]";
  76. import library "equal_constraint";
  77. import library "nested_rewrites";
  78. fn Calls() {
  79. // CHECK:STDERR: fail_import_rewrites.carbon:[[@LINE+8]]:3: error: cannot convert type `bool` into type implementing `N where .(N.P) = {}` [ConversionFailureTypeToFacet]
  80. // CHECK:STDERR: Equal(bool);
  81. // CHECK:STDERR: ^~~~~~~~~~~
  82. // CHECK:STDERR: fail_import_rewrites.carbon:[[@LINE-7]]:1: in import [InImport]
  83. // CHECK:STDERR: equal_constraint.carbon:9:10: note: initializing generic parameter `T` declared here [InitializingGenericParam]
  84. // CHECK:STDERR: fn Equal(T:! N where .P = {});
  85. // CHECK:STDERR: ^
  86. // CHECK:STDERR:
  87. Equal(bool);
  88. // CHECK:STDERR: fail_import_rewrites.carbon:[[@LINE+8]]:3: error: cannot convert type `i32` into type implementing `A where .(A.B) = bool and .(A.C) = ()` [ConversionFailureTypeToFacet]
  89. // CHECK:STDERR: NestedRewrite(i32);
  90. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~
  91. // CHECK:STDERR: fail_import_rewrites.carbon:[[@LINE-17]]:1: in import [InImport]
  92. // CHECK:STDERR: nested_rewrites.carbon:10:18: note: initializing generic parameter `D` declared here [InitializingGenericParam]
  93. // CHECK:STDERR: fn NestedRewrite(D:! (A where .B = bool) where .C = ());
  94. // CHECK:STDERR: ^
  95. // CHECK:STDERR:
  96. NestedRewrite(i32);
  97. }
  98. // --- fail_check_rewrite_constraints.carbon
  99. library "[[@TEST_NAME]]";
  100. interface I {
  101. let Member:! type;
  102. }
  103. // `2` can't be converted to the type of `I.Member`
  104. // CHECK:STDERR: fail_check_rewrite_constraints.carbon:[[@LINE+7]]:46: error: cannot implicitly convert non-type value of type `Core.IntLiteral` to `type` [ConversionFailureNonTypeToFacet]
  105. // CHECK:STDERR: fn RewriteTypeMismatch(X:! I where .Member = 2);
  106. // CHECK:STDERR: ^
  107. // CHECK:STDERR: fail_check_rewrite_constraints.carbon:[[@LINE+4]]:46: note: type `Core.IntLiteral` does not implement interface `Core.ImplicitAs(type)` [MissingImplInMemberAccessNote]
  108. // CHECK:STDERR: fn RewriteTypeMismatch(X:! I where .Member = 2);
  109. // CHECK:STDERR: ^
  110. // CHECK:STDERR:
  111. fn RewriteTypeMismatch(X:! I where .Member = 2);
  112. // --- todo_let.carbon
  113. library "[[@TEST_NAME]]";
  114. interface A {}
  115. class D {}
  116. impl D as A {}
  117. // TODO: This should be a compile-time binding, once that is supported at file scope.
  118. let B: type where .Self impls A = D;
  119. fn F() {
  120. let E:! type where .Self impls A = D;
  121. }
  122. // --- fail_todo_let_compile_time.carbon
  123. library "[[@TEST_NAME]]";
  124. interface A {}
  125. class D {}
  126. impl D as A {}
  127. // TODO: Compile-time binding are not yet supported at file scope.
  128. // CHECK:STDERR: fail_todo_let_compile_time.carbon:[[@LINE+4]]:5: error: semantics TODO: ``let` compile time binding outside function or interface` [SemanticsTodo]
  129. // CHECK:STDERR: let B:! type where .Self impls A = D;
  130. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
  131. // CHECK:STDERR:
  132. let B:! type where .Self impls A = D;
  133. // --- fail_type_does_not_implement_where.carbon
  134. library "[[@TEST_NAME]]";
  135. interface E {
  136. let F:! type;
  137. let G:! type;
  138. }
  139. // Testing how these types get stringified in error messages.
  140. // TODO: This should be a compile-time binding, once that is supported.
  141. // CHECK:STDERR: fail_type_does_not_implement_where.carbon:[[@LINE+4]]:42: error: cannot convert type `f64` into type implementing `E where .(E.F) = bool and .(E.G) = ()` [ConversionFailureTypeToFacet]
  142. // CHECK:STDERR: let H: (E where .F = bool and .G = ()) = f64;
  143. // CHECK:STDERR: ^~~
  144. // CHECK:STDERR:
  145. let H: (E where .F = bool and .G = ()) = f64;
  146. // CHECK:STDERR: fail_type_does_not_implement_where.carbon:[[@LINE+4]]:45: error: cannot convert type `bool` into type implementing `E where .(E.F) = {} and .(E.G) = i32` [ConversionFailureTypeToFacet]
  147. // CHECK:STDERR: let J: ((E where .F = {}) where .G = i32) = bool;
  148. // CHECK:STDERR: ^~~~
  149. // CHECK:STDERR:
  150. let J: ((E where .F = {}) where .G = i32) = bool;
  151. // CHECK:STDERR: fail_type_does_not_implement_where.carbon:[[@LINE+4]]:33: error: cannot convert type `bool` into type implementing `E where .(E.F) = .(E.G)` [ConversionFailureTypeToFacet]
  152. // CHECK:STDERR: let K: (E where .F = .Self.G) = bool;
  153. // CHECK:STDERR: ^~~~
  154. // CHECK:STDERR:
  155. let K: (E where .F = .Self.G) = bool;
  156. // CHECK:STDOUT: --- equal_constraint.carbon
  157. // CHECK:STDOUT:
  158. // CHECK:STDOUT: constants {
  159. // CHECK:STDOUT: %N.type: type = facet_type <@N> [concrete]
  160. // CHECK:STDOUT: %N.assoc_type: type = assoc_entity_type @N [concrete]
  161. // CHECK:STDOUT: %assoc0: %N.assoc_type = assoc_entity element0, @N.%P [concrete]
  162. // CHECK:STDOUT: %.Self: %N.type = bind_symbolic_name .Self [symbolic_self]
  163. // CHECK:STDOUT: %.Self.as_type: type = facet_access_type %.Self [symbolic_self]
  164. // CHECK:STDOUT: %N.lookup_impl_witness: <witness> = lookup_impl_witness %.Self, @N [symbolic_self]
  165. // CHECK:STDOUT: %impl.elem0: type = impl_witness_access %N.lookup_impl_witness, element0 [symbolic_self]
  166. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  167. // CHECK:STDOUT: %N_where.type: type = facet_type <@N where %impl.elem0 = %empty_struct_type> [concrete]
  168. // CHECK:STDOUT: %T: %N_where.type = bind_symbolic_name T, 0 [symbolic]
  169. // CHECK:STDOUT: %pattern_type: type = pattern_type %N_where.type [concrete]
  170. // CHECK:STDOUT: %Equal.type: type = fn_type @Equal [concrete]
  171. // CHECK:STDOUT: %Equal: %Equal.type = struct_value () [concrete]
  172. // CHECK:STDOUT: }
  173. // CHECK:STDOUT:
  174. // CHECK:STDOUT: imports {
  175. // CHECK:STDOUT: }
  176. // CHECK:STDOUT:
  177. // CHECK:STDOUT: file {
  178. // CHECK:STDOUT: %Equal.decl: %Equal.type = fn_decl @Equal [concrete = constants.%Equal] {
  179. // CHECK:STDOUT: %T.patt: %pattern_type = symbolic_binding_pattern T, 0 [concrete]
  180. // CHECK:STDOUT: } {
  181. // CHECK:STDOUT: %.loc9_16.1: type = splice_block %.loc9_16.2 [concrete = constants.%N_where.type] {
  182. // CHECK:STDOUT: %N.ref: type = name_ref N, file.%N.decl [concrete = constants.%N.type]
  183. // CHECK:STDOUT: <elided>
  184. // CHECK:STDOUT: %.Self.ref: %N.type = name_ref .Self, %.Self [symbolic_self = constants.%.Self]
  185. // CHECK:STDOUT: %P.ref: %N.assoc_type = name_ref P, @P.%assoc0 [concrete = constants.%assoc0]
  186. // CHECK:STDOUT: %.Self.as_type: type = facet_access_type %.Self.ref [symbolic_self = constants.%.Self.as_type]
  187. // CHECK:STDOUT: %.loc9_22: type = converted %.Self.ref, %.Self.as_type [symbolic_self = constants.%.Self.as_type]
  188. // CHECK:STDOUT: %impl.elem0: type = impl_witness_access constants.%N.lookup_impl_witness, element0 [symbolic_self = constants.%impl.elem0]
  189. // CHECK:STDOUT: %.loc9_28.1: %empty_struct_type = struct_literal ()
  190. // CHECK:STDOUT: %.loc9_28.2: type = converted %.loc9_28.1, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  191. // CHECK:STDOUT: %.loc9_16.2: type = where_expr %.Self [concrete = constants.%N_where.type] {
  192. // CHECK:STDOUT: requirement_rewrite %impl.elem0, %.loc9_28.2
  193. // CHECK:STDOUT: }
  194. // CHECK:STDOUT: }
  195. // CHECK:STDOUT: %T.loc9_10.1: %N_where.type = bind_symbolic_name T, 0 [symbolic = %T.loc9_10.2 (constants.%T)]
  196. // CHECK:STDOUT: }
  197. // CHECK:STDOUT: }
  198. // CHECK:STDOUT:
  199. // CHECK:STDOUT: generic fn @Equal(%T.loc9_10.1: %N_where.type) {
  200. // CHECK:STDOUT: %T.loc9_10.2: %N_where.type = bind_symbolic_name T, 0 [symbolic = %T.loc9_10.2 (constants.%T)]
  201. // CHECK:STDOUT:
  202. // CHECK:STDOUT: fn();
  203. // CHECK:STDOUT: }
  204. // CHECK:STDOUT:
  205. // CHECK:STDOUT: specific @Equal(constants.%T) {
  206. // CHECK:STDOUT: %T.loc9_10.2 => constants.%T
  207. // CHECK:STDOUT: }
  208. // CHECK:STDOUT:
  209. // CHECK:STDOUT: --- nested_rewrites.carbon
  210. // CHECK:STDOUT:
  211. // CHECK:STDOUT: constants {
  212. // CHECK:STDOUT: %A.type: type = facet_type <@A> [concrete]
  213. // CHECK:STDOUT: %A.assoc_type: type = assoc_entity_type @A [concrete]
  214. // CHECK:STDOUT: %assoc0: %A.assoc_type = assoc_entity element0, @A.%B [concrete]
  215. // CHECK:STDOUT: %assoc1: %A.assoc_type = assoc_entity element1, @A.%C [concrete]
  216. // CHECK:STDOUT: %.Self.3ca: %A.type = bind_symbolic_name .Self [symbolic_self]
  217. // CHECK:STDOUT: %.Self.as_type.adb: type = facet_access_type %.Self.3ca [symbolic_self]
  218. // CHECK:STDOUT: %A.lookup_impl_witness.5ad: <witness> = lookup_impl_witness %.Self.3ca, @A [symbolic_self]
  219. // CHECK:STDOUT: %impl.elem0: type = impl_witness_access %A.lookup_impl_witness.5ad, element0 [symbolic_self]
  220. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [concrete]
  221. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  222. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [concrete]
  223. // CHECK:STDOUT: %A_where.type.ef7: type = facet_type <@A where %impl.elem0 = bool> [concrete]
  224. // CHECK:STDOUT: %.Self.60a: %A_where.type.ef7 = bind_symbolic_name .Self [symbolic_self]
  225. // CHECK:STDOUT: %.Self.as_type.e64: type = facet_access_type %.Self.60a [symbolic_self]
  226. // CHECK:STDOUT: %A.lookup_impl_witness.138: <witness> = lookup_impl_witness %.Self.60a, @A [symbolic_self]
  227. // CHECK:STDOUT: %impl.elem1: type = impl_witness_access %A.lookup_impl_witness.138, element1 [symbolic_self]
  228. // CHECK:STDOUT: %A_where.type.2d0: type = facet_type <@A where %impl.elem0 = bool and %impl.elem1 = %empty_tuple.type> [concrete]
  229. // CHECK:STDOUT: %D: %A_where.type.2d0 = bind_symbolic_name D, 0 [symbolic]
  230. // CHECK:STDOUT: %pattern_type.24c: type = pattern_type %A_where.type.2d0 [concrete]
  231. // CHECK:STDOUT: %NestedRewrite.type: type = fn_type @NestedRewrite [concrete]
  232. // CHECK:STDOUT: %NestedRewrite: %NestedRewrite.type = struct_value () [concrete]
  233. // CHECK:STDOUT: }
  234. // CHECK:STDOUT:
  235. // CHECK:STDOUT: imports {
  236. // CHECK:STDOUT: }
  237. // CHECK:STDOUT:
  238. // CHECK:STDOUT: file {
  239. // CHECK:STDOUT: %NestedRewrite.decl: %NestedRewrite.type = fn_decl @NestedRewrite [concrete = constants.%NestedRewrite] {
  240. // CHECK:STDOUT: %D.patt: %pattern_type.24c = symbolic_binding_pattern D, 0 [concrete]
  241. // CHECK:STDOUT: } {
  242. // CHECK:STDOUT: %.loc10_42.1: type = splice_block %.loc10_42.2 [concrete = constants.%A_where.type.2d0] {
  243. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [concrete = constants.%A.type]
  244. // CHECK:STDOUT: <elided>
  245. // CHECK:STDOUT: %.Self.ref.loc10_31: %A.type = name_ref .Self, %.Self.1 [symbolic_self = constants.%.Self.3ca]
  246. // CHECK:STDOUT: %B.ref: %A.assoc_type = name_ref B, @B.%assoc0 [concrete = constants.%assoc0]
  247. // CHECK:STDOUT: %.Self.as_type.loc10_31: type = facet_access_type %.Self.ref.loc10_31 [symbolic_self = constants.%.Self.as_type.adb]
  248. // CHECK:STDOUT: %.loc10_31: type = converted %.Self.ref.loc10_31, %.Self.as_type.loc10_31 [symbolic_self = constants.%.Self.as_type.adb]
  249. // CHECK:STDOUT: %impl.elem0: type = impl_witness_access constants.%A.lookup_impl_witness.5ad, element0 [symbolic_self = constants.%impl.elem0]
  250. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [concrete = bool]
  251. // CHECK:STDOUT: %.loc10_36.1: type = value_of_initializer %bool.make_type [concrete = bool]
  252. // CHECK:STDOUT: %.loc10_36.2: type = converted %bool.make_type, %.loc10_36.1 [concrete = bool]
  253. // CHECK:STDOUT: %.loc10_25: type = where_expr %.Self.1 [concrete = constants.%A_where.type.ef7] {
  254. // CHECK:STDOUT: requirement_rewrite %impl.elem0, %.loc10_36.2
  255. // CHECK:STDOUT: }
  256. // CHECK:STDOUT: <elided>
  257. // CHECK:STDOUT: %.Self.ref.loc10_48: %A_where.type.ef7 = name_ref .Self, %.Self.2 [symbolic_self = constants.%.Self.60a]
  258. // CHECK:STDOUT: %C.ref: %A.assoc_type = name_ref C, @C.%assoc1 [concrete = constants.%assoc1]
  259. // CHECK:STDOUT: %.Self.as_type.loc10_48: type = facet_access_type %.Self.ref.loc10_48 [symbolic_self = constants.%.Self.as_type.e64]
  260. // CHECK:STDOUT: %.loc10_48: type = converted %.Self.ref.loc10_48, %.Self.as_type.loc10_48 [symbolic_self = constants.%.Self.as_type.e64]
  261. // CHECK:STDOUT: %impl.elem1: type = impl_witness_access constants.%A.lookup_impl_witness.138, element1 [symbolic_self = constants.%impl.elem1]
  262. // CHECK:STDOUT: %.loc10_54.1: %empty_tuple.type = tuple_literal ()
  263. // CHECK:STDOUT: %.loc10_54.2: type = converted %.loc10_54.1, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  264. // CHECK:STDOUT: %.loc10_42.2: type = where_expr %.Self.2 [concrete = constants.%A_where.type.2d0] {
  265. // CHECK:STDOUT: requirement_rewrite %impl.elem1, %.loc10_54.2
  266. // CHECK:STDOUT: }
  267. // CHECK:STDOUT: }
  268. // CHECK:STDOUT: %D.loc10_18.1: %A_where.type.2d0 = bind_symbolic_name D, 0 [symbolic = %D.loc10_18.2 (constants.%D)]
  269. // CHECK:STDOUT: }
  270. // CHECK:STDOUT: }
  271. // CHECK:STDOUT:
  272. // CHECK:STDOUT: generic fn @NestedRewrite(%D.loc10_18.1: %A_where.type.2d0) {
  273. // CHECK:STDOUT: %D.loc10_18.2: %A_where.type.2d0 = bind_symbolic_name D, 0 [symbolic = %D.loc10_18.2 (constants.%D)]
  274. // CHECK:STDOUT:
  275. // CHECK:STDOUT: fn();
  276. // CHECK:STDOUT: }
  277. // CHECK:STDOUT:
  278. // CHECK:STDOUT: specific @NestedRewrite(constants.%D) {
  279. // CHECK:STDOUT: %D.loc10_18.2 => constants.%D
  280. // CHECK:STDOUT: }
  281. // CHECK:STDOUT:
  282. // CHECK:STDOUT: --- repeated_rewrite.carbon
  283. // CHECK:STDOUT:
  284. // CHECK:STDOUT: constants {
  285. // CHECK:STDOUT: %E.type: type = facet_type <@E> [concrete]
  286. // CHECK:STDOUT: %E.assoc_type: type = assoc_entity_type @E [concrete]
  287. // CHECK:STDOUT: %assoc0: %E.assoc_type = assoc_entity element0, @E.%F [concrete]
  288. // CHECK:STDOUT: %.Self: %E.type = bind_symbolic_name .Self [symbolic_self]
  289. // CHECK:STDOUT: %.Self.as_type: type = facet_access_type %.Self [symbolic_self]
  290. // CHECK:STDOUT: %E.lookup_impl_witness: <witness> = lookup_impl_witness %.Self, @E [symbolic_self]
  291. // CHECK:STDOUT: %impl.elem0: type = impl_witness_access %E.lookup_impl_witness, element0 [symbolic_self]
  292. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  293. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  294. // CHECK:STDOUT: %E_where.type: type = facet_type <@E where %impl.elem0 = %i32> [concrete]
  295. // CHECK:STDOUT: %G: %E_where.type = bind_symbolic_name G, 0 [symbolic]
  296. // CHECK:STDOUT: %pattern_type.c64: type = pattern_type %E_where.type [concrete]
  297. // CHECK:STDOUT: %OneRewrite.type: type = fn_type @OneRewrite [concrete]
  298. // CHECK:STDOUT: %OneRewrite: %OneRewrite.type = struct_value () [concrete]
  299. // CHECK:STDOUT: %H: %E_where.type = bind_symbolic_name H, 0 [symbolic]
  300. // CHECK:STDOUT: %RepeatedRewrite.type: type = fn_type @RepeatedRewrite [concrete]
  301. // CHECK:STDOUT: %RepeatedRewrite: %RepeatedRewrite.type = struct_value () [concrete]
  302. // CHECK:STDOUT: %I: %E_where.type = bind_symbolic_name I, 0 [symbolic]
  303. // CHECK:STDOUT: %OneRewrite.specific_fn.7fa5d5.2: <specific function> = specific_function %OneRewrite, @OneRewrite(%I) [symbolic]
  304. // CHECK:STDOUT: }
  305. // CHECK:STDOUT:
  306. // CHECK:STDOUT: imports {
  307. // CHECK:STDOUT: }
  308. // CHECK:STDOUT:
  309. // CHECK:STDOUT: file {
  310. // CHECK:STDOUT: %OneRewrite.decl: %OneRewrite.type = fn_decl @OneRewrite [concrete = constants.%OneRewrite] {
  311. // CHECK:STDOUT: %G.patt: %pattern_type.c64 = symbolic_binding_pattern G, 0 [concrete]
  312. // CHECK:STDOUT: } {
  313. // CHECK:STDOUT: %.loc9_21.1: type = splice_block %.loc9_21.2 [concrete = constants.%E_where.type] {
  314. // CHECK:STDOUT: %E.ref: type = name_ref E, file.%E.decl [concrete = constants.%E.type]
  315. // CHECK:STDOUT: <elided>
  316. // CHECK:STDOUT: %.Self.ref: %E.type = name_ref .Self, %.Self [symbolic_self = constants.%.Self]
  317. // CHECK:STDOUT: %F.ref: %E.assoc_type = name_ref F, @F.%assoc0 [concrete = constants.%assoc0]
  318. // CHECK:STDOUT: %.Self.as_type: type = facet_access_type %.Self.ref [symbolic_self = constants.%.Self.as_type]
  319. // CHECK:STDOUT: %.loc9_27: type = converted %.Self.ref, %.Self.as_type [symbolic_self = constants.%.Self.as_type]
  320. // CHECK:STDOUT: %impl.elem0: type = impl_witness_access constants.%E.lookup_impl_witness, element0 [symbolic_self = constants.%impl.elem0]
  321. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  322. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  323. // CHECK:STDOUT: %.loc9_21.2: type = where_expr %.Self [concrete = constants.%E_where.type] {
  324. // CHECK:STDOUT: requirement_rewrite %impl.elem0, %i32
  325. // CHECK:STDOUT: }
  326. // CHECK:STDOUT: }
  327. // CHECK:STDOUT: %G.loc9_15.1: %E_where.type = bind_symbolic_name G, 0 [symbolic = %G.loc9_15.2 (constants.%G)]
  328. // CHECK:STDOUT: }
  329. // CHECK:STDOUT: %RepeatedRewrite.decl: %RepeatedRewrite.type = fn_decl @RepeatedRewrite [concrete = constants.%RepeatedRewrite] {
  330. // CHECK:STDOUT: %H.patt: %pattern_type.c64 = symbolic_binding_pattern H, 0 [concrete]
  331. // CHECK:STDOUT: } {
  332. // CHECK:STDOUT: %.loc11_26.1: type = splice_block %.loc11_26.2 [concrete = constants.%E_where.type] {
  333. // CHECK:STDOUT: %E.ref: type = name_ref E, file.%E.decl [concrete = constants.%E.type]
  334. // CHECK:STDOUT: <elided>
  335. // CHECK:STDOUT: %.Self.ref.loc11_32: %E.type = name_ref .Self, %.Self [symbolic_self = constants.%.Self]
  336. // CHECK:STDOUT: %F.ref.loc11_32: %E.assoc_type = name_ref F, @F.%assoc0 [concrete = constants.%assoc0]
  337. // CHECK:STDOUT: %.Self.as_type.loc11_32: type = facet_access_type %.Self.ref.loc11_32 [symbolic_self = constants.%.Self.as_type]
  338. // CHECK:STDOUT: %.loc11_32: type = converted %.Self.ref.loc11_32, %.Self.as_type.loc11_32 [symbolic_self = constants.%.Self.as_type]
  339. // CHECK:STDOUT: %impl.elem0.loc11_32: type = impl_witness_access constants.%E.lookup_impl_witness, element0 [symbolic_self = constants.%impl.elem0]
  340. // CHECK:STDOUT: %int_32.loc11_37: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  341. // CHECK:STDOUT: %i32.loc11_37: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  342. // CHECK:STDOUT: %.Self.ref.loc11_45: %E.type = name_ref .Self, %.Self [symbolic_self = constants.%.Self]
  343. // CHECK:STDOUT: %F.ref.loc11_45: %E.assoc_type = name_ref F, @F.%assoc0 [concrete = constants.%assoc0]
  344. // CHECK:STDOUT: %.Self.as_type.loc11_45: type = facet_access_type %.Self.ref.loc11_45 [symbolic_self = constants.%.Self.as_type]
  345. // CHECK:STDOUT: %.loc11_45: type = converted %.Self.ref.loc11_45, %.Self.as_type.loc11_45 [symbolic_self = constants.%.Self.as_type]
  346. // CHECK:STDOUT: %impl.elem0.loc11_45: type = impl_witness_access constants.%E.lookup_impl_witness, element0 [symbolic_self = constants.%impl.elem0]
  347. // CHECK:STDOUT: %int_32.loc11_50: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  348. // CHECK:STDOUT: %i32.loc11_50: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  349. // CHECK:STDOUT: %.loc11_26.2: type = where_expr %.Self [concrete = constants.%E_where.type] {
  350. // CHECK:STDOUT: requirement_rewrite %impl.elem0.loc11_32, %i32.loc11_37
  351. // CHECK:STDOUT: requirement_rewrite %impl.elem0.loc11_45, %i32.loc11_50
  352. // CHECK:STDOUT: }
  353. // CHECK:STDOUT: }
  354. // CHECK:STDOUT: %H.loc11_20.1: %E_where.type = bind_symbolic_name H, 0 [symbolic = %H.loc11_20.2 (constants.%H)]
  355. // CHECK:STDOUT: }
  356. // CHECK:STDOUT: }
  357. // CHECK:STDOUT:
  358. // CHECK:STDOUT: generic fn @OneRewrite(%G.loc9_15.1: %E_where.type) {
  359. // CHECK:STDOUT: %G.loc9_15.2: %E_where.type = bind_symbolic_name G, 0 [symbolic = %G.loc9_15.2 (constants.%G)]
  360. // CHECK:STDOUT:
  361. // CHECK:STDOUT: !definition:
  362. // CHECK:STDOUT:
  363. // CHECK:STDOUT: fn() {
  364. // CHECK:STDOUT: !entry:
  365. // CHECK:STDOUT: return
  366. // CHECK:STDOUT: }
  367. // CHECK:STDOUT: }
  368. // CHECK:STDOUT:
  369. // CHECK:STDOUT: generic fn @RepeatedRewrite(%H.loc11_20.1: %E_where.type) {
  370. // CHECK:STDOUT: %H.loc11_20.2: %E_where.type = bind_symbolic_name H, 0 [symbolic = %H.loc11_20.2 (constants.%H)]
  371. // CHECK:STDOUT:
  372. // CHECK:STDOUT: !definition:
  373. // CHECK:STDOUT: <elided>
  374. // CHECK:STDOUT:
  375. // CHECK:STDOUT: fn() {
  376. // CHECK:STDOUT: !entry:
  377. // CHECK:STDOUT: <elided>
  378. // CHECK:STDOUT: }
  379. // CHECK:STDOUT: }
  380. // CHECK:STDOUT:
  381. // CHECK:STDOUT: specific @OneRewrite(constants.%G) {
  382. // CHECK:STDOUT: %G.loc9_15.2 => constants.%G
  383. // CHECK:STDOUT: }
  384. // CHECK:STDOUT:
  385. // CHECK:STDOUT: specific @RepeatedRewrite(constants.%H) {
  386. // CHECK:STDOUT: %H.loc11_20.2 => constants.%H
  387. // CHECK:STDOUT: }
  388. // CHECK:STDOUT:
  389. // CHECK:STDOUT: specific @OneRewrite(constants.%H) {
  390. // CHECK:STDOUT: %G.loc9_15.2 => constants.%H
  391. // CHECK:STDOUT:
  392. // CHECK:STDOUT: !definition:
  393. // CHECK:STDOUT: }
  394. // CHECK:STDOUT:
  395. // CHECK:STDOUT: specific @RepeatedRewrite(constants.%I) {
  396. // CHECK:STDOUT: %H.loc11_20.2 => constants.%I
  397. // CHECK:STDOUT:
  398. // CHECK:STDOUT: !definition:
  399. // CHECK:STDOUT: %OneRewrite.specific_fn.loc13_3.2 => constants.%OneRewrite.specific_fn.7fa5d5.2
  400. // CHECK:STDOUT: }
  401. // CHECK:STDOUT:
  402. // CHECK:STDOUT: specific @OneRewrite(constants.%I) {
  403. // CHECK:STDOUT: %G.loc9_15.2 => constants.%I
  404. // CHECK:STDOUT:
  405. // CHECK:STDOUT: !definition:
  406. // CHECK:STDOUT: }
  407. // CHECK:STDOUT:
  408. // CHECK:STDOUT: --- rewrites_reordered.carbon
  409. // CHECK:STDOUT:
  410. // CHECK:STDOUT: constants {
  411. // CHECK:STDOUT: %J.type: type = facet_type <@J> [concrete]
  412. // CHECK:STDOUT: %J.assoc_type: type = assoc_entity_type @J [concrete]
  413. // CHECK:STDOUT: %assoc0: %J.assoc_type = assoc_entity element0, @J.%K [concrete]
  414. // CHECK:STDOUT: %assoc1: %J.assoc_type = assoc_entity element1, @J.%L [concrete]
  415. // CHECK:STDOUT: %.Self: %J.type = bind_symbolic_name .Self [symbolic_self]
  416. // CHECK:STDOUT: %.Self.as_type: type = facet_access_type %.Self [symbolic_self]
  417. // CHECK:STDOUT: %J.lookup_impl_witness: <witness> = lookup_impl_witness %.Self, @J [symbolic_self]
  418. // CHECK:STDOUT: %impl.elem0: type = impl_witness_access %J.lookup_impl_witness, element0 [symbolic_self]
  419. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  420. // CHECK:STDOUT: %impl.elem1: type = impl_witness_access %J.lookup_impl_witness, element1 [symbolic_self]
  421. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [concrete]
  422. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [concrete]
  423. // CHECK:STDOUT: %J_where.type: type = facet_type <@J where %impl.elem0 = %empty_tuple.type and %impl.elem1 = bool> [concrete]
  424. // CHECK:STDOUT: %M: %J_where.type = bind_symbolic_name M, 0 [symbolic]
  425. // CHECK:STDOUT: %pattern_type.49f: type = pattern_type %J_where.type [concrete]
  426. // CHECK:STDOUT: %Alphabetical.type: type = fn_type @Alphabetical [concrete]
  427. // CHECK:STDOUT: %Alphabetical: %Alphabetical.type = struct_value () [concrete]
  428. // CHECK:STDOUT: %N: %J_where.type = bind_symbolic_name N, 0 [symbolic]
  429. // CHECK:STDOUT: %Reversed.type: type = fn_type @Reversed [concrete]
  430. // CHECK:STDOUT: %Reversed: %Reversed.type = struct_value () [concrete]
  431. // CHECK:STDOUT: }
  432. // CHECK:STDOUT:
  433. // CHECK:STDOUT: imports {
  434. // CHECK:STDOUT: }
  435. // CHECK:STDOUT:
  436. // CHECK:STDOUT: file {
  437. // CHECK:STDOUT: %Alphabetical.decl: %Alphabetical.type = fn_decl @Alphabetical [concrete = constants.%Alphabetical] {
  438. // CHECK:STDOUT: %M.patt: %pattern_type.49f = symbolic_binding_pattern M, 0 [concrete]
  439. // CHECK:STDOUT: } {
  440. // CHECK:STDOUT: %.loc10_23.1: type = splice_block %.loc10_23.2 [concrete = constants.%J_where.type] {
  441. // CHECK:STDOUT: %J.ref: type = name_ref J, file.%J.decl [concrete = constants.%J.type]
  442. // CHECK:STDOUT: <elided>
  443. // CHECK:STDOUT: %.Self.ref.loc10_29: %J.type = name_ref .Self, %.Self [symbolic_self = constants.%.Self]
  444. // CHECK:STDOUT: %K.ref: %J.assoc_type = name_ref K, @K.%assoc0 [concrete = constants.%assoc0]
  445. // CHECK:STDOUT: %.Self.as_type.loc10_29: type = facet_access_type %.Self.ref.loc10_29 [symbolic_self = constants.%.Self.as_type]
  446. // CHECK:STDOUT: %.loc10_29: type = converted %.Self.ref.loc10_29, %.Self.as_type.loc10_29 [symbolic_self = constants.%.Self.as_type]
  447. // CHECK:STDOUT: %impl.elem0: type = impl_witness_access constants.%J.lookup_impl_witness, element0 [symbolic_self = constants.%impl.elem0]
  448. // CHECK:STDOUT: %.loc10_35.1: %empty_tuple.type = tuple_literal ()
  449. // CHECK:STDOUT: %.loc10_35.2: type = converted %.loc10_35.1, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  450. // CHECK:STDOUT: %.Self.ref.loc10_41: %J.type = name_ref .Self, %.Self [symbolic_self = constants.%.Self]
  451. // CHECK:STDOUT: %L.ref: %J.assoc_type = name_ref L, @L.%assoc1 [concrete = constants.%assoc1]
  452. // CHECK:STDOUT: %.Self.as_type.loc10_41: type = facet_access_type %.Self.ref.loc10_41 [symbolic_self = constants.%.Self.as_type]
  453. // CHECK:STDOUT: %.loc10_41: type = converted %.Self.ref.loc10_41, %.Self.as_type.loc10_41 [symbolic_self = constants.%.Self.as_type]
  454. // CHECK:STDOUT: %impl.elem1: type = impl_witness_access constants.%J.lookup_impl_witness, element1 [symbolic_self = constants.%impl.elem1]
  455. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [concrete = bool]
  456. // CHECK:STDOUT: %.loc10_46.1: type = value_of_initializer %bool.make_type [concrete = bool]
  457. // CHECK:STDOUT: %.loc10_46.2: type = converted %bool.make_type, %.loc10_46.1 [concrete = bool]
  458. // CHECK:STDOUT: %.loc10_23.2: type = where_expr %.Self [concrete = constants.%J_where.type] {
  459. // CHECK:STDOUT: requirement_rewrite %impl.elem0, %.loc10_35.2
  460. // CHECK:STDOUT: requirement_rewrite %impl.elem1, %.loc10_46.2
  461. // CHECK:STDOUT: }
  462. // CHECK:STDOUT: }
  463. // CHECK:STDOUT: %M.loc10_17.1: %J_where.type = bind_symbolic_name M, 0 [symbolic = %M.loc10_17.2 (constants.%M)]
  464. // CHECK:STDOUT: }
  465. // CHECK:STDOUT: %Reversed.decl: %Reversed.type = fn_decl @Reversed [concrete = constants.%Reversed] {
  466. // CHECK:STDOUT: %N.patt: %pattern_type.49f = symbolic_binding_pattern N, 0 [concrete]
  467. // CHECK:STDOUT: } {
  468. // CHECK:STDOUT: %.loc12_19.1: type = splice_block %.loc12_19.2 [concrete = constants.%J_where.type] {
  469. // CHECK:STDOUT: %J.ref: type = name_ref J, file.%J.decl [concrete = constants.%J.type]
  470. // CHECK:STDOUT: <elided>
  471. // CHECK:STDOUT: %.Self.ref.loc12_25: %J.type = name_ref .Self, %.Self [symbolic_self = constants.%.Self]
  472. // CHECK:STDOUT: %L.ref: %J.assoc_type = name_ref L, @L.%assoc1 [concrete = constants.%assoc1]
  473. // CHECK:STDOUT: %.Self.as_type.loc12_25: type = facet_access_type %.Self.ref.loc12_25 [symbolic_self = constants.%.Self.as_type]
  474. // CHECK:STDOUT: %.loc12_25: type = converted %.Self.ref.loc12_25, %.Self.as_type.loc12_25 [symbolic_self = constants.%.Self.as_type]
  475. // CHECK:STDOUT: %impl.elem1: type = impl_witness_access constants.%J.lookup_impl_witness, element1 [symbolic_self = constants.%impl.elem1]
  476. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [concrete = bool]
  477. // CHECK:STDOUT: %.loc12_30.1: type = value_of_initializer %bool.make_type [concrete = bool]
  478. // CHECK:STDOUT: %.loc12_30.2: type = converted %bool.make_type, %.loc12_30.1 [concrete = bool]
  479. // CHECK:STDOUT: %.Self.ref.loc12_39: %J.type = name_ref .Self, %.Self [symbolic_self = constants.%.Self]
  480. // CHECK:STDOUT: %K.ref: %J.assoc_type = name_ref K, @K.%assoc0 [concrete = constants.%assoc0]
  481. // CHECK:STDOUT: %.Self.as_type.loc12_39: type = facet_access_type %.Self.ref.loc12_39 [symbolic_self = constants.%.Self.as_type]
  482. // CHECK:STDOUT: %.loc12_39: type = converted %.Self.ref.loc12_39, %.Self.as_type.loc12_39 [symbolic_self = constants.%.Self.as_type]
  483. // CHECK:STDOUT: %impl.elem0: type = impl_witness_access constants.%J.lookup_impl_witness, element0 [symbolic_self = constants.%impl.elem0]
  484. // CHECK:STDOUT: %.loc12_45.1: %empty_tuple.type = tuple_literal ()
  485. // CHECK:STDOUT: %.loc12_45.2: type = converted %.loc12_45.1, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  486. // CHECK:STDOUT: %.loc12_19.2: type = where_expr %.Self [concrete = constants.%J_where.type] {
  487. // CHECK:STDOUT: requirement_rewrite %impl.elem1, %.loc12_30.2
  488. // CHECK:STDOUT: requirement_rewrite %impl.elem0, %.loc12_45.2
  489. // CHECK:STDOUT: }
  490. // CHECK:STDOUT: }
  491. // CHECK:STDOUT: %N.loc12_13.1: %J_where.type = bind_symbolic_name N, 0 [symbolic = %N.loc12_13.2 (constants.%N)]
  492. // CHECK:STDOUT: }
  493. // CHECK:STDOUT: }
  494. // CHECK:STDOUT:
  495. // CHECK:STDOUT: generic fn @Alphabetical(%M.loc10_17.1: %J_where.type) {
  496. // CHECK:STDOUT: %M.loc10_17.2: %J_where.type = bind_symbolic_name M, 0 [symbolic = %M.loc10_17.2 (constants.%M)]
  497. // CHECK:STDOUT:
  498. // CHECK:STDOUT: !definition:
  499. // CHECK:STDOUT:
  500. // CHECK:STDOUT: fn() {
  501. // CHECK:STDOUT: !entry:
  502. // CHECK:STDOUT: return
  503. // CHECK:STDOUT: }
  504. // CHECK:STDOUT: }
  505. // CHECK:STDOUT:
  506. // CHECK:STDOUT: generic fn @Reversed(%N.loc12_13.1: %J_where.type) {
  507. // CHECK:STDOUT: %N.loc12_13.2: %J_where.type = bind_symbolic_name N, 0 [symbolic = %N.loc12_13.2 (constants.%N)]
  508. // CHECK:STDOUT:
  509. // CHECK:STDOUT: !definition:
  510. // CHECK:STDOUT: <elided>
  511. // CHECK:STDOUT:
  512. // CHECK:STDOUT: fn() {
  513. // CHECK:STDOUT: !entry:
  514. // CHECK:STDOUT: <elided>
  515. // CHECK:STDOUT: }
  516. // CHECK:STDOUT: }
  517. // CHECK:STDOUT:
  518. // CHECK:STDOUT: specific @Alphabetical(constants.%M) {
  519. // CHECK:STDOUT: %M.loc10_17.2 => constants.%M
  520. // CHECK:STDOUT: }
  521. // CHECK:STDOUT:
  522. // CHECK:STDOUT: specific @Reversed(constants.%N) {
  523. // CHECK:STDOUT: %N.loc12_13.2 => constants.%N
  524. // CHECK:STDOUT: }
  525. // CHECK:STDOUT:
  526. // CHECK:STDOUT: specific @Alphabetical(constants.%N) {
  527. // CHECK:STDOUT: %M.loc10_17.2 => constants.%N
  528. // CHECK:STDOUT:
  529. // CHECK:STDOUT: !definition:
  530. // CHECK:STDOUT: }
  531. // CHECK:STDOUT: