export_mixed.carbon 22 KB

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