import_indirect.carbon 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  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/import_indirect.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/import_indirect.carbon
  10. // Triangle:
  11. //
  12. // a <-- Define
  13. // |\
  14. // | b <-- Re-export
  15. // |/
  16. // X <-- Use both
  17. //
  18. // Diamond:
  19. //
  20. // a <-- Define
  21. // / \
  22. // b c <-- Re-export
  23. // \ /
  24. // X <-- Use both
  25. // ============================================================================
  26. // Setup files
  27. // ============================================================================
  28. // --- a.carbon
  29. library "[[@TEST_NAME]]";
  30. class C {}
  31. // --- b.carbon
  32. library "[[@TEST_NAME]]";
  33. import library "a";
  34. alias D = C;
  35. var b_val: C = {};
  36. var b_ptr: D* = &b_val;
  37. // --- c.carbon
  38. library "[[@TEST_NAME]]";
  39. import library "a";
  40. alias E = C;
  41. var c_val: C = {};
  42. var c_ptr: E* = &c_val;
  43. // ============================================================================
  44. // Test files
  45. // ============================================================================
  46. // --- triangle.carbon
  47. library "[[@TEST_NAME]]";
  48. import library "a";
  49. import library "b";
  50. var val: C = {};
  51. var ptr: D* = &val;
  52. // --- triangle_reverse.carbon
  53. library "[[@TEST_NAME]]";
  54. import library "b";
  55. import library "a";
  56. var val: C = {};
  57. var ptr: D* = &val;
  58. // --- diamond.carbon
  59. library "[[@TEST_NAME]]";
  60. import library "b";
  61. import library "c";
  62. var val: D = {};
  63. var ptr: E* = &val;
  64. // --- diamond_reverse.carbon
  65. library "[[@TEST_NAME]]";
  66. import library "c";
  67. import library "b";
  68. var val: D = {};
  69. var ptr: E* = &val;
  70. // CHECK:STDOUT: --- a.carbon
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: constants {
  73. // CHECK:STDOUT: %C: type = class_type @C [template]
  74. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  75. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: imports {
  79. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  80. // CHECK:STDOUT: import Core//prelude
  81. // CHECK:STDOUT: import Core//prelude/...
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: file {
  86. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  87. // CHECK:STDOUT: .Core = imports.%Core
  88. // CHECK:STDOUT: .C = %C.decl
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT: %Core.import = import Core
  91. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: class @C {
  95. // CHECK:STDOUT: %.loc4: <witness> = complete_type_witness %.1 [template = constants.%.2]
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: !members:
  98. // CHECK:STDOUT: .Self = constants.%C
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: --- b.carbon
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: constants {
  104. // CHECK:STDOUT: %C: type = class_type @C [template]
  105. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  106. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  107. // CHECK:STDOUT: %.3: type = tuple_type () [template]
  108. // CHECK:STDOUT: %.4: type = ptr_type %.1 [template]
  109. // CHECK:STDOUT: %struct: %C = struct_value () [template]
  110. // CHECK:STDOUT: %.5: type = ptr_type %C [template]
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT:
  113. // CHECK:STDOUT: imports {
  114. // CHECK:STDOUT: %import_ref.1: type = import_ref Main//a, inst+3, loaded [template = constants.%C]
  115. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  116. // CHECK:STDOUT: import Core//prelude
  117. // CHECK:STDOUT: import Core//prelude/...
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT: %import_ref.2 = import_ref Main//a, inst+4, unloaded
  120. // CHECK:STDOUT: }
  121. // CHECK:STDOUT:
  122. // CHECK:STDOUT: file {
  123. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  124. // CHECK:STDOUT: .C = imports.%import_ref.1
  125. // CHECK:STDOUT: .Core = imports.%Core
  126. // CHECK:STDOUT: .D = %D
  127. // CHECK:STDOUT: .b_val = %b_val
  128. // CHECK:STDOUT: .b_ptr = %b_ptr
  129. // CHECK:STDOUT: }
  130. // CHECK:STDOUT: %Core.import = import Core
  131. // CHECK:STDOUT: %default.import = import <invalid>
  132. // CHECK:STDOUT: %C.ref.loc6: type = name_ref C, imports.%import_ref.1 [template = constants.%C]
  133. // CHECK:STDOUT: %D: type = bind_alias D, imports.%import_ref.1 [template = constants.%C]
  134. // CHECK:STDOUT: %C.ref.loc8: type = name_ref C, imports.%import_ref.1 [template = constants.%C]
  135. // CHECK:STDOUT: %b_val.var: ref %C = var b_val
  136. // CHECK:STDOUT: %b_val: ref %C = bind_name b_val, %b_val.var
  137. // CHECK:STDOUT: %D.ref: type = name_ref D, %D [template = constants.%C]
  138. // CHECK:STDOUT: %.loc9: type = ptr_type %C [template = constants.%.5]
  139. // CHECK:STDOUT: %b_ptr.var: ref %.5 = var b_ptr
  140. // CHECK:STDOUT: %b_ptr: ref %.5 = bind_name b_ptr, %b_ptr.var
  141. // CHECK:STDOUT: }
  142. // CHECK:STDOUT:
  143. // CHECK:STDOUT: class @C {
  144. // CHECK:STDOUT: !members:
  145. // CHECK:STDOUT: .Self = imports.%import_ref.2
  146. // CHECK:STDOUT: }
  147. // CHECK:STDOUT:
  148. // CHECK:STDOUT: fn @__global_init() {
  149. // CHECK:STDOUT: !entry:
  150. // CHECK:STDOUT: %.loc8_17.1: %.1 = struct_literal ()
  151. // CHECK:STDOUT: %.loc8_17.2: init %C = class_init (), file.%b_val.var [template = constants.%struct]
  152. // CHECK:STDOUT: %.loc8_18: init %C = converted %.loc8_17.1, %.loc8_17.2 [template = constants.%struct]
  153. // CHECK:STDOUT: assign file.%b_val.var, %.loc8_18
  154. // CHECK:STDOUT: %b_val.ref: ref %C = name_ref b_val, file.%b_val
  155. // CHECK:STDOUT: %.loc9: %.5 = addr_of %b_val.ref
  156. // CHECK:STDOUT: assign file.%b_ptr.var, %.loc9
  157. // CHECK:STDOUT: return
  158. // CHECK:STDOUT: }
  159. // CHECK:STDOUT:
  160. // CHECK:STDOUT: --- c.carbon
  161. // CHECK:STDOUT:
  162. // CHECK:STDOUT: constants {
  163. // CHECK:STDOUT: %C: type = class_type @C [template]
  164. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  165. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  166. // CHECK:STDOUT: %.3: type = tuple_type () [template]
  167. // CHECK:STDOUT: %.4: type = ptr_type %.1 [template]
  168. // CHECK:STDOUT: %struct: %C = struct_value () [template]
  169. // CHECK:STDOUT: %.5: type = ptr_type %C [template]
  170. // CHECK:STDOUT: }
  171. // CHECK:STDOUT:
  172. // CHECK:STDOUT: imports {
  173. // CHECK:STDOUT: %import_ref.1: type = import_ref Main//a, inst+3, loaded [template = constants.%C]
  174. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  175. // CHECK:STDOUT: import Core//prelude
  176. // CHECK:STDOUT: import Core//prelude/...
  177. // CHECK:STDOUT: }
  178. // CHECK:STDOUT: %import_ref.2 = import_ref Main//a, inst+4, unloaded
  179. // CHECK:STDOUT: }
  180. // CHECK:STDOUT:
  181. // CHECK:STDOUT: file {
  182. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  183. // CHECK:STDOUT: .C = imports.%import_ref.1
  184. // CHECK:STDOUT: .Core = imports.%Core
  185. // CHECK:STDOUT: .E = %E
  186. // CHECK:STDOUT: .c_val = %c_val
  187. // CHECK:STDOUT: .c_ptr = %c_ptr
  188. // CHECK:STDOUT: }
  189. // CHECK:STDOUT: %Core.import = import Core
  190. // CHECK:STDOUT: %default.import = import <invalid>
  191. // CHECK:STDOUT: %C.ref.loc6: type = name_ref C, imports.%import_ref.1 [template = constants.%C]
  192. // CHECK:STDOUT: %E: type = bind_alias E, imports.%import_ref.1 [template = constants.%C]
  193. // CHECK:STDOUT: %C.ref.loc8: type = name_ref C, imports.%import_ref.1 [template = constants.%C]
  194. // CHECK:STDOUT: %c_val.var: ref %C = var c_val
  195. // CHECK:STDOUT: %c_val: ref %C = bind_name c_val, %c_val.var
  196. // CHECK:STDOUT: %E.ref: type = name_ref E, %E [template = constants.%C]
  197. // CHECK:STDOUT: %.loc9: type = ptr_type %C [template = constants.%.5]
  198. // CHECK:STDOUT: %c_ptr.var: ref %.5 = var c_ptr
  199. // CHECK:STDOUT: %c_ptr: ref %.5 = bind_name c_ptr, %c_ptr.var
  200. // CHECK:STDOUT: }
  201. // CHECK:STDOUT:
  202. // CHECK:STDOUT: class @C {
  203. // CHECK:STDOUT: !members:
  204. // CHECK:STDOUT: .Self = imports.%import_ref.2
  205. // CHECK:STDOUT: }
  206. // CHECK:STDOUT:
  207. // CHECK:STDOUT: fn @__global_init() {
  208. // CHECK:STDOUT: !entry:
  209. // CHECK:STDOUT: %.loc8_17.1: %.1 = struct_literal ()
  210. // CHECK:STDOUT: %.loc8_17.2: init %C = class_init (), file.%c_val.var [template = constants.%struct]
  211. // CHECK:STDOUT: %.loc8_18: init %C = converted %.loc8_17.1, %.loc8_17.2 [template = constants.%struct]
  212. // CHECK:STDOUT: assign file.%c_val.var, %.loc8_18
  213. // CHECK:STDOUT: %c_val.ref: ref %C = name_ref c_val, file.%c_val
  214. // CHECK:STDOUT: %.loc9: %.5 = addr_of %c_val.ref
  215. // CHECK:STDOUT: assign file.%c_ptr.var, %.loc9
  216. // CHECK:STDOUT: return
  217. // CHECK:STDOUT: }
  218. // CHECK:STDOUT:
  219. // CHECK:STDOUT: --- triangle.carbon
  220. // CHECK:STDOUT:
  221. // CHECK:STDOUT: constants {
  222. // CHECK:STDOUT: %C: type = class_type @C [template]
  223. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  224. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  225. // CHECK:STDOUT: %.3: type = tuple_type () [template]
  226. // CHECK:STDOUT: %.4: type = ptr_type %.1 [template]
  227. // CHECK:STDOUT: %struct: %C = struct_value () [template]
  228. // CHECK:STDOUT: %.5: type = ptr_type %C [template]
  229. // CHECK:STDOUT: }
  230. // CHECK:STDOUT:
  231. // CHECK:STDOUT: imports {
  232. // CHECK:STDOUT: %import_ref.1: type = import_ref Main//a, inst+3, loaded [template = constants.%C]
  233. // CHECK:STDOUT: %import_ref.2: type = import_ref Main//b, inst+11, loaded [template = constants.%C]
  234. // CHECK:STDOUT: %import_ref.3 = import_ref Main//b, inst+16, unloaded
  235. // CHECK:STDOUT: %import_ref.4 = import_ref Main//b, inst+26, unloaded
  236. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  237. // CHECK:STDOUT: import Core//prelude
  238. // CHECK:STDOUT: import Core//prelude/...
  239. // CHECK:STDOUT: }
  240. // CHECK:STDOUT: %import_ref.5 = import_ref Main//a, inst+4, unloaded
  241. // CHECK:STDOUT: }
  242. // CHECK:STDOUT:
  243. // CHECK:STDOUT: file {
  244. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  245. // CHECK:STDOUT: .C = imports.%import_ref.1
  246. // CHECK:STDOUT: .D = imports.%import_ref.2
  247. // CHECK:STDOUT: .b_val = imports.%import_ref.3
  248. // CHECK:STDOUT: .b_ptr = imports.%import_ref.4
  249. // CHECK:STDOUT: .Core = imports.%Core
  250. // CHECK:STDOUT: .val = %val
  251. // CHECK:STDOUT: .ptr = %ptr
  252. // CHECK:STDOUT: }
  253. // CHECK:STDOUT: %Core.import = import Core
  254. // CHECK:STDOUT: %default.import = import <invalid>
  255. // CHECK:STDOUT: %C.ref: type = name_ref C, imports.%import_ref.1 [template = constants.%C]
  256. // CHECK:STDOUT: %val.var: ref %C = var val
  257. // CHECK:STDOUT: %val: ref %C = bind_name val, %val.var
  258. // CHECK:STDOUT: %D.ref: type = name_ref D, imports.%import_ref.2 [template = constants.%C]
  259. // CHECK:STDOUT: %.loc8: type = ptr_type %C [template = constants.%.5]
  260. // CHECK:STDOUT: %ptr.var: ref %.5 = var ptr
  261. // CHECK:STDOUT: %ptr: ref %.5 = bind_name ptr, %ptr.var
  262. // CHECK:STDOUT: }
  263. // CHECK:STDOUT:
  264. // CHECK:STDOUT: class @C {
  265. // CHECK:STDOUT: !members:
  266. // CHECK:STDOUT: .Self = imports.%import_ref.5
  267. // CHECK:STDOUT: }
  268. // CHECK:STDOUT:
  269. // CHECK:STDOUT: fn @__global_init() {
  270. // CHECK:STDOUT: !entry:
  271. // CHECK:STDOUT: %.loc7_15.1: %.1 = struct_literal ()
  272. // CHECK:STDOUT: %.loc7_15.2: init %C = class_init (), file.%val.var [template = constants.%struct]
  273. // CHECK:STDOUT: %.loc7_16: init %C = converted %.loc7_15.1, %.loc7_15.2 [template = constants.%struct]
  274. // CHECK:STDOUT: assign file.%val.var, %.loc7_16
  275. // CHECK:STDOUT: %val.ref: ref %C = name_ref val, file.%val
  276. // CHECK:STDOUT: %.loc8: %.5 = addr_of %val.ref
  277. // CHECK:STDOUT: assign file.%ptr.var, %.loc8
  278. // CHECK:STDOUT: return
  279. // CHECK:STDOUT: }
  280. // CHECK:STDOUT:
  281. // CHECK:STDOUT: --- triangle_reverse.carbon
  282. // CHECK:STDOUT:
  283. // CHECK:STDOUT: constants {
  284. // CHECK:STDOUT: %C: type = class_type @C [template]
  285. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  286. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  287. // CHECK:STDOUT: %.3: type = tuple_type () [template]
  288. // CHECK:STDOUT: %.4: type = ptr_type %.1 [template]
  289. // CHECK:STDOUT: %struct: %C = struct_value () [template]
  290. // CHECK:STDOUT: %.5: type = ptr_type %C [template]
  291. // CHECK:STDOUT: }
  292. // CHECK:STDOUT:
  293. // CHECK:STDOUT: imports {
  294. // CHECK:STDOUT: %import_ref.1: type = import_ref Main//b, inst+11, loaded [template = constants.%C]
  295. // CHECK:STDOUT: %import_ref.2 = import_ref Main//b, inst+16, unloaded
  296. // CHECK:STDOUT: %import_ref.3 = import_ref Main//b, inst+26, unloaded
  297. // CHECK:STDOUT: %import_ref.4: type = import_ref Main//a, inst+3, loaded [template = constants.%C]
  298. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  299. // CHECK:STDOUT: import Core//prelude
  300. // CHECK:STDOUT: import Core//prelude/...
  301. // CHECK:STDOUT: }
  302. // CHECK:STDOUT: %import_ref.5 = import_ref Main//a, inst+4, unloaded
  303. // CHECK:STDOUT: }
  304. // CHECK:STDOUT:
  305. // CHECK:STDOUT: file {
  306. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  307. // CHECK:STDOUT: .D = imports.%import_ref.1
  308. // CHECK:STDOUT: .b_val = imports.%import_ref.2
  309. // CHECK:STDOUT: .b_ptr = imports.%import_ref.3
  310. // CHECK:STDOUT: .C = imports.%import_ref.4
  311. // CHECK:STDOUT: .Core = imports.%Core
  312. // CHECK:STDOUT: .val = %val
  313. // CHECK:STDOUT: .ptr = %ptr
  314. // CHECK:STDOUT: }
  315. // CHECK:STDOUT: %Core.import = import Core
  316. // CHECK:STDOUT: %default.import = import <invalid>
  317. // CHECK:STDOUT: %C.ref: type = name_ref C, imports.%import_ref.4 [template = constants.%C]
  318. // CHECK:STDOUT: %val.var: ref %C = var val
  319. // CHECK:STDOUT: %val: ref %C = bind_name val, %val.var
  320. // CHECK:STDOUT: %D.ref: type = name_ref D, imports.%import_ref.1 [template = constants.%C]
  321. // CHECK:STDOUT: %.loc8: type = ptr_type %C [template = constants.%.5]
  322. // CHECK:STDOUT: %ptr.var: ref %.5 = var ptr
  323. // CHECK:STDOUT: %ptr: ref %.5 = bind_name ptr, %ptr.var
  324. // CHECK:STDOUT: }
  325. // CHECK:STDOUT:
  326. // CHECK:STDOUT: class @C {
  327. // CHECK:STDOUT: !members:
  328. // CHECK:STDOUT: .Self = imports.%import_ref.5
  329. // CHECK:STDOUT: }
  330. // CHECK:STDOUT:
  331. // CHECK:STDOUT: fn @__global_init() {
  332. // CHECK:STDOUT: !entry:
  333. // CHECK:STDOUT: %.loc7_15.1: %.1 = struct_literal ()
  334. // CHECK:STDOUT: %.loc7_15.2: init %C = class_init (), file.%val.var [template = constants.%struct]
  335. // CHECK:STDOUT: %.loc7_16: init %C = converted %.loc7_15.1, %.loc7_15.2 [template = constants.%struct]
  336. // CHECK:STDOUT: assign file.%val.var, %.loc7_16
  337. // CHECK:STDOUT: %val.ref: ref %C = name_ref val, file.%val
  338. // CHECK:STDOUT: %.loc8: %.5 = addr_of %val.ref
  339. // CHECK:STDOUT: assign file.%ptr.var, %.loc8
  340. // CHECK:STDOUT: return
  341. // CHECK:STDOUT: }
  342. // CHECK:STDOUT:
  343. // CHECK:STDOUT: --- diamond.carbon
  344. // CHECK:STDOUT:
  345. // CHECK:STDOUT: constants {
  346. // CHECK:STDOUT: %C: type = class_type @C [template]
  347. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  348. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  349. // CHECK:STDOUT: %.3: type = tuple_type () [template]
  350. // CHECK:STDOUT: %.4: type = ptr_type %.1 [template]
  351. // CHECK:STDOUT: %struct: %C = struct_value () [template]
  352. // CHECK:STDOUT: %.5: type = ptr_type %C [template]
  353. // CHECK:STDOUT: }
  354. // CHECK:STDOUT:
  355. // CHECK:STDOUT: imports {
  356. // CHECK:STDOUT: %import_ref.1: type = import_ref Main//b, inst+11, loaded [template = constants.%C]
  357. // CHECK:STDOUT: %import_ref.2 = import_ref Main//b, inst+16, unloaded
  358. // CHECK:STDOUT: %import_ref.3 = import_ref Main//b, inst+26, unloaded
  359. // CHECK:STDOUT: %import_ref.4: type = import_ref Main//c, inst+11, loaded [template = constants.%C]
  360. // CHECK:STDOUT: %import_ref.5 = import_ref Main//c, inst+16, unloaded
  361. // CHECK:STDOUT: %import_ref.6 = import_ref Main//c, inst+26, unloaded
  362. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  363. // CHECK:STDOUT: import Core//prelude
  364. // CHECK:STDOUT: import Core//prelude/...
  365. // CHECK:STDOUT: }
  366. // CHECK:STDOUT: %import_ref.7 = import_ref Main//b, inst+9, unloaded
  367. // CHECK:STDOUT: }
  368. // CHECK:STDOUT:
  369. // CHECK:STDOUT: file {
  370. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  371. // CHECK:STDOUT: .D = imports.%import_ref.1
  372. // CHECK:STDOUT: .b_val = imports.%import_ref.2
  373. // CHECK:STDOUT: .b_ptr = imports.%import_ref.3
  374. // CHECK:STDOUT: .E = imports.%import_ref.4
  375. // CHECK:STDOUT: .c_val = imports.%import_ref.5
  376. // CHECK:STDOUT: .c_ptr = imports.%import_ref.6
  377. // CHECK:STDOUT: .Core = imports.%Core
  378. // CHECK:STDOUT: .val = %val
  379. // CHECK:STDOUT: .ptr = %ptr
  380. // CHECK:STDOUT: }
  381. // CHECK:STDOUT: %Core.import = import Core
  382. // CHECK:STDOUT: %default.import = import <invalid>
  383. // CHECK:STDOUT: %D.ref: type = name_ref D, imports.%import_ref.1 [template = constants.%C]
  384. // CHECK:STDOUT: %val.var: ref %C = var val
  385. // CHECK:STDOUT: %val: ref %C = bind_name val, %val.var
  386. // CHECK:STDOUT: %E.ref: type = name_ref E, imports.%import_ref.4 [template = constants.%C]
  387. // CHECK:STDOUT: %.loc8: type = ptr_type %C [template = constants.%.5]
  388. // CHECK:STDOUT: %ptr.var: ref %.5 = var ptr
  389. // CHECK:STDOUT: %ptr: ref %.5 = bind_name ptr, %ptr.var
  390. // CHECK:STDOUT: }
  391. // CHECK:STDOUT:
  392. // CHECK:STDOUT: class @C {
  393. // CHECK:STDOUT: !members:
  394. // CHECK:STDOUT: .Self = imports.%import_ref.7
  395. // CHECK:STDOUT: }
  396. // CHECK:STDOUT:
  397. // CHECK:STDOUT: fn @__global_init() {
  398. // CHECK:STDOUT: !entry:
  399. // CHECK:STDOUT: %.loc7_15.1: %.1 = struct_literal ()
  400. // CHECK:STDOUT: %.loc7_15.2: init %C = class_init (), file.%val.var [template = constants.%struct]
  401. // CHECK:STDOUT: %.loc7_16: init %C = converted %.loc7_15.1, %.loc7_15.2 [template = constants.%struct]
  402. // CHECK:STDOUT: assign file.%val.var, %.loc7_16
  403. // CHECK:STDOUT: %val.ref: ref %C = name_ref val, file.%val
  404. // CHECK:STDOUT: %.loc8: %.5 = addr_of %val.ref
  405. // CHECK:STDOUT: assign file.%ptr.var, %.loc8
  406. // CHECK:STDOUT: return
  407. // CHECK:STDOUT: }
  408. // CHECK:STDOUT:
  409. // CHECK:STDOUT: --- diamond_reverse.carbon
  410. // CHECK:STDOUT:
  411. // CHECK:STDOUT: constants {
  412. // CHECK:STDOUT: %C: type = class_type @C [template]
  413. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  414. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  415. // CHECK:STDOUT: %.3: type = tuple_type () [template]
  416. // CHECK:STDOUT: %.4: type = ptr_type %.1 [template]
  417. // CHECK:STDOUT: %struct: %C = struct_value () [template]
  418. // CHECK:STDOUT: %.5: type = ptr_type %C [template]
  419. // CHECK:STDOUT: }
  420. // CHECK:STDOUT:
  421. // CHECK:STDOUT: imports {
  422. // CHECK:STDOUT: %import_ref.1: type = import_ref Main//c, inst+11, loaded [template = constants.%C]
  423. // CHECK:STDOUT: %import_ref.2 = import_ref Main//c, inst+16, unloaded
  424. // CHECK:STDOUT: %import_ref.3 = import_ref Main//c, inst+26, unloaded
  425. // CHECK:STDOUT: %import_ref.4: type = import_ref Main//b, inst+11, loaded [template = constants.%C]
  426. // CHECK:STDOUT: %import_ref.5 = import_ref Main//b, inst+16, unloaded
  427. // CHECK:STDOUT: %import_ref.6 = import_ref Main//b, inst+26, unloaded
  428. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  429. // CHECK:STDOUT: import Core//prelude
  430. // CHECK:STDOUT: import Core//prelude/...
  431. // CHECK:STDOUT: }
  432. // CHECK:STDOUT: %import_ref.7 = import_ref Main//b, inst+9, unloaded
  433. // CHECK:STDOUT: }
  434. // CHECK:STDOUT:
  435. // CHECK:STDOUT: file {
  436. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  437. // CHECK:STDOUT: .E = imports.%import_ref.1
  438. // CHECK:STDOUT: .c_val = imports.%import_ref.2
  439. // CHECK:STDOUT: .c_ptr = imports.%import_ref.3
  440. // CHECK:STDOUT: .D = imports.%import_ref.4
  441. // CHECK:STDOUT: .b_val = imports.%import_ref.5
  442. // CHECK:STDOUT: .b_ptr = imports.%import_ref.6
  443. // CHECK:STDOUT: .Core = imports.%Core
  444. // CHECK:STDOUT: .val = %val
  445. // CHECK:STDOUT: .ptr = %ptr
  446. // CHECK:STDOUT: }
  447. // CHECK:STDOUT: %Core.import = import Core
  448. // CHECK:STDOUT: %default.import = import <invalid>
  449. // CHECK:STDOUT: %D.ref: type = name_ref D, imports.%import_ref.4 [template = constants.%C]
  450. // CHECK:STDOUT: %val.var: ref %C = var val
  451. // CHECK:STDOUT: %val: ref %C = bind_name val, %val.var
  452. // CHECK:STDOUT: %E.ref: type = name_ref E, imports.%import_ref.1 [template = constants.%C]
  453. // CHECK:STDOUT: %.loc8: type = ptr_type %C [template = constants.%.5]
  454. // CHECK:STDOUT: %ptr.var: ref %.5 = var ptr
  455. // CHECK:STDOUT: %ptr: ref %.5 = bind_name ptr, %ptr.var
  456. // CHECK:STDOUT: }
  457. // CHECK:STDOUT:
  458. // CHECK:STDOUT: class @C {
  459. // CHECK:STDOUT: !members:
  460. // CHECK:STDOUT: .Self = imports.%import_ref.7
  461. // CHECK:STDOUT: }
  462. // CHECK:STDOUT:
  463. // CHECK:STDOUT: fn @__global_init() {
  464. // CHECK:STDOUT: !entry:
  465. // CHECK:STDOUT: %.loc7_15.1: %.1 = struct_literal ()
  466. // CHECK:STDOUT: %.loc7_15.2: init %C = class_init (), file.%val.var [template = constants.%struct]
  467. // CHECK:STDOUT: %.loc7_16: init %C = converted %.loc7_15.1, %.loc7_15.2 [template = constants.%struct]
  468. // CHECK:STDOUT: assign file.%val.var, %.loc7_16
  469. // CHECK:STDOUT: %val.ref: ref %C = name_ref val, file.%val
  470. // CHECK:STDOUT: %.loc8: %.5 = addr_of %val.ref
  471. // CHECK:STDOUT: assign file.%ptr.var, %.loc8
  472. // CHECK:STDOUT: return
  473. // CHECK:STDOUT: }
  474. // CHECK:STDOUT: