array.carbon 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  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/deduce/array.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/deduce/array.carbon
  10. // --- type_only.carbon
  11. library "[[@TEST_NAME]]";
  12. class C {}
  13. fn F[T:! type](a: [T; 3]) -> T { return a[0]; }
  14. fn G() -> C {
  15. var a: [C; 3] = ({}, {}, {});
  16. return F(a);
  17. }
  18. // --- fail_todo_bound_only.carbon
  19. library "[[@TEST_NAME]]";
  20. class C {}
  21. // CHECK:STDERR: fail_todo_bound_only.carbon:[[@LINE+4]]:22: error: semantics TODO: `symbolic array bound`
  22. // CHECK:STDERR: fn F[N:! i32](a: [C; N]) -> i32 { return N; }
  23. // CHECK:STDERR: ^
  24. // CHECK:STDERR:
  25. fn F[N:! i32](a: [C; N]) -> i32 { return N; }
  26. fn G() -> C {
  27. var a: [C; 3] = ({}, {}, {});
  28. return F(a);
  29. }
  30. // --- fail_todo_type_and_bound.carbon
  31. library "[[@TEST_NAME]]";
  32. class C {}
  33. // CHECK:STDERR: fail_todo_type_and_bound.carbon:[[@LINE+4]]:32: error: semantics TODO: `symbolic array bound`
  34. // CHECK:STDERR: fn F[T:! type, N:! i32](a: [T; N]) -> T;
  35. // CHECK:STDERR: ^
  36. // CHECK:STDERR:
  37. fn F[T:! type, N:! i32](a: [T; N]) -> T;
  38. fn G() -> C {
  39. var a: [C; 3] = ({}, {}, {});
  40. return F(a);
  41. }
  42. // --- fail_bound_mismatch.carbon
  43. library "[[@TEST_NAME]]";
  44. class C {}
  45. fn F[T:! type](a: [T; 2]) -> T { return a[0]; }
  46. fn G() -> C {
  47. // TODO: We succeed at deducing T here but fail to convert. Is this the right behavior?
  48. var a: [C; 3] = ({}, {}, {});
  49. // CHECK:STDERR: fail_bound_mismatch.carbon:[[@LINE+10]]:10: error: cannot implicitly convert from `[C; 3]` to `[C; 2]`
  50. // CHECK:STDERR: return F(a);
  51. // CHECK:STDERR: ^~
  52. // CHECK:STDERR: fail_bound_mismatch.carbon:[[@LINE+7]]:10: note: type `[C; 3]` does not implement interface `ImplicitAs`
  53. // CHECK:STDERR: return F(a);
  54. // CHECK:STDERR: ^~
  55. // CHECK:STDERR: fail_bound_mismatch.carbon:[[@LINE-11]]:1: note: initializing parameter 1 of function declared here
  56. // CHECK:STDERR: fn F[T:! type](a: [T; 2]) -> T { return a[0]; }
  57. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  58. // CHECK:STDERR:
  59. return F(a);
  60. }
  61. // --- fail_type_mismatch.carbon
  62. library "[[@TEST_NAME]]";
  63. class C {}
  64. class D {}
  65. // CHECK:STDERR: fail_type_mismatch.carbon:[[@LINE+3]]:22: error: semantics TODO: `symbolic array bound`
  66. // CHECK:STDERR: fn F[N:! i32](a: [C; N]) -> i32 { return N; }
  67. // CHECK:STDERR: ^
  68. fn F[N:! i32](a: [C; N]) -> i32 { return N; }
  69. fn G() -> C {
  70. var a: [D; 3] = ({}, {}, {});
  71. return F(a);
  72. }
  73. // CHECK:STDOUT: --- type_only.carbon
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: constants {
  76. // CHECK:STDOUT: %C: type = class_type @C [template]
  77. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  78. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  79. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  80. // CHECK:STDOUT: %.3: i32 = int_literal 3 [template]
  81. // CHECK:STDOUT: %.4: type = array_type %.3, %T [symbolic]
  82. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  83. // CHECK:STDOUT: %.5: type = tuple_type () [template]
  84. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  85. // CHECK:STDOUT: %.6: type = ptr_type %.4 [symbolic]
  86. // CHECK:STDOUT: %.7: i32 = int_literal 0 [template]
  87. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  88. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  89. // CHECK:STDOUT: %.8: type = ptr_type %.1 [template]
  90. // CHECK:STDOUT: %.9: type = array_type %.3, %C [template]
  91. // CHECK:STDOUT: %.10: type = ptr_type %.9 [template]
  92. // CHECK:STDOUT: %.11: type = tuple_type (%.1, %.1, %.1) [template]
  93. // CHECK:STDOUT: %struct: %C = struct_value () [template]
  94. // CHECK:STDOUT: %.12: i32 = int_literal 1 [template]
  95. // CHECK:STDOUT: %.13: i32 = int_literal 2 [template]
  96. // CHECK:STDOUT: %array: %.9 = tuple_value (%struct, %struct, %struct) [template]
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: imports {
  100. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  101. // CHECK:STDOUT: import Core//prelude
  102. // CHECK:STDOUT: import Core//prelude/operators
  103. // CHECK:STDOUT: import Core//prelude/types
  104. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  105. // CHECK:STDOUT: import Core//prelude/operators/as
  106. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  107. // CHECK:STDOUT: import Core//prelude/operators/comparison
  108. // CHECK:STDOUT: import Core//prelude/types/bool
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT:
  112. // CHECK:STDOUT: file {
  113. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  114. // CHECK:STDOUT: .Core = imports.%Core
  115. // CHECK:STDOUT: .C = %C.decl
  116. // CHECK:STDOUT: .F = %F.decl
  117. // CHECK:STDOUT: .G = %G.decl
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT: %Core.import = import Core
  120. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  121. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  122. // CHECK:STDOUT: %T.patt: type = symbolic_binding_pattern T, 0
  123. // CHECK:STDOUT: %a.patt: @F.%.loc6_24.2 (%.4) = binding_pattern a
  124. // CHECK:STDOUT: } {
  125. // CHECK:STDOUT: %T.param: type = param T, runtime_param<invalid>
  126. // CHECK:STDOUT: %T.loc6_6.1: type = bind_symbolic_name T, 0, %T.param [symbolic = %T.loc6_6.2 (constants.%T)]
  127. // CHECK:STDOUT: %T.ref.loc6_20: type = name_ref T, %T.loc6_6.1 [symbolic = %T.loc6_6.2 (constants.%T)]
  128. // CHECK:STDOUT: %.loc6_23: i32 = int_literal 3 [template = constants.%.3]
  129. // CHECK:STDOUT: %.loc6_24.1: type = array_type %.loc6_23, %T [symbolic = %.loc6_24.2 (constants.%.4)]
  130. // CHECK:STDOUT: %a.param: @F.%.loc6_24.2 (%.4) = param a, runtime_param0
  131. // CHECK:STDOUT: %a: @F.%.loc6_24.2 (%.4) = bind_name a, %a.param
  132. // CHECK:STDOUT: %T.ref.loc6_30: type = name_ref T, %T.loc6_6.1 [symbolic = %T.loc6_6.2 (constants.%T)]
  133. // CHECK:STDOUT: %return: ref @F.%T.loc6_6.2 (%T) = var <return slot>
  134. // CHECK:STDOUT: }
  135. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {} {
  136. // CHECK:STDOUT: %C.ref.loc8: type = name_ref C, file.%C.decl [template = constants.%C]
  137. // CHECK:STDOUT: %return: ref %C = var <return slot>
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT:
  141. // CHECK:STDOUT: class @C {
  142. // CHECK:STDOUT: %.loc4: <witness> = complete_type_witness %.1 [template = constants.%.2]
  143. // CHECK:STDOUT:
  144. // CHECK:STDOUT: !members:
  145. // CHECK:STDOUT: .Self = constants.%C
  146. // CHECK:STDOUT: }
  147. // CHECK:STDOUT:
  148. // CHECK:STDOUT: generic fn @F(%T.loc6_6.1: type) {
  149. // CHECK:STDOUT: %T.loc6_6.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc6_6.2 (constants.%T)]
  150. // CHECK:STDOUT: %.loc6_24.2: type = array_type constants.%.3, @F.%T.loc6_6.2 (%T) [symbolic = %.loc6_24.2 (constants.%.4)]
  151. // CHECK:STDOUT:
  152. // CHECK:STDOUT: !definition:
  153. // CHECK:STDOUT:
  154. // CHECK:STDOUT: fn[%T.loc6_6.1: type](%a: @F.%.loc6_24.2 (%.4)) -> @F.%T.loc6_6.2 (%T) {
  155. // CHECK:STDOUT: !entry:
  156. // CHECK:STDOUT: %a.ref: @F.%.loc6_24.2 (%.4) = name_ref a, %a
  157. // CHECK:STDOUT: %.loc6_43: i32 = int_literal 0 [template = constants.%.7]
  158. // CHECK:STDOUT: %.loc6_44.1: ref @F.%.loc6_24.2 (%.4) = value_as_ref %a.ref
  159. // CHECK:STDOUT: %.loc6_44.2: ref @F.%T.loc6_6.2 (%T) = array_index %.loc6_44.1, %.loc6_43
  160. // CHECK:STDOUT: %.loc6_44.3: @F.%T.loc6_6.2 (%T) = bind_value %.loc6_44.2
  161. // CHECK:STDOUT: return %.loc6_44.3
  162. // CHECK:STDOUT: }
  163. // CHECK:STDOUT: }
  164. // CHECK:STDOUT:
  165. // CHECK:STDOUT: fn @G() -> %return: %C {
  166. // CHECK:STDOUT: !entry:
  167. // CHECK:STDOUT: %C.ref.loc9: type = name_ref C, file.%C.decl [template = constants.%C]
  168. // CHECK:STDOUT: %.loc9_14: i32 = int_literal 3 [template = constants.%.3]
  169. // CHECK:STDOUT: %.loc9_15: type = array_type %.loc9_14, %C [template = constants.%.9]
  170. // CHECK:STDOUT: %a.var: ref %.9 = var a
  171. // CHECK:STDOUT: %a: ref %.9 = bind_name a, %a.var
  172. // CHECK:STDOUT: %.loc9_21.1: %.1 = struct_literal ()
  173. // CHECK:STDOUT: %.loc9_25.1: %.1 = struct_literal ()
  174. // CHECK:STDOUT: %.loc9_29.1: %.1 = struct_literal ()
  175. // CHECK:STDOUT: %.loc9_30.1: %.11 = tuple_literal (%.loc9_21.1, %.loc9_25.1, %.loc9_29.1)
  176. // CHECK:STDOUT: %.loc9_30.2: i32 = int_literal 0 [template = constants.%.7]
  177. // CHECK:STDOUT: %.loc9_30.3: ref %C = array_index %a.var, %.loc9_30.2
  178. // CHECK:STDOUT: %.loc9_21.2: init %C = class_init (), %.loc9_30.3 [template = constants.%struct]
  179. // CHECK:STDOUT: %.loc9_30.4: init %C = converted %.loc9_21.1, %.loc9_21.2 [template = constants.%struct]
  180. // CHECK:STDOUT: %.loc9_30.5: i32 = int_literal 1 [template = constants.%.12]
  181. // CHECK:STDOUT: %.loc9_30.6: ref %C = array_index %a.var, %.loc9_30.5
  182. // CHECK:STDOUT: %.loc9_25.2: init %C = class_init (), %.loc9_30.6 [template = constants.%struct]
  183. // CHECK:STDOUT: %.loc9_30.7: init %C = converted %.loc9_25.1, %.loc9_25.2 [template = constants.%struct]
  184. // CHECK:STDOUT: %.loc9_30.8: i32 = int_literal 2 [template = constants.%.13]
  185. // CHECK:STDOUT: %.loc9_30.9: ref %C = array_index %a.var, %.loc9_30.8
  186. // CHECK:STDOUT: %.loc9_29.2: init %C = class_init (), %.loc9_30.9 [template = constants.%struct]
  187. // CHECK:STDOUT: %.loc9_30.10: init %C = converted %.loc9_29.1, %.loc9_29.2 [template = constants.%struct]
  188. // CHECK:STDOUT: %.loc9_30.11: init %.9 = array_init (%.loc9_30.4, %.loc9_30.7, %.loc9_30.10) to %a.var [template = constants.%array]
  189. // CHECK:STDOUT: %.loc9_31: init %.9 = converted %.loc9_30.1, %.loc9_30.11 [template = constants.%array]
  190. // CHECK:STDOUT: assign %a.var, %.loc9_31
  191. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  192. // CHECK:STDOUT: %a.ref: ref %.9 = name_ref a, %a
  193. // CHECK:STDOUT: %.loc8: ref %C = splice_block %return {}
  194. // CHECK:STDOUT: %.loc10: %.9 = bind_value %a.ref
  195. // CHECK:STDOUT: %F.call: init %C = call %F.ref(%.loc10) to %.loc8
  196. // CHECK:STDOUT: return %F.call to %return
  197. // CHECK:STDOUT: }
  198. // CHECK:STDOUT:
  199. // CHECK:STDOUT: specific @F(constants.%T) {
  200. // CHECK:STDOUT: %T.loc6_6.2 => constants.%T
  201. // CHECK:STDOUT: %.loc6_24.2 => constants.%.4
  202. // CHECK:STDOUT: }
  203. // CHECK:STDOUT:
  204. // CHECK:STDOUT: specific @F(constants.%C) {
  205. // CHECK:STDOUT: %T.loc6_6.2 => constants.%C
  206. // CHECK:STDOUT: %.loc6_24.2 => constants.%.9
  207. // CHECK:STDOUT: }
  208. // CHECK:STDOUT:
  209. // CHECK:STDOUT: --- fail_todo_bound_only.carbon
  210. // CHECK:STDOUT:
  211. // CHECK:STDOUT: constants {
  212. // CHECK:STDOUT: %C: type = class_type @C [template]
  213. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  214. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  215. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  216. // CHECK:STDOUT: %.3: type = tuple_type () [template]
  217. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  218. // CHECK:STDOUT: %N: i32 = bind_symbolic_name N, 0 [symbolic]
  219. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  220. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  221. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  222. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  223. // CHECK:STDOUT: %.4: type = ptr_type %.1 [template]
  224. // CHECK:STDOUT: %.5: i32 = int_literal 3 [template]
  225. // CHECK:STDOUT: %.6: type = array_type %.5, %C [template]
  226. // CHECK:STDOUT: %.7: type = ptr_type %.6 [template]
  227. // CHECK:STDOUT: %.8: type = tuple_type (%.1, %.1, %.1) [template]
  228. // CHECK:STDOUT: %.9: i32 = int_literal 0 [template]
  229. // CHECK:STDOUT: %struct: %C = struct_value () [template]
  230. // CHECK:STDOUT: %.10: i32 = int_literal 1 [template]
  231. // CHECK:STDOUT: %.11: i32 = int_literal 2 [template]
  232. // CHECK:STDOUT: %array: %.6 = tuple_value (%struct, %struct, %struct) [template]
  233. // CHECK:STDOUT: }
  234. // CHECK:STDOUT:
  235. // CHECK:STDOUT: imports {
  236. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  237. // CHECK:STDOUT: .Int32 = %import_ref
  238. // CHECK:STDOUT: import Core//prelude
  239. // CHECK:STDOUT: import Core//prelude/operators
  240. // CHECK:STDOUT: import Core//prelude/types
  241. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  242. // CHECK:STDOUT: import Core//prelude/operators/as
  243. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  244. // CHECK:STDOUT: import Core//prelude/operators/comparison
  245. // CHECK:STDOUT: import Core//prelude/types/bool
  246. // CHECK:STDOUT: }
  247. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  248. // CHECK:STDOUT: }
  249. // CHECK:STDOUT:
  250. // CHECK:STDOUT: file {
  251. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  252. // CHECK:STDOUT: .Core = imports.%Core
  253. // CHECK:STDOUT: .C = %C.decl
  254. // CHECK:STDOUT: .F = %F.decl
  255. // CHECK:STDOUT: .G = %G.decl
  256. // CHECK:STDOUT: }
  257. // CHECK:STDOUT: %Core.import = import Core
  258. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  259. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  260. // CHECK:STDOUT: %N.patt: i32 = symbolic_binding_pattern N, 0
  261. // CHECK:STDOUT: %a.patt: <error> = binding_pattern a
  262. // CHECK:STDOUT: } {
  263. // CHECK:STDOUT: %int.make_type_32.loc10_10: init type = call constants.%Int32() [template = i32]
  264. // CHECK:STDOUT: %.loc10_10.1: type = value_of_initializer %int.make_type_32.loc10_10 [template = i32]
  265. // CHECK:STDOUT: %.loc10_10.2: type = converted %int.make_type_32.loc10_10, %.loc10_10.1 [template = i32]
  266. // CHECK:STDOUT: %N.param: i32 = param N, runtime_param<invalid>
  267. // CHECK:STDOUT: %N.loc10_6.1: i32 = bind_symbolic_name N, 0, %N.param [symbolic = %N.loc10_6.2 (constants.%N)]
  268. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  269. // CHECK:STDOUT: %N.ref.loc10_22: i32 = name_ref N, %N.loc10_6.1 [symbolic = %N.loc10_6.2 (constants.%N)]
  270. // CHECK:STDOUT: %.loc10_23: type = array_type %N.ref.loc10_22, %C [template = <error>]
  271. // CHECK:STDOUT: %a.param: <error> = param a, runtime_param0
  272. // CHECK:STDOUT: %a: <error> = bind_name a, %a.param
  273. // CHECK:STDOUT: %int.make_type_32.loc10_29: init type = call constants.%Int32() [template = i32]
  274. // CHECK:STDOUT: %.loc10_29.1: type = value_of_initializer %int.make_type_32.loc10_29 [template = i32]
  275. // CHECK:STDOUT: %.loc10_29.2: type = converted %int.make_type_32.loc10_29, %.loc10_29.1 [template = i32]
  276. // CHECK:STDOUT: %return: ref i32 = var <return slot>
  277. // CHECK:STDOUT: }
  278. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {} {
  279. // CHECK:STDOUT: %C.ref.loc12: type = name_ref C, file.%C.decl [template = constants.%C]
  280. // CHECK:STDOUT: %return: ref %C = var <return slot>
  281. // CHECK:STDOUT: }
  282. // CHECK:STDOUT: }
  283. // CHECK:STDOUT:
  284. // CHECK:STDOUT: class @C {
  285. // CHECK:STDOUT: %.loc4: <witness> = complete_type_witness %.1 [template = constants.%.2]
  286. // CHECK:STDOUT:
  287. // CHECK:STDOUT: !members:
  288. // CHECK:STDOUT: .Self = constants.%C
  289. // CHECK:STDOUT: }
  290. // CHECK:STDOUT:
  291. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  292. // CHECK:STDOUT:
  293. // CHECK:STDOUT: generic fn @F(%N.loc10_6.1: i32) {
  294. // CHECK:STDOUT: %N.loc10_6.2: i32 = bind_symbolic_name N, 0 [symbolic = %N.loc10_6.2 (constants.%N)]
  295. // CHECK:STDOUT:
  296. // CHECK:STDOUT: !definition:
  297. // CHECK:STDOUT:
  298. // CHECK:STDOUT: fn[%N.loc10_6.1: i32](%a: <error>) -> i32 {
  299. // CHECK:STDOUT: !entry:
  300. // CHECK:STDOUT: %N.ref.loc10_42: i32 = name_ref N, %N.loc10_6.1 [symbolic = %N.loc10_6.2 (constants.%N)]
  301. // CHECK:STDOUT: return %N.ref.loc10_42
  302. // CHECK:STDOUT: }
  303. // CHECK:STDOUT: }
  304. // CHECK:STDOUT:
  305. // CHECK:STDOUT: fn @G() -> %return: %C {
  306. // CHECK:STDOUT: !entry:
  307. // CHECK:STDOUT: %C.ref.loc13: type = name_ref C, file.%C.decl [template = constants.%C]
  308. // CHECK:STDOUT: %.loc13_14: i32 = int_literal 3 [template = constants.%.5]
  309. // CHECK:STDOUT: %.loc13_15: type = array_type %.loc13_14, %C [template = constants.%.6]
  310. // CHECK:STDOUT: %a.var: ref %.6 = var a
  311. // CHECK:STDOUT: %a: ref %.6 = bind_name a, %a.var
  312. // CHECK:STDOUT: %.loc13_21.1: %.1 = struct_literal ()
  313. // CHECK:STDOUT: %.loc13_25.1: %.1 = struct_literal ()
  314. // CHECK:STDOUT: %.loc13_29.1: %.1 = struct_literal ()
  315. // CHECK:STDOUT: %.loc13_30.1: %.8 = tuple_literal (%.loc13_21.1, %.loc13_25.1, %.loc13_29.1)
  316. // CHECK:STDOUT: %.loc13_30.2: i32 = int_literal 0 [template = constants.%.9]
  317. // CHECK:STDOUT: %.loc13_30.3: ref %C = array_index %a.var, %.loc13_30.2
  318. // CHECK:STDOUT: %.loc13_21.2: init %C = class_init (), %.loc13_30.3 [template = constants.%struct]
  319. // CHECK:STDOUT: %.loc13_30.4: init %C = converted %.loc13_21.1, %.loc13_21.2 [template = constants.%struct]
  320. // CHECK:STDOUT: %.loc13_30.5: i32 = int_literal 1 [template = constants.%.10]
  321. // CHECK:STDOUT: %.loc13_30.6: ref %C = array_index %a.var, %.loc13_30.5
  322. // CHECK:STDOUT: %.loc13_25.2: init %C = class_init (), %.loc13_30.6 [template = constants.%struct]
  323. // CHECK:STDOUT: %.loc13_30.7: init %C = converted %.loc13_25.1, %.loc13_25.2 [template = constants.%struct]
  324. // CHECK:STDOUT: %.loc13_30.8: i32 = int_literal 2 [template = constants.%.11]
  325. // CHECK:STDOUT: %.loc13_30.9: ref %C = array_index %a.var, %.loc13_30.8
  326. // CHECK:STDOUT: %.loc13_29.2: init %C = class_init (), %.loc13_30.9 [template = constants.%struct]
  327. // CHECK:STDOUT: %.loc13_30.10: init %C = converted %.loc13_29.1, %.loc13_29.2 [template = constants.%struct]
  328. // CHECK:STDOUT: %.loc13_30.11: init %.6 = array_init (%.loc13_30.4, %.loc13_30.7, %.loc13_30.10) to %a.var [template = constants.%array]
  329. // CHECK:STDOUT: %.loc13_31: init %.6 = converted %.loc13_30.1, %.loc13_30.11 [template = constants.%array]
  330. // CHECK:STDOUT: assign %a.var, %.loc13_31
  331. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  332. // CHECK:STDOUT: %a.ref: ref %.6 = name_ref a, %a
  333. // CHECK:STDOUT: return <error> to %return
  334. // CHECK:STDOUT: }
  335. // CHECK:STDOUT:
  336. // CHECK:STDOUT: specific @F(constants.%N) {
  337. // CHECK:STDOUT: %N.loc10_6.2 => constants.%N
  338. // CHECK:STDOUT: }
  339. // CHECK:STDOUT:
  340. // CHECK:STDOUT: --- fail_todo_type_and_bound.carbon
  341. // CHECK:STDOUT:
  342. // CHECK:STDOUT: constants {
  343. // CHECK:STDOUT: %C: type = class_type @C [template]
  344. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  345. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  346. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  347. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  348. // CHECK:STDOUT: %.3: type = tuple_type () [template]
  349. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  350. // CHECK:STDOUT: %N: i32 = bind_symbolic_name N, 1 [symbolic]
  351. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  352. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  353. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  354. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  355. // CHECK:STDOUT: %.4: type = ptr_type %.1 [template]
  356. // CHECK:STDOUT: %.5: i32 = int_literal 3 [template]
  357. // CHECK:STDOUT: %.6: type = array_type %.5, %C [template]
  358. // CHECK:STDOUT: %.7: type = ptr_type %.6 [template]
  359. // CHECK:STDOUT: %.8: type = tuple_type (%.1, %.1, %.1) [template]
  360. // CHECK:STDOUT: %.9: i32 = int_literal 0 [template]
  361. // CHECK:STDOUT: %struct: %C = struct_value () [template]
  362. // CHECK:STDOUT: %.10: i32 = int_literal 1 [template]
  363. // CHECK:STDOUT: %.11: i32 = int_literal 2 [template]
  364. // CHECK:STDOUT: %array: %.6 = tuple_value (%struct, %struct, %struct) [template]
  365. // CHECK:STDOUT: }
  366. // CHECK:STDOUT:
  367. // CHECK:STDOUT: imports {
  368. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  369. // CHECK:STDOUT: .Int32 = %import_ref
  370. // CHECK:STDOUT: import Core//prelude
  371. // CHECK:STDOUT: import Core//prelude/operators
  372. // CHECK:STDOUT: import Core//prelude/types
  373. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  374. // CHECK:STDOUT: import Core//prelude/operators/as
  375. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  376. // CHECK:STDOUT: import Core//prelude/operators/comparison
  377. // CHECK:STDOUT: import Core//prelude/types/bool
  378. // CHECK:STDOUT: }
  379. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  380. // CHECK:STDOUT: }
  381. // CHECK:STDOUT:
  382. // CHECK:STDOUT: file {
  383. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  384. // CHECK:STDOUT: .Core = imports.%Core
  385. // CHECK:STDOUT: .C = %C.decl
  386. // CHECK:STDOUT: .F = %F.decl
  387. // CHECK:STDOUT: .G = %G.decl
  388. // CHECK:STDOUT: }
  389. // CHECK:STDOUT: %Core.import = import Core
  390. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  391. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  392. // CHECK:STDOUT: %T.patt: type = symbolic_binding_pattern T, 0
  393. // CHECK:STDOUT: %N.patt: i32 = symbolic_binding_pattern N, 1
  394. // CHECK:STDOUT: %a.patt: <error> = binding_pattern a
  395. // CHECK:STDOUT: } {
  396. // CHECK:STDOUT: %T.param: type = param T, runtime_param<invalid>
  397. // CHECK:STDOUT: %T.loc10_6.1: type = bind_symbolic_name T, 0, %T.param [symbolic = %T.loc10_6.2 (constants.%T)]
  398. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  399. // CHECK:STDOUT: %.loc10_20.1: type = value_of_initializer %int.make_type_32 [template = i32]
  400. // CHECK:STDOUT: %.loc10_20.2: type = converted %int.make_type_32, %.loc10_20.1 [template = i32]
  401. // CHECK:STDOUT: %N.param: i32 = param N, runtime_param<invalid>
  402. // CHECK:STDOUT: %N.loc10_16.1: i32 = bind_symbolic_name N, 1, %N.param [symbolic = %N.loc10_16.2 (constants.%N)]
  403. // CHECK:STDOUT: %T.ref.loc10_29: type = name_ref T, %T.loc10_6.1 [symbolic = %T.loc10_6.2 (constants.%T)]
  404. // CHECK:STDOUT: %N.ref: i32 = name_ref N, %N.loc10_16.1 [symbolic = %N.loc10_16.2 (constants.%N)]
  405. // CHECK:STDOUT: %.loc10_33: type = array_type %N.ref, %T [template = <error>]
  406. // CHECK:STDOUT: %a.param: <error> = param a, runtime_param0
  407. // CHECK:STDOUT: %a: <error> = bind_name a, %a.param
  408. // CHECK:STDOUT: %T.ref.loc10_39: type = name_ref T, %T.loc10_6.1 [symbolic = %T.loc10_6.2 (constants.%T)]
  409. // CHECK:STDOUT: %return: ref @F.%T.loc10_6.2 (%T) = var <return slot>
  410. // CHECK:STDOUT: }
  411. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {} {
  412. // CHECK:STDOUT: %C.ref.loc12: type = name_ref C, file.%C.decl [template = constants.%C]
  413. // CHECK:STDOUT: %return: ref %C = var <return slot>
  414. // CHECK:STDOUT: }
  415. // CHECK:STDOUT: }
  416. // CHECK:STDOUT:
  417. // CHECK:STDOUT: class @C {
  418. // CHECK:STDOUT: %.loc4: <witness> = complete_type_witness %.1 [template = constants.%.2]
  419. // CHECK:STDOUT:
  420. // CHECK:STDOUT: !members:
  421. // CHECK:STDOUT: .Self = constants.%C
  422. // CHECK:STDOUT: }
  423. // CHECK:STDOUT:
  424. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  425. // CHECK:STDOUT:
  426. // CHECK:STDOUT: generic fn @F(%T.loc10_6.1: type, %N.loc10_16.1: i32) {
  427. // CHECK:STDOUT: %T.loc10_6.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc10_6.2 (constants.%T)]
  428. // CHECK:STDOUT: %N.loc10_16.2: i32 = bind_symbolic_name N, 1 [symbolic = %N.loc10_16.2 (constants.%N)]
  429. // CHECK:STDOUT:
  430. // CHECK:STDOUT: fn[%T.loc10_6.1: type, %N.loc10_16.1: i32](%a: <error>) -> @F.%T.loc10_6.2 (%T);
  431. // CHECK:STDOUT: }
  432. // CHECK:STDOUT:
  433. // CHECK:STDOUT: fn @G() -> %return: %C {
  434. // CHECK:STDOUT: !entry:
  435. // CHECK:STDOUT: %C.ref.loc13: type = name_ref C, file.%C.decl [template = constants.%C]
  436. // CHECK:STDOUT: %.loc13_14: i32 = int_literal 3 [template = constants.%.5]
  437. // CHECK:STDOUT: %.loc13_15: type = array_type %.loc13_14, %C [template = constants.%.6]
  438. // CHECK:STDOUT: %a.var: ref %.6 = var a
  439. // CHECK:STDOUT: %a: ref %.6 = bind_name a, %a.var
  440. // CHECK:STDOUT: %.loc13_21.1: %.1 = struct_literal ()
  441. // CHECK:STDOUT: %.loc13_25.1: %.1 = struct_literal ()
  442. // CHECK:STDOUT: %.loc13_29.1: %.1 = struct_literal ()
  443. // CHECK:STDOUT: %.loc13_30.1: %.8 = tuple_literal (%.loc13_21.1, %.loc13_25.1, %.loc13_29.1)
  444. // CHECK:STDOUT: %.loc13_30.2: i32 = int_literal 0 [template = constants.%.9]
  445. // CHECK:STDOUT: %.loc13_30.3: ref %C = array_index %a.var, %.loc13_30.2
  446. // CHECK:STDOUT: %.loc13_21.2: init %C = class_init (), %.loc13_30.3 [template = constants.%struct]
  447. // CHECK:STDOUT: %.loc13_30.4: init %C = converted %.loc13_21.1, %.loc13_21.2 [template = constants.%struct]
  448. // CHECK:STDOUT: %.loc13_30.5: i32 = int_literal 1 [template = constants.%.10]
  449. // CHECK:STDOUT: %.loc13_30.6: ref %C = array_index %a.var, %.loc13_30.5
  450. // CHECK:STDOUT: %.loc13_25.2: init %C = class_init (), %.loc13_30.6 [template = constants.%struct]
  451. // CHECK:STDOUT: %.loc13_30.7: init %C = converted %.loc13_25.1, %.loc13_25.2 [template = constants.%struct]
  452. // CHECK:STDOUT: %.loc13_30.8: i32 = int_literal 2 [template = constants.%.11]
  453. // CHECK:STDOUT: %.loc13_30.9: ref %C = array_index %a.var, %.loc13_30.8
  454. // CHECK:STDOUT: %.loc13_29.2: init %C = class_init (), %.loc13_30.9 [template = constants.%struct]
  455. // CHECK:STDOUT: %.loc13_30.10: init %C = converted %.loc13_29.1, %.loc13_29.2 [template = constants.%struct]
  456. // CHECK:STDOUT: %.loc13_30.11: init %.6 = array_init (%.loc13_30.4, %.loc13_30.7, %.loc13_30.10) to %a.var [template = constants.%array]
  457. // CHECK:STDOUT: %.loc13_31: init %.6 = converted %.loc13_30.1, %.loc13_30.11 [template = constants.%array]
  458. // CHECK:STDOUT: assign %a.var, %.loc13_31
  459. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  460. // CHECK:STDOUT: %a.ref: ref %.6 = name_ref a, %a
  461. // CHECK:STDOUT: return <error> to %return
  462. // CHECK:STDOUT: }
  463. // CHECK:STDOUT:
  464. // CHECK:STDOUT: specific @F(constants.%T, constants.%N) {
  465. // CHECK:STDOUT: %T.loc10_6.2 => constants.%T
  466. // CHECK:STDOUT: %N.loc10_16.2 => constants.%N
  467. // CHECK:STDOUT: }
  468. // CHECK:STDOUT:
  469. // CHECK:STDOUT: --- fail_bound_mismatch.carbon
  470. // CHECK:STDOUT:
  471. // CHECK:STDOUT: constants {
  472. // CHECK:STDOUT: %C: type = class_type @C [template]
  473. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  474. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  475. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  476. // CHECK:STDOUT: %.3: i32 = int_literal 2 [template]
  477. // CHECK:STDOUT: %.4: type = array_type %.3, %T [symbolic]
  478. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  479. // CHECK:STDOUT: %.5: type = tuple_type () [template]
  480. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  481. // CHECK:STDOUT: %.6: type = ptr_type %.4 [symbolic]
  482. // CHECK:STDOUT: %.7: i32 = int_literal 0 [template]
  483. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  484. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  485. // CHECK:STDOUT: %.8: type = ptr_type %.1 [template]
  486. // CHECK:STDOUT: %.9: i32 = int_literal 3 [template]
  487. // CHECK:STDOUT: %.10: type = array_type %.9, %C [template]
  488. // CHECK:STDOUT: %.11: type = ptr_type %.10 [template]
  489. // CHECK:STDOUT: %.12: type = tuple_type (%.1, %.1, %.1) [template]
  490. // CHECK:STDOUT: %struct: %C = struct_value () [template]
  491. // CHECK:STDOUT: %.13: i32 = int_literal 1 [template]
  492. // CHECK:STDOUT: %array: %.10 = tuple_value (%struct, %struct, %struct) [template]
  493. // CHECK:STDOUT: %.14: type = array_type %.3, %C [template]
  494. // CHECK:STDOUT: %.15: type = ptr_type %.14 [template]
  495. // CHECK:STDOUT: %ImplicitAs.type.1: type = generic_interface_type @ImplicitAs [template]
  496. // CHECK:STDOUT: %ImplicitAs: %ImplicitAs.type.1 = struct_value () [template]
  497. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest, 0 [symbolic]
  498. // CHECK:STDOUT: %ImplicitAs.type.2: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic]
  499. // CHECK:STDOUT: %Self.1: @ImplicitAs.%ImplicitAs.type (%ImplicitAs.type.2) = bind_symbolic_name Self, 1 [symbolic]
  500. // CHECK:STDOUT: %Self.2: %ImplicitAs.type.2 = bind_symbolic_name Self, 1 [symbolic]
  501. // CHECK:STDOUT: %Convert.type.1: type = fn_type @Convert, @ImplicitAs(%Dest) [symbolic]
  502. // CHECK:STDOUT: %Convert.1: %Convert.type.1 = struct_value () [symbolic]
  503. // CHECK:STDOUT: %.16: type = assoc_entity_type %ImplicitAs.type.2, %Convert.type.1 [symbolic]
  504. // CHECK:STDOUT: %.17: %.16 = assoc_entity element0, imports.%import_ref.5 [symbolic]
  505. // CHECK:STDOUT: %ImplicitAs.type.3: type = interface_type @ImplicitAs, @ImplicitAs(%.14) [template]
  506. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert, @ImplicitAs(%.14) [template]
  507. // CHECK:STDOUT: %Convert.2: %Convert.type.2 = struct_value () [template]
  508. // CHECK:STDOUT: %.18: type = assoc_entity_type %ImplicitAs.type.3, %Convert.type.2 [template]
  509. // CHECK:STDOUT: %.19: %.18 = assoc_entity element0, imports.%import_ref.5 [template]
  510. // CHECK:STDOUT: %.20: %.16 = assoc_entity element0, imports.%import_ref.6 [symbolic]
  511. // CHECK:STDOUT: }
  512. // CHECK:STDOUT:
  513. // CHECK:STDOUT: imports {
  514. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  515. // CHECK:STDOUT: .ImplicitAs = %import_ref.1
  516. // CHECK:STDOUT: import Core//prelude
  517. // CHECK:STDOUT: import Core//prelude/operators
  518. // CHECK:STDOUT: import Core//prelude/types
  519. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  520. // CHECK:STDOUT: import Core//prelude/operators/as
  521. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  522. // CHECK:STDOUT: import Core//prelude/operators/comparison
  523. // CHECK:STDOUT: import Core//prelude/types/bool
  524. // CHECK:STDOUT: }
  525. // CHECK:STDOUT: %import_ref.1: %ImplicitAs.type.1 = import_ref Core//prelude/operators/as, inst+40, loaded [template = constants.%ImplicitAs]
  526. // CHECK:STDOUT: %import_ref.2 = import_ref Core//prelude/operators/as, inst+45, unloaded
  527. // CHECK:STDOUT: %import_ref.3: @ImplicitAs.%.1 (%.16) = import_ref Core//prelude/operators/as, inst+63, loaded [symbolic = @ImplicitAs.%.2 (constants.%.20)]
  528. // CHECK:STDOUT: %import_ref.4 = import_ref Core//prelude/operators/as, inst+56, unloaded
  529. // CHECK:STDOUT: %import_ref.5 = import_ref Core//prelude/operators/as, inst+56, unloaded
  530. // CHECK:STDOUT: %import_ref.6 = import_ref Core//prelude/operators/as, inst+56, unloaded
  531. // CHECK:STDOUT: }
  532. // CHECK:STDOUT:
  533. // CHECK:STDOUT: file {
  534. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  535. // CHECK:STDOUT: .Core = imports.%Core
  536. // CHECK:STDOUT: .C = %C.decl
  537. // CHECK:STDOUT: .F = %F.decl
  538. // CHECK:STDOUT: .G = %G.decl
  539. // CHECK:STDOUT: }
  540. // CHECK:STDOUT: %Core.import = import Core
  541. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  542. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  543. // CHECK:STDOUT: %T.patt: type = symbolic_binding_pattern T, 0
  544. // CHECK:STDOUT: %a.patt: @F.%.loc6_24.2 (%.4) = binding_pattern a
  545. // CHECK:STDOUT: } {
  546. // CHECK:STDOUT: %T.param: type = param T, runtime_param<invalid>
  547. // CHECK:STDOUT: %T.loc6_6.1: type = bind_symbolic_name T, 0, %T.param [symbolic = %T.loc6_6.2 (constants.%T)]
  548. // CHECK:STDOUT: %T.ref.loc6_20: type = name_ref T, %T.loc6_6.1 [symbolic = %T.loc6_6.2 (constants.%T)]
  549. // CHECK:STDOUT: %.loc6_23: i32 = int_literal 2 [template = constants.%.3]
  550. // CHECK:STDOUT: %.loc6_24.1: type = array_type %.loc6_23, %T [symbolic = %.loc6_24.2 (constants.%.4)]
  551. // CHECK:STDOUT: %a.param: @F.%.loc6_24.2 (%.4) = param a, runtime_param0
  552. // CHECK:STDOUT: %a: @F.%.loc6_24.2 (%.4) = bind_name a, %a.param
  553. // CHECK:STDOUT: %T.ref.loc6_30: type = name_ref T, %T.loc6_6.1 [symbolic = %T.loc6_6.2 (constants.%T)]
  554. // CHECK:STDOUT: %return: ref @F.%T.loc6_6.2 (%T) = var <return slot>
  555. // CHECK:STDOUT: }
  556. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {} {
  557. // CHECK:STDOUT: %C.ref.loc8: type = name_ref C, file.%C.decl [template = constants.%C]
  558. // CHECK:STDOUT: %return: ref %C = var <return slot>
  559. // CHECK:STDOUT: }
  560. // CHECK:STDOUT: }
  561. // CHECK:STDOUT:
  562. // CHECK:STDOUT: generic interface @ImplicitAs(constants.%Dest: type) {
  563. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest, 0 [symbolic = %Dest (constants.%Dest)]
  564. // CHECK:STDOUT:
  565. // CHECK:STDOUT: !definition:
  566. // CHECK:STDOUT: %ImplicitAs.type: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic = %ImplicitAs.type (constants.%ImplicitAs.type.2)]
  567. // CHECK:STDOUT: %Self: %ImplicitAs.type.2 = bind_symbolic_name Self, 1 [symbolic = %Self (constants.%Self.2)]
  568. // CHECK:STDOUT: %Convert.type: type = fn_type @Convert, @ImplicitAs(%Dest) [symbolic = %Convert.type (constants.%Convert.type.1)]
  569. // CHECK:STDOUT: %Convert: @ImplicitAs.%Convert.type (%Convert.type.1) = struct_value () [symbolic = %Convert (constants.%Convert.1)]
  570. // CHECK:STDOUT: %.1: type = assoc_entity_type @ImplicitAs.%ImplicitAs.type (%ImplicitAs.type.2), @ImplicitAs.%Convert.type (%Convert.type.1) [symbolic = %.1 (constants.%.16)]
  571. // CHECK:STDOUT: %.2: @ImplicitAs.%.1 (%.16) = assoc_entity element0, imports.%import_ref.5 [symbolic = %.2 (constants.%.17)]
  572. // CHECK:STDOUT:
  573. // CHECK:STDOUT: interface {
  574. // CHECK:STDOUT: !members:
  575. // CHECK:STDOUT: .Self = imports.%import_ref.2
  576. // CHECK:STDOUT: .Convert = imports.%import_ref.3
  577. // CHECK:STDOUT: witness = (imports.%import_ref.4)
  578. // CHECK:STDOUT: }
  579. // CHECK:STDOUT: }
  580. // CHECK:STDOUT:
  581. // CHECK:STDOUT: class @C {
  582. // CHECK:STDOUT: %.loc4: <witness> = complete_type_witness %.1 [template = constants.%.2]
  583. // CHECK:STDOUT:
  584. // CHECK:STDOUT: !members:
  585. // CHECK:STDOUT: .Self = constants.%C
  586. // CHECK:STDOUT: }
  587. // CHECK:STDOUT:
  588. // CHECK:STDOUT: generic fn @F(%T.loc6_6.1: type) {
  589. // CHECK:STDOUT: %T.loc6_6.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc6_6.2 (constants.%T)]
  590. // CHECK:STDOUT: %.loc6_24.2: type = array_type constants.%.3, @F.%T.loc6_6.2 (%T) [symbolic = %.loc6_24.2 (constants.%.4)]
  591. // CHECK:STDOUT:
  592. // CHECK:STDOUT: !definition:
  593. // CHECK:STDOUT:
  594. // CHECK:STDOUT: fn[%T.loc6_6.1: type](%a: @F.%.loc6_24.2 (%.4)) -> @F.%T.loc6_6.2 (%T) {
  595. // CHECK:STDOUT: !entry:
  596. // CHECK:STDOUT: %a.ref: @F.%.loc6_24.2 (%.4) = name_ref a, %a
  597. // CHECK:STDOUT: %.loc6_43: i32 = int_literal 0 [template = constants.%.7]
  598. // CHECK:STDOUT: %.loc6_44.1: ref @F.%.loc6_24.2 (%.4) = value_as_ref %a.ref
  599. // CHECK:STDOUT: %.loc6_44.2: ref @F.%T.loc6_6.2 (%T) = array_index %.loc6_44.1, %.loc6_43
  600. // CHECK:STDOUT: %.loc6_44.3: @F.%T.loc6_6.2 (%T) = bind_value %.loc6_44.2
  601. // CHECK:STDOUT: return %.loc6_44.3
  602. // CHECK:STDOUT: }
  603. // CHECK:STDOUT: }
  604. // CHECK:STDOUT:
  605. // CHECK:STDOUT: fn @G() -> %return: %C {
  606. // CHECK:STDOUT: !entry:
  607. // CHECK:STDOUT: %C.ref.loc10: type = name_ref C, file.%C.decl [template = constants.%C]
  608. // CHECK:STDOUT: %.loc10_14: i32 = int_literal 3 [template = constants.%.9]
  609. // CHECK:STDOUT: %.loc10_15: type = array_type %.loc10_14, %C [template = constants.%.10]
  610. // CHECK:STDOUT: %a.var: ref %.10 = var a
  611. // CHECK:STDOUT: %a: ref %.10 = bind_name a, %a.var
  612. // CHECK:STDOUT: %.loc10_21.1: %.1 = struct_literal ()
  613. // CHECK:STDOUT: %.loc10_25.1: %.1 = struct_literal ()
  614. // CHECK:STDOUT: %.loc10_29.1: %.1 = struct_literal ()
  615. // CHECK:STDOUT: %.loc10_30.1: %.12 = tuple_literal (%.loc10_21.1, %.loc10_25.1, %.loc10_29.1)
  616. // CHECK:STDOUT: %.loc10_30.2: i32 = int_literal 0 [template = constants.%.7]
  617. // CHECK:STDOUT: %.loc10_30.3: ref %C = array_index %a.var, %.loc10_30.2
  618. // CHECK:STDOUT: %.loc10_21.2: init %C = class_init (), %.loc10_30.3 [template = constants.%struct]
  619. // CHECK:STDOUT: %.loc10_30.4: init %C = converted %.loc10_21.1, %.loc10_21.2 [template = constants.%struct]
  620. // CHECK:STDOUT: %.loc10_30.5: i32 = int_literal 1 [template = constants.%.13]
  621. // CHECK:STDOUT: %.loc10_30.6: ref %C = array_index %a.var, %.loc10_30.5
  622. // CHECK:STDOUT: %.loc10_25.2: init %C = class_init (), %.loc10_30.6 [template = constants.%struct]
  623. // CHECK:STDOUT: %.loc10_30.7: init %C = converted %.loc10_25.1, %.loc10_25.2 [template = constants.%struct]
  624. // CHECK:STDOUT: %.loc10_30.8: i32 = int_literal 2 [template = constants.%.3]
  625. // CHECK:STDOUT: %.loc10_30.9: ref %C = array_index %a.var, %.loc10_30.8
  626. // CHECK:STDOUT: %.loc10_29.2: init %C = class_init (), %.loc10_30.9 [template = constants.%struct]
  627. // CHECK:STDOUT: %.loc10_30.10: init %C = converted %.loc10_29.1, %.loc10_29.2 [template = constants.%struct]
  628. // CHECK:STDOUT: %.loc10_30.11: init %.10 = array_init (%.loc10_30.4, %.loc10_30.7, %.loc10_30.10) to %a.var [template = constants.%array]
  629. // CHECK:STDOUT: %.loc10_31: init %.10 = converted %.loc10_30.1, %.loc10_30.11 [template = constants.%array]
  630. // CHECK:STDOUT: assign %a.var, %.loc10_31
  631. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  632. // CHECK:STDOUT: %a.ref: ref %.10 = name_ref a, %a
  633. // CHECK:STDOUT: %.loc21_11.1: ref %C = temporary_storage
  634. // CHECK:STDOUT: %ImplicitAs.type: type = interface_type @ImplicitAs, @ImplicitAs(constants.%.14) [template = constants.%ImplicitAs.type.3]
  635. // CHECK:STDOUT: %.loc21_11.2: %.18 = specific_constant imports.%import_ref.3, @ImplicitAs(constants.%.14) [template = constants.%.19]
  636. // CHECK:STDOUT: %Convert.ref: %.18 = name_ref Convert, %.loc21_11.2 [template = constants.%.19]
  637. // CHECK:STDOUT: %.loc21_11.3: %.14 = converted %a.ref, <error> [template = <error>]
  638. // CHECK:STDOUT: %F.call: init %C = call %F.ref(<invalid>) [template = <error>]
  639. // CHECK:STDOUT: return %F.call to %return
  640. // CHECK:STDOUT: }
  641. // CHECK:STDOUT:
  642. // CHECK:STDOUT: generic fn @Convert(constants.%Dest: type, constants.%Self.1: @ImplicitAs.%ImplicitAs.type (%ImplicitAs.type.2)) {
  643. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest, 0 [symbolic = %Dest (constants.%Dest)]
  644. // CHECK:STDOUT: %ImplicitAs.type: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic = %ImplicitAs.type (constants.%ImplicitAs.type.2)]
  645. // CHECK:STDOUT: %Self: %ImplicitAs.type.2 = bind_symbolic_name Self, 1 [symbolic = %Self (constants.%Self.2)]
  646. // CHECK:STDOUT:
  647. // CHECK:STDOUT: fn[%self: @Convert.%Self (%Self.2)]() -> @Convert.%Dest (%Dest);
  648. // CHECK:STDOUT: }
  649. // CHECK:STDOUT:
  650. // CHECK:STDOUT: specific @F(constants.%T) {
  651. // CHECK:STDOUT: %T.loc6_6.2 => constants.%T
  652. // CHECK:STDOUT: %.loc6_24.2 => constants.%.4
  653. // CHECK:STDOUT: }
  654. // CHECK:STDOUT:
  655. // CHECK:STDOUT: specific @F(constants.%C) {
  656. // CHECK:STDOUT: %T.loc6_6.2 => constants.%C
  657. // CHECK:STDOUT: %.loc6_24.2 => constants.%.14
  658. // CHECK:STDOUT: }
  659. // CHECK:STDOUT:
  660. // CHECK:STDOUT: specific @ImplicitAs(constants.%Dest) {
  661. // CHECK:STDOUT: %Dest => constants.%Dest
  662. // CHECK:STDOUT: }
  663. // CHECK:STDOUT:
  664. // CHECK:STDOUT: specific @ImplicitAs(@ImplicitAs.%Dest) {
  665. // CHECK:STDOUT: %Dest => constants.%Dest
  666. // CHECK:STDOUT: }
  667. // CHECK:STDOUT:
  668. // CHECK:STDOUT: specific @ImplicitAs(@Convert.%Dest) {
  669. // CHECK:STDOUT: %Dest => constants.%Dest
  670. // CHECK:STDOUT: }
  671. // CHECK:STDOUT:
  672. // CHECK:STDOUT: specific @Convert(constants.%Dest, constants.%Self.1) {
  673. // CHECK:STDOUT: %Dest => constants.%Dest
  674. // CHECK:STDOUT: %ImplicitAs.type => constants.%ImplicitAs.type.2
  675. // CHECK:STDOUT: %Self => constants.%Self.1
  676. // CHECK:STDOUT: }
  677. // CHECK:STDOUT:
  678. // CHECK:STDOUT: specific @ImplicitAs(constants.%.14) {
  679. // CHECK:STDOUT: %Dest => constants.%.14
  680. // CHECK:STDOUT:
  681. // CHECK:STDOUT: !definition:
  682. // CHECK:STDOUT: %ImplicitAs.type => constants.%ImplicitAs.type.3
  683. // CHECK:STDOUT: %Self => constants.%Self.2
  684. // CHECK:STDOUT: %Convert.type => constants.%Convert.type.2
  685. // CHECK:STDOUT: %Convert => constants.%Convert.2
  686. // CHECK:STDOUT: %.1 => constants.%.18
  687. // CHECK:STDOUT: %.2 => constants.%.19
  688. // CHECK:STDOUT: }
  689. // CHECK:STDOUT:
  690. // CHECK:STDOUT: --- fail_type_mismatch.carbon
  691. // CHECK:STDOUT:
  692. // CHECK:STDOUT: constants {
  693. // CHECK:STDOUT: %C: type = class_type @C [template]
  694. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  695. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  696. // CHECK:STDOUT: %D: type = class_type @D [template]
  697. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  698. // CHECK:STDOUT: %.3: type = tuple_type () [template]
  699. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  700. // CHECK:STDOUT: %N: i32 = bind_symbolic_name N, 0 [symbolic]
  701. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  702. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  703. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  704. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  705. // CHECK:STDOUT: %.4: type = ptr_type %.1 [template]
  706. // CHECK:STDOUT: %.5: i32 = int_literal 3 [template]
  707. // CHECK:STDOUT: %.6: type = array_type %.5, %D [template]
  708. // CHECK:STDOUT: %.7: type = ptr_type %.6 [template]
  709. // CHECK:STDOUT: %.8: type = tuple_type (%.1, %.1, %.1) [template]
  710. // CHECK:STDOUT: %.9: i32 = int_literal 0 [template]
  711. // CHECK:STDOUT: %struct: %D = struct_value () [template]
  712. // CHECK:STDOUT: %.10: i32 = int_literal 1 [template]
  713. // CHECK:STDOUT: %.11: i32 = int_literal 2 [template]
  714. // CHECK:STDOUT: %array: %.6 = tuple_value (%struct, %struct, %struct) [template]
  715. // CHECK:STDOUT: }
  716. // CHECK:STDOUT:
  717. // CHECK:STDOUT: imports {
  718. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  719. // CHECK:STDOUT: .Int32 = %import_ref
  720. // CHECK:STDOUT: import Core//prelude
  721. // CHECK:STDOUT: import Core//prelude/operators
  722. // CHECK:STDOUT: import Core//prelude/types
  723. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  724. // CHECK:STDOUT: import Core//prelude/operators/as
  725. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  726. // CHECK:STDOUT: import Core//prelude/operators/comparison
  727. // CHECK:STDOUT: import Core//prelude/types/bool
  728. // CHECK:STDOUT: }
  729. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  730. // CHECK:STDOUT: }
  731. // CHECK:STDOUT:
  732. // CHECK:STDOUT: file {
  733. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  734. // CHECK:STDOUT: .Core = imports.%Core
  735. // CHECK:STDOUT: .C = %C.decl
  736. // CHECK:STDOUT: .D = %D.decl
  737. // CHECK:STDOUT: .F = %F.decl
  738. // CHECK:STDOUT: .G = %G.decl
  739. // CHECK:STDOUT: }
  740. // CHECK:STDOUT: %Core.import = import Core
  741. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  742. // CHECK:STDOUT: %D.decl: type = class_decl @D [template = constants.%D] {} {}
  743. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  744. // CHECK:STDOUT: %N.patt: i32 = symbolic_binding_pattern N, 0
  745. // CHECK:STDOUT: %a.patt: <error> = binding_pattern a
  746. // CHECK:STDOUT: } {
  747. // CHECK:STDOUT: %int.make_type_32.loc10_10: init type = call constants.%Int32() [template = i32]
  748. // CHECK:STDOUT: %.loc10_10.1: type = value_of_initializer %int.make_type_32.loc10_10 [template = i32]
  749. // CHECK:STDOUT: %.loc10_10.2: type = converted %int.make_type_32.loc10_10, %.loc10_10.1 [template = i32]
  750. // CHECK:STDOUT: %N.param: i32 = param N, runtime_param<invalid>
  751. // CHECK:STDOUT: %N.loc10_6.1: i32 = bind_symbolic_name N, 0, %N.param [symbolic = %N.loc10_6.2 (constants.%N)]
  752. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  753. // CHECK:STDOUT: %N.ref.loc10_22: i32 = name_ref N, %N.loc10_6.1 [symbolic = %N.loc10_6.2 (constants.%N)]
  754. // CHECK:STDOUT: %.loc10_23: type = array_type %N.ref.loc10_22, %C [template = <error>]
  755. // CHECK:STDOUT: %a.param: <error> = param a, runtime_param0
  756. // CHECK:STDOUT: %a: <error> = bind_name a, %a.param
  757. // CHECK:STDOUT: %int.make_type_32.loc10_29: init type = call constants.%Int32() [template = i32]
  758. // CHECK:STDOUT: %.loc10_29.1: type = value_of_initializer %int.make_type_32.loc10_29 [template = i32]
  759. // CHECK:STDOUT: %.loc10_29.2: type = converted %int.make_type_32.loc10_29, %.loc10_29.1 [template = i32]
  760. // CHECK:STDOUT: %return: ref i32 = var <return slot>
  761. // CHECK:STDOUT: }
  762. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {} {
  763. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  764. // CHECK:STDOUT: %return: ref %C = var <return slot>
  765. // CHECK:STDOUT: }
  766. // CHECK:STDOUT: }
  767. // CHECK:STDOUT:
  768. // CHECK:STDOUT: class @C {
  769. // CHECK:STDOUT: %.loc4: <witness> = complete_type_witness %.1 [template = constants.%.2]
  770. // CHECK:STDOUT:
  771. // CHECK:STDOUT: !members:
  772. // CHECK:STDOUT: .Self = constants.%C
  773. // CHECK:STDOUT: }
  774. // CHECK:STDOUT:
  775. // CHECK:STDOUT: class @D {
  776. // CHECK:STDOUT: %.loc5: <witness> = complete_type_witness %.1 [template = constants.%.2]
  777. // CHECK:STDOUT:
  778. // CHECK:STDOUT: !members:
  779. // CHECK:STDOUT: .Self = constants.%D
  780. // CHECK:STDOUT: }
  781. // CHECK:STDOUT:
  782. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  783. // CHECK:STDOUT:
  784. // CHECK:STDOUT: generic fn @F(%N.loc10_6.1: i32) {
  785. // CHECK:STDOUT: %N.loc10_6.2: i32 = bind_symbolic_name N, 0 [symbolic = %N.loc10_6.2 (constants.%N)]
  786. // CHECK:STDOUT:
  787. // CHECK:STDOUT: !definition:
  788. // CHECK:STDOUT:
  789. // CHECK:STDOUT: fn[%N.loc10_6.1: i32](%a: <error>) -> i32 {
  790. // CHECK:STDOUT: !entry:
  791. // CHECK:STDOUT: %N.ref.loc10_42: i32 = name_ref N, %N.loc10_6.1 [symbolic = %N.loc10_6.2 (constants.%N)]
  792. // CHECK:STDOUT: return %N.ref.loc10_42
  793. // CHECK:STDOUT: }
  794. // CHECK:STDOUT: }
  795. // CHECK:STDOUT:
  796. // CHECK:STDOUT: fn @G() -> %return: %C {
  797. // CHECK:STDOUT: !entry:
  798. // CHECK:STDOUT: %D.ref: type = name_ref D, file.%D.decl [template = constants.%D]
  799. // CHECK:STDOUT: %.loc13_14: i32 = int_literal 3 [template = constants.%.5]
  800. // CHECK:STDOUT: %.loc13_15: type = array_type %.loc13_14, %D [template = constants.%.6]
  801. // CHECK:STDOUT: %a.var: ref %.6 = var a
  802. // CHECK:STDOUT: %a: ref %.6 = bind_name a, %a.var
  803. // CHECK:STDOUT: %.loc13_21.1: %.1 = struct_literal ()
  804. // CHECK:STDOUT: %.loc13_25.1: %.1 = struct_literal ()
  805. // CHECK:STDOUT: %.loc13_29.1: %.1 = struct_literal ()
  806. // CHECK:STDOUT: %.loc13_30.1: %.8 = tuple_literal (%.loc13_21.1, %.loc13_25.1, %.loc13_29.1)
  807. // CHECK:STDOUT: %.loc13_30.2: i32 = int_literal 0 [template = constants.%.9]
  808. // CHECK:STDOUT: %.loc13_30.3: ref %D = array_index %a.var, %.loc13_30.2
  809. // CHECK:STDOUT: %.loc13_21.2: init %D = class_init (), %.loc13_30.3 [template = constants.%struct]
  810. // CHECK:STDOUT: %.loc13_30.4: init %D = converted %.loc13_21.1, %.loc13_21.2 [template = constants.%struct]
  811. // CHECK:STDOUT: %.loc13_30.5: i32 = int_literal 1 [template = constants.%.10]
  812. // CHECK:STDOUT: %.loc13_30.6: ref %D = array_index %a.var, %.loc13_30.5
  813. // CHECK:STDOUT: %.loc13_25.2: init %D = class_init (), %.loc13_30.6 [template = constants.%struct]
  814. // CHECK:STDOUT: %.loc13_30.7: init %D = converted %.loc13_25.1, %.loc13_25.2 [template = constants.%struct]
  815. // CHECK:STDOUT: %.loc13_30.8: i32 = int_literal 2 [template = constants.%.11]
  816. // CHECK:STDOUT: %.loc13_30.9: ref %D = array_index %a.var, %.loc13_30.8
  817. // CHECK:STDOUT: %.loc13_29.2: init %D = class_init (), %.loc13_30.9 [template = constants.%struct]
  818. // CHECK:STDOUT: %.loc13_30.10: init %D = converted %.loc13_29.1, %.loc13_29.2 [template = constants.%struct]
  819. // CHECK:STDOUT: %.loc13_30.11: init %.6 = array_init (%.loc13_30.4, %.loc13_30.7, %.loc13_30.10) to %a.var [template = constants.%array]
  820. // CHECK:STDOUT: %.loc13_31: init %.6 = converted %.loc13_30.1, %.loc13_30.11 [template = constants.%array]
  821. // CHECK:STDOUT: assign %a.var, %.loc13_31
  822. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  823. // CHECK:STDOUT: %a.ref: ref %.6 = name_ref a, %a
  824. // CHECK:STDOUT: return <error> to %return
  825. // CHECK:STDOUT: }
  826. // CHECK:STDOUT:
  827. // CHECK:STDOUT: specific @F(constants.%N) {
  828. // CHECK:STDOUT: %N.loc10_6.2 => constants.%N
  829. // CHECK:STDOUT: }
  830. // CHECK:STDOUT: