constraints.carbon 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  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/constraints.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/where_expr/constraints.carbon
  10. // --- state_constraints.carbon
  11. library "[[@TEST_NAME]]";
  12. interface J {}
  13. interface I {
  14. let Member:! type;
  15. let Second:! J;
  16. }
  17. fn Equal(T:! I where .Member = {});
  18. fn EqualEqual(U:! I where .Self == ());
  19. fn Impls(V:! J where .Self impls I);
  20. fn And(W:! I where .Second impls I and .Member = .Second);
  21. // --- todo_check_constraints.carbon
  22. library "[[@TEST_NAME]]";
  23. import library "state_constraints";
  24. // TODO: Should fail since `2` can't be converted to the type of `I.Member`,
  25. // but constraints are not yet type checked.
  26. fn TypeMismatch(X:! I where .Member = 2);
  27. // --- fail_todo_enforce_constraint.carbon
  28. library "[[@TEST_NAME]]";
  29. import library "state_constraints";
  30. // C implements J but not I.
  31. class C {}
  32. impl C as J {}
  33. // TODO: Should report that `C` does not meet the constraint.
  34. fn DoesNotImplI() {
  35. // CHECK:STDERR: fail_todo_enforce_constraint.carbon:[[@LINE+11]]:3: error: cannot implicitly convert from `type` to `J`
  36. // CHECK:STDERR: Impls(C);
  37. // CHECK:STDERR: ^~~~~~
  38. // CHECK:STDERR: fail_todo_enforce_constraint.carbon:[[@LINE+8]]:3: note: type `type` does not implement interface `ImplicitAs`
  39. // CHECK:STDERR: Impls(C);
  40. // CHECK:STDERR: ^~~~~~
  41. // CHECK:STDERR: fail_todo_enforce_constraint.carbon:[[@LINE-14]]:1: in import
  42. // CHECK:STDERR: state_constraints.carbon:15:10: note: initializing generic parameter `V` declared here
  43. // CHECK:STDERR: fn Impls(V:! J where .Self impls I);
  44. // CHECK:STDERR: ^
  45. // CHECK:STDERR:
  46. Impls(C);
  47. }
  48. fn EmptyStruct(Y:! J where .Self == {});
  49. // TODO: Should report that `C` does not meeet the constraint.
  50. fn NotEmptyStruct() {
  51. // CHECK:STDERR: fail_todo_enforce_constraint.carbon:[[@LINE+9]]:3: error: cannot implicitly convert from `type` to `J`
  52. // CHECK:STDERR: EmptyStruct(C);
  53. // CHECK:STDERR: ^~~~~~~~~~~~
  54. // CHECK:STDERR: fail_todo_enforce_constraint.carbon:[[@LINE+6]]:3: note: type `type` does not implement interface `ImplicitAs`
  55. // CHECK:STDERR: EmptyStruct(C);
  56. // CHECK:STDERR: ^~~~~~~~~~~~
  57. // CHECK:STDERR: fail_todo_enforce_constraint.carbon:[[@LINE-10]]:16: note: initializing generic parameter `Y` declared here
  58. // CHECK:STDERR: fn EmptyStruct(Y:! J where .Self == {});
  59. // CHECK:STDERR: ^
  60. EmptyStruct(C);
  61. }
  62. // CHECK:STDOUT: --- state_constraints.carbon
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: constants {
  65. // CHECK:STDOUT: %.1: type = interface_type @J [template]
  66. // CHECK:STDOUT: %Self.1: %.1 = bind_symbolic_name Self 0 [symbolic]
  67. // CHECK:STDOUT: %.2: type = interface_type @I [template]
  68. // CHECK:STDOUT: %Self.2: %.2 = bind_symbolic_name Self 0 [symbolic]
  69. // CHECK:STDOUT: %.3: type = assoc_entity_type %.2, type [template]
  70. // CHECK:STDOUT: %.4: %.3 = assoc_entity element0, @I.%Member [template]
  71. // CHECK:STDOUT: %.5: type = tuple_type () [template]
  72. // CHECK:STDOUT: %.6: type = assoc_entity_type %.2, %.1 [template]
  73. // CHECK:STDOUT: %.7: %.6 = assoc_entity element1, @I.%Second [template]
  74. // CHECK:STDOUT: %.Self.1: %.2 = bind_symbolic_name .Self 0 [symbolic]
  75. // CHECK:STDOUT: %.8: type = struct_type {} [template]
  76. // CHECK:STDOUT: %T: %.2 = bind_symbolic_name T 0 [symbolic]
  77. // CHECK:STDOUT: %Equal.type: type = fn_type @Equal [template]
  78. // CHECK:STDOUT: %Equal: %Equal.type = struct_value () [template]
  79. // CHECK:STDOUT: %U: %.2 = bind_symbolic_name U 0 [symbolic]
  80. // CHECK:STDOUT: %EqualEqual.type: type = fn_type @EqualEqual [template]
  81. // CHECK:STDOUT: %EqualEqual: %EqualEqual.type = struct_value () [template]
  82. // CHECK:STDOUT: %.Self.2: %.1 = bind_symbolic_name .Self 0 [symbolic]
  83. // CHECK:STDOUT: %V: %.1 = bind_symbolic_name V 0 [symbolic]
  84. // CHECK:STDOUT: %Impls.type: type = fn_type @Impls [template]
  85. // CHECK:STDOUT: %Impls: %Impls.type = struct_value () [template]
  86. // CHECK:STDOUT: %W: %.2 = bind_symbolic_name W 0 [symbolic]
  87. // CHECK:STDOUT: %And.type: type = fn_type @And [template]
  88. // CHECK:STDOUT: %And: %And.type = struct_value () [template]
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: imports {
  92. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  93. // CHECK:STDOUT: import Core//prelude
  94. // CHECK:STDOUT: import Core//prelude/operators
  95. // CHECK:STDOUT: import Core//prelude/types
  96. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  97. // CHECK:STDOUT: import Core//prelude/operators/as
  98. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  99. // CHECK:STDOUT: import Core//prelude/operators/comparison
  100. // CHECK:STDOUT: import Core//prelude/types/bool
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: file {
  105. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  106. // CHECK:STDOUT: .Core = imports.%Core
  107. // CHECK:STDOUT: .J = %J.decl
  108. // CHECK:STDOUT: .I = %I.decl
  109. // CHECK:STDOUT: .Equal = %Equal.decl
  110. // CHECK:STDOUT: .EqualEqual = %EqualEqual.decl
  111. // CHECK:STDOUT: .Impls = %Impls.decl
  112. // CHECK:STDOUT: .And = %And.decl
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT: %Core.import = import Core
  115. // CHECK:STDOUT: %J.decl: type = interface_decl @J [template = constants.%.1] {} {}
  116. // CHECK:STDOUT: %I.decl: type = interface_decl @I [template = constants.%.2] {} {}
  117. // CHECK:STDOUT: %Equal.decl: %Equal.type = fn_decl @Equal [template = constants.%Equal] {
  118. // CHECK:STDOUT: %T.patt: %.2 = symbolic_binding_pattern T 0
  119. // CHECK:STDOUT: } {
  120. // CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [template = constants.%.2]
  121. // CHECK:STDOUT: %.Self: %.2 = bind_symbolic_name .Self 0 [symbolic = constants.%.Self.1]
  122. // CHECK:STDOUT: %.Self.ref: %.2 = name_ref .Self, %.Self [symbolic = constants.%.Self.1]
  123. // CHECK:STDOUT: %Member.ref: %.3 = name_ref Member, @I.%.loc7 [template = constants.%.4]
  124. // CHECK:STDOUT: %.loc11_33: %.8 = struct_literal ()
  125. // CHECK:STDOUT: %.loc11_16: type = where_expr %.Self [template = constants.%.2] {
  126. // CHECK:STDOUT: requirement_rewrite %Member.ref, %.loc11_33
  127. // CHECK:STDOUT: }
  128. // CHECK:STDOUT: %T.param: %.2 = param T, runtime_param<invalid>
  129. // CHECK:STDOUT: %T.loc11: %.2 = bind_symbolic_name T 0, %T.param [symbolic = %T.1 (constants.%T)]
  130. // CHECK:STDOUT: }
  131. // CHECK:STDOUT: %EqualEqual.decl: %EqualEqual.type = fn_decl @EqualEqual [template = constants.%EqualEqual] {
  132. // CHECK:STDOUT: %U.patt: %.2 = symbolic_binding_pattern U 0
  133. // CHECK:STDOUT: } {
  134. // CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [template = constants.%.2]
  135. // CHECK:STDOUT: %.Self: %.2 = bind_symbolic_name .Self 0 [symbolic = constants.%.Self.1]
  136. // CHECK:STDOUT: %.Self.ref: %.2 = name_ref .Self, %.Self [symbolic = constants.%.Self.1]
  137. // CHECK:STDOUT: %.loc13_37: %.5 = tuple_literal ()
  138. // CHECK:STDOUT: %.loc13_21: type = where_expr %.Self [template = constants.%.2] {
  139. // CHECK:STDOUT: requirement_equivalent %.Self.ref, %.loc13_37
  140. // CHECK:STDOUT: }
  141. // CHECK:STDOUT: %U.param: %.2 = param U, runtime_param<invalid>
  142. // CHECK:STDOUT: %U.loc13: %.2 = bind_symbolic_name U 0, %U.param [symbolic = %U.1 (constants.%U)]
  143. // CHECK:STDOUT: }
  144. // CHECK:STDOUT: %Impls.decl: %Impls.type = fn_decl @Impls [template = constants.%Impls] {
  145. // CHECK:STDOUT: %V.patt: %.1 = symbolic_binding_pattern V 0
  146. // CHECK:STDOUT: } {
  147. // CHECK:STDOUT: %J.ref: type = name_ref J, file.%J.decl [template = constants.%.1]
  148. // CHECK:STDOUT: %.Self: %.1 = bind_symbolic_name .Self 0 [symbolic = constants.%.Self.2]
  149. // CHECK:STDOUT: %.Self.ref: %.1 = name_ref .Self, %.Self [symbolic = constants.%.Self.2]
  150. // CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [template = constants.%.2]
  151. // CHECK:STDOUT: %.loc15: type = where_expr %.Self [template = constants.%.1] {
  152. // CHECK:STDOUT: requirement_impls %.Self.ref, %I.ref
  153. // CHECK:STDOUT: }
  154. // CHECK:STDOUT: %V.param: %.1 = param V, runtime_param<invalid>
  155. // CHECK:STDOUT: %V.loc15: %.1 = bind_symbolic_name V 0, %V.param [symbolic = %V.1 (constants.%V)]
  156. // CHECK:STDOUT: }
  157. // CHECK:STDOUT: %And.decl: %And.type = fn_decl @And [template = constants.%And] {
  158. // CHECK:STDOUT: %W.patt: %.2 = symbolic_binding_pattern W 0
  159. // CHECK:STDOUT: } {
  160. // CHECK:STDOUT: %I.ref.loc17_12: type = name_ref I, file.%I.decl [template = constants.%.2]
  161. // CHECK:STDOUT: %.Self: %.2 = bind_symbolic_name .Self 0 [symbolic = constants.%.Self.1]
  162. // CHECK:STDOUT: %.Self.ref.loc17_20: %.2 = name_ref .Self, %.Self [symbolic = constants.%.Self.1]
  163. // CHECK:STDOUT: %Second.ref.loc17_20: %.6 = name_ref Second, @I.%.loc8 [template = constants.%.7]
  164. // CHECK:STDOUT: %I.ref.loc17_34: type = name_ref I, file.%I.decl [template = constants.%.2]
  165. // CHECK:STDOUT: %.Self.ref.loc17_40: %.2 = name_ref .Self, %.Self [symbolic = constants.%.Self.1]
  166. // CHECK:STDOUT: %Member.ref: %.3 = name_ref Member, @I.%.loc7 [template = constants.%.4]
  167. // CHECK:STDOUT: %.Self.ref.loc17_50: %.2 = name_ref .Self, %.Self [symbolic = constants.%.Self.1]
  168. // CHECK:STDOUT: %Second.ref.loc17_50: %.6 = name_ref Second, @I.%.loc8 [template = constants.%.7]
  169. // CHECK:STDOUT: %.loc17: type = where_expr %.Self [template = constants.%.2] {
  170. // CHECK:STDOUT: requirement_impls %Second.ref.loc17_20, %I.ref.loc17_34
  171. // CHECK:STDOUT: requirement_rewrite %Member.ref, %Second.ref.loc17_50
  172. // CHECK:STDOUT: }
  173. // CHECK:STDOUT: %W.param: %.2 = param W, runtime_param<invalid>
  174. // CHECK:STDOUT: %W.loc17: %.2 = bind_symbolic_name W 0, %W.param [symbolic = %W.1 (constants.%W)]
  175. // CHECK:STDOUT: }
  176. // CHECK:STDOUT: }
  177. // CHECK:STDOUT:
  178. // CHECK:STDOUT: interface @J {
  179. // CHECK:STDOUT: %Self: %.1 = bind_symbolic_name Self 0 [symbolic = constants.%Self.1]
  180. // CHECK:STDOUT:
  181. // CHECK:STDOUT: !members:
  182. // CHECK:STDOUT: .Self = %Self
  183. // CHECK:STDOUT: witness = ()
  184. // CHECK:STDOUT: }
  185. // CHECK:STDOUT:
  186. // CHECK:STDOUT: interface @I {
  187. // CHECK:STDOUT: %Self: %.2 = bind_symbolic_name Self 0 [symbolic = constants.%Self.2]
  188. // CHECK:STDOUT: %Member: type = assoc_const_decl Member [template]
  189. // CHECK:STDOUT: %.loc7: %.3 = assoc_entity element0, %Member [template = constants.%.4]
  190. // CHECK:STDOUT: %J.ref: type = name_ref J, file.%J.decl [template = constants.%.1]
  191. // CHECK:STDOUT: %Second: %.1 = assoc_const_decl Second [template]
  192. // CHECK:STDOUT: %.loc8: %.6 = assoc_entity element1, %Second [template = constants.%.7]
  193. // CHECK:STDOUT:
  194. // CHECK:STDOUT: !members:
  195. // CHECK:STDOUT: .Self = %Self
  196. // CHECK:STDOUT: .Member = %.loc7
  197. // CHECK:STDOUT: .Second = %.loc8
  198. // CHECK:STDOUT: witness = (%Member, %Second)
  199. // CHECK:STDOUT: }
  200. // CHECK:STDOUT:
  201. // CHECK:STDOUT: generic fn @Equal(%T.loc11: %.2) {
  202. // CHECK:STDOUT: %T.1: %.2 = bind_symbolic_name T 0 [symbolic = %T.1 (constants.%T)]
  203. // CHECK:STDOUT:
  204. // CHECK:STDOUT: fn(%T.loc11: %.2);
  205. // CHECK:STDOUT: }
  206. // CHECK:STDOUT:
  207. // CHECK:STDOUT: generic fn @EqualEqual(%U.loc13: %.2) {
  208. // CHECK:STDOUT: %U.1: %.2 = bind_symbolic_name U 0 [symbolic = %U.1 (constants.%U)]
  209. // CHECK:STDOUT:
  210. // CHECK:STDOUT: fn(%U.loc13: %.2);
  211. // CHECK:STDOUT: }
  212. // CHECK:STDOUT:
  213. // CHECK:STDOUT: generic fn @Impls(%V.loc15: %.1) {
  214. // CHECK:STDOUT: %V.1: %.1 = bind_symbolic_name V 0 [symbolic = %V.1 (constants.%V)]
  215. // CHECK:STDOUT:
  216. // CHECK:STDOUT: fn(%V.loc15: %.1);
  217. // CHECK:STDOUT: }
  218. // CHECK:STDOUT:
  219. // CHECK:STDOUT: generic fn @And(%W.loc17: %.2) {
  220. // CHECK:STDOUT: %W.1: %.2 = bind_symbolic_name W 0 [symbolic = %W.1 (constants.%W)]
  221. // CHECK:STDOUT:
  222. // CHECK:STDOUT: fn(%W.loc17: %.2);
  223. // CHECK:STDOUT: }
  224. // CHECK:STDOUT:
  225. // CHECK:STDOUT: specific @Equal(constants.%T) {
  226. // CHECK:STDOUT: %T.1 => constants.%T
  227. // CHECK:STDOUT: }
  228. // CHECK:STDOUT:
  229. // CHECK:STDOUT: specific @EqualEqual(constants.%U) {
  230. // CHECK:STDOUT: %U.1 => constants.%U
  231. // CHECK:STDOUT: }
  232. // CHECK:STDOUT:
  233. // CHECK:STDOUT: specific @Impls(constants.%V) {
  234. // CHECK:STDOUT: %V.1 => constants.%V
  235. // CHECK:STDOUT: }
  236. // CHECK:STDOUT:
  237. // CHECK:STDOUT: specific @And(constants.%W) {
  238. // CHECK:STDOUT: %W.1 => constants.%W
  239. // CHECK:STDOUT: }
  240. // CHECK:STDOUT:
  241. // CHECK:STDOUT: --- todo_check_constraints.carbon
  242. // CHECK:STDOUT:
  243. // CHECK:STDOUT: constants {
  244. // CHECK:STDOUT: %.1: type = interface_type @I [template]
  245. // CHECK:STDOUT: %Self: %.1 = bind_symbolic_name Self 0 [symbolic]
  246. // CHECK:STDOUT: %.Self: %.1 = bind_symbolic_name .Self 0 [symbolic]
  247. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  248. // CHECK:STDOUT: %.3: type = assoc_entity_type %.1, type [template]
  249. // CHECK:STDOUT: %.4: %.3 = assoc_entity element0, imports.%import_ref.12 [template]
  250. // CHECK:STDOUT: %.5: i32 = int_literal 2 [template]
  251. // CHECK:STDOUT: %X: %.1 = bind_symbolic_name X 0 [symbolic]
  252. // CHECK:STDOUT: %TypeMismatch.type: type = fn_type @TypeMismatch [template]
  253. // CHECK:STDOUT: %TypeMismatch: %TypeMismatch.type = struct_value () [template]
  254. // CHECK:STDOUT: }
  255. // CHECK:STDOUT:
  256. // CHECK:STDOUT: imports {
  257. // CHECK:STDOUT: %import_ref.1 = import_ref Main//state_constraints, inst+3, unloaded
  258. // CHECK:STDOUT: %import_ref.2: type = import_ref Main//state_constraints, inst+7, loaded [template = constants.%.1]
  259. // CHECK:STDOUT: %import_ref.3 = import_ref Main//state_constraints, inst+34, unloaded
  260. // CHECK:STDOUT: %import_ref.4 = import_ref Main//state_constraints, inst+48, unloaded
  261. // CHECK:STDOUT: %import_ref.5 = import_ref Main//state_constraints, inst+63, unloaded
  262. // CHECK:STDOUT: %import_ref.6 = import_ref Main//state_constraints, inst+83, unloaded
  263. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  264. // CHECK:STDOUT: import Core//prelude
  265. // CHECK:STDOUT: import Core//prelude/operators
  266. // CHECK:STDOUT: import Core//prelude/types
  267. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  268. // CHECK:STDOUT: import Core//prelude/operators/as
  269. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  270. // CHECK:STDOUT: import Core//prelude/operators/comparison
  271. // CHECK:STDOUT: import Core//prelude/types/bool
  272. // CHECK:STDOUT: }
  273. // CHECK:STDOUT: %import_ref.7 = import_ref Main//state_constraints, inst+9, unloaded
  274. // CHECK:STDOUT: %import_ref.8: %.3 = import_ref Main//state_constraints, inst+13, loaded [template = constants.%.4]
  275. // CHECK:STDOUT: %import_ref.9 = import_ref Main//state_constraints, inst+19, unloaded
  276. // CHECK:STDOUT: %import_ref.10 = import_ref Main//state_constraints, inst+11, unloaded
  277. // CHECK:STDOUT: %import_ref.11 = import_ref Main//state_constraints, inst+17, unloaded
  278. // CHECK:STDOUT: %import_ref.12 = import_ref Main//state_constraints, inst+11, unloaded
  279. // CHECK:STDOUT: }
  280. // CHECK:STDOUT:
  281. // CHECK:STDOUT: file {
  282. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  283. // CHECK:STDOUT: .J = imports.%import_ref.1
  284. // CHECK:STDOUT: .I = imports.%import_ref.2
  285. // CHECK:STDOUT: .Equal = imports.%import_ref.3
  286. // CHECK:STDOUT: .EqualEqual = imports.%import_ref.4
  287. // CHECK:STDOUT: .Impls = imports.%import_ref.5
  288. // CHECK:STDOUT: .And = imports.%import_ref.6
  289. // CHECK:STDOUT: .Core = imports.%Core
  290. // CHECK:STDOUT: .TypeMismatch = %TypeMismatch.decl
  291. // CHECK:STDOUT: }
  292. // CHECK:STDOUT: %Core.import = import Core
  293. // CHECK:STDOUT: %default.import = import <invalid>
  294. // CHECK:STDOUT: %TypeMismatch.decl: %TypeMismatch.type = fn_decl @TypeMismatch [template = constants.%TypeMismatch] {
  295. // CHECK:STDOUT: %X.patt: %.1 = symbolic_binding_pattern X 0
  296. // CHECK:STDOUT: } {
  297. // CHECK:STDOUT: %I.ref: type = name_ref I, imports.%import_ref.2 [template = constants.%.1]
  298. // CHECK:STDOUT: %.Self: %.1 = bind_symbolic_name .Self 0 [symbolic = constants.%.Self]
  299. // CHECK:STDOUT: %.Self.ref: %.1 = name_ref .Self, %.Self [symbolic = constants.%.Self]
  300. // CHECK:STDOUT: %Member.ref: %.3 = name_ref Member, imports.%import_ref.8 [template = constants.%.4]
  301. // CHECK:STDOUT: %.loc8_39: i32 = int_literal 2 [template = constants.%.5]
  302. // CHECK:STDOUT: %.loc8_23: type = where_expr %.Self [template = constants.%.1] {
  303. // CHECK:STDOUT: requirement_rewrite %Member.ref, %.loc8_39
  304. // CHECK:STDOUT: }
  305. // CHECK:STDOUT: %X.param: %.1 = param X, runtime_param<invalid>
  306. // CHECK:STDOUT: %X.loc8: %.1 = bind_symbolic_name X 0, %X.param [symbolic = %X.1 (constants.%X)]
  307. // CHECK:STDOUT: }
  308. // CHECK:STDOUT: }
  309. // CHECK:STDOUT:
  310. // CHECK:STDOUT: interface @I {
  311. // CHECK:STDOUT: !members:
  312. // CHECK:STDOUT: .Self = imports.%import_ref.7
  313. // CHECK:STDOUT: .Member = imports.%import_ref.8
  314. // CHECK:STDOUT: .Second = imports.%import_ref.9
  315. // CHECK:STDOUT: witness = (imports.%import_ref.10, imports.%import_ref.11)
  316. // CHECK:STDOUT: }
  317. // CHECK:STDOUT:
  318. // CHECK:STDOUT: generic fn @TypeMismatch(%X.loc8: %.1) {
  319. // CHECK:STDOUT: %X.1: %.1 = bind_symbolic_name X 0 [symbolic = %X.1 (constants.%X)]
  320. // CHECK:STDOUT:
  321. // CHECK:STDOUT: fn(%X.loc8: %.1);
  322. // CHECK:STDOUT: }
  323. // CHECK:STDOUT:
  324. // CHECK:STDOUT: specific @TypeMismatch(constants.%X) {
  325. // CHECK:STDOUT: %X.1 => constants.%X
  326. // CHECK:STDOUT: }
  327. // CHECK:STDOUT:
  328. // CHECK:STDOUT: --- fail_todo_enforce_constraint.carbon
  329. // CHECK:STDOUT:
  330. // CHECK:STDOUT: constants {
  331. // CHECK:STDOUT: %C: type = class_type @C [template]
  332. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  333. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  334. // CHECK:STDOUT: %.3: type = interface_type @J [template]
  335. // CHECK:STDOUT: %Self.1: %.3 = bind_symbolic_name Self 0 [symbolic]
  336. // CHECK:STDOUT: %.4: type = tuple_type () [template]
  337. // CHECK:STDOUT: %.5: <witness> = interface_witness () [template]
  338. // CHECK:STDOUT: %DoesNotImplI.type: type = fn_type @DoesNotImplI [template]
  339. // CHECK:STDOUT: %DoesNotImplI: %DoesNotImplI.type = struct_value () [template]
  340. // CHECK:STDOUT: %Impls.type: type = fn_type @Impls [template]
  341. // CHECK:STDOUT: %Impls: %Impls.type = struct_value () [template]
  342. // CHECK:STDOUT: %V: %.3 = bind_symbolic_name V 0 [symbolic]
  343. // CHECK:STDOUT: %ImplicitAs.type: type = generic_interface_type @ImplicitAs [template]
  344. // CHECK:STDOUT: %ImplicitAs: %ImplicitAs.type = struct_value () [template]
  345. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest 0 [symbolic]
  346. // CHECK:STDOUT: %.6: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic]
  347. // CHECK:STDOUT: %Self.2: @ImplicitAs.%.1 (%.6) = bind_symbolic_name Self 1 [symbolic]
  348. // CHECK:STDOUT: %Self.3: %.6 = bind_symbolic_name Self 1 [symbolic]
  349. // CHECK:STDOUT: %Convert.type.1: type = fn_type @Convert, @ImplicitAs(%Dest) [symbolic]
  350. // CHECK:STDOUT: %Convert.1: %Convert.type.1 = struct_value () [symbolic]
  351. // CHECK:STDOUT: %.7: type = assoc_entity_type %.6, %Convert.type.1 [symbolic]
  352. // CHECK:STDOUT: %.8: %.7 = assoc_entity element0, imports.%import_ref.12 [symbolic]
  353. // CHECK:STDOUT: %.9: type = interface_type @ImplicitAs, @ImplicitAs(%.3) [template]
  354. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert, @ImplicitAs(%.3) [template]
  355. // CHECK:STDOUT: %Convert.2: %Convert.type.2 = struct_value () [template]
  356. // CHECK:STDOUT: %.10: type = assoc_entity_type %.9, %Convert.type.2 [template]
  357. // CHECK:STDOUT: %.11: %.10 = assoc_entity element0, imports.%import_ref.12 [template]
  358. // CHECK:STDOUT: %.12: %.7 = assoc_entity element0, imports.%import_ref.13 [symbolic]
  359. // CHECK:STDOUT: %.Self: %.3 = bind_symbolic_name .Self 0 [symbolic]
  360. // CHECK:STDOUT: %Y: %.3 = bind_symbolic_name Y 0 [symbolic]
  361. // CHECK:STDOUT: %EmptyStruct.type: type = fn_type @EmptyStruct [template]
  362. // CHECK:STDOUT: %EmptyStruct: %EmptyStruct.type = struct_value () [template]
  363. // CHECK:STDOUT: %NotEmptyStruct.type: type = fn_type @NotEmptyStruct [template]
  364. // CHECK:STDOUT: %NotEmptyStruct: %NotEmptyStruct.type = struct_value () [template]
  365. // CHECK:STDOUT: }
  366. // CHECK:STDOUT:
  367. // CHECK:STDOUT: imports {
  368. // CHECK:STDOUT: %import_ref.1: type = import_ref Main//state_constraints, inst+3, loaded [template = constants.%.3]
  369. // CHECK:STDOUT: %import_ref.2 = import_ref Main//state_constraints, inst+7, unloaded
  370. // CHECK:STDOUT: %import_ref.3 = import_ref Main//state_constraints, inst+34, unloaded
  371. // CHECK:STDOUT: %import_ref.4 = import_ref Main//state_constraints, inst+48, unloaded
  372. // CHECK:STDOUT: %import_ref.5: %Impls.type = import_ref Main//state_constraints, inst+63, loaded [template = constants.%Impls]
  373. // CHECK:STDOUT: %import_ref.6 = import_ref Main//state_constraints, inst+83, unloaded
  374. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  375. // CHECK:STDOUT: .ImplicitAs = %import_ref.8
  376. // CHECK:STDOUT: import Core//prelude
  377. // CHECK:STDOUT: import Core//prelude/operators
  378. // CHECK:STDOUT: import Core//prelude/types
  379. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  380. // CHECK:STDOUT: import Core//prelude/operators/as
  381. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  382. // CHECK:STDOUT: import Core//prelude/operators/comparison
  383. // CHECK:STDOUT: import Core//prelude/types/bool
  384. // CHECK:STDOUT: }
  385. // CHECK:STDOUT: %import_ref.7 = import_ref Main//state_constraints, inst+5, unloaded
  386. // CHECK:STDOUT: %import_ref.8: %ImplicitAs.type = import_ref Core//prelude/operators/as, inst+40, loaded [template = constants.%ImplicitAs]
  387. // CHECK:STDOUT: %import_ref.9 = import_ref Core//prelude/operators/as, inst+45, unloaded
  388. // CHECK:STDOUT: %import_ref.10: @ImplicitAs.%.2 (%.7) = import_ref Core//prelude/operators/as, inst+63, loaded [symbolic = @ImplicitAs.%.3 (constants.%.12)]
  389. // CHECK:STDOUT: %import_ref.11 = import_ref Core//prelude/operators/as, inst+56, unloaded
  390. // CHECK:STDOUT: %import_ref.12 = import_ref Core//prelude/operators/as, inst+56, unloaded
  391. // CHECK:STDOUT: %import_ref.13 = import_ref Core//prelude/operators/as, inst+56, unloaded
  392. // CHECK:STDOUT: }
  393. // CHECK:STDOUT:
  394. // CHECK:STDOUT: file {
  395. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  396. // CHECK:STDOUT: .J = imports.%import_ref.1
  397. // CHECK:STDOUT: .I = imports.%import_ref.2
  398. // CHECK:STDOUT: .Equal = imports.%import_ref.3
  399. // CHECK:STDOUT: .EqualEqual = imports.%import_ref.4
  400. // CHECK:STDOUT: .Impls = imports.%import_ref.5
  401. // CHECK:STDOUT: .And = imports.%import_ref.6
  402. // CHECK:STDOUT: .Core = imports.%Core
  403. // CHECK:STDOUT: .C = %C.decl
  404. // CHECK:STDOUT: .DoesNotImplI = %DoesNotImplI.decl
  405. // CHECK:STDOUT: .EmptyStruct = %EmptyStruct.decl
  406. // CHECK:STDOUT: .NotEmptyStruct = %NotEmptyStruct.decl
  407. // CHECK:STDOUT: }
  408. // CHECK:STDOUT: %Core.import = import Core
  409. // CHECK:STDOUT: %default.import = import <invalid>
  410. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  411. // CHECK:STDOUT: impl_decl @impl {} {
  412. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  413. // CHECK:STDOUT: %J.ref: type = name_ref J, imports.%import_ref.1 [template = constants.%.3]
  414. // CHECK:STDOUT: }
  415. // CHECK:STDOUT: %DoesNotImplI.decl: %DoesNotImplI.type = fn_decl @DoesNotImplI [template = constants.%DoesNotImplI] {} {}
  416. // CHECK:STDOUT: %EmptyStruct.decl: %EmptyStruct.type = fn_decl @EmptyStruct [template = constants.%EmptyStruct] {
  417. // CHECK:STDOUT: %Y.patt: %.3 = symbolic_binding_pattern Y 0
  418. // CHECK:STDOUT: } {
  419. // CHECK:STDOUT: %J.ref: type = name_ref J, imports.%import_ref.1 [template = constants.%.3]
  420. // CHECK:STDOUT: %.Self: %.3 = bind_symbolic_name .Self 0 [symbolic = constants.%.Self]
  421. // CHECK:STDOUT: %.Self.ref: %.3 = name_ref .Self, %.Self [symbolic = constants.%.Self]
  422. // CHECK:STDOUT: %.loc26_38: %.1 = struct_literal ()
  423. // CHECK:STDOUT: %.loc26_22: type = where_expr %.Self [template = constants.%.3] {
  424. // CHECK:STDOUT: requirement_equivalent %.Self.ref, %.loc26_38
  425. // CHECK:STDOUT: }
  426. // CHECK:STDOUT: %Y.param: %.3 = param Y, runtime_param<invalid>
  427. // CHECK:STDOUT: %Y.loc26: %.3 = bind_symbolic_name Y 0, %Y.param [symbolic = %Y.1 (constants.%Y)]
  428. // CHECK:STDOUT: }
  429. // CHECK:STDOUT: %NotEmptyStruct.decl: %NotEmptyStruct.type = fn_decl @NotEmptyStruct [template = constants.%NotEmptyStruct] {} {}
  430. // CHECK:STDOUT: }
  431. // CHECK:STDOUT:
  432. // CHECK:STDOUT: interface @J {
  433. // CHECK:STDOUT: !members:
  434. // CHECK:STDOUT: .Self = imports.%import_ref.7
  435. // CHECK:STDOUT: witness = ()
  436. // CHECK:STDOUT: }
  437. // CHECK:STDOUT:
  438. // CHECK:STDOUT: generic interface @ImplicitAs(constants.%Dest: type) {
  439. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest 0 [symbolic = %Dest (constants.%Dest)]
  440. // CHECK:STDOUT:
  441. // CHECK:STDOUT: !definition:
  442. // CHECK:STDOUT: %.1: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic = %.1 (constants.%.6)]
  443. // CHECK:STDOUT: %Self: %.6 = bind_symbolic_name Self 1 [symbolic = %Self (constants.%Self.3)]
  444. // CHECK:STDOUT: %Convert.type: type = fn_type @Convert, @ImplicitAs(%Dest) [symbolic = %Convert.type (constants.%Convert.type.1)]
  445. // CHECK:STDOUT: %Convert: @ImplicitAs.%Convert.type (%Convert.type.1) = struct_value () [symbolic = %Convert (constants.%Convert.1)]
  446. // CHECK:STDOUT: %.2: type = assoc_entity_type @ImplicitAs.%.1 (%.6), @ImplicitAs.%Convert.type (%Convert.type.1) [symbolic = %.2 (constants.%.7)]
  447. // CHECK:STDOUT: %.3: @ImplicitAs.%.2 (%.7) = assoc_entity element0, imports.%import_ref.12 [symbolic = %.3 (constants.%.8)]
  448. // CHECK:STDOUT:
  449. // CHECK:STDOUT: interface {
  450. // CHECK:STDOUT: !members:
  451. // CHECK:STDOUT: .Self = imports.%import_ref.9
  452. // CHECK:STDOUT: .Convert = imports.%import_ref.10
  453. // CHECK:STDOUT: witness = (imports.%import_ref.11)
  454. // CHECK:STDOUT: }
  455. // CHECK:STDOUT: }
  456. // CHECK:STDOUT:
  457. // CHECK:STDOUT: impl @impl: %C as %.3 {
  458. // CHECK:STDOUT: %.loc8: <witness> = interface_witness () [template = constants.%.5]
  459. // CHECK:STDOUT:
  460. // CHECK:STDOUT: !members:
  461. // CHECK:STDOUT: witness = %.loc8
  462. // CHECK:STDOUT: }
  463. // CHECK:STDOUT:
  464. // CHECK:STDOUT: class @C {
  465. // CHECK:STDOUT: %.loc7: <witness> = complete_type_witness %.1 [template = constants.%.2]
  466. // CHECK:STDOUT:
  467. // CHECK:STDOUT: !members:
  468. // CHECK:STDOUT: .Self = constants.%C
  469. // CHECK:STDOUT: }
  470. // CHECK:STDOUT:
  471. // CHECK:STDOUT: fn @DoesNotImplI() {
  472. // CHECK:STDOUT: !entry:
  473. // CHECK:STDOUT: %Impls.ref: %Impls.type = name_ref Impls, imports.%import_ref.5 [template = constants.%Impls]
  474. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  475. // CHECK:STDOUT: %.loc23_8.1: type = interface_type @ImplicitAs, @ImplicitAs(constants.%.3) [template = constants.%.9]
  476. // CHECK:STDOUT: %.loc23_8.2: %.10 = specific_constant imports.%import_ref.10, @ImplicitAs(constants.%.3) [template = constants.%.11]
  477. // CHECK:STDOUT: %Convert.ref: %.10 = name_ref Convert, %.loc23_8.2 [template = constants.%.11]
  478. // CHECK:STDOUT: %.loc23_8.3: %.3 = converted %C.ref, <error> [template = <error>]
  479. // CHECK:STDOUT: return
  480. // CHECK:STDOUT: }
  481. // CHECK:STDOUT:
  482. // CHECK:STDOUT: generic fn @Impls(constants.%V: %.3) {
  483. // CHECK:STDOUT: %V.2: %.3 = bind_symbolic_name V 0 [symbolic = %V.2 (constants.%V)]
  484. // CHECK:STDOUT:
  485. // CHECK:STDOUT: fn(%V.1: %.3);
  486. // CHECK:STDOUT: }
  487. // CHECK:STDOUT:
  488. // CHECK:STDOUT: generic fn @Convert(constants.%Dest: type, constants.%Self.2: @ImplicitAs.%.1 (%.6)) {
  489. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest 0 [symbolic = %Dest (constants.%Dest)]
  490. // CHECK:STDOUT: %.1: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic = %.1 (constants.%.6)]
  491. // CHECK:STDOUT: %Self: %.6 = bind_symbolic_name Self 1 [symbolic = %Self (constants.%Self.3)]
  492. // CHECK:STDOUT:
  493. // CHECK:STDOUT: fn[%self: @Convert.%Self (%Self.3)]() -> @Convert.%Dest (%Dest);
  494. // CHECK:STDOUT: }
  495. // CHECK:STDOUT:
  496. // CHECK:STDOUT: generic fn @EmptyStruct(%Y.loc26: %.3) {
  497. // CHECK:STDOUT: %Y.1: %.3 = bind_symbolic_name Y 0 [symbolic = %Y.1 (constants.%Y)]
  498. // CHECK:STDOUT:
  499. // CHECK:STDOUT: fn(%Y.loc26: %.3);
  500. // CHECK:STDOUT: }
  501. // CHECK:STDOUT:
  502. // CHECK:STDOUT: fn @NotEmptyStruct() {
  503. // CHECK:STDOUT: !entry:
  504. // CHECK:STDOUT: %EmptyStruct.ref: %EmptyStruct.type = name_ref EmptyStruct, file.%EmptyStruct.decl [template = constants.%EmptyStruct]
  505. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  506. // CHECK:STDOUT: %.loc39_14.1: type = interface_type @ImplicitAs, @ImplicitAs(constants.%.3) [template = constants.%.9]
  507. // CHECK:STDOUT: %.loc39_14.2: %.10 = specific_constant imports.%import_ref.10, @ImplicitAs(constants.%.3) [template = constants.%.11]
  508. // CHECK:STDOUT: %Convert.ref: %.10 = name_ref Convert, %.loc39_14.2 [template = constants.%.11]
  509. // CHECK:STDOUT: %.loc39_14.3: %.3 = converted %C.ref, <error> [template = <error>]
  510. // CHECK:STDOUT: return
  511. // CHECK:STDOUT: }
  512. // CHECK:STDOUT:
  513. // CHECK:STDOUT: specific @Impls(constants.%V) {
  514. // CHECK:STDOUT: %V.2 => constants.%V
  515. // CHECK:STDOUT: }
  516. // CHECK:STDOUT:
  517. // CHECK:STDOUT: specific @ImplicitAs(constants.%Dest) {
  518. // CHECK:STDOUT: %Dest => constants.%Dest
  519. // CHECK:STDOUT: }
  520. // CHECK:STDOUT:
  521. // CHECK:STDOUT: specific @ImplicitAs(@ImplicitAs.%Dest) {
  522. // CHECK:STDOUT: %Dest => constants.%Dest
  523. // CHECK:STDOUT: }
  524. // CHECK:STDOUT:
  525. // CHECK:STDOUT: specific @ImplicitAs(@Convert.%Dest) {
  526. // CHECK:STDOUT: %Dest => constants.%Dest
  527. // CHECK:STDOUT: }
  528. // CHECK:STDOUT:
  529. // CHECK:STDOUT: specific @Convert(constants.%Dest, constants.%Self.2) {
  530. // CHECK:STDOUT: %Dest => constants.%Dest
  531. // CHECK:STDOUT: %.1 => constants.%.6
  532. // CHECK:STDOUT: %Self => constants.%Self.2
  533. // CHECK:STDOUT: }
  534. // CHECK:STDOUT:
  535. // CHECK:STDOUT: specific @ImplicitAs(constants.%.3) {
  536. // CHECK:STDOUT: %Dest => constants.%.3
  537. // CHECK:STDOUT:
  538. // CHECK:STDOUT: !definition:
  539. // CHECK:STDOUT: %.1 => constants.%.9
  540. // CHECK:STDOUT: %Self => constants.%Self.3
  541. // CHECK:STDOUT: %Convert.type => constants.%Convert.type.2
  542. // CHECK:STDOUT: %Convert => constants.%Convert.2
  543. // CHECK:STDOUT: %.2 => constants.%.10
  544. // CHECK:STDOUT: %.3 => constants.%.11
  545. // CHECK:STDOUT: }
  546. // CHECK:STDOUT:
  547. // CHECK:STDOUT: specific @EmptyStruct(constants.%Y) {
  548. // CHECK:STDOUT: %Y.1 => constants.%Y
  549. // CHECK:STDOUT: }
  550. // CHECK:STDOUT: