init_adapt.carbon 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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/class/adapter/init_adapt.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/adapter/init_adapt.carbon
  10. // --- init_adapt.carbon
  11. library "[[@TEST_NAME]]";
  12. class C {
  13. var a: i32;
  14. var b: i32;
  15. }
  16. class AdaptC {
  17. adapt C;
  18. }
  19. let a: C = {.a = 1, .b = 2};
  20. let b: AdaptC = a as AdaptC;
  21. let c: C = b as C;
  22. fn MakeC() -> C;
  23. fn MakeAdaptC() -> AdaptC;
  24. var d: AdaptC = MakeC() as AdaptC;
  25. var e: C = MakeAdaptC() as C;
  26. // --- fail_not_implicit.carbon
  27. library "[[@TEST_NAME]]";
  28. class C {
  29. var a: i32;
  30. var b: i32;
  31. }
  32. class AdaptC {
  33. adapt C;
  34. }
  35. let a: C = {.a = 1, .b = 2};
  36. // Cannot implicitly convert between a type and an adapter for the type.
  37. // CHECK:STDERR: fail_not_implicit.carbon:[[@LINE+7]]:17: error: cannot implicitly convert from `C` to `AdaptC` [ImplicitAsConversionFailure]
  38. // CHECK:STDERR: let b: AdaptC = a;
  39. // CHECK:STDERR: ^
  40. // CHECK:STDERR: fail_not_implicit.carbon:[[@LINE+4]]:17: note: type `C` does not implement interface `Core.ImplicitAs(AdaptC)` [MissingImplInMemberAccessNote]
  41. // CHECK:STDERR: let b: AdaptC = a;
  42. // CHECK:STDERR: ^
  43. // CHECK:STDERR:
  44. let b: AdaptC = a;
  45. // CHECK:STDERR: fail_not_implicit.carbon:[[@LINE+7]]:12: error: cannot implicitly convert from `AdaptC` to `C` [ImplicitAsConversionFailure]
  46. // CHECK:STDERR: let c: C = b;
  47. // CHECK:STDERR: ^
  48. // CHECK:STDERR: fail_not_implicit.carbon:[[@LINE+4]]:12: note: type `AdaptC` does not implement interface `Core.ImplicitAs(C)` [MissingImplInMemberAccessNote]
  49. // CHECK:STDERR: let c: C = b;
  50. // CHECK:STDERR: ^
  51. // CHECK:STDERR:
  52. let c: C = b;
  53. fn MakeC() -> C;
  54. fn MakeAdaptC() -> AdaptC;
  55. // CHECK:STDERR: fail_not_implicit.carbon:[[@LINE+7]]:1: error: cannot implicitly convert from `C` to `AdaptC` [ImplicitAsConversionFailure]
  56. // CHECK:STDERR: var d: AdaptC = MakeC();
  57. // CHECK:STDERR: ^~~~~~~~~~~~~
  58. // CHECK:STDERR: fail_not_implicit.carbon:[[@LINE+4]]:1: note: type `C` does not implement interface `Core.ImplicitAs(AdaptC)` [MissingImplInMemberAccessNote]
  59. // CHECK:STDERR: var d: AdaptC = MakeC();
  60. // CHECK:STDERR: ^~~~~~~~~~~~~
  61. // CHECK:STDERR:
  62. var d: AdaptC = MakeC();
  63. // CHECK:STDERR: fail_not_implicit.carbon:[[@LINE+7]]:1: error: cannot implicitly convert from `AdaptC` to `C` [ImplicitAsConversionFailure]
  64. // CHECK:STDERR: var e: C = MakeAdaptC();
  65. // CHECK:STDERR: ^~~~~~~~
  66. // CHECK:STDERR: fail_not_implicit.carbon:[[@LINE+4]]:1: note: type `AdaptC` does not implement interface `Core.ImplicitAs(C)` [MissingImplInMemberAccessNote]
  67. // CHECK:STDERR: var e: C = MakeAdaptC();
  68. // CHECK:STDERR: ^~~~~~~~
  69. // CHECK:STDERR:
  70. var e: C = MakeAdaptC();
  71. // CHECK:STDOUT: --- init_adapt.carbon
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: constants {
  74. // CHECK:STDOUT: %C: type = class_type @C [template]
  75. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  76. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  77. // CHECK:STDOUT: %C.elem: type = unbound_element_type %C, %i32 [template]
  78. // CHECK:STDOUT: %struct_type.a.b.501: type = struct_type {.a: %i32, .b: %i32} [template]
  79. // CHECK:STDOUT: %complete_type.705: <witness> = complete_type_witness %struct_type.a.b.501 [template]
  80. // CHECK:STDOUT: %AdaptC: type = class_type @AdaptC [template]
  81. // CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [template]
  82. // CHECK:STDOUT: %int_2.ecc: Core.IntLiteral = int_value 2 [template]
  83. // CHECK:STDOUT: %struct_type.a.b.cfd: type = struct_type {.a: Core.IntLiteral, .b: Core.IntLiteral} [template]
  84. // CHECK:STDOUT: %ImplicitAs.type.205: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [template]
  85. // CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  86. // CHECK:STDOUT: %impl_witness.d39: <witness> = impl_witness (imports.%Core.import_ref.a5b), @impl.1(%int_32) [template]
  87. // CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.1(%int_32) [template]
  88. // CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [template]
  89. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.205 = facet_value Core.IntLiteral, %impl_witness.d39 [template]
  90. // CHECK:STDOUT: %.a0b: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet [template]
  91. // CHECK:STDOUT: %Convert.bound.ab5: <bound method> = bound_method %int_1.5b8, %Convert.956 [template]
  92. // CHECK:STDOUT: %Convert.specific_fn.70c: <specific function> = specific_function %Convert.bound.ab5, @Convert.2(%int_32) [template]
  93. // CHECK:STDOUT: %int_1.5d2: %i32 = int_value 1 [template]
  94. // CHECK:STDOUT: %Convert.bound.ef9: <bound method> = bound_method %int_2.ecc, %Convert.956 [template]
  95. // CHECK:STDOUT: %Convert.specific_fn.787: <specific function> = specific_function %Convert.bound.ef9, @Convert.2(%int_32) [template]
  96. // CHECK:STDOUT: %int_2.ef8: %i32 = int_value 2 [template]
  97. // CHECK:STDOUT: %C.val: %C = struct_value (%int_1.5d2, %int_2.ef8) [template]
  98. // CHECK:STDOUT: %MakeC.type: type = fn_type @MakeC [template]
  99. // CHECK:STDOUT: %MakeC: %MakeC.type = struct_value () [template]
  100. // CHECK:STDOUT: %MakeAdaptC.type: type = fn_type @MakeAdaptC [template]
  101. // CHECK:STDOUT: %MakeAdaptC: %MakeAdaptC.type = struct_value () [template]
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: imports {
  105. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  106. // CHECK:STDOUT: .Int = %Core.Int
  107. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  108. // CHECK:STDOUT: import Core//prelude
  109. // CHECK:STDOUT: import Core//prelude/...
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT:
  113. // CHECK:STDOUT: file {
  114. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  115. // CHECK:STDOUT: .Core = imports.%Core
  116. // CHECK:STDOUT: .C = %C.decl
  117. // CHECK:STDOUT: .AdaptC = %AdaptC.decl
  118. // CHECK:STDOUT: .a = %a
  119. // CHECK:STDOUT: .b = %b
  120. // CHECK:STDOUT: .c = %c
  121. // CHECK:STDOUT: .MakeC = %MakeC.decl
  122. // CHECK:STDOUT: .MakeAdaptC = %MakeAdaptC.decl
  123. // CHECK:STDOUT: .d = %d
  124. // CHECK:STDOUT: .e = %e
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT: %Core.import = import Core
  127. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  128. // CHECK:STDOUT: %AdaptC.decl: type = class_decl @AdaptC [template = constants.%AdaptC] {} {}
  129. // CHECK:STDOUT: name_binding_decl {
  130. // CHECK:STDOUT: %a.patt: %C = binding_pattern a
  131. // CHECK:STDOUT: }
  132. // CHECK:STDOUT: %C.ref.loc13: type = name_ref C, %C.decl [template = constants.%C]
  133. // CHECK:STDOUT: %impl.elem0.loc13_27.1: %.a0b = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
  134. // CHECK:STDOUT: %bound_method.loc13_27.1: <bound method> = bound_method @__global_init.%int_1, %impl.elem0.loc13_27.1 [template = constants.%Convert.bound.ab5]
  135. // CHECK:STDOUT: %specific_fn.loc13_27.1: <specific function> = specific_function %bound_method.loc13_27.1, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.70c]
  136. // CHECK:STDOUT: %int.convert_checked.loc13_27.1: init %i32 = call %specific_fn.loc13_27.1(@__global_init.%int_1) [template = constants.%int_1.5d2]
  137. // CHECK:STDOUT: %.loc13_27.1: init %i32 = converted @__global_init.%int_1, %int.convert_checked.loc13_27.1 [template = constants.%int_1.5d2]
  138. // CHECK:STDOUT: %.loc13_27.2: ref %C = temporary_storage
  139. // CHECK:STDOUT: %.loc13_27.3: ref %i32 = class_element_access %.loc13_27.2, element0
  140. // CHECK:STDOUT: %.loc13_27.4: init %i32 = initialize_from %.loc13_27.1 to %.loc13_27.3 [template = constants.%int_1.5d2]
  141. // CHECK:STDOUT: %impl.elem0.loc13_27.2: %.a0b = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
  142. // CHECK:STDOUT: %bound_method.loc13_27.2: <bound method> = bound_method @__global_init.%int_2, %impl.elem0.loc13_27.2 [template = constants.%Convert.bound.ef9]
  143. // CHECK:STDOUT: %specific_fn.loc13_27.2: <specific function> = specific_function %bound_method.loc13_27.2, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.787]
  144. // CHECK:STDOUT: %int.convert_checked.loc13_27.2: init %i32 = call %specific_fn.loc13_27.2(@__global_init.%int_2) [template = constants.%int_2.ef8]
  145. // CHECK:STDOUT: %.loc13_27.5: init %i32 = converted @__global_init.%int_2, %int.convert_checked.loc13_27.2 [template = constants.%int_2.ef8]
  146. // CHECK:STDOUT: %.loc13_27.6: ref %i32 = class_element_access %.loc13_27.2, element1
  147. // CHECK:STDOUT: %.loc13_27.7: init %i32 = initialize_from %.loc13_27.5 to %.loc13_27.6 [template = constants.%int_2.ef8]
  148. // CHECK:STDOUT: %.loc13_27.8: init %C = class_init (%.loc13_27.4, %.loc13_27.7), %.loc13_27.2 [template = constants.%C.val]
  149. // CHECK:STDOUT: %.loc13_27.9: ref %C = temporary %.loc13_27.2, %.loc13_27.8
  150. // CHECK:STDOUT: %.loc13_27.10: ref %C = converted @__global_init.%.loc13, %.loc13_27.9
  151. // CHECK:STDOUT: %a: ref %C = bind_name a, %.loc13_27.10
  152. // CHECK:STDOUT: name_binding_decl {
  153. // CHECK:STDOUT: %b.patt: %AdaptC = binding_pattern b
  154. // CHECK:STDOUT: }
  155. // CHECK:STDOUT: %AdaptC.ref.loc15: type = name_ref AdaptC, %AdaptC.decl [template = constants.%AdaptC]
  156. // CHECK:STDOUT: %b: ref %AdaptC = bind_name b, @__global_init.%.loc15_19.2
  157. // CHECK:STDOUT: name_binding_decl {
  158. // CHECK:STDOUT: %c.patt: %C = binding_pattern c
  159. // CHECK:STDOUT: }
  160. // CHECK:STDOUT: %C.ref.loc17: type = name_ref C, %C.decl [template = constants.%C]
  161. // CHECK:STDOUT: %c: ref %C = bind_name c, @__global_init.%.loc17_14.2
  162. // CHECK:STDOUT: %MakeC.decl: %MakeC.type = fn_decl @MakeC [template = constants.%MakeC] {
  163. // CHECK:STDOUT: %return.patt: %C = return_slot_pattern
  164. // CHECK:STDOUT: %return.param_patt: %C = out_param_pattern %return.patt, runtime_param0
  165. // CHECK:STDOUT: } {
  166. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  167. // CHECK:STDOUT: %return.param: ref %C = out_param runtime_param0
  168. // CHECK:STDOUT: %return: ref %C = return_slot %return.param
  169. // CHECK:STDOUT: }
  170. // CHECK:STDOUT: %MakeAdaptC.decl: %MakeAdaptC.type = fn_decl @MakeAdaptC [template = constants.%MakeAdaptC] {
  171. // CHECK:STDOUT: %return.patt: %AdaptC = return_slot_pattern
  172. // CHECK:STDOUT: %return.param_patt: %AdaptC = out_param_pattern %return.patt, runtime_param0
  173. // CHECK:STDOUT: } {
  174. // CHECK:STDOUT: %AdaptC.ref: type = name_ref AdaptC, file.%AdaptC.decl [template = constants.%AdaptC]
  175. // CHECK:STDOUT: %return.param: ref %AdaptC = out_param runtime_param0
  176. // CHECK:STDOUT: %return: ref %AdaptC = return_slot %return.param
  177. // CHECK:STDOUT: }
  178. // CHECK:STDOUT: name_binding_decl {
  179. // CHECK:STDOUT: %d.patt: %AdaptC = binding_pattern d
  180. // CHECK:STDOUT: %.loc23: %AdaptC = var_pattern %d.patt
  181. // CHECK:STDOUT: }
  182. // CHECK:STDOUT: %d.var: ref %AdaptC = var d
  183. // CHECK:STDOUT: %AdaptC.ref.loc23: type = name_ref AdaptC, %AdaptC.decl [template = constants.%AdaptC]
  184. // CHECK:STDOUT: %d: ref %AdaptC = bind_name d, %d.var
  185. // CHECK:STDOUT: name_binding_decl {
  186. // CHECK:STDOUT: %e.patt: %C = binding_pattern e
  187. // CHECK:STDOUT: %.loc25: %C = var_pattern %e.patt
  188. // CHECK:STDOUT: }
  189. // CHECK:STDOUT: %e.var: ref %C = var e
  190. // CHECK:STDOUT: %C.ref.loc25: type = name_ref C, %C.decl [template = constants.%C]
  191. // CHECK:STDOUT: %e: ref %C = bind_name e, %e.var
  192. // CHECK:STDOUT: }
  193. // CHECK:STDOUT:
  194. // CHECK:STDOUT: class @C {
  195. // CHECK:STDOUT: %.loc5_8: %C.elem = field_decl a, element0 [template]
  196. // CHECK:STDOUT: name_binding_decl {
  197. // CHECK:STDOUT: %.loc5_3: %C.elem = var_pattern %.loc5_8
  198. // CHECK:STDOUT: }
  199. // CHECK:STDOUT: %.var.loc5: ref %C.elem = var <none>
  200. // CHECK:STDOUT: %.loc6_8: %C.elem = field_decl b, element1 [template]
  201. // CHECK:STDOUT: name_binding_decl {
  202. // CHECK:STDOUT: %.loc6_3: %C.elem = var_pattern %.loc6_8
  203. // CHECK:STDOUT: }
  204. // CHECK:STDOUT: %.var.loc6: ref %C.elem = var <none>
  205. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.a.b.501 [template = constants.%complete_type.705]
  206. // CHECK:STDOUT: complete_type_witness = %complete_type
  207. // CHECK:STDOUT:
  208. // CHECK:STDOUT: !members:
  209. // CHECK:STDOUT: .Self = constants.%C
  210. // CHECK:STDOUT: .a = %.loc5_8
  211. // CHECK:STDOUT: .b = %.loc6_8
  212. // CHECK:STDOUT: }
  213. // CHECK:STDOUT:
  214. // CHECK:STDOUT: class @AdaptC {
  215. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  216. // CHECK:STDOUT: adapt_decl %C.ref [template]
  217. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.a.b.501 [template = constants.%complete_type.705]
  218. // CHECK:STDOUT: complete_type_witness = %complete_type
  219. // CHECK:STDOUT:
  220. // CHECK:STDOUT: !members:
  221. // CHECK:STDOUT: .Self = constants.%AdaptC
  222. // CHECK:STDOUT: }
  223. // CHECK:STDOUT:
  224. // CHECK:STDOUT: fn @MakeC() -> %C;
  225. // CHECK:STDOUT:
  226. // CHECK:STDOUT: fn @MakeAdaptC() -> %AdaptC;
  227. // CHECK:STDOUT:
  228. // CHECK:STDOUT: fn @__global_init() {
  229. // CHECK:STDOUT: !entry:
  230. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1.5b8]
  231. // CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [template = constants.%int_2.ecc]
  232. // CHECK:STDOUT: %.loc13: %struct_type.a.b.cfd = struct_literal (%int_1, %int_2)
  233. // CHECK:STDOUT: %a.ref: ref %C = name_ref a, file.%a
  234. // CHECK:STDOUT: %AdaptC.ref.loc15: type = name_ref AdaptC, file.%AdaptC.decl [template = constants.%AdaptC]
  235. // CHECK:STDOUT: %.loc15_19.1: ref %AdaptC = as_compatible %a.ref
  236. // CHECK:STDOUT: %.loc15_19.2: ref %AdaptC = converted %a.ref, %.loc15_19.1
  237. // CHECK:STDOUT: %b.ref: ref %AdaptC = name_ref b, file.%b
  238. // CHECK:STDOUT: %C.ref.loc17: type = name_ref C, file.%C.decl [template = constants.%C]
  239. // CHECK:STDOUT: %.loc17_14.1: ref %C = as_compatible %b.ref
  240. // CHECK:STDOUT: %.loc17_14.2: ref %C = converted %b.ref, %.loc17_14.1
  241. // CHECK:STDOUT: %MakeC.ref: %MakeC.type = name_ref MakeC, file.%MakeC.decl [template = constants.%MakeC]
  242. // CHECK:STDOUT: %.loc23_1: ref %AdaptC = splice_block file.%d.var {}
  243. // CHECK:STDOUT: %MakeC.call: init %C = call %MakeC.ref() to %.loc23_1
  244. // CHECK:STDOUT: %AdaptC.ref.loc23: type = name_ref AdaptC, file.%AdaptC.decl [template = constants.%AdaptC]
  245. // CHECK:STDOUT: %.loc23_25.1: init %AdaptC = as_compatible %MakeC.call
  246. // CHECK:STDOUT: %.loc23_25.2: init %AdaptC = converted %MakeC.call, %.loc23_25.1
  247. // CHECK:STDOUT: assign file.%d.var, %.loc23_25.2
  248. // CHECK:STDOUT: %MakeAdaptC.ref: %MakeAdaptC.type = name_ref MakeAdaptC, file.%MakeAdaptC.decl [template = constants.%MakeAdaptC]
  249. // CHECK:STDOUT: %.loc25_1: ref %C = splice_block file.%e.var {}
  250. // CHECK:STDOUT: %MakeAdaptC.call: init %AdaptC = call %MakeAdaptC.ref() to %.loc25_1
  251. // CHECK:STDOUT: %C.ref.loc25: type = name_ref C, file.%C.decl [template = constants.%C]
  252. // CHECK:STDOUT: %.loc25_25.1: init %C = as_compatible %MakeAdaptC.call
  253. // CHECK:STDOUT: %.loc25_25.2: init %C = converted %MakeAdaptC.call, %.loc25_25.1
  254. // CHECK:STDOUT: assign file.%e.var, %.loc25_25.2
  255. // CHECK:STDOUT: return
  256. // CHECK:STDOUT: }
  257. // CHECK:STDOUT:
  258. // CHECK:STDOUT: --- fail_not_implicit.carbon
  259. // CHECK:STDOUT:
  260. // CHECK:STDOUT: constants {
  261. // CHECK:STDOUT: %C: type = class_type @C [template]
  262. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  263. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  264. // CHECK:STDOUT: %C.elem: type = unbound_element_type %C, %i32 [template]
  265. // CHECK:STDOUT: %struct_type.a.b.501: type = struct_type {.a: %i32, .b: %i32} [template]
  266. // CHECK:STDOUT: %complete_type.705: <witness> = complete_type_witness %struct_type.a.b.501 [template]
  267. // CHECK:STDOUT: %AdaptC: type = class_type @AdaptC [template]
  268. // CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [template]
  269. // CHECK:STDOUT: %int_2.ecc: Core.IntLiteral = int_value 2 [template]
  270. // CHECK:STDOUT: %struct_type.a.b.cfd: type = struct_type {.a: Core.IntLiteral, .b: Core.IntLiteral} [template]
  271. // CHECK:STDOUT: %ImplicitAs.type.205: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [template]
  272. // CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  273. // CHECK:STDOUT: %impl_witness.d39: <witness> = impl_witness (imports.%Core.import_ref.a5b), @impl.1(%int_32) [template]
  274. // CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.1(%int_32) [template]
  275. // CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [template]
  276. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.205 = facet_value Core.IntLiteral, %impl_witness.d39 [template]
  277. // CHECK:STDOUT: %.a0b: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet [template]
  278. // CHECK:STDOUT: %Convert.bound.ab5: <bound method> = bound_method %int_1.5b8, %Convert.956 [template]
  279. // CHECK:STDOUT: %Convert.specific_fn.70c: <specific function> = specific_function %Convert.bound.ab5, @Convert.2(%int_32) [template]
  280. // CHECK:STDOUT: %int_1.5d2: %i32 = int_value 1 [template]
  281. // CHECK:STDOUT: %Convert.bound.ef9: <bound method> = bound_method %int_2.ecc, %Convert.956 [template]
  282. // CHECK:STDOUT: %Convert.specific_fn.787: <specific function> = specific_function %Convert.bound.ef9, @Convert.2(%int_32) [template]
  283. // CHECK:STDOUT: %int_2.ef8: %i32 = int_value 2 [template]
  284. // CHECK:STDOUT: %C.val: %C = struct_value (%int_1.5d2, %int_2.ef8) [template]
  285. // CHECK:STDOUT: %MakeC.type: type = fn_type @MakeC [template]
  286. // CHECK:STDOUT: %MakeC: %MakeC.type = struct_value () [template]
  287. // CHECK:STDOUT: %MakeAdaptC.type: type = fn_type @MakeAdaptC [template]
  288. // CHECK:STDOUT: %MakeAdaptC: %MakeAdaptC.type = struct_value () [template]
  289. // CHECK:STDOUT: }
  290. // CHECK:STDOUT:
  291. // CHECK:STDOUT: imports {
  292. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  293. // CHECK:STDOUT: .Int = %Core.Int
  294. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  295. // CHECK:STDOUT: import Core//prelude
  296. // CHECK:STDOUT: import Core//prelude/...
  297. // CHECK:STDOUT: }
  298. // CHECK:STDOUT: }
  299. // CHECK:STDOUT:
  300. // CHECK:STDOUT: file {
  301. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  302. // CHECK:STDOUT: .Core = imports.%Core
  303. // CHECK:STDOUT: .C = %C.decl
  304. // CHECK:STDOUT: .AdaptC = %AdaptC.decl
  305. // CHECK:STDOUT: .a = %a
  306. // CHECK:STDOUT: .b = %b
  307. // CHECK:STDOUT: .c = %c
  308. // CHECK:STDOUT: .MakeC = %MakeC.decl
  309. // CHECK:STDOUT: .MakeAdaptC = %MakeAdaptC.decl
  310. // CHECK:STDOUT: .d = %d
  311. // CHECK:STDOUT: .e = %e
  312. // CHECK:STDOUT: }
  313. // CHECK:STDOUT: %Core.import = import Core
  314. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  315. // CHECK:STDOUT: %AdaptC.decl: type = class_decl @AdaptC [template = constants.%AdaptC] {} {}
  316. // CHECK:STDOUT: name_binding_decl {
  317. // CHECK:STDOUT: %a.patt: %C = binding_pattern a
  318. // CHECK:STDOUT: }
  319. // CHECK:STDOUT: %C.ref.loc13: type = name_ref C, %C.decl [template = constants.%C]
  320. // CHECK:STDOUT: %impl.elem0.loc13_27.1: %.a0b = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
  321. // CHECK:STDOUT: %bound_method.loc13_27.1: <bound method> = bound_method @__global_init.%int_1, %impl.elem0.loc13_27.1 [template = constants.%Convert.bound.ab5]
  322. // CHECK:STDOUT: %specific_fn.loc13_27.1: <specific function> = specific_function %bound_method.loc13_27.1, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.70c]
  323. // CHECK:STDOUT: %int.convert_checked.loc13_27.1: init %i32 = call %specific_fn.loc13_27.1(@__global_init.%int_1) [template = constants.%int_1.5d2]
  324. // CHECK:STDOUT: %.loc13_27.1: init %i32 = converted @__global_init.%int_1, %int.convert_checked.loc13_27.1 [template = constants.%int_1.5d2]
  325. // CHECK:STDOUT: %.loc13_27.2: ref %C = temporary_storage
  326. // CHECK:STDOUT: %.loc13_27.3: ref %i32 = class_element_access %.loc13_27.2, element0
  327. // CHECK:STDOUT: %.loc13_27.4: init %i32 = initialize_from %.loc13_27.1 to %.loc13_27.3 [template = constants.%int_1.5d2]
  328. // CHECK:STDOUT: %impl.elem0.loc13_27.2: %.a0b = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
  329. // CHECK:STDOUT: %bound_method.loc13_27.2: <bound method> = bound_method @__global_init.%int_2, %impl.elem0.loc13_27.2 [template = constants.%Convert.bound.ef9]
  330. // CHECK:STDOUT: %specific_fn.loc13_27.2: <specific function> = specific_function %bound_method.loc13_27.2, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.787]
  331. // CHECK:STDOUT: %int.convert_checked.loc13_27.2: init %i32 = call %specific_fn.loc13_27.2(@__global_init.%int_2) [template = constants.%int_2.ef8]
  332. // CHECK:STDOUT: %.loc13_27.5: init %i32 = converted @__global_init.%int_2, %int.convert_checked.loc13_27.2 [template = constants.%int_2.ef8]
  333. // CHECK:STDOUT: %.loc13_27.6: ref %i32 = class_element_access %.loc13_27.2, element1
  334. // CHECK:STDOUT: %.loc13_27.7: init %i32 = initialize_from %.loc13_27.5 to %.loc13_27.6 [template = constants.%int_2.ef8]
  335. // CHECK:STDOUT: %.loc13_27.8: init %C = class_init (%.loc13_27.4, %.loc13_27.7), %.loc13_27.2 [template = constants.%C.val]
  336. // CHECK:STDOUT: %.loc13_27.9: ref %C = temporary %.loc13_27.2, %.loc13_27.8
  337. // CHECK:STDOUT: %.loc13_27.10: ref %C = converted @__global_init.%.loc13, %.loc13_27.9
  338. // CHECK:STDOUT: %a: ref %C = bind_name a, %.loc13_27.10
  339. // CHECK:STDOUT: name_binding_decl {
  340. // CHECK:STDOUT: %b.patt: %AdaptC = binding_pattern b
  341. // CHECK:STDOUT: }
  342. // CHECK:STDOUT: %AdaptC.ref.loc24: type = name_ref AdaptC, %AdaptC.decl [template = constants.%AdaptC]
  343. // CHECK:STDOUT: %.loc24: %AdaptC = converted @__global_init.%a.ref, <error> [template = <error>]
  344. // CHECK:STDOUT: %b: %AdaptC = bind_name b, <error>
  345. // CHECK:STDOUT: name_binding_decl {
  346. // CHECK:STDOUT: %c.patt: %C = binding_pattern c
  347. // CHECK:STDOUT: }
  348. // CHECK:STDOUT: %C.ref.loc33: type = name_ref C, %C.decl [template = constants.%C]
  349. // CHECK:STDOUT: %.loc33: %C = converted @__global_init.%b.ref, <error> [template = <error>]
  350. // CHECK:STDOUT: %c: %C = bind_name c, <error>
  351. // CHECK:STDOUT: %MakeC.decl: %MakeC.type = fn_decl @MakeC [template = constants.%MakeC] {
  352. // CHECK:STDOUT: %return.patt: %C = return_slot_pattern
  353. // CHECK:STDOUT: %return.param_patt: %C = out_param_pattern %return.patt, runtime_param0
  354. // CHECK:STDOUT: } {
  355. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  356. // CHECK:STDOUT: %return.param: ref %C = out_param runtime_param0
  357. // CHECK:STDOUT: %return: ref %C = return_slot %return.param
  358. // CHECK:STDOUT: }
  359. // CHECK:STDOUT: %MakeAdaptC.decl: %MakeAdaptC.type = fn_decl @MakeAdaptC [template = constants.%MakeAdaptC] {
  360. // CHECK:STDOUT: %return.patt: %AdaptC = return_slot_pattern
  361. // CHECK:STDOUT: %return.param_patt: %AdaptC = out_param_pattern %return.patt, runtime_param0
  362. // CHECK:STDOUT: } {
  363. // CHECK:STDOUT: %AdaptC.ref: type = name_ref AdaptC, file.%AdaptC.decl [template = constants.%AdaptC]
  364. // CHECK:STDOUT: %return.param: ref %AdaptC = out_param runtime_param0
  365. // CHECK:STDOUT: %return: ref %AdaptC = return_slot %return.param
  366. // CHECK:STDOUT: }
  367. // CHECK:STDOUT: name_binding_decl {
  368. // CHECK:STDOUT: %d.patt: %AdaptC = binding_pattern d
  369. // CHECK:STDOUT: %.loc46: %AdaptC = var_pattern %d.patt
  370. // CHECK:STDOUT: }
  371. // CHECK:STDOUT: %d.var: ref %AdaptC = var d
  372. // CHECK:STDOUT: %AdaptC.ref.loc46: type = name_ref AdaptC, %AdaptC.decl [template = constants.%AdaptC]
  373. // CHECK:STDOUT: %d: ref %AdaptC = bind_name d, %d.var
  374. // CHECK:STDOUT: name_binding_decl {
  375. // CHECK:STDOUT: %e.patt: %C = binding_pattern e
  376. // CHECK:STDOUT: %.loc55: %C = var_pattern %e.patt
  377. // CHECK:STDOUT: }
  378. // CHECK:STDOUT: %e.var: ref %C = var e
  379. // CHECK:STDOUT: %C.ref.loc55: type = name_ref C, %C.decl [template = constants.%C]
  380. // CHECK:STDOUT: %e: ref %C = bind_name e, %e.var
  381. // CHECK:STDOUT: }
  382. // CHECK:STDOUT:
  383. // CHECK:STDOUT: class @C {
  384. // CHECK:STDOUT: %.loc5_8: %C.elem = field_decl a, element0 [template]
  385. // CHECK:STDOUT: name_binding_decl {
  386. // CHECK:STDOUT: %.loc5_3: %C.elem = var_pattern %.loc5_8
  387. // CHECK:STDOUT: }
  388. // CHECK:STDOUT: %.var.loc5: ref %C.elem = var <none>
  389. // CHECK:STDOUT: %.loc6_8: %C.elem = field_decl b, element1 [template]
  390. // CHECK:STDOUT: name_binding_decl {
  391. // CHECK:STDOUT: %.loc6_3: %C.elem = var_pattern %.loc6_8
  392. // CHECK:STDOUT: }
  393. // CHECK:STDOUT: %.var.loc6: ref %C.elem = var <none>
  394. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.a.b.501 [template = constants.%complete_type.705]
  395. // CHECK:STDOUT: complete_type_witness = %complete_type
  396. // CHECK:STDOUT:
  397. // CHECK:STDOUT: !members:
  398. // CHECK:STDOUT: .Self = constants.%C
  399. // CHECK:STDOUT: .a = %.loc5_8
  400. // CHECK:STDOUT: .b = %.loc6_8
  401. // CHECK:STDOUT: }
  402. // CHECK:STDOUT:
  403. // CHECK:STDOUT: class @AdaptC {
  404. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  405. // CHECK:STDOUT: adapt_decl %C.ref [template]
  406. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.a.b.501 [template = constants.%complete_type.705]
  407. // CHECK:STDOUT: complete_type_witness = %complete_type
  408. // CHECK:STDOUT:
  409. // CHECK:STDOUT: !members:
  410. // CHECK:STDOUT: .Self = constants.%AdaptC
  411. // CHECK:STDOUT: }
  412. // CHECK:STDOUT:
  413. // CHECK:STDOUT: fn @MakeC() -> %C;
  414. // CHECK:STDOUT:
  415. // CHECK:STDOUT: fn @MakeAdaptC() -> %AdaptC;
  416. // CHECK:STDOUT:
  417. // CHECK:STDOUT: fn @__global_init() {
  418. // CHECK:STDOUT: !entry:
  419. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1.5b8]
  420. // CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [template = constants.%int_2.ecc]
  421. // CHECK:STDOUT: %.loc13: %struct_type.a.b.cfd = struct_literal (%int_1, %int_2)
  422. // CHECK:STDOUT: %a.ref: ref %C = name_ref a, file.%a
  423. // CHECK:STDOUT: %b.ref: %AdaptC = name_ref b, file.%b
  424. // CHECK:STDOUT: %MakeC.ref: %MakeC.type = name_ref MakeC, file.%MakeC.decl [template = constants.%MakeC]
  425. // CHECK:STDOUT: %.loc46_23: ref %C = temporary_storage
  426. // CHECK:STDOUT: %MakeC.call: init %C = call %MakeC.ref() to %.loc46_23
  427. // CHECK:STDOUT: %.loc46_1: %AdaptC = converted %MakeC.call, <error> [template = <error>]
  428. // CHECK:STDOUT: assign file.%d.var, <error>
  429. // CHECK:STDOUT: %MakeAdaptC.ref: %MakeAdaptC.type = name_ref MakeAdaptC, file.%MakeAdaptC.decl [template = constants.%MakeAdaptC]
  430. // CHECK:STDOUT: %.loc55_23: ref %AdaptC = temporary_storage
  431. // CHECK:STDOUT: %MakeAdaptC.call: init %AdaptC = call %MakeAdaptC.ref() to %.loc55_23
  432. // CHECK:STDOUT: %.loc55_1: %C = converted %MakeAdaptC.call, <error> [template = <error>]
  433. // CHECK:STDOUT: assign file.%e.var, <error>
  434. // CHECK:STDOUT: return
  435. // CHECK:STDOUT: }
  436. // CHECK:STDOUT: