adapter_conversion.carbon 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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/as/adapter_conversion.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/as/adapter_conversion.carbon
  12. // --- adapt_class.carbon
  13. library "[[@TEST_NAME]]";
  14. class A {
  15. var x: i32;
  16. var y: i32;
  17. fn Make() -> A {
  18. return {.x = 1, .y = 2};
  19. }
  20. }
  21. class B {
  22. adapt A;
  23. }
  24. var a_ref: A = {.x = 1, .y = 2};
  25. let a_val: A = a_ref;
  26. // An `as` conversion to an adapter type preserves the expression category.
  27. //@dump-sem-ir-begin
  28. let b_val: B = a_val as B;
  29. let b_ptr: B* = &(a_ref as B);
  30. var b_factory: B = A.Make() as B;
  31. //@dump-sem-ir-end
  32. // --- adapt_i32.carbon
  33. library "[[@TEST_NAME]]";
  34. class A {
  35. adapt i32;
  36. }
  37. //@dump-sem-ir-begin
  38. let a: A = (1 as i32) as A;
  39. let n: i32 = a as i32;
  40. //@dump-sem-ir-end
  41. // --- multi_level_adapt.carbon
  42. library "[[@TEST_NAME]]";
  43. class A { adapt {}; }
  44. class B { adapt A; }
  45. class C { adapt B; }
  46. class D { adapt C; }
  47. //@dump-sem-ir-begin
  48. let d: D = {} as D;
  49. //@dump-sem-ir-end
  50. // --- init_class_value.carbon
  51. library "[[@TEST_NAME]]";
  52. class A {
  53. var x: i32;
  54. var y: i32;
  55. }
  56. class B {
  57. adapt A;
  58. }
  59. //@dump-sem-ir-begin
  60. let b_value: B = ({.x = 1, .y = 2} as A) as B;
  61. //@dump-sem-ir-end
  62. // --- fail_init_class_variable.carbon
  63. library "[[@TEST_NAME]]";
  64. class A {
  65. var x: i32;
  66. var y: i32;
  67. }
  68. class B {
  69. adapt A;
  70. }
  71. // TODO: Here, we treat `{.x = 1, .y = 2} as A` as a value expression, not an
  72. // initializing expression, so `(...) as B` is a value expression too, requiring
  73. // a copy to perform initialization. It's not clear whether that is the right
  74. // behavior.
  75. // CHECK:STDERR: fail_init_class_variable.carbon:[[@LINE+7]]:17: error: cannot copy value of type `B` [CopyOfUncopyableType]
  76. // CHECK:STDERR: var b_init: B = ({.x = 1, .y = 2} as A) as B;
  77. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
  78. // CHECK:STDERR: fail_init_class_variable.carbon:[[@LINE+4]]:17: note: type `B` does not implement interface `Core.Copy` [MissingImplInMemberAccessNote]
  79. // CHECK:STDERR: var b_init: B = ({.x = 1, .y = 2} as A) as B;
  80. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
  81. // CHECK:STDERR:
  82. var b_init: B = ({.x = 1, .y = 2} as A) as B;
  83. // --- init_tuple_value.carbon
  84. library "[[@TEST_NAME]]";
  85. class Noncopyable {
  86. // TODO: Ensure this remains non-copyable once we have rules for class copyability.
  87. }
  88. class A {
  89. adapt ({}, Noncopyable);
  90. }
  91. fn F(a: A) {
  92. //@dump-sem-ir-begin
  93. let a_value: A = (a as ({}, Noncopyable)) as A;
  94. //@dump-sem-ir-end
  95. }
  96. // --- fail_init_tuple_variable.carbon
  97. library "[[@TEST_NAME]]";
  98. class Noncopyable {
  99. // TODO: Ensure this remains non-copyable once we have rules for class copyability.
  100. }
  101. class A {
  102. adapt ({}, Noncopyable);
  103. }
  104. fn F(a: A) {
  105. // TODO: Here, we treat `a as (i32, Noncopyable)` as a value expression, not an
  106. // initializing expression, so `(...) as A` is a value expression too, requiring
  107. // a copy to perform initialization. It's not clear whether that is the right
  108. // behavior.
  109. // CHECK:STDERR: fail_init_tuple_variable.carbon:[[@LINE+10]]:3: error: cannot copy value of type `Noncopyable` [CopyOfUncopyableType]
  110. // CHECK:STDERR: var a_init: A = (a as ({}, Noncopyable)) as A;
  111. // CHECK:STDERR: ^~~~~~~~~~~~~
  112. // CHECK:STDERR: fail_init_tuple_variable.carbon:[[@LINE+7]]:3: note: type `Noncopyable` does not implement interface `Core.Copy` [MissingImplInMemberAccessNote]
  113. // CHECK:STDERR: var a_init: A = (a as ({}, Noncopyable)) as A;
  114. // CHECK:STDERR: ^~~~~~~~~~~~~
  115. // CHECK:STDERR: fail_init_tuple_variable.carbon:[[@LINE+4]]:19: note: in copy of `A` [InCopy]
  116. // CHECK:STDERR: var a_init: A = (a as ({}, Noncopyable)) as A;
  117. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  118. // CHECK:STDERR:
  119. var a_init: A = (a as ({}, Noncopyable)) as A;
  120. }
  121. // --- fail_adapt_init_from_struct.carbon
  122. library "[[@TEST_NAME]]";
  123. class A {
  124. var x: ();
  125. }
  126. class B {
  127. adapt A;
  128. }
  129. // We do not try to implicitly convert from the first operand of `as` to the
  130. // adapted type of the second operand.
  131. // CHECK:STDERR: fail_adapt_init_from_struct.carbon:[[@LINE+7]]:12: error: cannot convert expression of type `{.x: ()}` to `B` with `as` [ConversionFailure]
  132. // CHECK:STDERR: var b: B = {.x = ()} as B;
  133. // CHECK:STDERR: ^~~~~~~~~~~~~~
  134. // CHECK:STDERR: fail_adapt_init_from_struct.carbon:[[@LINE+4]]:12: note: type `{.x: ()}` does not implement interface `Core.As(B)` [MissingImplInMemberAccessNote]
  135. // CHECK:STDERR: var b: B = {.x = ()} as B;
  136. // CHECK:STDERR: ^~~~~~~~~~~~~~
  137. // CHECK:STDERR:
  138. var b: B = {.x = ()} as B;
  139. // CHECK:STDOUT: --- adapt_class.carbon
  140. // CHECK:STDOUT:
  141. // CHECK:STDOUT: constants {
  142. // CHECK:STDOUT: %A: type = class_type @A [concrete]
  143. // CHECK:STDOUT: %A.Make.type: type = fn_type @A.Make [concrete]
  144. // CHECK:STDOUT: %A.Make: %A.Make.type = struct_value () [concrete]
  145. // CHECK:STDOUT: %B: type = class_type @B [concrete]
  146. // CHECK:STDOUT: %pattern_type.1f4: type = pattern_type %B [concrete]
  147. // CHECK:STDOUT: %ptr.27c: type = ptr_type %B [concrete]
  148. // CHECK:STDOUT: %pattern_type.191: type = pattern_type %ptr.27c [concrete]
  149. // CHECK:STDOUT: %a_ref.var: ref %B = var file.%a_ref.var_patt [concrete]
  150. // CHECK:STDOUT: %addr: %ptr.27c = addr_of %a_ref.var [concrete]
  151. // CHECK:STDOUT: }
  152. // CHECK:STDOUT:
  153. // CHECK:STDOUT: imports {
  154. // CHECK:STDOUT: }
  155. // CHECK:STDOUT:
  156. // CHECK:STDOUT: file {
  157. // CHECK:STDOUT: name_binding_decl {
  158. // CHECK:STDOUT: %b_val.patt: %pattern_type.1f4 = value_binding_pattern b_val [concrete]
  159. // CHECK:STDOUT: }
  160. // CHECK:STDOUT: %B.ref.loc22: type = name_ref B, %B.decl [concrete = constants.%B]
  161. // CHECK:STDOUT: %b_val: %B = value_binding b_val, @__global_init.%.loc22_22.2
  162. // CHECK:STDOUT: name_binding_decl {
  163. // CHECK:STDOUT: %b_ptr.patt: %pattern_type.191 = value_binding_pattern b_ptr [concrete]
  164. // CHECK:STDOUT: }
  165. // CHECK:STDOUT: %.loc23: type = splice_block %ptr [concrete = constants.%ptr.27c] {
  166. // CHECK:STDOUT: %B.ref.loc23: type = name_ref B, %B.decl [concrete = constants.%B]
  167. // CHECK:STDOUT: %ptr: type = ptr_type %B.ref.loc23 [concrete = constants.%ptr.27c]
  168. // CHECK:STDOUT: }
  169. // CHECK:STDOUT: %b_ptr: %ptr.27c = value_binding b_ptr, @__global_init.%addr
  170. // CHECK:STDOUT: name_binding_decl {
  171. // CHECK:STDOUT: %b_factory.patt: %pattern_type.1f4 = ref_binding_pattern b_factory [concrete]
  172. // CHECK:STDOUT: %b_factory.var_patt: %pattern_type.1f4 = var_pattern %b_factory.patt [concrete]
  173. // CHECK:STDOUT: }
  174. // CHECK:STDOUT: %b_factory.var: ref %B = var %b_factory.var_patt [concrete]
  175. // CHECK:STDOUT: %B.ref.loc25: type = name_ref B, %B.decl [concrete = constants.%B]
  176. // CHECK:STDOUT: %b_factory: ref %B = ref_binding b_factory, %b_factory.var [concrete = %b_factory.var]
  177. // CHECK:STDOUT: }
  178. // CHECK:STDOUT:
  179. // CHECK:STDOUT: fn @__global_init() {
  180. // CHECK:STDOUT: !entry:
  181. // CHECK:STDOUT: <elided>
  182. // CHECK:STDOUT: %a_val.ref: %A = name_ref a_val, file.%a_val
  183. // CHECK:STDOUT: %B.ref.loc22: type = name_ref B, file.%B.decl [concrete = constants.%B]
  184. // CHECK:STDOUT: %.loc22_22.1: %B = as_compatible %a_val.ref
  185. // CHECK:STDOUT: %.loc22_22.2: %B = converted %a_val.ref, %.loc22_22.1
  186. // CHECK:STDOUT: %a_ref.ref.loc23: ref %A = name_ref a_ref, file.%a_ref [concrete = file.%a_ref.var]
  187. // CHECK:STDOUT: %B.ref.loc23: type = name_ref B, file.%B.decl [concrete = constants.%B]
  188. // CHECK:STDOUT: %.loc23_25.1: ref %B = as_compatible %a_ref.ref.loc23 [concrete = constants.%a_ref.var]
  189. // CHECK:STDOUT: %.loc23_25.2: ref %B = converted %a_ref.ref.loc23, %.loc23_25.1 [concrete = constants.%a_ref.var]
  190. // CHECK:STDOUT: %addr: %ptr.27c = addr_of %.loc23_25.2 [concrete = constants.%addr]
  191. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [concrete = constants.%A]
  192. // CHECK:STDOUT: %Make.ref: %A.Make.type = name_ref Make, @A.%A.Make.decl [concrete = constants.%A.Make]
  193. // CHECK:STDOUT: %.loc25_1: ref %B = splice_block file.%b_factory.var [concrete = file.%b_factory.var] {}
  194. // CHECK:STDOUT: %A.Make.call: init %A to %.loc25_1 = call %Make.ref()
  195. // CHECK:STDOUT: %B.ref.loc25: type = name_ref B, file.%B.decl [concrete = constants.%B]
  196. // CHECK:STDOUT: %.loc25_29.1: init %B = as_compatible %A.Make.call
  197. // CHECK:STDOUT: %.loc25_29.2: init %B = converted %A.Make.call, %.loc25_29.1
  198. // CHECK:STDOUT: assign file.%b_factory.var, %.loc25_29.2
  199. // CHECK:STDOUT: <elided>
  200. // CHECK:STDOUT: }
  201. // CHECK:STDOUT:
  202. // CHECK:STDOUT: --- adapt_i32.carbon
  203. // CHECK:STDOUT:
  204. // CHECK:STDOUT: constants {
  205. // CHECK:STDOUT: %A: type = class_type @A [concrete]
  206. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  207. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  208. // CHECK:STDOUT: %pattern_type.1ab: type = pattern_type %A [concrete]
  209. // CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [concrete]
  210. // CHECK:STDOUT: %As.type.047: type = facet_type <@As, @As(%i32)> [concrete]
  211. // CHECK:STDOUT: %To: Core.IntLiteral = symbolic_binding To, 0 [symbolic]
  212. // CHECK:STDOUT: %Core.IntLiteral.as.As.impl.Convert.type.09e: type = fn_type @Core.IntLiteral.as.As.impl.Convert, @Core.IntLiteral.as.As.impl(%To) [symbolic]
  213. // CHECK:STDOUT: %Core.IntLiteral.as.As.impl.Convert.dbe: %Core.IntLiteral.as.As.impl.Convert.type.09e = struct_value () [symbolic]
  214. // CHECK:STDOUT: %As.impl_witness.ab6: <witness> = impl_witness imports.%As.impl_witness_table.9fc, @Core.IntLiteral.as.As.impl(%int_32) [concrete]
  215. // CHECK:STDOUT: %Core.IntLiteral.as.As.impl.Convert.type.8ec: type = fn_type @Core.IntLiteral.as.As.impl.Convert, @Core.IntLiteral.as.As.impl(%int_32) [concrete]
  216. // CHECK:STDOUT: %Core.IntLiteral.as.As.impl.Convert.29b: %Core.IntLiteral.as.As.impl.Convert.type.8ec = struct_value () [concrete]
  217. // CHECK:STDOUT: %As.facet: %As.type.047 = facet_value Core.IntLiteral, (%As.impl_witness.ab6) [concrete]
  218. // CHECK:STDOUT: %As.WithSelf.Convert.type.e5b: type = fn_type @As.WithSelf.Convert, @As(%i32, %As.facet) [concrete]
  219. // CHECK:STDOUT: %.9ed: type = fn_type_with_self_type %As.WithSelf.Convert.type.e5b, %As.facet [concrete]
  220. // CHECK:STDOUT: %Core.IntLiteral.as.As.impl.Convert.bound: <bound method> = bound_method %int_1.5b8, %Core.IntLiteral.as.As.impl.Convert.29b [concrete]
  221. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  222. // CHECK:STDOUT: %Core.IntLiteral.as.As.impl.Convert.specific_fn: <specific function> = specific_function %Core.IntLiteral.as.As.impl.Convert.29b, @Core.IntLiteral.as.As.impl.Convert(%int_32) [concrete]
  223. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %int_1.5b8, %Core.IntLiteral.as.As.impl.Convert.specific_fn [concrete]
  224. // CHECK:STDOUT: %int_1.5d2: %i32 = int_value 1 [concrete]
  225. // CHECK:STDOUT: %int_1.360: %A = int_value 1 [concrete]
  226. // CHECK:STDOUT: }
  227. // CHECK:STDOUT:
  228. // CHECK:STDOUT: imports {
  229. // CHECK:STDOUT: %Core.import_ref.ca0: @Core.IntLiteral.as.As.impl.%Core.IntLiteral.as.As.impl.Convert.type (%Core.IntLiteral.as.As.impl.Convert.type.09e) = import_ref Core//prelude/parts/int, loc{{\d+_\d+}}, loaded [symbolic = @Core.IntLiteral.as.As.impl.%Core.IntLiteral.as.As.impl.Convert (constants.%Core.IntLiteral.as.As.impl.Convert.dbe)]
  230. // CHECK:STDOUT: %As.impl_witness_table.9fc = impl_witness_table (%Core.import_ref.ca0), @Core.IntLiteral.as.As.impl [concrete]
  231. // CHECK:STDOUT: }
  232. // CHECK:STDOUT:
  233. // CHECK:STDOUT: file {
  234. // CHECK:STDOUT: name_binding_decl {
  235. // CHECK:STDOUT: %a.patt: %pattern_type.1ab = value_binding_pattern a [concrete]
  236. // CHECK:STDOUT: }
  237. // CHECK:STDOUT: %A.ref: type = name_ref A, %A.decl [concrete = constants.%A]
  238. // CHECK:STDOUT: %a: %A = value_binding a, @__global_init.%.loc9_23.2
  239. // CHECK:STDOUT: name_binding_decl {
  240. // CHECK:STDOUT: %n.patt: %pattern_type.7ce = value_binding_pattern n [concrete]
  241. // CHECK:STDOUT: }
  242. // CHECK:STDOUT: %.loc10: type = splice_block %i32 [concrete = constants.%i32] {
  243. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  244. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  245. // CHECK:STDOUT: }
  246. // CHECK:STDOUT: %n: %i32 = value_binding n, @__global_init.%.loc10_16.2
  247. // CHECK:STDOUT: }
  248. // CHECK:STDOUT:
  249. // CHECK:STDOUT: fn @__global_init() {
  250. // CHECK:STDOUT: !entry:
  251. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
  252. // CHECK:STDOUT: %int_32.loc9: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  253. // CHECK:STDOUT: %i32.loc9: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  254. // CHECK:STDOUT: %impl.elem0: %.9ed = impl_witness_access constants.%As.impl_witness.ab6, element0 [concrete = constants.%Core.IntLiteral.as.As.impl.Convert.29b]
  255. // CHECK:STDOUT: %bound_method.loc9_15.1: <bound method> = bound_method %int_1, %impl.elem0 [concrete = constants.%Core.IntLiteral.as.As.impl.Convert.bound]
  256. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Core.IntLiteral.as.As.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.As.impl.Convert.specific_fn]
  257. // CHECK:STDOUT: %bound_method.loc9_15.2: <bound method> = bound_method %int_1, %specific_fn [concrete = constants.%bound_method]
  258. // CHECK:STDOUT: %Core.IntLiteral.as.As.impl.Convert.call: init %i32 = call %bound_method.loc9_15.2(%int_1) [concrete = constants.%int_1.5d2]
  259. // CHECK:STDOUT: %.loc9_15.1: %i32 = value_of_initializer %Core.IntLiteral.as.As.impl.Convert.call [concrete = constants.%int_1.5d2]
  260. // CHECK:STDOUT: %.loc9_15.2: %i32 = converted %int_1, %.loc9_15.1 [concrete = constants.%int_1.5d2]
  261. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [concrete = constants.%A]
  262. // CHECK:STDOUT: %.loc9_23.1: %A = as_compatible %.loc9_15.2 [concrete = constants.%int_1.360]
  263. // CHECK:STDOUT: %.loc9_23.2: %A = converted %.loc9_15.2, %.loc9_23.1 [concrete = constants.%int_1.360]
  264. // CHECK:STDOUT: %a.ref: %A = name_ref a, file.%a
  265. // CHECK:STDOUT: %int_32.loc10: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  266. // CHECK:STDOUT: %i32.loc10: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  267. // CHECK:STDOUT: %.loc10_16.1: %i32 = as_compatible %a.ref
  268. // CHECK:STDOUT: %.loc10_16.2: %i32 = converted %a.ref, %.loc10_16.1
  269. // CHECK:STDOUT: <elided>
  270. // CHECK:STDOUT: }
  271. // CHECK:STDOUT:
  272. // CHECK:STDOUT: --- multi_level_adapt.carbon
  273. // CHECK:STDOUT:
  274. // CHECK:STDOUT: constants {
  275. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  276. // CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
  277. // CHECK:STDOUT: %D: type = class_type @D [concrete]
  278. // CHECK:STDOUT: %pattern_type: type = pattern_type %D [concrete]
  279. // CHECK:STDOUT: %D.val: %D = struct_value () [concrete]
  280. // CHECK:STDOUT: }
  281. // CHECK:STDOUT:
  282. // CHECK:STDOUT: imports {
  283. // CHECK:STDOUT: }
  284. // CHECK:STDOUT:
  285. // CHECK:STDOUT: file {
  286. // CHECK:STDOUT: name_binding_decl {
  287. // CHECK:STDOUT: %d.patt: %pattern_type = value_binding_pattern d [concrete]
  288. // CHECK:STDOUT: }
  289. // CHECK:STDOUT: %D.ref: type = name_ref D, %D.decl [concrete = constants.%D]
  290. // CHECK:STDOUT: %d: %D = value_binding d, @__global_init.%.loc10_15.2
  291. // CHECK:STDOUT: }
  292. // CHECK:STDOUT:
  293. // CHECK:STDOUT: fn @__global_init() {
  294. // CHECK:STDOUT: !entry:
  295. // CHECK:STDOUT: %.loc10_13: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
  296. // CHECK:STDOUT: %D.ref: type = name_ref D, file.%D.decl [concrete = constants.%D]
  297. // CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete = constants.%empty_struct]
  298. // CHECK:STDOUT: %.loc10_15.1: %D = as_compatible %empty_struct [concrete = constants.%D.val]
  299. // CHECK:STDOUT: %.loc10_15.2: %D = converted %.loc10_13, %.loc10_15.1 [concrete = constants.%D.val]
  300. // CHECK:STDOUT: <elided>
  301. // CHECK:STDOUT: }
  302. // CHECK:STDOUT:
  303. // CHECK:STDOUT: --- init_class_value.carbon
  304. // CHECK:STDOUT:
  305. // CHECK:STDOUT: constants {
  306. // CHECK:STDOUT: %A: type = class_type @A [concrete]
  307. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  308. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  309. // CHECK:STDOUT: %B: type = class_type @B [concrete]
  310. // CHECK:STDOUT: %pattern_type.1f4: type = pattern_type %B [concrete]
  311. // CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [concrete]
  312. // CHECK:STDOUT: %int_2.ecc: Core.IntLiteral = int_value 2 [concrete]
  313. // CHECK:STDOUT: %struct_type.x.y.4cf: type = struct_type {.x: Core.IntLiteral, .y: Core.IntLiteral} [concrete]
  314. // CHECK:STDOUT: %struct: %struct_type.x.y.4cf = struct_value (%int_1.5b8, %int_2.ecc) [concrete]
  315. // CHECK:STDOUT: %ImplicitAs.type.e8c: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete]
  316. // CHECK:STDOUT: %To: Core.IntLiteral = symbolic_binding To, 0 [symbolic]
  317. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.4e6: type = fn_type @Core.IntLiteral.as.ImplicitAs.impl.Convert, @Core.IntLiteral.as.ImplicitAs.impl(%To) [symbolic]
  318. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.3c2: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.4e6 = struct_value () [symbolic]
  319. // CHECK:STDOUT: %ImplicitAs.impl_witness.6bc: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.74f, @Core.IntLiteral.as.ImplicitAs.impl(%int_32) [concrete]
  320. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.e0d: type = fn_type @Core.IntLiteral.as.ImplicitAs.impl.Convert, @Core.IntLiteral.as.ImplicitAs.impl(%int_32) [concrete]
  321. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.0b5: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.e0d = struct_value () [concrete]
  322. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.e8c = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.6bc) [concrete]
  323. // CHECK:STDOUT: %ImplicitAs.WithSelf.Convert.type.b37: type = fn_type @ImplicitAs.WithSelf.Convert, @ImplicitAs(%i32, %ImplicitAs.facet) [concrete]
  324. // CHECK:STDOUT: %.545: type = fn_type_with_self_type %ImplicitAs.WithSelf.Convert.type.b37, %ImplicitAs.facet [concrete]
  325. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.bound.215: <bound method> = bound_method %int_1.5b8, %Core.IntLiteral.as.ImplicitAs.impl.Convert.0b5 [concrete]
  326. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn: <specific function> = specific_function %Core.IntLiteral.as.ImplicitAs.impl.Convert.0b5, @Core.IntLiteral.as.ImplicitAs.impl.Convert(%int_32) [concrete]
  327. // CHECK:STDOUT: %bound_method.38b: <bound method> = bound_method %int_1.5b8, %Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn [concrete]
  328. // CHECK:STDOUT: %int_1.5d2: %i32 = int_value 1 [concrete]
  329. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.bound.4e5: <bound method> = bound_method %int_2.ecc, %Core.IntLiteral.as.ImplicitAs.impl.Convert.0b5 [concrete]
  330. // CHECK:STDOUT: %bound_method.646: <bound method> = bound_method %int_2.ecc, %Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn [concrete]
  331. // CHECK:STDOUT: %int_2.ef8: %i32 = int_value 2 [concrete]
  332. // CHECK:STDOUT: %A.val: %A = struct_value (%int_1.5d2, %int_2.ef8) [concrete]
  333. // CHECK:STDOUT: }
  334. // CHECK:STDOUT:
  335. // CHECK:STDOUT: imports {
  336. // CHECK:STDOUT: %Core.import_ref.42d: @Core.IntLiteral.as.ImplicitAs.impl.%Core.IntLiteral.as.ImplicitAs.impl.Convert.type (%Core.IntLiteral.as.ImplicitAs.impl.Convert.type.4e6) = import_ref Core//prelude/parts/int, loc{{\d+_\d+}}, loaded [symbolic = @Core.IntLiteral.as.ImplicitAs.impl.%Core.IntLiteral.as.ImplicitAs.impl.Convert (constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.3c2)]
  337. // CHECK:STDOUT: %ImplicitAs.impl_witness_table.74f = impl_witness_table (%Core.import_ref.42d), @Core.IntLiteral.as.ImplicitAs.impl [concrete]
  338. // CHECK:STDOUT: }
  339. // CHECK:STDOUT:
  340. // CHECK:STDOUT: file {
  341. // CHECK:STDOUT: name_binding_decl {
  342. // CHECK:STDOUT: %b_value.patt: %pattern_type.1f4 = value_binding_pattern b_value [concrete]
  343. // CHECK:STDOUT: }
  344. // CHECK:STDOUT: %B.ref: type = name_ref B, %B.decl [concrete = constants.%B]
  345. // CHECK:STDOUT: %.loc14: %B = acquire_value @__global_init.%.loc14_42.2
  346. // CHECK:STDOUT: %b_value: %B = value_binding b_value, %.loc14
  347. // CHECK:STDOUT: }
  348. // CHECK:STDOUT:
  349. // CHECK:STDOUT: fn @__global_init() {
  350. // CHECK:STDOUT: !entry:
  351. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
  352. // CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [concrete = constants.%int_2.ecc]
  353. // CHECK:STDOUT: %.loc14_34.1: %struct_type.x.y.4cf = struct_literal (%int_1, %int_2) [concrete = constants.%struct]
  354. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [concrete = constants.%A]
  355. // CHECK:STDOUT: %impl.elem0.loc14_34.1: %.545 = impl_witness_access constants.%ImplicitAs.impl_witness.6bc, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.0b5]
  356. // CHECK:STDOUT: %bound_method.loc14_34.1: <bound method> = bound_method %int_1, %impl.elem0.loc14_34.1 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound.215]
  357. // CHECK:STDOUT: %specific_fn.loc14_34.1: <specific function> = specific_function %impl.elem0.loc14_34.1, @Core.IntLiteral.as.ImplicitAs.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn]
  358. // CHECK:STDOUT: %bound_method.loc14_34.2: <bound method> = bound_method %int_1, %specific_fn.loc14_34.1 [concrete = constants.%bound_method.38b]
  359. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc14_34.1: init %i32 = call %bound_method.loc14_34.2(%int_1) [concrete = constants.%int_1.5d2]
  360. // CHECK:STDOUT: %.loc14_34.2: init %i32 = converted %int_1, %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc14_34.1 [concrete = constants.%int_1.5d2]
  361. // CHECK:STDOUT: %.loc14_34.3: ref %A = temporary_storage
  362. // CHECK:STDOUT: %.loc14_34.4: ref %i32 = class_element_access %.loc14_34.3, element0
  363. // CHECK:STDOUT: %.loc14_34.5: init %i32 to %.loc14_34.4 = in_place_init %.loc14_34.2 [concrete = constants.%int_1.5d2]
  364. // CHECK:STDOUT: %impl.elem0.loc14_34.2: %.545 = impl_witness_access constants.%ImplicitAs.impl_witness.6bc, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.0b5]
  365. // CHECK:STDOUT: %bound_method.loc14_34.3: <bound method> = bound_method %int_2, %impl.elem0.loc14_34.2 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound.4e5]
  366. // CHECK:STDOUT: %specific_fn.loc14_34.2: <specific function> = specific_function %impl.elem0.loc14_34.2, @Core.IntLiteral.as.ImplicitAs.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn]
  367. // CHECK:STDOUT: %bound_method.loc14_34.4: <bound method> = bound_method %int_2, %specific_fn.loc14_34.2 [concrete = constants.%bound_method.646]
  368. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc14_34.2: init %i32 = call %bound_method.loc14_34.4(%int_2) [concrete = constants.%int_2.ef8]
  369. // CHECK:STDOUT: %.loc14_34.6: init %i32 = converted %int_2, %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc14_34.2 [concrete = constants.%int_2.ef8]
  370. // CHECK:STDOUT: %.loc14_34.7: ref %i32 = class_element_access %.loc14_34.3, element1
  371. // CHECK:STDOUT: %.loc14_34.8: init %i32 to %.loc14_34.7 = in_place_init %.loc14_34.6 [concrete = constants.%int_2.ef8]
  372. // CHECK:STDOUT: %.loc14_34.9: init %A to %.loc14_34.3 = class_init (%.loc14_34.5, %.loc14_34.8) [concrete = constants.%A.val]
  373. // CHECK:STDOUT: %.loc14_34.10: ref %A = temporary %.loc14_34.3, %.loc14_34.9
  374. // CHECK:STDOUT: %.loc14_36: ref %A = converted %.loc14_34.1, %.loc14_34.10
  375. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [concrete = constants.%B]
  376. // CHECK:STDOUT: %.loc14_42.1: ref %B = as_compatible %.loc14_36
  377. // CHECK:STDOUT: %.loc14_42.2: ref %B = converted %.loc14_36, %.loc14_42.1
  378. // CHECK:STDOUT: <elided>
  379. // CHECK:STDOUT: }
  380. // CHECK:STDOUT:
  381. // CHECK:STDOUT: --- init_tuple_value.carbon
  382. // CHECK:STDOUT:
  383. // CHECK:STDOUT: constants {
  384. // CHECK:STDOUT: %Noncopyable: type = class_type @Noncopyable [concrete]
  385. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  386. // CHECK:STDOUT: %A: type = class_type @A [concrete]
  387. // CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
  388. // CHECK:STDOUT: %tuple.type.c8c: type = tuple_type (%empty_struct_type, type) [concrete]
  389. // CHECK:STDOUT: %tuple: %tuple.type.c8c = tuple_value (%empty_struct, %Noncopyable) [concrete]
  390. // CHECK:STDOUT: %tuple.type.037: type = tuple_type (%empty_struct_type, %Noncopyable) [concrete]
  391. // CHECK:STDOUT: %pattern_type: type = pattern_type %A [concrete]
  392. // CHECK:STDOUT: }
  393. // CHECK:STDOUT:
  394. // CHECK:STDOUT: imports {
  395. // CHECK:STDOUT: }
  396. // CHECK:STDOUT:
  397. // CHECK:STDOUT: fn @F(%a.param: %A) {
  398. // CHECK:STDOUT: !entry:
  399. // CHECK:STDOUT: name_binding_decl {
  400. // CHECK:STDOUT: %a_value.patt: %pattern_type = value_binding_pattern a_value [concrete]
  401. // CHECK:STDOUT: }
  402. // CHECK:STDOUT: %a.ref: %A = name_ref a, %a
  403. // CHECK:STDOUT: %.loc14_28: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
  404. // CHECK:STDOUT: %Noncopyable.ref: type = name_ref Noncopyable, file.%Noncopyable.decl [concrete = constants.%Noncopyable]
  405. // CHECK:STDOUT: %.loc14_42.1: %tuple.type.c8c = tuple_literal (%.loc14_28, %Noncopyable.ref) [concrete = constants.%tuple]
  406. // CHECK:STDOUT: %.loc14_42.2: type = converted constants.%empty_struct, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  407. // CHECK:STDOUT: %.loc14_42.3: type = converted %.loc14_42.1, constants.%tuple.type.037 [concrete = constants.%tuple.type.037]
  408. // CHECK:STDOUT: %.loc14_23.1: %tuple.type.037 = as_compatible %a.ref
  409. // CHECK:STDOUT: %.loc14_23.2: %tuple.type.037 = converted %a.ref, %.loc14_23.1
  410. // CHECK:STDOUT: %A.ref.loc14_48: type = name_ref A, file.%A.decl [concrete = constants.%A]
  411. // CHECK:STDOUT: %.loc14_45.1: %A = as_compatible %.loc14_23.2
  412. // CHECK:STDOUT: %.loc14_45.2: %A = converted %.loc14_23.2, %.loc14_45.1
  413. // CHECK:STDOUT: %A.ref.loc14_16: type = name_ref A, file.%A.decl [concrete = constants.%A]
  414. // CHECK:STDOUT: %a_value: %A = value_binding a_value, %.loc14_45.2
  415. // CHECK:STDOUT: <elided>
  416. // CHECK:STDOUT: }
  417. // CHECK:STDOUT: