adapter_conversion.carbon 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  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/as/adapter_conversion.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/as/adapter_conversion.carbon
  10. // --- adapt_class.carbon
  11. library "[[@TEST_NAME]]";
  12. class A {
  13. var x: i32;
  14. var y: i32;
  15. fn Make() -> A {
  16. return {.x = 1, .y = 2};
  17. }
  18. }
  19. class B {
  20. adapt A;
  21. }
  22. var a_ref: A = {.x = 1, .y = 2};
  23. let a_val: A = a_ref;
  24. // An `as` conversion to an adapter type preserves the expression category.
  25. let b_val: B = a_val as B;
  26. let b_ptr: B* = &(a_ref as B);
  27. var b_factory: B = A.Make() as B;
  28. // --- adapt_i32.carbon
  29. library "[[@TEST_NAME]]";
  30. class A {
  31. adapt i32;
  32. }
  33. let a: A = (1 as i32) as A;
  34. let n: i32 = a as i32;
  35. // --- multi_level_adapt.carbon
  36. library "[[@TEST_NAME]]";
  37. class A { adapt {}; }
  38. class B { adapt A; }
  39. class C { adapt B; }
  40. class D { adapt C; }
  41. let d: D = {} as D;
  42. // --- fail_init_class.carbon
  43. library "[[@TEST_NAME]]";
  44. class A {
  45. var x: i32;
  46. var y: i32;
  47. }
  48. class B {
  49. adapt A;
  50. }
  51. let b_value: B = ({.x = 1, .y = 2} as A) as B;
  52. // TODO: Here, we treat `{.x = 1, .y = 2} as A` as a value expression, not an
  53. // initializing expression, so `(...) as B` is a value expression too, requiring
  54. // a copy to perform initialization. It's not clear whether that is the right
  55. // behavior.
  56. // CHECK:STDERR: fail_init_class.carbon:[[@LINE+4]]:17: error: cannot copy value of type `B` [CopyOfUncopyableType]
  57. // CHECK:STDERR: var b_init: B = ({.x = 1, .y = 2} as A) as B;
  58. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
  59. // CHECK:STDERR:
  60. var b_init: B = ({.x = 1, .y = 2} as A) as B;
  61. // --- fail_adapt_init_from_struct.carbon
  62. library "[[@TEST_NAME]]";
  63. class A {
  64. var x: i32;
  65. }
  66. class B {
  67. adapt A;
  68. }
  69. // We do not try to implicitly convert from the first operand of `as` to the
  70. // adapted type of the second operand.
  71. // CHECK:STDERR: fail_adapt_init_from_struct.carbon:[[@LINE+6]]:12: error: cannot convert from `{.x: Core.IntLiteral}` to `B` with `as` [ExplicitAsConversionFailure]
  72. // CHECK:STDERR: var b: B = {.x = 1} as B;
  73. // CHECK:STDERR: ^~~~~~~~~~~~~
  74. // CHECK:STDERR: fail_adapt_init_from_struct.carbon:[[@LINE+3]]:12: note: type `{.x: Core.IntLiteral}` does not implement interface `Core.As(B)` [MissingImplInMemberAccessNote]
  75. // CHECK:STDERR: var b: B = {.x = 1} as B;
  76. // CHECK:STDERR: ^~~~~~~~~~~~~
  77. var b: B = {.x = 1} as B;
  78. // CHECK:STDOUT: --- adapt_class.carbon
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: constants {
  81. // CHECK:STDOUT: %A: type = class_type @A [template]
  82. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  83. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  84. // CHECK:STDOUT: %A.elem: type = unbound_element_type %A, %i32 [template]
  85. // CHECK:STDOUT: %Make.type: type = fn_type @Make [template]
  86. // CHECK:STDOUT: %Make: %Make.type = struct_value () [template]
  87. // CHECK:STDOUT: %struct_type.x.y.1: type = struct_type {.x: %i32, .y: %i32} [template]
  88. // CHECK:STDOUT: %complete_type.3: <witness> = complete_type_witness %struct_type.x.y.1 [template]
  89. // CHECK:STDOUT: %int_1.1: Core.IntLiteral = int_value 1 [template]
  90. // CHECK:STDOUT: %int_2.1: Core.IntLiteral = int_value 2 [template]
  91. // CHECK:STDOUT: %struct_type.x.y.2: type = struct_type {.x: Core.IntLiteral, .y: Core.IntLiteral} [template]
  92. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  93. // CHECK:STDOUT: %Convert.type.10: type = fn_type @Convert.2, @impl.1(%int_32) [template]
  94. // CHECK:STDOUT: %Convert.10: %Convert.type.10 = struct_value () [template]
  95. // CHECK:STDOUT: %interface.5: <witness> = interface_witness (%Convert.10) [template]
  96. // CHECK:STDOUT: %Convert.bound.1: <bound method> = bound_method %int_1.1, %Convert.10 [template]
  97. // CHECK:STDOUT: %Convert.specific_fn.1: <specific function> = specific_function %Convert.bound.1, @Convert.2(%int_32) [template]
  98. // CHECK:STDOUT: %int_1.2: %i32 = int_value 1 [template]
  99. // CHECK:STDOUT: %Convert.bound.2: <bound method> = bound_method %int_2.1, %Convert.10 [template]
  100. // CHECK:STDOUT: %Convert.specific_fn.2: <specific function> = specific_function %Convert.bound.2, @Convert.2(%int_32) [template]
  101. // CHECK:STDOUT: %int_2.2: %i32 = int_value 2 [template]
  102. // CHECK:STDOUT: %A.val: %A = struct_value (%int_1.2, %int_2.2) [template]
  103. // CHECK:STDOUT: %B: type = class_type @B [template]
  104. // CHECK:STDOUT: %ptr.2: type = ptr_type %B [template]
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: imports {
  108. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  109. // CHECK:STDOUT: .Int = %import_ref.1
  110. // CHECK:STDOUT: .ImplicitAs = %import_ref.5
  111. // CHECK:STDOUT: import Core//prelude
  112. // CHECK:STDOUT: import Core//prelude/...
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT:
  116. // CHECK:STDOUT: file {
  117. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  118. // CHECK:STDOUT: .Core = imports.%Core
  119. // CHECK:STDOUT: .A = %A.decl
  120. // CHECK:STDOUT: .B = %B.decl
  121. // CHECK:STDOUT: .a_ref = %a_ref
  122. // CHECK:STDOUT: .a_val = @__global_init.%a_val
  123. // CHECK:STDOUT: .b_val = @__global_init.%b_val
  124. // CHECK:STDOUT: .b_ptr = @__global_init.%b_ptr
  125. // CHECK:STDOUT: .b_factory = %b_factory
  126. // CHECK:STDOUT: }
  127. // CHECK:STDOUT: %Core.import = import Core
  128. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {} {}
  129. // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {} {}
  130. // CHECK:STDOUT: %a_ref.var: ref %A = var a_ref
  131. // CHECK:STDOUT: %a_ref: ref %A = bind_name a_ref, %a_ref.var
  132. // CHECK:STDOUT: %b_factory.var: ref %B = var b_factory
  133. // CHECK:STDOUT: %b_factory: ref %B = bind_name b_factory, %b_factory.var
  134. // CHECK:STDOUT: }
  135. // CHECK:STDOUT:
  136. // CHECK:STDOUT: class @A {
  137. // CHECK:STDOUT: %.loc5: %A.elem = field_decl x, element0 [template]
  138. // CHECK:STDOUT: %.loc6: %A.elem = field_decl y, element1 [template]
  139. // CHECK:STDOUT: %Make.decl: %Make.type = fn_decl @Make [template = constants.%Make] {
  140. // CHECK:STDOUT: %return.patt: %A = return_slot_pattern
  141. // CHECK:STDOUT: %return.param_patt: %A = out_param_pattern %return.patt, runtime_param0
  142. // CHECK:STDOUT: } {
  143. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  144. // CHECK:STDOUT: %return.param: ref %A = out_param runtime_param0
  145. // CHECK:STDOUT: %return: ref %A = return_slot %return.param
  146. // CHECK:STDOUT: }
  147. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.x.y.1 [template = constants.%complete_type.3]
  148. // CHECK:STDOUT:
  149. // CHECK:STDOUT: !members:
  150. // CHECK:STDOUT: .Self = constants.%A
  151. // CHECK:STDOUT: .x = %.loc5
  152. // CHECK:STDOUT: .y = %.loc6
  153. // CHECK:STDOUT: .Make = %Make.decl
  154. // CHECK:STDOUT: complete_type_witness = %complete_type
  155. // CHECK:STDOUT: }
  156. // CHECK:STDOUT:
  157. // CHECK:STDOUT: class @B {
  158. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  159. // CHECK:STDOUT: adapt_decl %A.ref [template]
  160. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.x.y.1 [template = constants.%complete_type.3]
  161. // CHECK:STDOUT:
  162. // CHECK:STDOUT: !members:
  163. // CHECK:STDOUT: .Self = constants.%B
  164. // CHECK:STDOUT: complete_type_witness = %complete_type
  165. // CHECK:STDOUT: }
  166. // CHECK:STDOUT:
  167. // CHECK:STDOUT: fn @Make() -> %return.param_patt: %A {
  168. // CHECK:STDOUT: !entry:
  169. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1.1]
  170. // CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [template = constants.%int_2.1]
  171. // CHECK:STDOUT: %.loc9_27.1: %struct_type.x.y.2 = struct_literal (%int_1, %int_2)
  172. // CHECK:STDOUT: %impl.elem0.loc9_27.1: %Convert.type.2 = interface_witness_access constants.%interface.5, element0 [template = constants.%Convert.10]
  173. // CHECK:STDOUT: %Convert.bound.loc9_27.1: <bound method> = bound_method %int_1, %impl.elem0.loc9_27.1 [template = constants.%Convert.bound.1]
  174. // CHECK:STDOUT: %Convert.specific_fn.loc9_27.1: <specific function> = specific_function %Convert.bound.loc9_27.1, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.1]
  175. // CHECK:STDOUT: %int.convert_checked.loc9_27.1: init %i32 = call %Convert.specific_fn.loc9_27.1(%int_1) [template = constants.%int_1.2]
  176. // CHECK:STDOUT: %.loc9_27.2: init %i32 = converted %int_1, %int.convert_checked.loc9_27.1 [template = constants.%int_1.2]
  177. // CHECK:STDOUT: %.loc9_27.3: ref %i32 = class_element_access %return, element0
  178. // CHECK:STDOUT: %.loc9_27.4: init %i32 = initialize_from %.loc9_27.2 to %.loc9_27.3 [template = constants.%int_1.2]
  179. // CHECK:STDOUT: %impl.elem0.loc9_27.2: %Convert.type.2 = interface_witness_access constants.%interface.5, element0 [template = constants.%Convert.10]
  180. // CHECK:STDOUT: %Convert.bound.loc9_27.2: <bound method> = bound_method %int_2, %impl.elem0.loc9_27.2 [template = constants.%Convert.bound.2]
  181. // CHECK:STDOUT: %Convert.specific_fn.loc9_27.2: <specific function> = specific_function %Convert.bound.loc9_27.2, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.2]
  182. // CHECK:STDOUT: %int.convert_checked.loc9_27.2: init %i32 = call %Convert.specific_fn.loc9_27.2(%int_2) [template = constants.%int_2.2]
  183. // CHECK:STDOUT: %.loc9_27.5: init %i32 = converted %int_2, %int.convert_checked.loc9_27.2 [template = constants.%int_2.2]
  184. // CHECK:STDOUT: %.loc9_27.6: ref %i32 = class_element_access %return, element1
  185. // CHECK:STDOUT: %.loc9_27.7: init %i32 = initialize_from %.loc9_27.5 to %.loc9_27.6 [template = constants.%int_2.2]
  186. // CHECK:STDOUT: %.loc9_27.8: init %A = class_init (%.loc9_27.4, %.loc9_27.7), %return [template = constants.%A.val]
  187. // CHECK:STDOUT: %.loc9_28: init %A = converted %.loc9_27.1, %.loc9_27.8 [template = constants.%A.val]
  188. // CHECK:STDOUT: return %.loc9_28 to %return
  189. // CHECK:STDOUT: }
  190. // CHECK:STDOUT:
  191. // CHECK:STDOUT: fn @__global_init() {
  192. // CHECK:STDOUT: !entry:
  193. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1.1]
  194. // CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [template = constants.%int_2.1]
  195. // CHECK:STDOUT: %.loc17_31.1: %struct_type.x.y.2 = struct_literal (%int_1, %int_2)
  196. // CHECK:STDOUT: %impl.elem0.loc17_31.1: %Convert.type.2 = interface_witness_access constants.%interface.5, element0 [template = constants.%Convert.10]
  197. // CHECK:STDOUT: %Convert.bound.loc17_31.1: <bound method> = bound_method %int_1, %impl.elem0.loc17_31.1 [template = constants.%Convert.bound.1]
  198. // CHECK:STDOUT: %Convert.specific_fn.loc17_31.1: <specific function> = specific_function %Convert.bound.loc17_31.1, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.1]
  199. // CHECK:STDOUT: %int.convert_checked.loc17_31.1: init %i32 = call %Convert.specific_fn.loc17_31.1(%int_1) [template = constants.%int_1.2]
  200. // CHECK:STDOUT: %.loc17_31.2: init %i32 = converted %int_1, %int.convert_checked.loc17_31.1 [template = constants.%int_1.2]
  201. // CHECK:STDOUT: %.loc17_31.3: ref %i32 = class_element_access file.%a_ref.var, element0
  202. // CHECK:STDOUT: %.loc17_31.4: init %i32 = initialize_from %.loc17_31.2 to %.loc17_31.3 [template = constants.%int_1.2]
  203. // CHECK:STDOUT: %impl.elem0.loc17_31.2: %Convert.type.2 = interface_witness_access constants.%interface.5, element0 [template = constants.%Convert.10]
  204. // CHECK:STDOUT: %Convert.bound.loc17_31.2: <bound method> = bound_method %int_2, %impl.elem0.loc17_31.2 [template = constants.%Convert.bound.2]
  205. // CHECK:STDOUT: %Convert.specific_fn.loc17_31.2: <specific function> = specific_function %Convert.bound.loc17_31.2, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.2]
  206. // CHECK:STDOUT: %int.convert_checked.loc17_31.2: init %i32 = call %Convert.specific_fn.loc17_31.2(%int_2) [template = constants.%int_2.2]
  207. // CHECK:STDOUT: %.loc17_31.5: init %i32 = converted %int_2, %int.convert_checked.loc17_31.2 [template = constants.%int_2.2]
  208. // CHECK:STDOUT: %.loc17_31.6: ref %i32 = class_element_access file.%a_ref.var, element1
  209. // CHECK:STDOUT: %.loc17_31.7: init %i32 = initialize_from %.loc17_31.5 to %.loc17_31.6 [template = constants.%int_2.2]
  210. // CHECK:STDOUT: %.loc17_31.8: init %A = class_init (%.loc17_31.4, %.loc17_31.7), file.%a_ref.var [template = constants.%A.val]
  211. // CHECK:STDOUT: %.loc17_32: init %A = converted %.loc17_31.1, %.loc17_31.8 [template = constants.%A.val]
  212. // CHECK:STDOUT: assign file.%a_ref.var, %.loc17_32
  213. // CHECK:STDOUT: %a_ref.ref.loc18: ref %A = name_ref a_ref, file.%a_ref
  214. // CHECK:STDOUT: %.loc18: %A = bind_value %a_ref.ref.loc18
  215. // CHECK:STDOUT: %a_val: %A = bind_name a_val, %.loc18
  216. // CHECK:STDOUT: %a_val.ref: %A = name_ref a_val, %a_val
  217. // CHECK:STDOUT: %B.ref.loc21: type = name_ref B, file.%B.decl [template = constants.%B]
  218. // CHECK:STDOUT: %.loc21_22.1: %B = as_compatible %a_val.ref
  219. // CHECK:STDOUT: %.loc21_22.2: %B = converted %a_val.ref, %.loc21_22.1
  220. // CHECK:STDOUT: %b_val: %B = bind_name b_val, %.loc21_22.2
  221. // CHECK:STDOUT: %a_ref.ref.loc22: ref %A = name_ref a_ref, file.%a_ref
  222. // CHECK:STDOUT: %B.ref.loc22: type = name_ref B, file.%B.decl [template = constants.%B]
  223. // CHECK:STDOUT: %.loc22_25.1: ref %B = as_compatible %a_ref.ref.loc22
  224. // CHECK:STDOUT: %.loc22_25.2: ref %B = converted %a_ref.ref.loc22, %.loc22_25.1
  225. // CHECK:STDOUT: %addr: %ptr.2 = addr_of %.loc22_25.2
  226. // CHECK:STDOUT: %b_ptr: %ptr.2 = bind_name b_ptr, %addr
  227. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  228. // CHECK:STDOUT: %Make.ref: %Make.type = name_ref Make, @A.%Make.decl [template = constants.%Make]
  229. // CHECK:STDOUT: %.loc24_5: ref %B = splice_block file.%b_factory.var {}
  230. // CHECK:STDOUT: %Make.call: init %A = call %Make.ref() to %.loc24_5
  231. // CHECK:STDOUT: %B.ref.loc24: type = name_ref B, file.%B.decl [template = constants.%B]
  232. // CHECK:STDOUT: %.loc24_29.1: init %B = as_compatible %Make.call
  233. // CHECK:STDOUT: %.loc24_29.2: init %B = converted %Make.call, %.loc24_29.1
  234. // CHECK:STDOUT: assign file.%b_factory.var, %.loc24_29.2
  235. // CHECK:STDOUT: return
  236. // CHECK:STDOUT: }
  237. // CHECK:STDOUT:
  238. // CHECK:STDOUT: --- adapt_i32.carbon
  239. // CHECK:STDOUT:
  240. // CHECK:STDOUT: constants {
  241. // CHECK:STDOUT: %A: type = class_type @A [template]
  242. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  243. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  244. // CHECK:STDOUT: %i32.builtin: type = int_type signed, %int_32 [template]
  245. // CHECK:STDOUT: %complete_type.2: <witness> = complete_type_witness %i32.builtin [template]
  246. // CHECK:STDOUT: %int_1.1: Core.IntLiteral = int_value 1 [template]
  247. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @As(%i32) [template]
  248. // CHECK:STDOUT: %Convert.type.10: type = fn_type @Convert.5, @impl.3(%int_32) [template]
  249. // CHECK:STDOUT: %Convert.10: %Convert.type.10 = struct_value () [template]
  250. // CHECK:STDOUT: %interface.5: <witness> = interface_witness (%Convert.10) [template]
  251. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_1.1, %Convert.10 [template]
  252. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.5(%int_32) [template]
  253. // CHECK:STDOUT: %int_1.2: %i32 = int_value 1 [template]
  254. // CHECK:STDOUT: }
  255. // CHECK:STDOUT:
  256. // CHECK:STDOUT: imports {
  257. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  258. // CHECK:STDOUT: .Int = %import_ref.1
  259. // CHECK:STDOUT: .As = %import_ref.5
  260. // CHECK:STDOUT: import Core//prelude
  261. // CHECK:STDOUT: import Core//prelude/...
  262. // CHECK:STDOUT: }
  263. // CHECK:STDOUT: }
  264. // CHECK:STDOUT:
  265. // CHECK:STDOUT: file {
  266. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  267. // CHECK:STDOUT: .Core = imports.%Core
  268. // CHECK:STDOUT: .A = %A.decl
  269. // CHECK:STDOUT: .a = @__global_init.%a
  270. // CHECK:STDOUT: .n = @__global_init.%n
  271. // CHECK:STDOUT: }
  272. // CHECK:STDOUT: %Core.import = import Core
  273. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {} {}
  274. // CHECK:STDOUT: }
  275. // CHECK:STDOUT:
  276. // CHECK:STDOUT: class @A {
  277. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  278. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  279. // CHECK:STDOUT: adapt_decl %i32 [template]
  280. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %i32.builtin [template = constants.%complete_type.2]
  281. // CHECK:STDOUT:
  282. // CHECK:STDOUT: !members:
  283. // CHECK:STDOUT: .Self = constants.%A
  284. // CHECK:STDOUT: complete_type_witness = %complete_type
  285. // CHECK:STDOUT: }
  286. // CHECK:STDOUT:
  287. // CHECK:STDOUT: fn @__global_init() {
  288. // CHECK:STDOUT: !entry:
  289. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1.1]
  290. // CHECK:STDOUT: %int_32.loc8: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  291. // CHECK:STDOUT: %i32.loc8: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  292. // CHECK:STDOUT: %impl.elem0: %Convert.type.2 = interface_witness_access constants.%interface.5, element0 [template = constants.%Convert.10]
  293. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_1, %impl.elem0 [template = constants.%Convert.bound]
  294. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.5(constants.%int_32) [template = constants.%Convert.specific_fn]
  295. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %Convert.specific_fn(%int_1) [template = constants.%int_1.2]
  296. // CHECK:STDOUT: %.loc8_15.1: %i32 = value_of_initializer %int.convert_checked [template = constants.%int_1.2]
  297. // CHECK:STDOUT: %.loc8_15.2: %i32 = converted %int_1, %.loc8_15.1 [template = constants.%int_1.2]
  298. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  299. // CHECK:STDOUT: %.loc8_23.1: %A = as_compatible %.loc8_15.2 [template = constants.%int_1.2]
  300. // CHECK:STDOUT: %.loc8_23.2: %A = converted %.loc8_15.2, %.loc8_23.1 [template = constants.%int_1.2]
  301. // CHECK:STDOUT: %a: %A = bind_name a, %.loc8_23.2
  302. // CHECK:STDOUT: %a.ref: %A = name_ref a, %a
  303. // CHECK:STDOUT: %int_32.loc9: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  304. // CHECK:STDOUT: %i32.loc9: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  305. // CHECK:STDOUT: %.loc9_16.1: %i32 = as_compatible %a.ref
  306. // CHECK:STDOUT: %.loc9_16.2: %i32 = converted %a.ref, %.loc9_16.1
  307. // CHECK:STDOUT: %n: %i32 = bind_name n, %.loc9_16.2
  308. // CHECK:STDOUT: return
  309. // CHECK:STDOUT: }
  310. // CHECK:STDOUT:
  311. // CHECK:STDOUT: --- multi_level_adapt.carbon
  312. // CHECK:STDOUT:
  313. // CHECK:STDOUT: constants {
  314. // CHECK:STDOUT: %A: type = class_type @A [template]
  315. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
  316. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template]
  317. // CHECK:STDOUT: %B: type = class_type @B [template]
  318. // CHECK:STDOUT: %C: type = class_type @C [template]
  319. // CHECK:STDOUT: %D: type = class_type @D [template]
  320. // CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [template]
  321. // CHECK:STDOUT: }
  322. // CHECK:STDOUT:
  323. // CHECK:STDOUT: imports {
  324. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  325. // CHECK:STDOUT: import Core//prelude
  326. // CHECK:STDOUT: import Core//prelude/...
  327. // CHECK:STDOUT: }
  328. // CHECK:STDOUT: }
  329. // CHECK:STDOUT:
  330. // CHECK:STDOUT: file {
  331. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  332. // CHECK:STDOUT: .Core = imports.%Core
  333. // CHECK:STDOUT: .A = %A.decl
  334. // CHECK:STDOUT: .B = %B.decl
  335. // CHECK:STDOUT: .C = %C.decl
  336. // CHECK:STDOUT: .D = %D.decl
  337. // CHECK:STDOUT: .d = @__global_init.%d
  338. // CHECK:STDOUT: }
  339. // CHECK:STDOUT: %Core.import = import Core
  340. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {} {}
  341. // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {} {}
  342. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  343. // CHECK:STDOUT: %D.decl: type = class_decl @D [template = constants.%D] {} {}
  344. // CHECK:STDOUT: }
  345. // CHECK:STDOUT:
  346. // CHECK:STDOUT: class @A {
  347. // CHECK:STDOUT: %.loc4_18: %empty_struct_type = struct_literal ()
  348. // CHECK:STDOUT: %.loc4_19: type = converted %.loc4_18, constants.%empty_struct_type [template = constants.%empty_struct_type]
  349. // CHECK:STDOUT: adapt_decl %.loc4_19 [template]
  350. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type]
  351. // CHECK:STDOUT:
  352. // CHECK:STDOUT: !members:
  353. // CHECK:STDOUT: .Self = constants.%A
  354. // CHECK:STDOUT: complete_type_witness = %complete_type
  355. // CHECK:STDOUT: }
  356. // CHECK:STDOUT:
  357. // CHECK:STDOUT: class @B {
  358. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  359. // CHECK:STDOUT: adapt_decl %A.ref [template]
  360. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type]
  361. // CHECK:STDOUT:
  362. // CHECK:STDOUT: !members:
  363. // CHECK:STDOUT: .Self = constants.%B
  364. // CHECK:STDOUT: complete_type_witness = %complete_type
  365. // CHECK:STDOUT: }
  366. // CHECK:STDOUT:
  367. // CHECK:STDOUT: class @C {
  368. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [template = constants.%B]
  369. // CHECK:STDOUT: adapt_decl %B.ref [template]
  370. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type]
  371. // CHECK:STDOUT:
  372. // CHECK:STDOUT: !members:
  373. // CHECK:STDOUT: .Self = constants.%C
  374. // CHECK:STDOUT: complete_type_witness = %complete_type
  375. // CHECK:STDOUT: }
  376. // CHECK:STDOUT:
  377. // CHECK:STDOUT: class @D {
  378. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  379. // CHECK:STDOUT: adapt_decl %C.ref [template]
  380. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type]
  381. // CHECK:STDOUT:
  382. // CHECK:STDOUT: !members:
  383. // CHECK:STDOUT: .Self = constants.%D
  384. // CHECK:STDOUT: complete_type_witness = %complete_type
  385. // CHECK:STDOUT: }
  386. // CHECK:STDOUT:
  387. // CHECK:STDOUT: fn @__global_init() {
  388. // CHECK:STDOUT: !entry:
  389. // CHECK:STDOUT: %.loc9_13: %empty_struct_type = struct_literal ()
  390. // CHECK:STDOUT: %D.ref: type = name_ref D, file.%D.decl [template = constants.%D]
  391. // CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [template = constants.%empty_struct]
  392. // CHECK:STDOUT: %.loc9_15.1: %D = as_compatible %empty_struct [template = constants.%empty_struct]
  393. // CHECK:STDOUT: %.loc9_15.2: %D = converted %.loc9_13, %.loc9_15.1 [template = constants.%empty_struct]
  394. // CHECK:STDOUT: %d: %D = bind_name d, %.loc9_15.2
  395. // CHECK:STDOUT: return
  396. // CHECK:STDOUT: }
  397. // CHECK:STDOUT:
  398. // CHECK:STDOUT: --- fail_init_class.carbon
  399. // CHECK:STDOUT:
  400. // CHECK:STDOUT: constants {
  401. // CHECK:STDOUT: %A: type = class_type @A [template]
  402. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  403. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  404. // CHECK:STDOUT: %A.elem: type = unbound_element_type %A, %i32 [template]
  405. // CHECK:STDOUT: %struct_type.x.y.1: type = struct_type {.x: %i32, .y: %i32} [template]
  406. // CHECK:STDOUT: %complete_type.3: <witness> = complete_type_witness %struct_type.x.y.1 [template]
  407. // CHECK:STDOUT: %B: type = class_type @B [template]
  408. // CHECK:STDOUT: %int_1.1: Core.IntLiteral = int_value 1 [template]
  409. // CHECK:STDOUT: %int_2.1: Core.IntLiteral = int_value 2 [template]
  410. // CHECK:STDOUT: %struct_type.x.y.2: type = struct_type {.x: Core.IntLiteral, .y: Core.IntLiteral} [template]
  411. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  412. // CHECK:STDOUT: %Convert.type.10: type = fn_type @Convert.2, @impl.1(%int_32) [template]
  413. // CHECK:STDOUT: %Convert.10: %Convert.type.10 = struct_value () [template]
  414. // CHECK:STDOUT: %interface.5: <witness> = interface_witness (%Convert.10) [template]
  415. // CHECK:STDOUT: %Convert.bound.1: <bound method> = bound_method %int_1.1, %Convert.10 [template]
  416. // CHECK:STDOUT: %Convert.specific_fn.1: <specific function> = specific_function %Convert.bound.1, @Convert.2(%int_32) [template]
  417. // CHECK:STDOUT: %int_1.2: %i32 = int_value 1 [template]
  418. // CHECK:STDOUT: %Convert.bound.2: <bound method> = bound_method %int_2.1, %Convert.10 [template]
  419. // CHECK:STDOUT: %Convert.specific_fn.2: <specific function> = specific_function %Convert.bound.2, @Convert.2(%int_32) [template]
  420. // CHECK:STDOUT: %int_2.2: %i32 = int_value 2 [template]
  421. // CHECK:STDOUT: %A.val: %A = struct_value (%int_1.2, %int_2.2) [template]
  422. // CHECK:STDOUT: }
  423. // CHECK:STDOUT:
  424. // CHECK:STDOUT: imports {
  425. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  426. // CHECK:STDOUT: .Int = %import_ref.1
  427. // CHECK:STDOUT: .ImplicitAs = %import_ref.5
  428. // CHECK:STDOUT: import Core//prelude
  429. // CHECK:STDOUT: import Core//prelude/...
  430. // CHECK:STDOUT: }
  431. // CHECK:STDOUT: }
  432. // CHECK:STDOUT:
  433. // CHECK:STDOUT: file {
  434. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  435. // CHECK:STDOUT: .Core = imports.%Core
  436. // CHECK:STDOUT: .A = %A.decl
  437. // CHECK:STDOUT: .B = %B.decl
  438. // CHECK:STDOUT: .b_value = @__global_init.%b_value
  439. // CHECK:STDOUT: .b_init = %b_init
  440. // CHECK:STDOUT: }
  441. // CHECK:STDOUT: %Core.import = import Core
  442. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {} {}
  443. // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {} {}
  444. // CHECK:STDOUT: %b_init.var: ref %B = var b_init
  445. // CHECK:STDOUT: %b_init: ref %B = bind_name b_init, %b_init.var
  446. // CHECK:STDOUT: }
  447. // CHECK:STDOUT:
  448. // CHECK:STDOUT: class @A {
  449. // CHECK:STDOUT: %.loc5: %A.elem = field_decl x, element0 [template]
  450. // CHECK:STDOUT: %.loc6: %A.elem = field_decl y, element1 [template]
  451. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.x.y.1 [template = constants.%complete_type.3]
  452. // CHECK:STDOUT:
  453. // CHECK:STDOUT: !members:
  454. // CHECK:STDOUT: .Self = constants.%A
  455. // CHECK:STDOUT: .x = %.loc5
  456. // CHECK:STDOUT: .y = %.loc6
  457. // CHECK:STDOUT: complete_type_witness = %complete_type
  458. // CHECK:STDOUT: }
  459. // CHECK:STDOUT:
  460. // CHECK:STDOUT: class @B {
  461. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  462. // CHECK:STDOUT: adapt_decl %A.ref [template]
  463. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.x.y.1 [template = constants.%complete_type.3]
  464. // CHECK:STDOUT:
  465. // CHECK:STDOUT: !members:
  466. // CHECK:STDOUT: .Self = constants.%B
  467. // CHECK:STDOUT: complete_type_witness = %complete_type
  468. // CHECK:STDOUT: }
  469. // CHECK:STDOUT:
  470. // CHECK:STDOUT: fn @__global_init() {
  471. // CHECK:STDOUT: !entry:
  472. // CHECK:STDOUT: %int_1.loc13: Core.IntLiteral = int_value 1 [template = constants.%int_1.1]
  473. // CHECK:STDOUT: %int_2.loc13: Core.IntLiteral = int_value 2 [template = constants.%int_2.1]
  474. // CHECK:STDOUT: %.loc13_34.1: %struct_type.x.y.2 = struct_literal (%int_1.loc13, %int_2.loc13)
  475. // CHECK:STDOUT: %A.ref.loc13: type = name_ref A, file.%A.decl [template = constants.%A]
  476. // CHECK:STDOUT: %impl.elem0.loc13_34.1: %Convert.type.2 = interface_witness_access constants.%interface.5, element0 [template = constants.%Convert.10]
  477. // CHECK:STDOUT: %Convert.bound.loc13_34.1: <bound method> = bound_method %int_1.loc13, %impl.elem0.loc13_34.1 [template = constants.%Convert.bound.1]
  478. // CHECK:STDOUT: %Convert.specific_fn.loc13_34.1: <specific function> = specific_function %Convert.bound.loc13_34.1, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.1]
  479. // CHECK:STDOUT: %int.convert_checked.loc13_34.1: init %i32 = call %Convert.specific_fn.loc13_34.1(%int_1.loc13) [template = constants.%int_1.2]
  480. // CHECK:STDOUT: %.loc13_34.2: init %i32 = converted %int_1.loc13, %int.convert_checked.loc13_34.1 [template = constants.%int_1.2]
  481. // CHECK:STDOUT: %.loc13_34.3: ref %A = temporary_storage
  482. // CHECK:STDOUT: %.loc13_34.4: ref %i32 = class_element_access %.loc13_34.3, element0
  483. // CHECK:STDOUT: %.loc13_34.5: init %i32 = initialize_from %.loc13_34.2 to %.loc13_34.4 [template = constants.%int_1.2]
  484. // CHECK:STDOUT: %impl.elem0.loc13_34.2: %Convert.type.2 = interface_witness_access constants.%interface.5, element0 [template = constants.%Convert.10]
  485. // CHECK:STDOUT: %Convert.bound.loc13_34.2: <bound method> = bound_method %int_2.loc13, %impl.elem0.loc13_34.2 [template = constants.%Convert.bound.2]
  486. // CHECK:STDOUT: %Convert.specific_fn.loc13_34.2: <specific function> = specific_function %Convert.bound.loc13_34.2, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.2]
  487. // CHECK:STDOUT: %int.convert_checked.loc13_34.2: init %i32 = call %Convert.specific_fn.loc13_34.2(%int_2.loc13) [template = constants.%int_2.2]
  488. // CHECK:STDOUT: %.loc13_34.6: init %i32 = converted %int_2.loc13, %int.convert_checked.loc13_34.2 [template = constants.%int_2.2]
  489. // CHECK:STDOUT: %.loc13_34.7: ref %i32 = class_element_access %.loc13_34.3, element1
  490. // CHECK:STDOUT: %.loc13_34.8: init %i32 = initialize_from %.loc13_34.6 to %.loc13_34.7 [template = constants.%int_2.2]
  491. // CHECK:STDOUT: %.loc13_34.9: init %A = class_init (%.loc13_34.5, %.loc13_34.8), %.loc13_34.3 [template = constants.%A.val]
  492. // CHECK:STDOUT: %.loc13_34.10: ref %A = temporary %.loc13_34.3, %.loc13_34.9
  493. // CHECK:STDOUT: %.loc13_36: ref %A = converted %.loc13_34.1, %.loc13_34.10
  494. // CHECK:STDOUT: %B.ref.loc13: type = name_ref B, file.%B.decl [template = constants.%B]
  495. // CHECK:STDOUT: %.loc13_42.1: ref %B = as_compatible %.loc13_36
  496. // CHECK:STDOUT: %.loc13_42.2: ref %B = converted %.loc13_36, %.loc13_42.1
  497. // CHECK:STDOUT: %.loc13_42.3: %B = bind_value %.loc13_42.2
  498. // CHECK:STDOUT: %b_value: %B = bind_name b_value, %.loc13_42.3
  499. // CHECK:STDOUT: %int_1.loc24: Core.IntLiteral = int_value 1 [template = constants.%int_1.1]
  500. // CHECK:STDOUT: %int_2.loc24: Core.IntLiteral = int_value 2 [template = constants.%int_2.1]
  501. // CHECK:STDOUT: %.loc24_33.1: %struct_type.x.y.2 = struct_literal (%int_1.loc24, %int_2.loc24)
  502. // CHECK:STDOUT: %A.ref.loc24: type = name_ref A, file.%A.decl [template = constants.%A]
  503. // CHECK:STDOUT: %impl.elem0.loc24_33.1: %Convert.type.2 = interface_witness_access constants.%interface.5, element0 [template = constants.%Convert.10]
  504. // CHECK:STDOUT: %Convert.bound.loc24_33.1: <bound method> = bound_method %int_1.loc24, %impl.elem0.loc24_33.1 [template = constants.%Convert.bound.1]
  505. // CHECK:STDOUT: %Convert.specific_fn.loc24_33.1: <specific function> = specific_function %Convert.bound.loc24_33.1, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.1]
  506. // CHECK:STDOUT: %int.convert_checked.loc24_33.1: init %i32 = call %Convert.specific_fn.loc24_33.1(%int_1.loc24) [template = constants.%int_1.2]
  507. // CHECK:STDOUT: %.loc24_33.2: init %i32 = converted %int_1.loc24, %int.convert_checked.loc24_33.1 [template = constants.%int_1.2]
  508. // CHECK:STDOUT: %.loc24_33.3: ref %A = temporary_storage
  509. // CHECK:STDOUT: %.loc24_33.4: ref %i32 = class_element_access %.loc24_33.3, element0
  510. // CHECK:STDOUT: %.loc24_33.5: init %i32 = initialize_from %.loc24_33.2 to %.loc24_33.4 [template = constants.%int_1.2]
  511. // CHECK:STDOUT: %impl.elem0.loc24_33.2: %Convert.type.2 = interface_witness_access constants.%interface.5, element0 [template = constants.%Convert.10]
  512. // CHECK:STDOUT: %Convert.bound.loc24_33.2: <bound method> = bound_method %int_2.loc24, %impl.elem0.loc24_33.2 [template = constants.%Convert.bound.2]
  513. // CHECK:STDOUT: %Convert.specific_fn.loc24_33.2: <specific function> = specific_function %Convert.bound.loc24_33.2, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.2]
  514. // CHECK:STDOUT: %int.convert_checked.loc24_33.2: init %i32 = call %Convert.specific_fn.loc24_33.2(%int_2.loc24) [template = constants.%int_2.2]
  515. // CHECK:STDOUT: %.loc24_33.6: init %i32 = converted %int_2.loc24, %int.convert_checked.loc24_33.2 [template = constants.%int_2.2]
  516. // CHECK:STDOUT: %.loc24_33.7: ref %i32 = class_element_access %.loc24_33.3, element1
  517. // CHECK:STDOUT: %.loc24_33.8: init %i32 = initialize_from %.loc24_33.6 to %.loc24_33.7 [template = constants.%int_2.2]
  518. // CHECK:STDOUT: %.loc24_33.9: init %A = class_init (%.loc24_33.5, %.loc24_33.8), %.loc24_33.3 [template = constants.%A.val]
  519. // CHECK:STDOUT: %.loc24_33.10: ref %A = temporary %.loc24_33.3, %.loc24_33.9
  520. // CHECK:STDOUT: %.loc24_35: ref %A = converted %.loc24_33.1, %.loc24_33.10
  521. // CHECK:STDOUT: %B.ref.loc24: type = name_ref B, file.%B.decl [template = constants.%B]
  522. // CHECK:STDOUT: %.loc24_41.1: ref %B = as_compatible %.loc24_35
  523. // CHECK:STDOUT: %.loc24_41.2: ref %B = converted %.loc24_35, %.loc24_41.1
  524. // CHECK:STDOUT: %.loc24_41.3: %B = bind_value %.loc24_41.2
  525. // CHECK:STDOUT: assign file.%b_init.var, <error>
  526. // CHECK:STDOUT: return
  527. // CHECK:STDOUT: }
  528. // CHECK:STDOUT:
  529. // CHECK:STDOUT: --- fail_adapt_init_from_struct.carbon
  530. // CHECK:STDOUT:
  531. // CHECK:STDOUT: constants {
  532. // CHECK:STDOUT: %A: type = class_type @A [template]
  533. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  534. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  535. // CHECK:STDOUT: %A.elem: type = unbound_element_type %A, %i32 [template]
  536. // CHECK:STDOUT: %struct_type.x.1: type = struct_type {.x: %i32} [template]
  537. // CHECK:STDOUT: %complete_type.3: <witness> = complete_type_witness %struct_type.x.1 [template]
  538. // CHECK:STDOUT: %B: type = class_type @B [template]
  539. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template]
  540. // CHECK:STDOUT: %struct_type.x.2: type = struct_type {.x: Core.IntLiteral} [template]
  541. // CHECK:STDOUT: }
  542. // CHECK:STDOUT:
  543. // CHECK:STDOUT: imports {
  544. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  545. // CHECK:STDOUT: .Int = %import_ref.1
  546. // CHECK:STDOUT: .As = %import_ref.5
  547. // CHECK:STDOUT: import Core//prelude
  548. // CHECK:STDOUT: import Core//prelude/...
  549. // CHECK:STDOUT: }
  550. // CHECK:STDOUT: }
  551. // CHECK:STDOUT:
  552. // CHECK:STDOUT: file {
  553. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  554. // CHECK:STDOUT: .Core = imports.%Core
  555. // CHECK:STDOUT: .A = %A.decl
  556. // CHECK:STDOUT: .B = %B.decl
  557. // CHECK:STDOUT: .b = %b
  558. // CHECK:STDOUT: }
  559. // CHECK:STDOUT: %Core.import = import Core
  560. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {} {}
  561. // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {} {}
  562. // CHECK:STDOUT: %b.var: ref %B = var b
  563. // CHECK:STDOUT: %b: ref %B = bind_name b, %b.var
  564. // CHECK:STDOUT: }
  565. // CHECK:STDOUT:
  566. // CHECK:STDOUT: class @A {
  567. // CHECK:STDOUT: %.loc5: %A.elem = field_decl x, element0 [template]
  568. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.x.1 [template = constants.%complete_type.3]
  569. // CHECK:STDOUT:
  570. // CHECK:STDOUT: !members:
  571. // CHECK:STDOUT: .Self = constants.%A
  572. // CHECK:STDOUT: .x = %.loc5
  573. // CHECK:STDOUT: complete_type_witness = %complete_type
  574. // CHECK:STDOUT: }
  575. // CHECK:STDOUT:
  576. // CHECK:STDOUT: class @B {
  577. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  578. // CHECK:STDOUT: adapt_decl %A.ref [template]
  579. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.x.1 [template = constants.%complete_type.3]
  580. // CHECK:STDOUT:
  581. // CHECK:STDOUT: !members:
  582. // CHECK:STDOUT: .Self = constants.%B
  583. // CHECK:STDOUT: complete_type_witness = %complete_type
  584. // CHECK:STDOUT: }
  585. // CHECK:STDOUT:
  586. // CHECK:STDOUT: fn @__global_init() {
  587. // CHECK:STDOUT: !entry:
  588. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1]
  589. // CHECK:STDOUT: %.loc21_19: %struct_type.x.2 = struct_literal (%int_1)
  590. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [template = constants.%B]
  591. // CHECK:STDOUT: %.loc21_21: %B = converted %.loc21_19, <error> [template = <error>]
  592. // CHECK:STDOUT: assign file.%b.var, <error>
  593. // CHECK:STDOUT: return
  594. // CHECK:STDOUT: }
  595. // CHECK:STDOUT: