element_access.carbon 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/int.carbon
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/tuple/element_access.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/tuple/element_access.carbon
  12. // --- basics.carbon
  13. library "[[@TEST_NAME]]";
  14. var a: (i32,) = (42,);
  15. var b: (i32,) = a;
  16. //@dump-sem-ir-begin
  17. var c: i32 = b.0;
  18. //@dump-sem-ir-end
  19. // --- index_not_literal.carbon
  20. library "[[@TEST_NAME]]";
  21. var a: ((), i32) = ((), 34);
  22. //@dump-sem-ir-begin
  23. var b: i32 = a.({.index = 1}.index);
  24. var c: () = a.(0 as i32);
  25. var d: i32 = a.({.index = 1 as i32}.index);
  26. //@dump-sem-ir-end
  27. // --- return_value_access.carbon
  28. library "[[@TEST_NAME]]";
  29. fn F() -> (i32,) { return (0,); }
  30. fn Run() -> i32 {
  31. //@dump-sem-ir-begin
  32. return F().0;
  33. //@dump-sem-ir-end
  34. }
  35. // --- fail_access_error.carbon
  36. library "[[@TEST_NAME]]";
  37. var a: (i32, i32) = (12, 6);
  38. // CHECK:STDERR: fail_access_error.carbon:[[@LINE+4]]:17: error: name `oops` not found [NameNotFound]
  39. // CHECK:STDERR: var b: i32 = a.(oops);
  40. // CHECK:STDERR: ^~~~
  41. // CHECK:STDERR:
  42. var b: i32 = a.(oops);
  43. // --- fail_empty_access.carbon
  44. library "[[@TEST_NAME]]";
  45. fn F() {}
  46. fn Run() {
  47. // CHECK:STDERR: fail_empty_access.carbon:[[@LINE+4]]:3: error: tuple element index `0` is past the end of type `()` [TupleIndexOutOfBounds]
  48. // CHECK:STDERR: F().0;
  49. // CHECK:STDERR: ^~~~~
  50. // CHECK:STDERR:
  51. F().0;
  52. }
  53. // --- fail_large_index.carbon
  54. library "[[@TEST_NAME]]";
  55. var a: (i32,) = (12,);
  56. var b: (i32,) = a;
  57. // CHECK:STDERR: fail_large_index.carbon:[[@LINE+4]]:14: error: tuple element index `1` is past the end of type `(i32,)` [TupleIndexOutOfBounds]
  58. // CHECK:STDERR: var c: i32 = b.1;
  59. // CHECK:STDERR: ^~~
  60. // CHECK:STDERR:
  61. var c: i32 = b.1;
  62. // CHECK:STDERR: fail_large_index.carbon:[[@LINE+4]]:14: error: tuple element index `2147483647` is past the end of type `(i32,)` [TupleIndexOutOfBounds]
  63. // CHECK:STDERR: var d: i32 = b.(0x7FFF_FFFF);
  64. // CHECK:STDERR: ^~~~~~~~~~~~~~~
  65. // CHECK:STDERR:
  66. var d: i32 = b.(0x7FFF_FFFF);
  67. // --- fail_negative_indexing.carbon
  68. library "[[@TEST_NAME]]";
  69. var a: (i32, i32) = (12, 6);
  70. // CHECK:STDERR: fail_negative_indexing.carbon:[[@LINE+4]]:14: error: tuple element index `-10` is past the end of type `(i32, i32)` [TupleIndexOutOfBounds]
  71. // CHECK:STDERR: var b: i32 = a.(-10);
  72. // CHECK:STDERR: ^~~~~~~
  73. // CHECK:STDERR:
  74. var b: i32 = a.(-10);
  75. // --- fail_non_deterministic_type.carbon
  76. library "[[@TEST_NAME]]";
  77. var a: (i32, i32) = (2, 3);
  78. var b: i32 = 0;
  79. // CHECK:STDERR: fail_non_deterministic_type.carbon:[[@LINE+11]]:17: error: non-constant call to compile-time-only function [NonConstantCallToCompTimeOnlyFunction]
  80. // CHECK:STDERR: var c: i32 = a.(b);
  81. // CHECK:STDERR: ^
  82. // CHECK:STDERR: min_prelude/parts/int.carbon:27:3: note: compile-time-only function declared here [CompTimeOnlyFunctionHere]
  83. // CHECK:STDERR: fn Convert[self: Self]() -> IntLiteral() = "int.convert_checked";
  84. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  85. // CHECK:STDERR:
  86. // CHECK:STDERR: fail_non_deterministic_type.carbon:[[@LINE+4]]:14: error: tuple index must be a constant [TupleIndexNotConstant]
  87. // CHECK:STDERR: var c: i32 = a.(b);
  88. // CHECK:STDERR: ^~~~~
  89. // CHECK:STDERR:
  90. var c: i32 = a.(b);
  91. // --- fail_non_int_indexing.carbon
  92. library "[[@TEST_NAME]]";
  93. var a: (i32, i32) = (12, 6);
  94. // CHECK:STDERR: fail_non_int_indexing.carbon:[[@LINE+7]]:17: error: cannot implicitly convert expression of type `Core.FloatLiteral` to `Core.IntLiteral` [ConversionFailure]
  95. // CHECK:STDERR: var b: i32 = a.(2.6);
  96. // CHECK:STDERR: ^~~
  97. // CHECK:STDERR: fail_non_int_indexing.carbon:[[@LINE+4]]:17: note: type `Core.FloatLiteral` does not implement interface `Core.ImplicitAs(Core.IntLiteral)` [MissingImplInMemberAccessNote]
  98. // CHECK:STDERR: var b: i32 = a.(2.6);
  99. // CHECK:STDERR: ^~~
  100. // CHECK:STDERR:
  101. var b: i32 = a.(2.6);
  102. // --- fail_non_tuple_access.carbon
  103. library "[[@TEST_NAME]]";
  104. fn Main() {
  105. var non_tuple: array(i32, 2) = (5, 5);
  106. // CHECK:STDERR: fail_non_tuple_access.carbon:[[@LINE+4]]:20: error: type `array(i32, 2)` does not support tuple indexing; only tuples can be indexed that way [TupleIndexOnANonTupleType]
  107. // CHECK:STDERR: var first: i32 = non_tuple.0;
  108. // CHECK:STDERR: ^~~~~~~~~~~
  109. // CHECK:STDERR:
  110. var first: i32 = non_tuple.0;
  111. }
  112. // --- fail_out_of_bound_access.carbon
  113. library "[[@TEST_NAME]]";
  114. var a: (i32, i32) = (12, 6);
  115. // CHECK:STDERR: fail_out_of_bound_access.carbon:[[@LINE+4]]:14: error: tuple element index `2` is past the end of type `(i32, i32)` [TupleIndexOutOfBounds]
  116. // CHECK:STDERR: var b: i32 = a.2;
  117. // CHECK:STDERR: ^~~
  118. // CHECK:STDERR:
  119. var b: i32 = a.2;
  120. // --- fail_out_of_bound_not_literal.carbon
  121. library "[[@TEST_NAME]]";
  122. var a: (i32, i32) = (12, 34);
  123. // CHECK:STDERR: fail_out_of_bound_not_literal.carbon:[[@LINE+4]]:14: error: tuple element index `2` is past the end of type `(i32, i32)` [TupleIndexOutOfBounds]
  124. // CHECK:STDERR: var b: i32 = a.({.index = 2}.index);
  125. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~
  126. // CHECK:STDERR:
  127. var b: i32 = a.({.index = 2}.index);
  128. // CHECK:STDOUT: --- basics.carbon
  129. // CHECK:STDOUT:
  130. // CHECK:STDOUT: constants {
  131. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  132. // CHECK:STDOUT: %N: Core.IntLiteral = bind_symbolic_name N, 0 [symbolic]
  133. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  134. // CHECK:STDOUT: %tuple.type.a1c: type = tuple_type (%i32) [concrete]
  135. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  136. // CHECK:STDOUT: %tuple.elem0.4d5: ref %i32 = tuple_access file.%b.var, element0 [concrete]
  137. // CHECK:STDOUT: %Copy.type: type = facet_type <@Copy> [concrete]
  138. // CHECK:STDOUT: %Copy.Op.type: type = fn_type @Copy.Op [concrete]
  139. // CHECK:STDOUT: %Int.as.Copy.impl.Op.type.afd: type = fn_type @Int.as.Copy.impl.Op, @Int.as.Copy.impl(%N) [symbolic]
  140. // CHECK:STDOUT: %Int.as.Copy.impl.Op.6cd: %Int.as.Copy.impl.Op.type.afd = struct_value () [symbolic]
  141. // CHECK:STDOUT: %Copy.impl_witness.a32: <witness> = impl_witness imports.%Copy.impl_witness_table.1ed, @Int.as.Copy.impl(%int_32) [concrete]
  142. // CHECK:STDOUT: %Int.as.Copy.impl.Op.type.276: type = fn_type @Int.as.Copy.impl.Op, @Int.as.Copy.impl(%int_32) [concrete]
  143. // CHECK:STDOUT: %Int.as.Copy.impl.Op.f59: %Int.as.Copy.impl.Op.type.276 = struct_value () [concrete]
  144. // CHECK:STDOUT: %Copy.facet.c49: %Copy.type = facet_value %i32, (%Copy.impl_witness.a32) [concrete]
  145. // CHECK:STDOUT: %.7fa: type = fn_type_with_self_type %Copy.Op.type, %Copy.facet.c49 [concrete]
  146. // CHECK:STDOUT: %Int.as.Copy.impl.Op.specific_fn: <specific function> = specific_function %Int.as.Copy.impl.Op.f59, @Int.as.Copy.impl.Op(%int_32) [concrete]
  147. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [concrete]
  148. // CHECK:STDOUT: }
  149. // CHECK:STDOUT:
  150. // CHECK:STDOUT: imports {
  151. // CHECK:STDOUT: %Core.import_ref.d0f6: @Int.as.Copy.impl.%Int.as.Copy.impl.Op.type (%Int.as.Copy.impl.Op.type.afd) = import_ref Core//prelude/parts/int, loc17_31, loaded [symbolic = @Int.as.Copy.impl.%Int.as.Copy.impl.Op (constants.%Int.as.Copy.impl.Op.6cd)]
  152. // CHECK:STDOUT: %Copy.impl_witness_table.1ed = impl_witness_table (%Core.import_ref.d0f6), @Int.as.Copy.impl [concrete]
  153. // CHECK:STDOUT: }
  154. // CHECK:STDOUT:
  155. // CHECK:STDOUT: file {
  156. // CHECK:STDOUT: name_binding_decl {
  157. // CHECK:STDOUT: %c.patt: %pattern_type.7ce = binding_pattern c [concrete]
  158. // CHECK:STDOUT: %c.var_patt: %pattern_type.7ce = var_pattern %c.patt [concrete]
  159. // CHECK:STDOUT: }
  160. // CHECK:STDOUT: %c.var: ref %i32 = var %c.var_patt [concrete]
  161. // CHECK:STDOUT: %.loc6: type = splice_block %i32.loc6 [concrete = constants.%i32] {
  162. // CHECK:STDOUT: %int_32.loc6: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  163. // CHECK:STDOUT: %i32.loc6: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  164. // CHECK:STDOUT: }
  165. // CHECK:STDOUT: %c: ref %i32 = bind_name c, %c.var [concrete = %c.var]
  166. // CHECK:STDOUT: }
  167. // CHECK:STDOUT:
  168. // CHECK:STDOUT: fn @__global_init() {
  169. // CHECK:STDOUT: !entry:
  170. // CHECK:STDOUT: <elided>
  171. // CHECK:STDOUT: %b.ref: ref %tuple.type.a1c = name_ref b, file.%b [concrete = file.%b.var]
  172. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [concrete = constants.%int_0]
  173. // CHECK:STDOUT: %tuple.elem0.loc6: ref %i32 = tuple_access %b.ref, element0 [concrete = constants.%tuple.elem0.4d5]
  174. // CHECK:STDOUT: %.loc6: %i32 = bind_value %tuple.elem0.loc6
  175. // CHECK:STDOUT: %impl.elem0.loc6: %.7fa = impl_witness_access constants.%Copy.impl_witness.a32, element0 [concrete = constants.%Int.as.Copy.impl.Op.f59]
  176. // CHECK:STDOUT: %bound_method.loc6_15.1: <bound method> = bound_method %.loc6, %impl.elem0.loc6
  177. // CHECK:STDOUT: %specific_fn.loc6: <specific function> = specific_function %impl.elem0.loc6, @Int.as.Copy.impl.Op(constants.%int_32) [concrete = constants.%Int.as.Copy.impl.Op.specific_fn]
  178. // CHECK:STDOUT: %bound_method.loc6_15.2: <bound method> = bound_method %.loc6, %specific_fn.loc6
  179. // CHECK:STDOUT: %Int.as.Copy.impl.Op.call.loc6: init %i32 = call %bound_method.loc6_15.2(%.loc6)
  180. // CHECK:STDOUT: assign file.%c.var, %Int.as.Copy.impl.Op.call.loc6
  181. // CHECK:STDOUT: <elided>
  182. // CHECK:STDOUT: }
  183. // CHECK:STDOUT:
  184. // CHECK:STDOUT: --- index_not_literal.carbon
  185. // CHECK:STDOUT:
  186. // CHECK:STDOUT: constants {
  187. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  188. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  189. // CHECK:STDOUT: %N: Core.IntLiteral = bind_symbolic_name N, 0 [symbolic]
  190. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  191. // CHECK:STDOUT: %tuple.type.0ce: type = tuple_type (%empty_tuple.type, %i32) [concrete]
  192. // CHECK:STDOUT: %tuple.elem0: ref %empty_tuple.type = tuple_access file.%a.var, element0 [concrete]
  193. // CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [concrete]
  194. // CHECK:STDOUT: %tuple.elem1: ref %i32 = tuple_access file.%a.var, element1 [concrete]
  195. // CHECK:STDOUT: %To: Core.IntLiteral = bind_symbolic_name To, 0 [symbolic]
  196. // CHECK:STDOUT: %ImplicitAs.type.7a9: type = facet_type <@ImplicitAs, @ImplicitAs(Core.IntLiteral)> [concrete]
  197. // CHECK:STDOUT: %From: Core.IntLiteral = bind_symbolic_name From, 0 [symbolic]
  198. // CHECK:STDOUT: %Int.as.ImplicitAs.impl.Convert.type.543: type = fn_type @Int.as.ImplicitAs.impl.Convert, @Int.as.ImplicitAs.impl(%From) [symbolic]
  199. // CHECK:STDOUT: %Int.as.ImplicitAs.impl.Convert.c08: %Int.as.ImplicitAs.impl.Convert.type.543 = struct_value () [symbolic]
  200. // CHECK:STDOUT: %ImplicitAs.Convert.type.71e: type = fn_type @ImplicitAs.Convert, @ImplicitAs(Core.IntLiteral) [concrete]
  201. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  202. // CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [concrete]
  203. // CHECK:STDOUT: %struct_type.index.b1b: type = struct_type {.index: Core.IntLiteral} [concrete]
  204. // CHECK:STDOUT: %struct.972: %struct_type.index.b1b = struct_value (%int_1.5b8) [concrete]
  205. // CHECK:STDOUT: %Copy.type: type = facet_type <@Copy> [concrete]
  206. // CHECK:STDOUT: %Copy.Op.type: type = fn_type @Copy.Op [concrete]
  207. // CHECK:STDOUT: %Int.as.Copy.impl.Op.type.afd: type = fn_type @Int.as.Copy.impl.Op, @Int.as.Copy.impl(%N) [symbolic]
  208. // CHECK:STDOUT: %Int.as.Copy.impl.Op.6cd: %Int.as.Copy.impl.Op.type.afd = struct_value () [symbolic]
  209. // CHECK:STDOUT: %Copy.impl_witness.a32: <witness> = impl_witness imports.%Copy.impl_witness_table.1ed, @Int.as.Copy.impl(%int_32) [concrete]
  210. // CHECK:STDOUT: %Int.as.Copy.impl.Op.type.276: type = fn_type @Int.as.Copy.impl.Op, @Int.as.Copy.impl(%int_32) [concrete]
  211. // CHECK:STDOUT: %Int.as.Copy.impl.Op.f59: %Int.as.Copy.impl.Op.type.276 = struct_value () [concrete]
  212. // CHECK:STDOUT: %Copy.facet.c49: %Copy.type = facet_value %i32, (%Copy.impl_witness.a32) [concrete]
  213. // CHECK:STDOUT: %.7fa: type = fn_type_with_self_type %Copy.Op.type, %Copy.facet.c49 [concrete]
  214. // CHECK:STDOUT: %Int.as.Copy.impl.Op.specific_fn: <specific function> = specific_function %Int.as.Copy.impl.Op.f59, @Int.as.Copy.impl.Op(%int_32) [concrete]
  215. // CHECK:STDOUT: %pattern_type.cb1: type = pattern_type %empty_tuple.type [concrete]
  216. // CHECK:STDOUT: %int_0.5c6: Core.IntLiteral = int_value 0 [concrete]
  217. // CHECK:STDOUT: %As.type.dbd: type = facet_type <@As, @As(%i32)> [concrete]
  218. // CHECK:STDOUT: %As.Convert.type.99b: type = fn_type @As.Convert, @As(%i32) [concrete]
  219. // CHECK:STDOUT: %Core.IntLiteral.as.As.impl.Convert.type.565: type = fn_type @Core.IntLiteral.as.As.impl.Convert, @Core.IntLiteral.as.As.impl(%To) [symbolic]
  220. // CHECK:STDOUT: %Core.IntLiteral.as.As.impl.Convert.d2c: %Core.IntLiteral.as.As.impl.Convert.type.565 = struct_value () [symbolic]
  221. // CHECK:STDOUT: %As.impl_witness.080: <witness> = impl_witness imports.%As.impl_witness_table.5ad, @Core.IntLiteral.as.As.impl(%int_32) [concrete]
  222. // CHECK:STDOUT: %Core.IntLiteral.as.As.impl.Convert.type.aaf: type = fn_type @Core.IntLiteral.as.As.impl.Convert, @Core.IntLiteral.as.As.impl(%int_32) [concrete]
  223. // CHECK:STDOUT: %Core.IntLiteral.as.As.impl.Convert.414: %Core.IntLiteral.as.As.impl.Convert.type.aaf = struct_value () [concrete]
  224. // CHECK:STDOUT: %As.facet: %As.type.dbd = facet_value Core.IntLiteral, (%As.impl_witness.080) [concrete]
  225. // CHECK:STDOUT: %.351: type = fn_type_with_self_type %As.Convert.type.99b, %As.facet [concrete]
  226. // CHECK:STDOUT: %Core.IntLiteral.as.As.impl.Convert.bound.533: <bound method> = bound_method %int_0.5c6, %Core.IntLiteral.as.As.impl.Convert.414 [concrete]
  227. // CHECK:STDOUT: %Core.IntLiteral.as.As.impl.Convert.specific_fn: <specific function> = specific_function %Core.IntLiteral.as.As.impl.Convert.414, @Core.IntLiteral.as.As.impl.Convert(%int_32) [concrete]
  228. // CHECK:STDOUT: %bound_method.18b: <bound method> = bound_method %int_0.5c6, %Core.IntLiteral.as.As.impl.Convert.specific_fn [concrete]
  229. // CHECK:STDOUT: %int_0.6a9: %i32 = int_value 0 [concrete]
  230. // CHECK:STDOUT: %ImplicitAs.impl_witness.6bf: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.e99, @Int.as.ImplicitAs.impl(%int_32) [concrete]
  231. // CHECK:STDOUT: %Int.as.ImplicitAs.impl.Convert.type.516: type = fn_type @Int.as.ImplicitAs.impl.Convert, @Int.as.ImplicitAs.impl(%int_32) [concrete]
  232. // CHECK:STDOUT: %Int.as.ImplicitAs.impl.Convert.b09: %Int.as.ImplicitAs.impl.Convert.type.516 = struct_value () [concrete]
  233. // CHECK:STDOUT: %ImplicitAs.facet.1a1: %ImplicitAs.type.7a9 = facet_value %i32, (%ImplicitAs.impl_witness.6bf) [concrete]
  234. // CHECK:STDOUT: %.81e: type = fn_type_with_self_type %ImplicitAs.Convert.type.71e, %ImplicitAs.facet.1a1 [concrete]
  235. // CHECK:STDOUT: %Int.as.ImplicitAs.impl.Convert.bound.b67: <bound method> = bound_method %int_0.6a9, %Int.as.ImplicitAs.impl.Convert.b09 [concrete]
  236. // CHECK:STDOUT: %Int.as.ImplicitAs.impl.Convert.specific_fn: <specific function> = specific_function %Int.as.ImplicitAs.impl.Convert.b09, @Int.as.ImplicitAs.impl.Convert(%int_32) [concrete]
  237. // CHECK:STDOUT: %bound_method.275: <bound method> = bound_method %int_0.6a9, %Int.as.ImplicitAs.impl.Convert.specific_fn [concrete]
  238. // CHECK:STDOUT: %Core.IntLiteral.as.As.impl.Convert.bound.9f3: <bound method> = bound_method %int_1.5b8, %Core.IntLiteral.as.As.impl.Convert.414 [concrete]
  239. // CHECK:STDOUT: %bound_method.fb8: <bound method> = bound_method %int_1.5b8, %Core.IntLiteral.as.As.impl.Convert.specific_fn [concrete]
  240. // CHECK:STDOUT: %int_1.5d2: %i32 = int_value 1 [concrete]
  241. // CHECK:STDOUT: %struct_type.index.6ea: type = struct_type {.index: %i32} [concrete]
  242. // CHECK:STDOUT: %struct.63a: %struct_type.index.6ea = struct_value (%int_1.5d2) [concrete]
  243. // CHECK:STDOUT: %Int.as.ImplicitAs.impl.Convert.bound.a06: <bound method> = bound_method %int_1.5d2, %Int.as.ImplicitAs.impl.Convert.b09 [concrete]
  244. // CHECK:STDOUT: %bound_method.c51: <bound method> = bound_method %int_1.5d2, %Int.as.ImplicitAs.impl.Convert.specific_fn [concrete]
  245. // CHECK:STDOUT: }
  246. // CHECK:STDOUT:
  247. // CHECK:STDOUT: imports {
  248. // CHECK:STDOUT: %Core.import_ref.25c: @Int.as.ImplicitAs.impl.%Int.as.ImplicitAs.impl.Convert.type (%Int.as.ImplicitAs.impl.Convert.type.543) = import_ref Core//prelude/parts/int, loc27_44, loaded [symbolic = @Int.as.ImplicitAs.impl.%Int.as.ImplicitAs.impl.Convert (constants.%Int.as.ImplicitAs.impl.Convert.c08)]
  249. // CHECK:STDOUT: %ImplicitAs.impl_witness_table.e99 = impl_witness_table (%Core.import_ref.25c), @Int.as.ImplicitAs.impl [concrete]
  250. // CHECK:STDOUT: %Core.import_ref.d0f6: @Int.as.Copy.impl.%Int.as.Copy.impl.Op.type (%Int.as.Copy.impl.Op.type.afd) = import_ref Core//prelude/parts/int, loc17_31, loaded [symbolic = @Int.as.Copy.impl.%Int.as.Copy.impl.Op (constants.%Int.as.Copy.impl.Op.6cd)]
  251. // CHECK:STDOUT: %Copy.impl_witness_table.1ed = impl_witness_table (%Core.import_ref.d0f6), @Int.as.Copy.impl [concrete]
  252. // CHECK:STDOUT: %Core.import_ref.99c: @Core.IntLiteral.as.As.impl.%Core.IntLiteral.as.As.impl.Convert.type (%Core.IntLiteral.as.As.impl.Convert.type.565) = import_ref Core//prelude/parts/int, loc32_39, loaded [symbolic = @Core.IntLiteral.as.As.impl.%Core.IntLiteral.as.As.impl.Convert (constants.%Core.IntLiteral.as.As.impl.Convert.d2c)]
  253. // CHECK:STDOUT: %As.impl_witness_table.5ad = impl_witness_table (%Core.import_ref.99c), @Core.IntLiteral.as.As.impl [concrete]
  254. // CHECK:STDOUT: }
  255. // CHECK:STDOUT:
  256. // CHECK:STDOUT: file {
  257. // CHECK:STDOUT: name_binding_decl {
  258. // CHECK:STDOUT: %b.patt: %pattern_type.7ce = binding_pattern b [concrete]
  259. // CHECK:STDOUT: %b.var_patt: %pattern_type.7ce = var_pattern %b.patt [concrete]
  260. // CHECK:STDOUT: }
  261. // CHECK:STDOUT: %b.var: ref %i32 = var %b.var_patt [concrete]
  262. // CHECK:STDOUT: %.loc5: type = splice_block %i32.loc5 [concrete = constants.%i32] {
  263. // CHECK:STDOUT: %int_32.loc5: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  264. // CHECK:STDOUT: %i32.loc5: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  265. // CHECK:STDOUT: }
  266. // CHECK:STDOUT: %b: ref %i32 = bind_name b, %b.var [concrete = %b.var]
  267. // CHECK:STDOUT: name_binding_decl {
  268. // CHECK:STDOUT: %c.patt: %pattern_type.cb1 = binding_pattern c [concrete]
  269. // CHECK:STDOUT: %c.var_patt: %pattern_type.cb1 = var_pattern %c.patt [concrete]
  270. // CHECK:STDOUT: }
  271. // CHECK:STDOUT: %c.var: ref %empty_tuple.type = var %c.var_patt [concrete]
  272. // CHECK:STDOUT: %.loc6_9.1: type = splice_block %.loc6_9.3 [concrete = constants.%empty_tuple.type] {
  273. // CHECK:STDOUT: %.loc6_9.2: %empty_tuple.type = tuple_literal ()
  274. // CHECK:STDOUT: %.loc6_9.3: type = converted %.loc6_9.2, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  275. // CHECK:STDOUT: }
  276. // CHECK:STDOUT: %c: ref %empty_tuple.type = bind_name c, %c.var [concrete = %c.var]
  277. // CHECK:STDOUT: name_binding_decl {
  278. // CHECK:STDOUT: %d.patt: %pattern_type.7ce = binding_pattern d [concrete]
  279. // CHECK:STDOUT: %d.var_patt: %pattern_type.7ce = var_pattern %d.patt [concrete]
  280. // CHECK:STDOUT: }
  281. // CHECK:STDOUT: %d.var: ref %i32 = var %d.var_patt [concrete]
  282. // CHECK:STDOUT: %.loc7: type = splice_block %i32.loc7 [concrete = constants.%i32] {
  283. // CHECK:STDOUT: %int_32.loc7: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  284. // CHECK:STDOUT: %i32.loc7: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  285. // CHECK:STDOUT: }
  286. // CHECK:STDOUT: %d: ref %i32 = bind_name d, %d.var [concrete = %d.var]
  287. // CHECK:STDOUT: }
  288. // CHECK:STDOUT:
  289. // CHECK:STDOUT: fn @__global_init() {
  290. // CHECK:STDOUT: !entry:
  291. // CHECK:STDOUT: <elided>
  292. // CHECK:STDOUT: %a.ref.loc5: ref %tuple.type.0ce = name_ref a, file.%a [concrete = file.%a.var]
  293. // CHECK:STDOUT: %int_1.loc5: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
  294. // CHECK:STDOUT: %.loc5_28.1: %struct_type.index.b1b = struct_literal (%int_1.loc5)
  295. // CHECK:STDOUT: %struct.loc5: %struct_type.index.b1b = struct_value (%int_1.loc5) [concrete = constants.%struct.972]
  296. // CHECK:STDOUT: %.loc5_28.2: %struct_type.index.b1b = converted %.loc5_28.1, %struct.loc5 [concrete = constants.%struct.972]
  297. // CHECK:STDOUT: %.loc5_29: Core.IntLiteral = struct_access %.loc5_28.2, element0 [concrete = constants.%int_1.5b8]
  298. // CHECK:STDOUT: %tuple.elem1.loc5: ref %i32 = tuple_access %a.ref.loc5, element1 [concrete = constants.%tuple.elem1]
  299. // CHECK:STDOUT: %.loc5_15: %i32 = bind_value %tuple.elem1.loc5
  300. // CHECK:STDOUT: %impl.elem0.loc5: %.7fa = impl_witness_access constants.%Copy.impl_witness.a32, element0 [concrete = constants.%Int.as.Copy.impl.Op.f59]
  301. // CHECK:STDOUT: %bound_method.loc5_15.1: <bound method> = bound_method %.loc5_15, %impl.elem0.loc5
  302. // CHECK:STDOUT: %specific_fn.loc5: <specific function> = specific_function %impl.elem0.loc5, @Int.as.Copy.impl.Op(constants.%int_32) [concrete = constants.%Int.as.Copy.impl.Op.specific_fn]
  303. // CHECK:STDOUT: %bound_method.loc5_15.2: <bound method> = bound_method %.loc5_15, %specific_fn.loc5
  304. // CHECK:STDOUT: %Int.as.Copy.impl.Op.call.loc5: init %i32 = call %bound_method.loc5_15.2(%.loc5_15)
  305. // CHECK:STDOUT: assign file.%b.var, %Int.as.Copy.impl.Op.call.loc5
  306. // CHECK:STDOUT: %a.ref.loc6: ref %tuple.type.0ce = name_ref a, file.%a [concrete = file.%a.var]
  307. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [concrete = constants.%int_0.5c6]
  308. // CHECK:STDOUT: %int_32.loc6: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  309. // CHECK:STDOUT: %i32.loc6: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  310. // CHECK:STDOUT: %impl.elem0.loc6_18.1: %.351 = impl_witness_access constants.%As.impl_witness.080, element0 [concrete = constants.%Core.IntLiteral.as.As.impl.Convert.414]
  311. // CHECK:STDOUT: %bound_method.loc6_18.1: <bound method> = bound_method %int_0, %impl.elem0.loc6_18.1 [concrete = constants.%Core.IntLiteral.as.As.impl.Convert.bound.533]
  312. // CHECK:STDOUT: %specific_fn.loc6_18.1: <specific function> = specific_function %impl.elem0.loc6_18.1, @Core.IntLiteral.as.As.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.As.impl.Convert.specific_fn]
  313. // CHECK:STDOUT: %bound_method.loc6_18.2: <bound method> = bound_method %int_0, %specific_fn.loc6_18.1 [concrete = constants.%bound_method.18b]
  314. // CHECK:STDOUT: %Core.IntLiteral.as.As.impl.Convert.call.loc6: init %i32 = call %bound_method.loc6_18.2(%int_0) [concrete = constants.%int_0.6a9]
  315. // CHECK:STDOUT: %.loc6_18.1: %i32 = value_of_initializer %Core.IntLiteral.as.As.impl.Convert.call.loc6 [concrete = constants.%int_0.6a9]
  316. // CHECK:STDOUT: %.loc6_18.2: %i32 = converted %int_0, %.loc6_18.1 [concrete = constants.%int_0.6a9]
  317. // CHECK:STDOUT: %impl.elem0.loc6_18.2: %.81e = impl_witness_access constants.%ImplicitAs.impl_witness.6bf, element0 [concrete = constants.%Int.as.ImplicitAs.impl.Convert.b09]
  318. // CHECK:STDOUT: %bound_method.loc6_18.3: <bound method> = bound_method %.loc6_18.2, %impl.elem0.loc6_18.2 [concrete = constants.%Int.as.ImplicitAs.impl.Convert.bound.b67]
  319. // CHECK:STDOUT: %specific_fn.loc6_18.2: <specific function> = specific_function %impl.elem0.loc6_18.2, @Int.as.ImplicitAs.impl.Convert(constants.%int_32) [concrete = constants.%Int.as.ImplicitAs.impl.Convert.specific_fn]
  320. // CHECK:STDOUT: %bound_method.loc6_18.4: <bound method> = bound_method %.loc6_18.2, %specific_fn.loc6_18.2 [concrete = constants.%bound_method.275]
  321. // CHECK:STDOUT: %Int.as.ImplicitAs.impl.Convert.call.loc6: init Core.IntLiteral = call %bound_method.loc6_18.4(%.loc6_18.2) [concrete = constants.%int_0.5c6]
  322. // CHECK:STDOUT: %.loc6_18.3: Core.IntLiteral = value_of_initializer %Int.as.ImplicitAs.impl.Convert.call.loc6 [concrete = constants.%int_0.5c6]
  323. // CHECK:STDOUT: %.loc6_18.4: Core.IntLiteral = converted %.loc6_18.2, %.loc6_18.3 [concrete = constants.%int_0.5c6]
  324. // CHECK:STDOUT: %tuple.elem0.loc6: ref %empty_tuple.type = tuple_access %a.ref.loc6, element0 [concrete = constants.%tuple.elem0]
  325. // CHECK:STDOUT: %.loc6_14: init %empty_tuple.type = tuple_init () to file.%c.var [concrete = constants.%empty_tuple]
  326. // CHECK:STDOUT: %.loc6_1: init %empty_tuple.type = converted %tuple.elem0.loc6, %.loc6_14 [concrete = constants.%empty_tuple]
  327. // CHECK:STDOUT: assign file.%c.var, %.loc6_1
  328. // CHECK:STDOUT: %a.ref.loc7: ref %tuple.type.0ce = name_ref a, file.%a [concrete = file.%a.var]
  329. // CHECK:STDOUT: %int_1.loc7: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
  330. // CHECK:STDOUT: %int_32.loc7: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  331. // CHECK:STDOUT: %i32.loc7: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  332. // CHECK:STDOUT: %impl.elem0.loc7_29: %.351 = impl_witness_access constants.%As.impl_witness.080, element0 [concrete = constants.%Core.IntLiteral.as.As.impl.Convert.414]
  333. // CHECK:STDOUT: %bound_method.loc7_29.1: <bound method> = bound_method %int_1.loc7, %impl.elem0.loc7_29 [concrete = constants.%Core.IntLiteral.as.As.impl.Convert.bound.9f3]
  334. // CHECK:STDOUT: %specific_fn.loc7_29: <specific function> = specific_function %impl.elem0.loc7_29, @Core.IntLiteral.as.As.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.As.impl.Convert.specific_fn]
  335. // CHECK:STDOUT: %bound_method.loc7_29.2: <bound method> = bound_method %int_1.loc7, %specific_fn.loc7_29 [concrete = constants.%bound_method.fb8]
  336. // CHECK:STDOUT: %Core.IntLiteral.as.As.impl.Convert.call.loc7: init %i32 = call %bound_method.loc7_29.2(%int_1.loc7) [concrete = constants.%int_1.5d2]
  337. // CHECK:STDOUT: %.loc7_29.1: %i32 = value_of_initializer %Core.IntLiteral.as.As.impl.Convert.call.loc7 [concrete = constants.%int_1.5d2]
  338. // CHECK:STDOUT: %.loc7_29.2: %i32 = converted %int_1.loc7, %.loc7_29.1 [concrete = constants.%int_1.5d2]
  339. // CHECK:STDOUT: %.loc7_35.1: %struct_type.index.6ea = struct_literal (%.loc7_29.2)
  340. // CHECK:STDOUT: %struct.loc7: %struct_type.index.6ea = struct_value (%.loc7_29.2) [concrete = constants.%struct.63a]
  341. // CHECK:STDOUT: %.loc7_35.2: %struct_type.index.6ea = converted %.loc7_35.1, %struct.loc7 [concrete = constants.%struct.63a]
  342. // CHECK:STDOUT: %.loc7_36.1: %i32 = struct_access %.loc7_35.2, element0 [concrete = constants.%int_1.5d2]
  343. // CHECK:STDOUT: %impl.elem0.loc7_36: %.81e = impl_witness_access constants.%ImplicitAs.impl_witness.6bf, element0 [concrete = constants.%Int.as.ImplicitAs.impl.Convert.b09]
  344. // CHECK:STDOUT: %bound_method.loc7_36.1: <bound method> = bound_method %.loc7_36.1, %impl.elem0.loc7_36 [concrete = constants.%Int.as.ImplicitAs.impl.Convert.bound.a06]
  345. // CHECK:STDOUT: %specific_fn.loc7_36: <specific function> = specific_function %impl.elem0.loc7_36, @Int.as.ImplicitAs.impl.Convert(constants.%int_32) [concrete = constants.%Int.as.ImplicitAs.impl.Convert.specific_fn]
  346. // CHECK:STDOUT: %bound_method.loc7_36.2: <bound method> = bound_method %.loc7_36.1, %specific_fn.loc7_36 [concrete = constants.%bound_method.c51]
  347. // CHECK:STDOUT: %Int.as.ImplicitAs.impl.Convert.call.loc7: init Core.IntLiteral = call %bound_method.loc7_36.2(%.loc7_36.1) [concrete = constants.%int_1.5b8]
  348. // CHECK:STDOUT: %.loc7_36.2: Core.IntLiteral = value_of_initializer %Int.as.ImplicitAs.impl.Convert.call.loc7 [concrete = constants.%int_1.5b8]
  349. // CHECK:STDOUT: %.loc7_36.3: Core.IntLiteral = converted %.loc7_36.1, %.loc7_36.2 [concrete = constants.%int_1.5b8]
  350. // CHECK:STDOUT: %tuple.elem1.loc7: ref %i32 = tuple_access %a.ref.loc7, element1 [concrete = constants.%tuple.elem1]
  351. // CHECK:STDOUT: %.loc7_15: %i32 = bind_value %tuple.elem1.loc7
  352. // CHECK:STDOUT: %impl.elem0.loc7_15: %.7fa = impl_witness_access constants.%Copy.impl_witness.a32, element0 [concrete = constants.%Int.as.Copy.impl.Op.f59]
  353. // CHECK:STDOUT: %bound_method.loc7_15.1: <bound method> = bound_method %.loc7_15, %impl.elem0.loc7_15
  354. // CHECK:STDOUT: %specific_fn.loc7_15: <specific function> = specific_function %impl.elem0.loc7_15, @Int.as.Copy.impl.Op(constants.%int_32) [concrete = constants.%Int.as.Copy.impl.Op.specific_fn]
  355. // CHECK:STDOUT: %bound_method.loc7_15.2: <bound method> = bound_method %.loc7_15, %specific_fn.loc7_15
  356. // CHECK:STDOUT: %Int.as.Copy.impl.Op.call.loc7: init %i32 = call %bound_method.loc7_15.2(%.loc7_15)
  357. // CHECK:STDOUT: assign file.%d.var, %Int.as.Copy.impl.Op.call.loc7
  358. // CHECK:STDOUT: <elided>
  359. // CHECK:STDOUT: }
  360. // CHECK:STDOUT:
  361. // CHECK:STDOUT: --- return_value_access.carbon
  362. // CHECK:STDOUT:
  363. // CHECK:STDOUT: constants {
  364. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  365. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  366. // CHECK:STDOUT: %N: Core.IntLiteral = bind_symbolic_name N, 0 [symbolic]
  367. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  368. // CHECK:STDOUT: %tuple.type.a1c: type = tuple_type (%i32) [concrete]
  369. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  370. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  371. // CHECK:STDOUT: %int_0.5c6: Core.IntLiteral = int_value 0 [concrete]
  372. // CHECK:STDOUT: %Copy.type: type = facet_type <@Copy> [concrete]
  373. // CHECK:STDOUT: %Copy.Op.type: type = fn_type @Copy.Op [concrete]
  374. // CHECK:STDOUT: %Int.as.Copy.impl.Op.type.afd: type = fn_type @Int.as.Copy.impl.Op, @Int.as.Copy.impl(%N) [symbolic]
  375. // CHECK:STDOUT: %Int.as.Copy.impl.Op.6cd: %Int.as.Copy.impl.Op.type.afd = struct_value () [symbolic]
  376. // CHECK:STDOUT: %Copy.impl_witness.a32: <witness> = impl_witness imports.%Copy.impl_witness_table.1ed, @Int.as.Copy.impl(%int_32) [concrete]
  377. // CHECK:STDOUT: %Int.as.Copy.impl.Op.type.276: type = fn_type @Int.as.Copy.impl.Op, @Int.as.Copy.impl(%int_32) [concrete]
  378. // CHECK:STDOUT: %Int.as.Copy.impl.Op.f59: %Int.as.Copy.impl.Op.type.276 = struct_value () [concrete]
  379. // CHECK:STDOUT: %Copy.facet.c49: %Copy.type = facet_value %i32, (%Copy.impl_witness.a32) [concrete]
  380. // CHECK:STDOUT: %.7fa: type = fn_type_with_self_type %Copy.Op.type, %Copy.facet.c49 [concrete]
  381. // CHECK:STDOUT: %Int.as.Copy.impl.Op.specific_fn: <specific function> = specific_function %Int.as.Copy.impl.Op.f59, @Int.as.Copy.impl.Op(%int_32) [concrete]
  382. // CHECK:STDOUT: %T.as.Destroy.impl.Op.type.a1d: type = fn_type @T.as.Destroy.impl.Op, @T.as.Destroy.impl(%tuple.type.a1c) [concrete]
  383. // CHECK:STDOUT: %T.as.Destroy.impl.Op.1b2: %T.as.Destroy.impl.Op.type.a1d = struct_value () [concrete]
  384. // CHECK:STDOUT: %ptr.0b7: type = ptr_type %tuple.type.a1c [concrete]
  385. // CHECK:STDOUT: }
  386. // CHECK:STDOUT:
  387. // CHECK:STDOUT: imports {
  388. // CHECK:STDOUT: %Core.import_ref.d0f6: @Int.as.Copy.impl.%Int.as.Copy.impl.Op.type (%Int.as.Copy.impl.Op.type.afd) = import_ref Core//prelude/parts/int, loc17_31, loaded [symbolic = @Int.as.Copy.impl.%Int.as.Copy.impl.Op (constants.%Int.as.Copy.impl.Op.6cd)]
  389. // CHECK:STDOUT: %Copy.impl_witness_table.1ed = impl_witness_table (%Core.import_ref.d0f6), @Int.as.Copy.impl [concrete]
  390. // CHECK:STDOUT: }
  391. // CHECK:STDOUT:
  392. // CHECK:STDOUT: fn @Run() -> %i32 {
  393. // CHECK:STDOUT: !entry:
  394. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [concrete = constants.%F]
  395. // CHECK:STDOUT: %F.call: init %tuple.type.a1c = call %F.ref()
  396. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [concrete = constants.%int_0.5c6]
  397. // CHECK:STDOUT: %.loc7_12.1: ref %tuple.type.a1c = temporary_storage
  398. // CHECK:STDOUT: %.loc7_12.2: ref %tuple.type.a1c = temporary %.loc7_12.1, %F.call
  399. // CHECK:STDOUT: %tuple.elem0: ref %i32 = tuple_access %.loc7_12.2, element0
  400. // CHECK:STDOUT: %.loc7_13: %i32 = bind_value %tuple.elem0
  401. // CHECK:STDOUT: %impl.elem0: %.7fa = impl_witness_access constants.%Copy.impl_witness.a32, element0 [concrete = constants.%Int.as.Copy.impl.Op.f59]
  402. // CHECK:STDOUT: %bound_method.loc7_13.1: <bound method> = bound_method %.loc7_13, %impl.elem0
  403. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Int.as.Copy.impl.Op(constants.%int_32) [concrete = constants.%Int.as.Copy.impl.Op.specific_fn]
  404. // CHECK:STDOUT: %bound_method.loc7_13.2: <bound method> = bound_method %.loc7_13, %specific_fn
  405. // CHECK:STDOUT: %Int.as.Copy.impl.Op.call: init %i32 = call %bound_method.loc7_13.2(%.loc7_13)
  406. // CHECK:STDOUT: %T.as.Destroy.impl.Op.bound: <bound method> = bound_method %.loc7_12.2, constants.%T.as.Destroy.impl.Op.1b2
  407. // CHECK:STDOUT: <elided>
  408. // CHECK:STDOUT: %bound_method.loc7_12: <bound method> = bound_method %.loc7_12.2, %T.as.Destroy.impl.Op.specific_fn
  409. // CHECK:STDOUT: %addr: %ptr.0b7 = addr_of %.loc7_12.2
  410. // CHECK:STDOUT: %T.as.Destroy.impl.Op.call: init %empty_tuple.type = call %bound_method.loc7_12(%addr)
  411. // CHECK:STDOUT: return %Int.as.Copy.impl.Op.call to %return
  412. // CHECK:STDOUT: }
  413. // CHECK:STDOUT: