init_adapt.carbon 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  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/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/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]]:1: error: cannot implicitly convert from `C` to `AdaptC`
  38. // CHECK:STDERR: let b: AdaptC = a;
  39. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~
  40. // CHECK:STDERR: fail_not_implicit.carbon:[[@LINE+4]]:1: note: type `C` does not implement interface `ImplicitAs`
  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]]:1: error: cannot implicitly convert from `AdaptC` to `C`
  46. // CHECK:STDERR: let c: C = b;
  47. // CHECK:STDERR: ^~~~~~~~~~~~~
  48. // CHECK:STDERR: fail_not_implicit.carbon:[[@LINE+4]]:1: note: type `<error>` does not implement interface `ImplicitAs`
  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`
  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 `ImplicitAs`
  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+6]]:1: error: cannot implicitly convert from `AdaptC` to `C`
  64. // CHECK:STDERR: var e: C = MakeAdaptC();
  65. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~
  66. // CHECK:STDERR: fail_not_implicit.carbon:[[@LINE+3]]:1: note: type `AdaptC` does not implement interface `ImplicitAs`
  67. // CHECK:STDERR: var e: C = MakeAdaptC();
  68. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~
  69. var e: C = MakeAdaptC();
  70. // CHECK:STDOUT: --- init_adapt.carbon
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: constants {
  73. // CHECK:STDOUT: %C: type = class_type @C [template]
  74. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  75. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  76. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  77. // CHECK:STDOUT: %.2: type = unbound_element_type %C, i32 [template]
  78. // CHECK:STDOUT: %.3: type = struct_type {.a: i32, .b: i32} [template]
  79. // CHECK:STDOUT: %.4: <witness> = complete_type_witness %.3 [template]
  80. // CHECK:STDOUT: %AdaptC: type = class_type @AdaptC [template]
  81. // CHECK:STDOUT: %.5: type = ptr_type %.3 [template]
  82. // CHECK:STDOUT: %.6: <witness> = complete_type_witness %C [template]
  83. // CHECK:STDOUT: %.7: i32 = int_literal 1 [template]
  84. // CHECK:STDOUT: %.8: i32 = int_literal 2 [template]
  85. // CHECK:STDOUT: %struct: %C = struct_value (%.7, %.8) [template]
  86. // CHECK:STDOUT: %MakeC.type: type = fn_type @MakeC [template]
  87. // CHECK:STDOUT: %MakeC: %MakeC.type = struct_value () [template]
  88. // CHECK:STDOUT: %MakeAdaptC.type: type = fn_type @MakeAdaptC [template]
  89. // CHECK:STDOUT: %MakeAdaptC: %MakeAdaptC.type = struct_value () [template]
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: imports {
  93. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  94. // CHECK:STDOUT: .Int32 = %import_ref
  95. // CHECK:STDOUT: import Core//prelude
  96. // CHECK:STDOUT: import Core//prelude/operators
  97. // CHECK:STDOUT: import Core//prelude/types
  98. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  99. // CHECK:STDOUT: import Core//prelude/operators/as
  100. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  101. // CHECK:STDOUT: import Core//prelude/operators/comparison
  102. // CHECK:STDOUT: import Core//prelude/types/bool
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+9, loaded [template = constants.%Int32]
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: file {
  108. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  109. // CHECK:STDOUT: .Core = imports.%Core
  110. // CHECK:STDOUT: .C = %C.decl
  111. // CHECK:STDOUT: .AdaptC = %AdaptC.decl
  112. // CHECK:STDOUT: .a = @__global_init.%a
  113. // CHECK:STDOUT: .b = @__global_init.%b
  114. // CHECK:STDOUT: .c = @__global_init.%c
  115. // CHECK:STDOUT: .MakeC = %MakeC.decl
  116. // CHECK:STDOUT: .MakeAdaptC = %MakeAdaptC.decl
  117. // CHECK:STDOUT: .d = %d
  118. // CHECK:STDOUT: .e = %e
  119. // CHECK:STDOUT: }
  120. // CHECK:STDOUT: %Core.import = import Core
  121. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  122. // CHECK:STDOUT: %AdaptC.decl: type = class_decl @AdaptC [template = constants.%AdaptC] {} {}
  123. // CHECK:STDOUT: %C.ref.loc13: type = name_ref C, %C.decl [template = constants.%C]
  124. // CHECK:STDOUT: %AdaptC.ref.loc15: type = name_ref AdaptC, %AdaptC.decl [template = constants.%AdaptC]
  125. // CHECK:STDOUT: %C.ref.loc17: type = name_ref C, %C.decl [template = constants.%C]
  126. // CHECK:STDOUT: %MakeC.decl: %MakeC.type = fn_decl @MakeC [template = constants.%MakeC] {} {
  127. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  128. // CHECK:STDOUT: %return: ref %C = var <return slot>
  129. // CHECK:STDOUT: }
  130. // CHECK:STDOUT: %MakeAdaptC.decl: %MakeAdaptC.type = fn_decl @MakeAdaptC [template = constants.%MakeAdaptC] {} {
  131. // CHECK:STDOUT: %AdaptC.ref: type = name_ref AdaptC, file.%AdaptC.decl [template = constants.%AdaptC]
  132. // CHECK:STDOUT: %return: ref %AdaptC = var <return slot>
  133. // CHECK:STDOUT: }
  134. // CHECK:STDOUT: %AdaptC.ref.loc23: type = name_ref AdaptC, %AdaptC.decl [template = constants.%AdaptC]
  135. // CHECK:STDOUT: %d.var: ref %AdaptC = var d
  136. // CHECK:STDOUT: %d: ref %AdaptC = bind_name d, %d.var
  137. // CHECK:STDOUT: %C.ref.loc25: type = name_ref C, %C.decl [template = constants.%C]
  138. // CHECK:STDOUT: %e.var: ref %C = var e
  139. // CHECK:STDOUT: %e: ref %C = bind_name e, %e.var
  140. // CHECK:STDOUT: }
  141. // CHECK:STDOUT:
  142. // CHECK:STDOUT: class @C {
  143. // CHECK:STDOUT: %int.make_type_32.loc5: init type = call constants.%Int32() [template = i32]
  144. // CHECK:STDOUT: %.loc5_10.1: type = value_of_initializer %int.make_type_32.loc5 [template = i32]
  145. // CHECK:STDOUT: %.loc5_10.2: type = converted %int.make_type_32.loc5, %.loc5_10.1 [template = i32]
  146. // CHECK:STDOUT: %.loc5_8: %.2 = field_decl a, element0 [template]
  147. // CHECK:STDOUT: %int.make_type_32.loc6: init type = call constants.%Int32() [template = i32]
  148. // CHECK:STDOUT: %.loc6_10.1: type = value_of_initializer %int.make_type_32.loc6 [template = i32]
  149. // CHECK:STDOUT: %.loc6_10.2: type = converted %int.make_type_32.loc6, %.loc6_10.1 [template = i32]
  150. // CHECK:STDOUT: %.loc6_8: %.2 = field_decl b, element1 [template]
  151. // CHECK:STDOUT: %.loc7: <witness> = complete_type_witness %.3 [template = constants.%.4]
  152. // CHECK:STDOUT:
  153. // CHECK:STDOUT: !members:
  154. // CHECK:STDOUT: .Self = constants.%C
  155. // CHECK:STDOUT: .a = %.loc5_8
  156. // CHECK:STDOUT: .b = %.loc6_8
  157. // CHECK:STDOUT: }
  158. // CHECK:STDOUT:
  159. // CHECK:STDOUT: class @AdaptC {
  160. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  161. // CHECK:STDOUT: adapt_decl %C
  162. // CHECK:STDOUT: %.loc11: <witness> = complete_type_witness %C [template = constants.%.6]
  163. // CHECK:STDOUT:
  164. // CHECK:STDOUT: !members:
  165. // CHECK:STDOUT: .Self = constants.%AdaptC
  166. // CHECK:STDOUT: }
  167. // CHECK:STDOUT:
  168. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  169. // CHECK:STDOUT:
  170. // CHECK:STDOUT: fn @MakeC() -> %C;
  171. // CHECK:STDOUT:
  172. // CHECK:STDOUT: fn @MakeAdaptC() -> %AdaptC;
  173. // CHECK:STDOUT:
  174. // CHECK:STDOUT: fn @__global_init() {
  175. // CHECK:STDOUT: !entry:
  176. // CHECK:STDOUT: %.loc13_18: i32 = int_literal 1 [template = constants.%.7]
  177. // CHECK:STDOUT: %.loc13_26: i32 = int_literal 2 [template = constants.%.8]
  178. // CHECK:STDOUT: %.loc13_27.1: %.3 = struct_literal (%.loc13_18, %.loc13_26)
  179. // CHECK:STDOUT: %.loc13_27.2: ref %C = temporary_storage
  180. // CHECK:STDOUT: %.loc13_27.3: ref i32 = class_element_access %.loc13_27.2, element0
  181. // CHECK:STDOUT: %.loc13_27.4: init i32 = initialize_from %.loc13_18 to %.loc13_27.3 [template = constants.%.7]
  182. // CHECK:STDOUT: %.loc13_27.5: ref i32 = class_element_access %.loc13_27.2, element1
  183. // CHECK:STDOUT: %.loc13_27.6: init i32 = initialize_from %.loc13_26 to %.loc13_27.5 [template = constants.%.8]
  184. // CHECK:STDOUT: %.loc13_27.7: init %C = class_init (%.loc13_27.4, %.loc13_27.6), %.loc13_27.2 [template = constants.%struct]
  185. // CHECK:STDOUT: %.loc13_27.8: ref %C = temporary %.loc13_27.2, %.loc13_27.7
  186. // CHECK:STDOUT: %.loc13_28.1: ref %C = converted %.loc13_27.1, %.loc13_27.8
  187. // CHECK:STDOUT: %.loc13_28.2: %C = bind_value %.loc13_28.1
  188. // CHECK:STDOUT: %a: %C = bind_name a, %.loc13_28.2
  189. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  190. // CHECK:STDOUT: %AdaptC.ref.loc15: type = name_ref AdaptC, file.%AdaptC.decl [template = constants.%AdaptC]
  191. // CHECK:STDOUT: %.loc15_19.1: %AdaptC = as_compatible %a.ref
  192. // CHECK:STDOUT: %.loc15_19.2: %AdaptC = converted %a.ref, %.loc15_19.1
  193. // CHECK:STDOUT: %b: %AdaptC = bind_name b, %.loc15_19.2
  194. // CHECK:STDOUT: %b.ref: %AdaptC = name_ref b, %b
  195. // CHECK:STDOUT: %C.ref.loc17: type = name_ref C, file.%C.decl [template = constants.%C]
  196. // CHECK:STDOUT: %.loc17_14.1: %C = as_compatible %b.ref
  197. // CHECK:STDOUT: %.loc17_14.2: %C = converted %b.ref, %.loc17_14.1
  198. // CHECK:STDOUT: %c: %C = bind_name c, %.loc17_14.2
  199. // CHECK:STDOUT: %MakeC.ref: %MakeC.type = name_ref MakeC, file.%MakeC.decl [template = constants.%MakeC]
  200. // CHECK:STDOUT: %.loc23_5: ref %AdaptC = splice_block file.%d.var {}
  201. // CHECK:STDOUT: %MakeC.call: init %C = call %MakeC.ref() to %.loc23_5
  202. // CHECK:STDOUT: %AdaptC.ref.loc23: type = name_ref AdaptC, file.%AdaptC.decl [template = constants.%AdaptC]
  203. // CHECK:STDOUT: %.loc23_25.1: init %AdaptC = as_compatible %MakeC.call
  204. // CHECK:STDOUT: %.loc23_25.2: init %AdaptC = converted %MakeC.call, %.loc23_25.1
  205. // CHECK:STDOUT: assign file.%d.var, %.loc23_25.2
  206. // CHECK:STDOUT: %MakeAdaptC.ref: %MakeAdaptC.type = name_ref MakeAdaptC, file.%MakeAdaptC.decl [template = constants.%MakeAdaptC]
  207. // CHECK:STDOUT: %.loc25_5: ref %C = splice_block file.%e.var {}
  208. // CHECK:STDOUT: %MakeAdaptC.call: init %AdaptC = call %MakeAdaptC.ref() to %.loc25_5
  209. // CHECK:STDOUT: %C.ref.loc25: type = name_ref C, file.%C.decl [template = constants.%C]
  210. // CHECK:STDOUT: %.loc25_25.1: init %C = as_compatible %MakeAdaptC.call
  211. // CHECK:STDOUT: %.loc25_25.2: init %C = converted %MakeAdaptC.call, %.loc25_25.1
  212. // CHECK:STDOUT: assign file.%e.var, %.loc25_25.2
  213. // CHECK:STDOUT: return
  214. // CHECK:STDOUT: }
  215. // CHECK:STDOUT:
  216. // CHECK:STDOUT: --- fail_not_implicit.carbon
  217. // CHECK:STDOUT:
  218. // CHECK:STDOUT: constants {
  219. // CHECK:STDOUT: %C: type = class_type @C [template]
  220. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  221. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  222. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  223. // CHECK:STDOUT: %.2: type = unbound_element_type %C, i32 [template]
  224. // CHECK:STDOUT: %.3: type = struct_type {.a: i32, .b: i32} [template]
  225. // CHECK:STDOUT: %.4: <witness> = complete_type_witness %.3 [template]
  226. // CHECK:STDOUT: %AdaptC: type = class_type @AdaptC [template]
  227. // CHECK:STDOUT: %.5: type = ptr_type %.3 [template]
  228. // CHECK:STDOUT: %.6: <witness> = complete_type_witness %C [template]
  229. // CHECK:STDOUT: %.7: i32 = int_literal 1 [template]
  230. // CHECK:STDOUT: %.8: i32 = int_literal 2 [template]
  231. // CHECK:STDOUT: %struct: %C = struct_value (%.7, %.8) [template]
  232. // CHECK:STDOUT: %ImplicitAs.type.1: type = generic_interface_type @ImplicitAs [template]
  233. // CHECK:STDOUT: %ImplicitAs: %ImplicitAs.type.1 = struct_value () [template]
  234. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest, 0 [symbolic]
  235. // CHECK:STDOUT: %ImplicitAs.type.2: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic]
  236. // CHECK:STDOUT: %Self.1: @ImplicitAs.%ImplicitAs.type (%ImplicitAs.type.2) = bind_symbolic_name Self, 1 [symbolic]
  237. // CHECK:STDOUT: %Dest.patt: type = symbolic_binding_pattern Dest, 0 [symbolic]
  238. // CHECK:STDOUT: %Self.2: %ImplicitAs.type.2 = bind_symbolic_name Self, 1 [symbolic]
  239. // CHECK:STDOUT: %Convert.type.1: type = fn_type @Convert, @ImplicitAs(%Dest) [symbolic]
  240. // CHECK:STDOUT: %Convert.1: %Convert.type.1 = struct_value () [symbolic]
  241. // CHECK:STDOUT: %.9: type = assoc_entity_type %ImplicitAs.type.2, %Convert.type.1 [symbolic]
  242. // CHECK:STDOUT: %.10: %.9 = assoc_entity element0, imports.%import_ref.6 [symbolic]
  243. // CHECK:STDOUT: %ImplicitAs.type.3: type = interface_type @ImplicitAs, @ImplicitAs(%AdaptC) [template]
  244. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert, @ImplicitAs(%AdaptC) [template]
  245. // CHECK:STDOUT: %Convert.2: %Convert.type.2 = struct_value () [template]
  246. // CHECK:STDOUT: %.11: type = assoc_entity_type %ImplicitAs.type.3, %Convert.type.2 [template]
  247. // CHECK:STDOUT: %.12: %.11 = assoc_entity element0, imports.%import_ref.6 [template]
  248. // CHECK:STDOUT: %.13: %.9 = assoc_entity element0, imports.%import_ref.7 [symbolic]
  249. // CHECK:STDOUT: %ImplicitAs.type.4: type = interface_type @ImplicitAs, @ImplicitAs(%C) [template]
  250. // CHECK:STDOUT: %Convert.type.3: type = fn_type @Convert, @ImplicitAs(%C) [template]
  251. // CHECK:STDOUT: %Convert.3: %Convert.type.3 = struct_value () [template]
  252. // CHECK:STDOUT: %.14: type = assoc_entity_type %ImplicitAs.type.4, %Convert.type.3 [template]
  253. // CHECK:STDOUT: %.15: %.14 = assoc_entity element0, imports.%import_ref.6 [template]
  254. // CHECK:STDOUT: %MakeC.type: type = fn_type @MakeC [template]
  255. // CHECK:STDOUT: %MakeC: %MakeC.type = struct_value () [template]
  256. // CHECK:STDOUT: %MakeAdaptC.type: type = fn_type @MakeAdaptC [template]
  257. // CHECK:STDOUT: %MakeAdaptC: %MakeAdaptC.type = struct_value () [template]
  258. // CHECK:STDOUT: }
  259. // CHECK:STDOUT:
  260. // CHECK:STDOUT: imports {
  261. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  262. // CHECK:STDOUT: .Int32 = %import_ref.1
  263. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  264. // CHECK:STDOUT: import Core//prelude
  265. // CHECK:STDOUT: import Core//prelude/operators
  266. // CHECK:STDOUT: import Core//prelude/types
  267. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  268. // CHECK:STDOUT: import Core//prelude/operators/as
  269. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  270. // CHECK:STDOUT: import Core//prelude/operators/comparison
  271. // CHECK:STDOUT: import Core//prelude/types/bool
  272. // CHECK:STDOUT: }
  273. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref Core//prelude/types, inst+9, loaded [template = constants.%Int32]
  274. // CHECK:STDOUT: %import_ref.2: %ImplicitAs.type.1 = import_ref Core//prelude/operators/as, inst+46, loaded [template = constants.%ImplicitAs]
  275. // CHECK:STDOUT: %import_ref.3 = import_ref Core//prelude/operators/as, inst+52, unloaded
  276. // CHECK:STDOUT: %import_ref.4: @ImplicitAs.%.1 (%.9) = import_ref Core//prelude/operators/as, inst+71, loaded [symbolic = @ImplicitAs.%.2 (constants.%.13)]
  277. // CHECK:STDOUT: %import_ref.5 = import_ref Core//prelude/operators/as, inst+64, unloaded
  278. // CHECK:STDOUT: %import_ref.6 = import_ref Core//prelude/operators/as, inst+64, unloaded
  279. // CHECK:STDOUT: %import_ref.7 = import_ref Core//prelude/operators/as, inst+64, unloaded
  280. // CHECK:STDOUT: }
  281. // CHECK:STDOUT:
  282. // CHECK:STDOUT: file {
  283. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  284. // CHECK:STDOUT: .Core = imports.%Core
  285. // CHECK:STDOUT: .C = %C.decl
  286. // CHECK:STDOUT: .AdaptC = %AdaptC.decl
  287. // CHECK:STDOUT: .a = @__global_init.%a
  288. // CHECK:STDOUT: .b = @__global_init.%b
  289. // CHECK:STDOUT: .c = @__global_init.%c
  290. // CHECK:STDOUT: .MakeC = %MakeC.decl
  291. // CHECK:STDOUT: .MakeAdaptC = %MakeAdaptC.decl
  292. // CHECK:STDOUT: .d = %d
  293. // CHECK:STDOUT: .e = %e
  294. // CHECK:STDOUT: }
  295. // CHECK:STDOUT: %Core.import = import Core
  296. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  297. // CHECK:STDOUT: %AdaptC.decl: type = class_decl @AdaptC [template = constants.%AdaptC] {} {}
  298. // CHECK:STDOUT: %C.ref.loc13: type = name_ref C, %C.decl [template = constants.%C]
  299. // CHECK:STDOUT: %AdaptC.ref.loc24: type = name_ref AdaptC, %AdaptC.decl [template = constants.%AdaptC]
  300. // CHECK:STDOUT: %C.ref.loc33: type = name_ref C, %C.decl [template = constants.%C]
  301. // CHECK:STDOUT: %MakeC.decl: %MakeC.type = fn_decl @MakeC [template = constants.%MakeC] {} {
  302. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  303. // CHECK:STDOUT: %return: ref %C = var <return slot>
  304. // CHECK:STDOUT: }
  305. // CHECK:STDOUT: %MakeAdaptC.decl: %MakeAdaptC.type = fn_decl @MakeAdaptC [template = constants.%MakeAdaptC] {} {
  306. // CHECK:STDOUT: %AdaptC.ref: type = name_ref AdaptC, file.%AdaptC.decl [template = constants.%AdaptC]
  307. // CHECK:STDOUT: %return: ref %AdaptC = var <return slot>
  308. // CHECK:STDOUT: }
  309. // CHECK:STDOUT: %AdaptC.ref.loc46: type = name_ref AdaptC, %AdaptC.decl [template = constants.%AdaptC]
  310. // CHECK:STDOUT: %d.var: ref %AdaptC = var d
  311. // CHECK:STDOUT: %d: ref %AdaptC = bind_name d, %d.var
  312. // CHECK:STDOUT: %C.ref.loc54: type = name_ref C, %C.decl [template = constants.%C]
  313. // CHECK:STDOUT: %e.var: ref %C = var e
  314. // CHECK:STDOUT: %e: ref %C = bind_name e, %e.var
  315. // CHECK:STDOUT: }
  316. // CHECK:STDOUT:
  317. // CHECK:STDOUT: generic interface @ImplicitAs(constants.%Dest: type) {
  318. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest, 0 [symbolic = %Dest (constants.%Dest)]
  319. // CHECK:STDOUT: %Dest.patt: type = symbolic_binding_pattern Dest, 0 [symbolic = %Dest.patt (constants.%Dest.patt)]
  320. // CHECK:STDOUT:
  321. // CHECK:STDOUT: !definition:
  322. // CHECK:STDOUT: %ImplicitAs.type: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic = %ImplicitAs.type (constants.%ImplicitAs.type.2)]
  323. // CHECK:STDOUT: %Self: %ImplicitAs.type.2 = bind_symbolic_name Self, 1 [symbolic = %Self (constants.%Self.2)]
  324. // CHECK:STDOUT: %Convert.type: type = fn_type @Convert, @ImplicitAs(%Dest) [symbolic = %Convert.type (constants.%Convert.type.1)]
  325. // CHECK:STDOUT: %Convert: @ImplicitAs.%Convert.type (%Convert.type.1) = struct_value () [symbolic = %Convert (constants.%Convert.1)]
  326. // CHECK:STDOUT: %.1: type = assoc_entity_type @ImplicitAs.%ImplicitAs.type (%ImplicitAs.type.2), @ImplicitAs.%Convert.type (%Convert.type.1) [symbolic = %.1 (constants.%.9)]
  327. // CHECK:STDOUT: %.2: @ImplicitAs.%.1 (%.9) = assoc_entity element0, imports.%import_ref.6 [symbolic = %.2 (constants.%.10)]
  328. // CHECK:STDOUT:
  329. // CHECK:STDOUT: interface {
  330. // CHECK:STDOUT: !members:
  331. // CHECK:STDOUT: .Self = imports.%import_ref.3
  332. // CHECK:STDOUT: .Convert = imports.%import_ref.4
  333. // CHECK:STDOUT: witness = (imports.%import_ref.5)
  334. // CHECK:STDOUT: }
  335. // CHECK:STDOUT: }
  336. // CHECK:STDOUT:
  337. // CHECK:STDOUT: class @C {
  338. // CHECK:STDOUT: %int.make_type_32.loc5: init type = call constants.%Int32() [template = i32]
  339. // CHECK:STDOUT: %.loc5_10.1: type = value_of_initializer %int.make_type_32.loc5 [template = i32]
  340. // CHECK:STDOUT: %.loc5_10.2: type = converted %int.make_type_32.loc5, %.loc5_10.1 [template = i32]
  341. // CHECK:STDOUT: %.loc5_8: %.2 = field_decl a, element0 [template]
  342. // CHECK:STDOUT: %int.make_type_32.loc6: init type = call constants.%Int32() [template = i32]
  343. // CHECK:STDOUT: %.loc6_10.1: type = value_of_initializer %int.make_type_32.loc6 [template = i32]
  344. // CHECK:STDOUT: %.loc6_10.2: type = converted %int.make_type_32.loc6, %.loc6_10.1 [template = i32]
  345. // CHECK:STDOUT: %.loc6_8: %.2 = field_decl b, element1 [template]
  346. // CHECK:STDOUT: %.loc7: <witness> = complete_type_witness %.3 [template = constants.%.4]
  347. // CHECK:STDOUT:
  348. // CHECK:STDOUT: !members:
  349. // CHECK:STDOUT: .Self = constants.%C
  350. // CHECK:STDOUT: .a = %.loc5_8
  351. // CHECK:STDOUT: .b = %.loc6_8
  352. // CHECK:STDOUT: }
  353. // CHECK:STDOUT:
  354. // CHECK:STDOUT: class @AdaptC {
  355. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  356. // CHECK:STDOUT: adapt_decl %C
  357. // CHECK:STDOUT: %.loc11: <witness> = complete_type_witness %C [template = constants.%.6]
  358. // CHECK:STDOUT:
  359. // CHECK:STDOUT: !members:
  360. // CHECK:STDOUT: .Self = constants.%AdaptC
  361. // CHECK:STDOUT: }
  362. // CHECK:STDOUT:
  363. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  364. // CHECK:STDOUT:
  365. // CHECK:STDOUT: generic fn @Convert(constants.%Dest: type, constants.%Self.1: @ImplicitAs.%ImplicitAs.type (%ImplicitAs.type.2)) {
  366. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest, 0 [symbolic = %Dest (constants.%Dest)]
  367. // CHECK:STDOUT: %ImplicitAs.type: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic = %ImplicitAs.type (constants.%ImplicitAs.type.2)]
  368. // CHECK:STDOUT: %Self: %ImplicitAs.type.2 = bind_symbolic_name Self, 1 [symbolic = %Self (constants.%Self.2)]
  369. // CHECK:STDOUT:
  370. // CHECK:STDOUT: fn[%self.param_patt: @Convert.%Self (%Self.2)]() -> @Convert.%Dest (%Dest);
  371. // CHECK:STDOUT: }
  372. // CHECK:STDOUT:
  373. // CHECK:STDOUT: fn @MakeC() -> %C;
  374. // CHECK:STDOUT:
  375. // CHECK:STDOUT: fn @MakeAdaptC() -> %AdaptC;
  376. // CHECK:STDOUT:
  377. // CHECK:STDOUT: fn @__global_init() {
  378. // CHECK:STDOUT: !entry:
  379. // CHECK:STDOUT: %.loc13_18: i32 = int_literal 1 [template = constants.%.7]
  380. // CHECK:STDOUT: %.loc13_26: i32 = int_literal 2 [template = constants.%.8]
  381. // CHECK:STDOUT: %.loc13_27.1: %.3 = struct_literal (%.loc13_18, %.loc13_26)
  382. // CHECK:STDOUT: %.loc13_27.2: ref %C = temporary_storage
  383. // CHECK:STDOUT: %.loc13_27.3: ref i32 = class_element_access %.loc13_27.2, element0
  384. // CHECK:STDOUT: %.loc13_27.4: init i32 = initialize_from %.loc13_18 to %.loc13_27.3 [template = constants.%.7]
  385. // CHECK:STDOUT: %.loc13_27.5: ref i32 = class_element_access %.loc13_27.2, element1
  386. // CHECK:STDOUT: %.loc13_27.6: init i32 = initialize_from %.loc13_26 to %.loc13_27.5 [template = constants.%.8]
  387. // CHECK:STDOUT: %.loc13_27.7: init %C = class_init (%.loc13_27.4, %.loc13_27.6), %.loc13_27.2 [template = constants.%struct]
  388. // CHECK:STDOUT: %.loc13_27.8: ref %C = temporary %.loc13_27.2, %.loc13_27.7
  389. // CHECK:STDOUT: %.loc13_28.1: ref %C = converted %.loc13_27.1, %.loc13_27.8
  390. // CHECK:STDOUT: %.loc13_28.2: %C = bind_value %.loc13_28.1
  391. // CHECK:STDOUT: %a: %C = bind_name a, %.loc13_28.2
  392. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  393. // CHECK:STDOUT: %ImplicitAs.type.loc24: type = interface_type @ImplicitAs, @ImplicitAs(constants.%AdaptC) [template = constants.%ImplicitAs.type.3]
  394. // CHECK:STDOUT: %.loc24_18.1: %.11 = specific_constant imports.%import_ref.4, @ImplicitAs(constants.%AdaptC) [template = constants.%.12]
  395. // CHECK:STDOUT: %Convert.ref.loc24: %.11 = name_ref Convert, %.loc24_18.1 [template = constants.%.12]
  396. // CHECK:STDOUT: %.loc24_18.2: %AdaptC = converted %a.ref, <error> [template = <error>]
  397. // CHECK:STDOUT: %b: %AdaptC = bind_name b, <error>
  398. // CHECK:STDOUT: %b.ref: %AdaptC = name_ref b, %b
  399. // CHECK:STDOUT: %ImplicitAs.type.loc33: type = interface_type @ImplicitAs, @ImplicitAs(constants.%C) [template = constants.%ImplicitAs.type.4]
  400. // CHECK:STDOUT: %.loc33_13.1: %.14 = specific_constant imports.%import_ref.4, @ImplicitAs(constants.%C) [template = constants.%.15]
  401. // CHECK:STDOUT: %Convert.ref.loc33: %.14 = name_ref Convert, %.loc33_13.1 [template = constants.%.15]
  402. // CHECK:STDOUT: %.loc33_13.2: %C = converted %b.ref, <error> [template = <error>]
  403. // CHECK:STDOUT: %c: %C = bind_name c, <error>
  404. // CHECK:STDOUT: %MakeC.ref: %MakeC.type = name_ref MakeC, file.%MakeC.decl [template = constants.%MakeC]
  405. // CHECK:STDOUT: %.loc46_22.1: ref %C = temporary_storage
  406. // CHECK:STDOUT: %MakeC.call: init %C = call %MakeC.ref() to %.loc46_22.1
  407. // CHECK:STDOUT: %ImplicitAs.type.loc46: type = interface_type @ImplicitAs, @ImplicitAs(constants.%AdaptC) [template = constants.%ImplicitAs.type.3]
  408. // CHECK:STDOUT: %.loc46_24.1: %.11 = specific_constant imports.%import_ref.4, @ImplicitAs(constants.%AdaptC) [template = constants.%.12]
  409. // CHECK:STDOUT: %Convert.ref.loc46: %.11 = name_ref Convert, %.loc46_24.1 [template = constants.%.12]
  410. // CHECK:STDOUT: %.loc46_22.2: ref %C = temporary %.loc46_22.1, %MakeC.call
  411. // CHECK:STDOUT: %.loc46_24.2: %AdaptC = converted %MakeC.call, <error> [template = <error>]
  412. // CHECK:STDOUT: assign file.%d.var, <error>
  413. // CHECK:STDOUT: %MakeAdaptC.ref: %MakeAdaptC.type = name_ref MakeAdaptC, file.%MakeAdaptC.decl [template = constants.%MakeAdaptC]
  414. // CHECK:STDOUT: %.loc54_22.1: ref %AdaptC = temporary_storage
  415. // CHECK:STDOUT: %MakeAdaptC.call: init %AdaptC = call %MakeAdaptC.ref() to %.loc54_22.1
  416. // CHECK:STDOUT: %ImplicitAs.type.loc54: type = interface_type @ImplicitAs, @ImplicitAs(constants.%C) [template = constants.%ImplicitAs.type.4]
  417. // CHECK:STDOUT: %.loc54_24.1: %.14 = specific_constant imports.%import_ref.4, @ImplicitAs(constants.%C) [template = constants.%.15]
  418. // CHECK:STDOUT: %Convert.ref.loc54: %.14 = name_ref Convert, %.loc54_24.1 [template = constants.%.15]
  419. // CHECK:STDOUT: %.loc54_22.2: ref %AdaptC = temporary %.loc54_22.1, %MakeAdaptC.call
  420. // CHECK:STDOUT: %.loc54_24.2: %C = converted %MakeAdaptC.call, <error> [template = <error>]
  421. // CHECK:STDOUT: assign file.%e.var, <error>
  422. // CHECK:STDOUT: return
  423. // CHECK:STDOUT: }
  424. // CHECK:STDOUT:
  425. // CHECK:STDOUT: specific @ImplicitAs(constants.%Dest) {
  426. // CHECK:STDOUT: %Dest => constants.%Dest
  427. // CHECK:STDOUT: %Dest.patt => constants.%Dest
  428. // CHECK:STDOUT: }
  429. // CHECK:STDOUT:
  430. // CHECK:STDOUT: specific @ImplicitAs(@ImplicitAs.%Dest) {
  431. // CHECK:STDOUT: %Dest => constants.%Dest
  432. // CHECK:STDOUT: %Dest.patt => constants.%Dest
  433. // CHECK:STDOUT: }
  434. // CHECK:STDOUT:
  435. // CHECK:STDOUT: specific @ImplicitAs(@Convert.%Dest) {
  436. // CHECK:STDOUT: %Dest => constants.%Dest
  437. // CHECK:STDOUT: %Dest.patt => constants.%Dest
  438. // CHECK:STDOUT: }
  439. // CHECK:STDOUT:
  440. // CHECK:STDOUT: specific @Convert(constants.%Dest, constants.%Self.1) {
  441. // CHECK:STDOUT: %Dest => constants.%Dest
  442. // CHECK:STDOUT: %ImplicitAs.type => constants.%ImplicitAs.type.2
  443. // CHECK:STDOUT: %Self => constants.%Self.1
  444. // CHECK:STDOUT: }
  445. // CHECK:STDOUT:
  446. // CHECK:STDOUT: specific @ImplicitAs(constants.%AdaptC) {
  447. // CHECK:STDOUT: %Dest => constants.%AdaptC
  448. // CHECK:STDOUT: %Dest.patt => constants.%AdaptC
  449. // CHECK:STDOUT:
  450. // CHECK:STDOUT: !definition:
  451. // CHECK:STDOUT: %ImplicitAs.type => constants.%ImplicitAs.type.3
  452. // CHECK:STDOUT: %Self => constants.%Self.2
  453. // CHECK:STDOUT: %Convert.type => constants.%Convert.type.2
  454. // CHECK:STDOUT: %Convert => constants.%Convert.2
  455. // CHECK:STDOUT: %.1 => constants.%.11
  456. // CHECK:STDOUT: %.2 => constants.%.12
  457. // CHECK:STDOUT: }
  458. // CHECK:STDOUT:
  459. // CHECK:STDOUT: specific @ImplicitAs(constants.%C) {
  460. // CHECK:STDOUT: %Dest => constants.%C
  461. // CHECK:STDOUT: %Dest.patt => constants.%C
  462. // CHECK:STDOUT:
  463. // CHECK:STDOUT: !definition:
  464. // CHECK:STDOUT: %ImplicitAs.type => constants.%ImplicitAs.type.4
  465. // CHECK:STDOUT: %Self => constants.%Self.2
  466. // CHECK:STDOUT: %Convert.type => constants.%Convert.type.3
  467. // CHECK:STDOUT: %Convert => constants.%Convert.3
  468. // CHECK:STDOUT: %.1 => constants.%.14
  469. // CHECK:STDOUT: %.2 => constants.%.15
  470. // CHECK:STDOUT: }
  471. // CHECK:STDOUT: