export_import.carbon 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  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_import.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_import.carbon
  10. // ============================================================================
  11. // Setup files
  12. // ============================================================================
  13. // --- base.carbon
  14. library "base";
  15. class C {
  16. var x: ();
  17. };
  18. // --- export.carbon
  19. library "export";
  20. export import library "base";
  21. // --- export_copy.carbon
  22. library "export_copy";
  23. export import library "base";
  24. // --- non_export.carbon
  25. library "non_export";
  26. import library "export";
  27. // --- export_export.carbon
  28. library "export_export";
  29. export import library "export";
  30. // --- import_then_export.carbon
  31. library "import_then_export";
  32. import library "base";
  33. export import library "export";
  34. // --- export_in_impl.carbon
  35. // This is just providing an API for the implicit import.
  36. library "export_in_impl";
  37. // ============================================================================
  38. // Test files
  39. // ============================================================================
  40. // --- use_export.carbon
  41. library "use_export";
  42. import library "export";
  43. var c: C = {.x = ()};
  44. // --- fail_export_in_impl.impl.carbon
  45. impl library "export_in_impl";
  46. // CHECK:STDERR: fail_export_in_impl.impl.carbon:[[@LINE+4]]:1: ERROR: `export` is only allowed in API files.
  47. // CHECK:STDERR: export import library "base";
  48. // CHECK:STDERR: ^~~~~~
  49. // CHECK:STDERR:
  50. export import library "base";
  51. // Note the import still occurs.
  52. var c: C = {.x = ()};
  53. // --- export_export.impl.carbon
  54. impl library "export_export";
  55. var c: C = {.x = ()};
  56. // --- use_export_export.carbon
  57. library "use_export_export";
  58. import library "export_export";
  59. var c: C = {.x = ()};
  60. // --- use_import_then_export.carbon
  61. library "use_import_then_export";
  62. import library "import_then_export";
  63. var c: C = {.x = ()};
  64. // --- use_import_when_export.carbon
  65. library "use_import_when_export";
  66. export import library "base";
  67. var c: C = {.x = ()};
  68. // --- use_base_and_export.carbon
  69. library "use_base_and_export";
  70. import library "base";
  71. import library "export";
  72. var c: C = {.x = ()};
  73. // --- use_export_and_base.carbon
  74. library "import_both_reversed";
  75. import library "export";
  76. import library "base";
  77. var c: C = {.x = ()};
  78. // --- use_export_copy.carbon
  79. library "use_export_copy";
  80. import library "export";
  81. import library "export_copy";
  82. var c: C = {.x = ()};
  83. // --- fail_use_non_export.carbon
  84. library "fail_use_non_export";
  85. import library "non_export";
  86. // CHECK:STDERR: fail_use_non_export.carbon:[[@LINE+3]]:15: ERROR: Name `C` not found.
  87. // CHECK:STDERR: alias Local = C;
  88. // CHECK:STDERR: ^
  89. alias Local = C;
  90. // --- use_non_export_then_base.carbon
  91. library "use_non_export_then_base";
  92. import library "non_export";
  93. export import library "base";
  94. var c: C = {.x = ()};
  95. // --- indirect_use_non_export_then_base.carbon
  96. library "indirect_use_non_export_then_base";
  97. import library "use_non_export_then_base";
  98. var indirect_c: C = {.x = ()};
  99. // CHECK:STDOUT: --- base.carbon
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: constants {
  102. // CHECK:STDOUT: %C: type = class_type @C [template]
  103. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  104. // CHECK:STDOUT: %.2: type = unbound_element_type %C, %.1 [template]
  105. // CHECK:STDOUT: %.3: type = struct_type {.x: %.1} [template]
  106. // CHECK:STDOUT: }
  107. // CHECK:STDOUT:
  108. // CHECK:STDOUT: file {
  109. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  110. // CHECK:STDOUT: .C = %C.decl
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT:
  115. // CHECK:STDOUT: class @C {
  116. // CHECK:STDOUT: %.loc5_11.1: %.1 = tuple_literal ()
  117. // CHECK:STDOUT: %.loc5_11.2: type = converted %.loc5_11.1, constants.%.1 [template = constants.%.1]
  118. // CHECK:STDOUT: %.loc5_8: %.2 = field_decl x, element0 [template]
  119. // CHECK:STDOUT:
  120. // CHECK:STDOUT: !members:
  121. // CHECK:STDOUT: .Self = constants.%C
  122. // CHECK:STDOUT: .x = %.loc5_8
  123. // CHECK:STDOUT: }
  124. // CHECK:STDOUT:
  125. // CHECK:STDOUT: --- export.carbon
  126. // CHECK:STDOUT:
  127. // CHECK:STDOUT: file {
  128. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  129. // CHECK:STDOUT: .C = %import_ref
  130. // CHECK:STDOUT: }
  131. // CHECK:STDOUT: %import_ref = import_ref ir1, inst+1, unloaded
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT:
  134. // CHECK:STDOUT: --- export_copy.carbon
  135. // CHECK:STDOUT:
  136. // CHECK:STDOUT: file {
  137. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  138. // CHECK:STDOUT: .C = %import_ref
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT: %import_ref = import_ref ir1, inst+1, unloaded
  141. // CHECK:STDOUT: }
  142. // CHECK:STDOUT:
  143. // CHECK:STDOUT: --- non_export.carbon
  144. // CHECK:STDOUT:
  145. // CHECK:STDOUT: file {
  146. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  147. // CHECK:STDOUT: .C = %import_ref
  148. // CHECK:STDOUT: }
  149. // CHECK:STDOUT: %import_ref = import_ref ir2, inst+1, unloaded
  150. // CHECK:STDOUT: }
  151. // CHECK:STDOUT:
  152. // CHECK:STDOUT: --- export_export.carbon
  153. // CHECK:STDOUT:
  154. // CHECK:STDOUT: file {
  155. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  156. // CHECK:STDOUT: .C = %import_ref
  157. // CHECK:STDOUT: }
  158. // CHECK:STDOUT: %import_ref = import_ref ir2, inst+1, unloaded
  159. // CHECK:STDOUT: }
  160. // CHECK:STDOUT:
  161. // CHECK:STDOUT: --- import_then_export.carbon
  162. // CHECK:STDOUT:
  163. // CHECK:STDOUT: file {
  164. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  165. // CHECK:STDOUT: .C = %import_ref
  166. // CHECK:STDOUT: }
  167. // CHECK:STDOUT: %import_ref = import_ref ir1, inst+1, unloaded
  168. // CHECK:STDOUT: }
  169. // CHECK:STDOUT:
  170. // CHECK:STDOUT: --- export_in_impl.carbon
  171. // CHECK:STDOUT:
  172. // CHECK:STDOUT: file {
  173. // CHECK:STDOUT: package: <namespace> = namespace [template] {}
  174. // CHECK:STDOUT: }
  175. // CHECK:STDOUT:
  176. // CHECK:STDOUT: --- use_export.carbon
  177. // CHECK:STDOUT:
  178. // CHECK:STDOUT: constants {
  179. // CHECK:STDOUT: %C: type = class_type @C [template]
  180. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  181. // CHECK:STDOUT: %.2: type = struct_type {.x: %.1} [template]
  182. // CHECK:STDOUT: %.3: type = ptr_type %.2 [template]
  183. // CHECK:STDOUT: %tuple: %.1 = tuple_value () [template]
  184. // CHECK:STDOUT: %struct: %C = struct_value (%tuple) [template]
  185. // CHECK:STDOUT: }
  186. // CHECK:STDOUT:
  187. // CHECK:STDOUT: file {
  188. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  189. // CHECK:STDOUT: .C = %import_ref.1
  190. // CHECK:STDOUT: .c = %c
  191. // CHECK:STDOUT: }
  192. // CHECK:STDOUT: %import_ref.1: type = import_ref ir2, inst+1, loaded [template = constants.%C]
  193. // CHECK:STDOUT: %import_ref.2 = import_ref ir2, inst+2, unloaded
  194. // CHECK:STDOUT: %import_ref.3 = import_ref ir2, inst+7, unloaded
  195. // CHECK:STDOUT: %C.ref: type = name_ref C, %import_ref.1 [template = constants.%C]
  196. // CHECK:STDOUT: %c.var: ref %C = var c
  197. // CHECK:STDOUT: %c: ref %C = bind_name c, %c.var
  198. // CHECK:STDOUT: }
  199. // CHECK:STDOUT:
  200. // CHECK:STDOUT: class @C {
  201. // CHECK:STDOUT: !members:
  202. // CHECK:STDOUT: .Self = file.%import_ref.2
  203. // CHECK:STDOUT: .x = file.%import_ref.3
  204. // CHECK:STDOUT: }
  205. // CHECK:STDOUT:
  206. // CHECK:STDOUT: fn @__global_init() {
  207. // CHECK:STDOUT: !entry:
  208. // CHECK:STDOUT: %.loc6_19.1: %.1 = tuple_literal ()
  209. // CHECK:STDOUT: %.loc6_20.1: %.2 = struct_literal (%.loc6_19.1)
  210. // CHECK:STDOUT: %.loc6_20.2: ref %.1 = class_element_access file.%c.var, element0
  211. // CHECK:STDOUT: %.loc6_19.2: init %.1 = tuple_init () to %.loc6_20.2 [template = constants.%tuple]
  212. // CHECK:STDOUT: %.loc6_20.3: init %.1 = converted %.loc6_19.1, %.loc6_19.2 [template = constants.%tuple]
  213. // CHECK:STDOUT: %.loc6_20.4: init %C = class_init (%.loc6_20.3), file.%c.var [template = constants.%struct]
  214. // CHECK:STDOUT: %.loc6_21: init %C = converted %.loc6_20.1, %.loc6_20.4 [template = constants.%struct]
  215. // CHECK:STDOUT: assign file.%c.var, %.loc6_21
  216. // CHECK:STDOUT: return
  217. // CHECK:STDOUT: }
  218. // CHECK:STDOUT:
  219. // CHECK:STDOUT: --- fail_export_in_impl.impl.carbon
  220. // CHECK:STDOUT:
  221. // CHECK:STDOUT: constants {
  222. // CHECK:STDOUT: %C: type = class_type @C [template]
  223. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  224. // CHECK:STDOUT: %.2: type = struct_type {.x: %.1} [template]
  225. // CHECK:STDOUT: %.3: type = ptr_type %.2 [template]
  226. // CHECK:STDOUT: %tuple: %.1 = tuple_value () [template]
  227. // CHECK:STDOUT: %struct: %C = struct_value (%tuple) [template]
  228. // CHECK:STDOUT: }
  229. // CHECK:STDOUT:
  230. // CHECK:STDOUT: file {
  231. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  232. // CHECK:STDOUT: .C = %import_ref.1
  233. // CHECK:STDOUT: .c = %c
  234. // CHECK:STDOUT: }
  235. // CHECK:STDOUT: %import_ref.1: type = import_ref ir1, inst+1, loaded [template = constants.%C]
  236. // CHECK:STDOUT: %import_ref.2 = import_ref ir1, inst+2, unloaded
  237. // CHECK:STDOUT: %import_ref.3 = import_ref ir1, inst+7, unloaded
  238. // CHECK:STDOUT: %C.ref: type = name_ref C, %import_ref.1 [template = constants.%C]
  239. // CHECK:STDOUT: %c.var: ref %C = var c
  240. // CHECK:STDOUT: %c: ref %C = bind_name c, %c.var
  241. // CHECK:STDOUT: }
  242. // CHECK:STDOUT:
  243. // CHECK:STDOUT: class @C {
  244. // CHECK:STDOUT: !members:
  245. // CHECK:STDOUT: .Self = file.%import_ref.2
  246. // CHECK:STDOUT: .x = file.%import_ref.3
  247. // CHECK:STDOUT: }
  248. // CHECK:STDOUT:
  249. // CHECK:STDOUT: fn @__global_init() {
  250. // CHECK:STDOUT: !entry:
  251. // CHECK:STDOUT: %.loc11_19.1: %.1 = tuple_literal ()
  252. // CHECK:STDOUT: %.loc11_20.1: %.2 = struct_literal (%.loc11_19.1)
  253. // CHECK:STDOUT: %.loc11_20.2: ref %.1 = class_element_access file.%c.var, element0
  254. // CHECK:STDOUT: %.loc11_19.2: init %.1 = tuple_init () to %.loc11_20.2 [template = constants.%tuple]
  255. // CHECK:STDOUT: %.loc11_20.3: init %.1 = converted %.loc11_19.1, %.loc11_19.2 [template = constants.%tuple]
  256. // CHECK:STDOUT: %.loc11_20.4: init %C = class_init (%.loc11_20.3), file.%c.var [template = constants.%struct]
  257. // CHECK:STDOUT: %.loc11_21: init %C = converted %.loc11_20.1, %.loc11_20.4 [template = constants.%struct]
  258. // CHECK:STDOUT: assign file.%c.var, %.loc11_21
  259. // CHECK:STDOUT: return
  260. // CHECK:STDOUT: }
  261. // CHECK:STDOUT:
  262. // CHECK:STDOUT: --- export_export.impl.carbon
  263. // CHECK:STDOUT:
  264. // CHECK:STDOUT: constants {
  265. // CHECK:STDOUT: %C: type = class_type @C [template]
  266. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  267. // CHECK:STDOUT: %.2: type = struct_type {.x: %.1} [template]
  268. // CHECK:STDOUT: %.3: type = ptr_type %.2 [template]
  269. // CHECK:STDOUT: %tuple: %.1 = tuple_value () [template]
  270. // CHECK:STDOUT: %struct: %C = struct_value (%tuple) [template]
  271. // CHECK:STDOUT: }
  272. // CHECK:STDOUT:
  273. // CHECK:STDOUT: file {
  274. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  275. // CHECK:STDOUT: .C = %import_ref.1
  276. // CHECK:STDOUT: .c = %c
  277. // CHECK:STDOUT: }
  278. // CHECK:STDOUT: %import_ref.1: type = import_ref ir2, inst+1, loaded [template = constants.%C]
  279. // CHECK:STDOUT: %import_ref.2 = import_ref ir2, inst+2, unloaded
  280. // CHECK:STDOUT: %import_ref.3 = import_ref ir2, inst+7, unloaded
  281. // CHECK:STDOUT: %C.ref: type = name_ref C, %import_ref.1 [template = constants.%C]
  282. // CHECK:STDOUT: %c.var: ref %C = var c
  283. // CHECK:STDOUT: %c: ref %C = bind_name c, %c.var
  284. // CHECK:STDOUT: }
  285. // CHECK:STDOUT:
  286. // CHECK:STDOUT: class @C {
  287. // CHECK:STDOUT: !members:
  288. // CHECK:STDOUT: .Self = file.%import_ref.2
  289. // CHECK:STDOUT: .x = file.%import_ref.3
  290. // CHECK:STDOUT: }
  291. // CHECK:STDOUT:
  292. // CHECK:STDOUT: fn @__global_init() {
  293. // CHECK:STDOUT: !entry:
  294. // CHECK:STDOUT: %.loc4_19.1: %.1 = tuple_literal ()
  295. // CHECK:STDOUT: %.loc4_20.1: %.2 = struct_literal (%.loc4_19.1)
  296. // CHECK:STDOUT: %.loc4_20.2: ref %.1 = class_element_access file.%c.var, element0
  297. // CHECK:STDOUT: %.loc4_19.2: init %.1 = tuple_init () to %.loc4_20.2 [template = constants.%tuple]
  298. // CHECK:STDOUT: %.loc4_20.3: init %.1 = converted %.loc4_19.1, %.loc4_19.2 [template = constants.%tuple]
  299. // CHECK:STDOUT: %.loc4_20.4: init %C = class_init (%.loc4_20.3), file.%c.var [template = constants.%struct]
  300. // CHECK:STDOUT: %.loc4_21: init %C = converted %.loc4_20.1, %.loc4_20.4 [template = constants.%struct]
  301. // CHECK:STDOUT: assign file.%c.var, %.loc4_21
  302. // CHECK:STDOUT: return
  303. // CHECK:STDOUT: }
  304. // CHECK:STDOUT:
  305. // CHECK:STDOUT: --- use_export_export.carbon
  306. // CHECK:STDOUT:
  307. // CHECK:STDOUT: constants {
  308. // CHECK:STDOUT: %C: type = class_type @C [template]
  309. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  310. // CHECK:STDOUT: %.2: type = struct_type {.x: %.1} [template]
  311. // CHECK:STDOUT: %.3: type = ptr_type %.2 [template]
  312. // CHECK:STDOUT: %tuple: %.1 = tuple_value () [template]
  313. // CHECK:STDOUT: %struct: %C = struct_value (%tuple) [template]
  314. // CHECK:STDOUT: }
  315. // CHECK:STDOUT:
  316. // CHECK:STDOUT: file {
  317. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  318. // CHECK:STDOUT: .C = %import_ref.1
  319. // CHECK:STDOUT: .c = %c
  320. // CHECK:STDOUT: }
  321. // CHECK:STDOUT: %import_ref.1: type = import_ref ir3, inst+1, loaded [template = constants.%C]
  322. // CHECK:STDOUT: %import_ref.2 = import_ref ir3, inst+2, unloaded
  323. // CHECK:STDOUT: %import_ref.3 = import_ref ir3, inst+7, unloaded
  324. // CHECK:STDOUT: %C.ref: type = name_ref C, %import_ref.1 [template = constants.%C]
  325. // CHECK:STDOUT: %c.var: ref %C = var c
  326. // CHECK:STDOUT: %c: ref %C = bind_name c, %c.var
  327. // CHECK:STDOUT: }
  328. // CHECK:STDOUT:
  329. // CHECK:STDOUT: class @C {
  330. // CHECK:STDOUT: !members:
  331. // CHECK:STDOUT: .Self = file.%import_ref.2
  332. // CHECK:STDOUT: .x = file.%import_ref.3
  333. // CHECK:STDOUT: }
  334. // CHECK:STDOUT:
  335. // CHECK:STDOUT: fn @__global_init() {
  336. // CHECK:STDOUT: !entry:
  337. // CHECK:STDOUT: %.loc6_19.1: %.1 = tuple_literal ()
  338. // CHECK:STDOUT: %.loc6_20.1: %.2 = struct_literal (%.loc6_19.1)
  339. // CHECK:STDOUT: %.loc6_20.2: ref %.1 = class_element_access file.%c.var, element0
  340. // CHECK:STDOUT: %.loc6_19.2: init %.1 = tuple_init () to %.loc6_20.2 [template = constants.%tuple]
  341. // CHECK:STDOUT: %.loc6_20.3: init %.1 = converted %.loc6_19.1, %.loc6_19.2 [template = constants.%tuple]
  342. // CHECK:STDOUT: %.loc6_20.4: init %C = class_init (%.loc6_20.3), file.%c.var [template = constants.%struct]
  343. // CHECK:STDOUT: %.loc6_21: init %C = converted %.loc6_20.1, %.loc6_20.4 [template = constants.%struct]
  344. // CHECK:STDOUT: assign file.%c.var, %.loc6_21
  345. // CHECK:STDOUT: return
  346. // CHECK:STDOUT: }
  347. // CHECK:STDOUT:
  348. // CHECK:STDOUT: --- use_import_then_export.carbon
  349. // CHECK:STDOUT:
  350. // CHECK:STDOUT: constants {
  351. // CHECK:STDOUT: %C: type = class_type @C [template]
  352. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  353. // CHECK:STDOUT: %.2: type = struct_type {.x: %.1} [template]
  354. // CHECK:STDOUT: %.3: type = ptr_type %.2 [template]
  355. // CHECK:STDOUT: %tuple: %.1 = tuple_value () [template]
  356. // CHECK:STDOUT: %struct: %C = struct_value (%tuple) [template]
  357. // CHECK:STDOUT: }
  358. // CHECK:STDOUT:
  359. // CHECK:STDOUT: file {
  360. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  361. // CHECK:STDOUT: .C = %import_ref.1
  362. // CHECK:STDOUT: .c = %c
  363. // CHECK:STDOUT: }
  364. // CHECK:STDOUT: %import_ref.1: type = import_ref ir2, inst+1, loaded [template = constants.%C]
  365. // CHECK:STDOUT: %import_ref.2 = import_ref ir2, inst+2, unloaded
  366. // CHECK:STDOUT: %import_ref.3 = import_ref ir2, inst+7, unloaded
  367. // CHECK:STDOUT: %C.ref: type = name_ref C, %import_ref.1 [template = constants.%C]
  368. // CHECK:STDOUT: %c.var: ref %C = var c
  369. // CHECK:STDOUT: %c: ref %C = bind_name c, %c.var
  370. // CHECK:STDOUT: }
  371. // CHECK:STDOUT:
  372. // CHECK:STDOUT: class @C {
  373. // CHECK:STDOUT: !members:
  374. // CHECK:STDOUT: .Self = file.%import_ref.2
  375. // CHECK:STDOUT: .x = file.%import_ref.3
  376. // CHECK:STDOUT: }
  377. // CHECK:STDOUT:
  378. // CHECK:STDOUT: fn @__global_init() {
  379. // CHECK:STDOUT: !entry:
  380. // CHECK:STDOUT: %.loc6_19.1: %.1 = tuple_literal ()
  381. // CHECK:STDOUT: %.loc6_20.1: %.2 = struct_literal (%.loc6_19.1)
  382. // CHECK:STDOUT: %.loc6_20.2: ref %.1 = class_element_access file.%c.var, element0
  383. // CHECK:STDOUT: %.loc6_19.2: init %.1 = tuple_init () to %.loc6_20.2 [template = constants.%tuple]
  384. // CHECK:STDOUT: %.loc6_20.3: init %.1 = converted %.loc6_19.1, %.loc6_19.2 [template = constants.%tuple]
  385. // CHECK:STDOUT: %.loc6_20.4: init %C = class_init (%.loc6_20.3), file.%c.var [template = constants.%struct]
  386. // CHECK:STDOUT: %.loc6_21: init %C = converted %.loc6_20.1, %.loc6_20.4 [template = constants.%struct]
  387. // CHECK:STDOUT: assign file.%c.var, %.loc6_21
  388. // CHECK:STDOUT: return
  389. // CHECK:STDOUT: }
  390. // CHECK:STDOUT:
  391. // CHECK:STDOUT: --- use_import_when_export.carbon
  392. // CHECK:STDOUT:
  393. // CHECK:STDOUT: constants {
  394. // CHECK:STDOUT: %C: type = class_type @C [template]
  395. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  396. // CHECK:STDOUT: %.2: type = struct_type {.x: %.1} [template]
  397. // CHECK:STDOUT: %.3: type = ptr_type %.2 [template]
  398. // CHECK:STDOUT: %tuple: %.1 = tuple_value () [template]
  399. // CHECK:STDOUT: %struct: %C = struct_value (%tuple) [template]
  400. // CHECK:STDOUT: }
  401. // CHECK:STDOUT:
  402. // CHECK:STDOUT: file {
  403. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  404. // CHECK:STDOUT: .C = %import_ref.1
  405. // CHECK:STDOUT: .c = %c
  406. // CHECK:STDOUT: }
  407. // CHECK:STDOUT: %import_ref.1: type = import_ref ir1, inst+1, loaded [template = constants.%C]
  408. // CHECK:STDOUT: %import_ref.2 = import_ref ir1, inst+2, unloaded
  409. // CHECK:STDOUT: %import_ref.3 = import_ref ir1, inst+7, unloaded
  410. // CHECK:STDOUT: %C.ref: type = name_ref C, %import_ref.1 [template = constants.%C]
  411. // CHECK:STDOUT: %c.var: ref %C = var c
  412. // CHECK:STDOUT: %c: ref %C = bind_name c, %c.var
  413. // CHECK:STDOUT: }
  414. // CHECK:STDOUT:
  415. // CHECK:STDOUT: class @C {
  416. // CHECK:STDOUT: !members:
  417. // CHECK:STDOUT: .Self = file.%import_ref.2
  418. // CHECK:STDOUT: .x = file.%import_ref.3
  419. // CHECK:STDOUT: }
  420. // CHECK:STDOUT:
  421. // CHECK:STDOUT: fn @__global_init() {
  422. // CHECK:STDOUT: !entry:
  423. // CHECK:STDOUT: %.loc6_19.1: %.1 = tuple_literal ()
  424. // CHECK:STDOUT: %.loc6_20.1: %.2 = struct_literal (%.loc6_19.1)
  425. // CHECK:STDOUT: %.loc6_20.2: ref %.1 = class_element_access file.%c.var, element0
  426. // CHECK:STDOUT: %.loc6_19.2: init %.1 = tuple_init () to %.loc6_20.2 [template = constants.%tuple]
  427. // CHECK:STDOUT: %.loc6_20.3: init %.1 = converted %.loc6_19.1, %.loc6_19.2 [template = constants.%tuple]
  428. // CHECK:STDOUT: %.loc6_20.4: init %C = class_init (%.loc6_20.3), file.%c.var [template = constants.%struct]
  429. // CHECK:STDOUT: %.loc6_21: init %C = converted %.loc6_20.1, %.loc6_20.4 [template = constants.%struct]
  430. // CHECK:STDOUT: assign file.%c.var, %.loc6_21
  431. // CHECK:STDOUT: return
  432. // CHECK:STDOUT: }
  433. // CHECK:STDOUT:
  434. // CHECK:STDOUT: --- use_base_and_export.carbon
  435. // CHECK:STDOUT:
  436. // CHECK:STDOUT: constants {
  437. // CHECK:STDOUT: %C: type = class_type @C [template]
  438. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  439. // CHECK:STDOUT: %.2: type = struct_type {.x: %.1} [template]
  440. // CHECK:STDOUT: %.3: type = ptr_type %.2 [template]
  441. // CHECK:STDOUT: %tuple: %.1 = tuple_value () [template]
  442. // CHECK:STDOUT: %struct: %C = struct_value (%tuple) [template]
  443. // CHECK:STDOUT: }
  444. // CHECK:STDOUT:
  445. // CHECK:STDOUT: file {
  446. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  447. // CHECK:STDOUT: .C = %import_ref.1
  448. // CHECK:STDOUT: .c = %c
  449. // CHECK:STDOUT: }
  450. // CHECK:STDOUT: %import_ref.1: type = import_ref ir1, inst+1, loaded [template = constants.%C]
  451. // CHECK:STDOUT: %import_ref.2 = import_ref ir1, inst+2, unloaded
  452. // CHECK:STDOUT: %import_ref.3 = import_ref ir1, inst+7, unloaded
  453. // CHECK:STDOUT: %C.ref: type = name_ref C, %import_ref.1 [template = constants.%C]
  454. // CHECK:STDOUT: %c.var: ref %C = var c
  455. // CHECK:STDOUT: %c: ref %C = bind_name c, %c.var
  456. // CHECK:STDOUT: }
  457. // CHECK:STDOUT:
  458. // CHECK:STDOUT: class @C {
  459. // CHECK:STDOUT: !members:
  460. // CHECK:STDOUT: .Self = file.%import_ref.2
  461. // CHECK:STDOUT: .x = file.%import_ref.3
  462. // CHECK:STDOUT: }
  463. // CHECK:STDOUT:
  464. // CHECK:STDOUT: fn @__global_init() {
  465. // CHECK:STDOUT: !entry:
  466. // CHECK:STDOUT: %.loc7_19.1: %.1 = tuple_literal ()
  467. // CHECK:STDOUT: %.loc7_20.1: %.2 = struct_literal (%.loc7_19.1)
  468. // CHECK:STDOUT: %.loc7_20.2: ref %.1 = class_element_access file.%c.var, element0
  469. // CHECK:STDOUT: %.loc7_19.2: init %.1 = tuple_init () to %.loc7_20.2 [template = constants.%tuple]
  470. // CHECK:STDOUT: %.loc7_20.3: init %.1 = converted %.loc7_19.1, %.loc7_19.2 [template = constants.%tuple]
  471. // CHECK:STDOUT: %.loc7_20.4: init %C = class_init (%.loc7_20.3), file.%c.var [template = constants.%struct]
  472. // CHECK:STDOUT: %.loc7_21: init %C = converted %.loc7_20.1, %.loc7_20.4 [template = constants.%struct]
  473. // CHECK:STDOUT: assign file.%c.var, %.loc7_21
  474. // CHECK:STDOUT: return
  475. // CHECK:STDOUT: }
  476. // CHECK:STDOUT:
  477. // CHECK:STDOUT: --- use_export_and_base.carbon
  478. // CHECK:STDOUT:
  479. // CHECK:STDOUT: constants {
  480. // CHECK:STDOUT: %C: type = class_type @C [template]
  481. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  482. // CHECK:STDOUT: %.2: type = struct_type {.x: %.1} [template]
  483. // CHECK:STDOUT: %.3: type = ptr_type %.2 [template]
  484. // CHECK:STDOUT: %tuple: %.1 = tuple_value () [template]
  485. // CHECK:STDOUT: %struct: %C = struct_value (%tuple) [template]
  486. // CHECK:STDOUT: }
  487. // CHECK:STDOUT:
  488. // CHECK:STDOUT: file {
  489. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  490. // CHECK:STDOUT: .C = %import_ref.1
  491. // CHECK:STDOUT: .c = %c
  492. // CHECK:STDOUT: }
  493. // CHECK:STDOUT: %import_ref.1: type = import_ref ir2, inst+1, loaded [template = constants.%C]
  494. // CHECK:STDOUT: %import_ref.2 = import_ref ir2, inst+2, unloaded
  495. // CHECK:STDOUT: %import_ref.3 = import_ref ir2, inst+7, unloaded
  496. // CHECK:STDOUT: %C.ref: type = name_ref C, %import_ref.1 [template = constants.%C]
  497. // CHECK:STDOUT: %c.var: ref %C = var c
  498. // CHECK:STDOUT: %c: ref %C = bind_name c, %c.var
  499. // CHECK:STDOUT: }
  500. // CHECK:STDOUT:
  501. // CHECK:STDOUT: class @C {
  502. // CHECK:STDOUT: !members:
  503. // CHECK:STDOUT: .Self = file.%import_ref.2
  504. // CHECK:STDOUT: .x = file.%import_ref.3
  505. // CHECK:STDOUT: }
  506. // CHECK:STDOUT:
  507. // CHECK:STDOUT: fn @__global_init() {
  508. // CHECK:STDOUT: !entry:
  509. // CHECK:STDOUT: %.loc7_19.1: %.1 = tuple_literal ()
  510. // CHECK:STDOUT: %.loc7_20.1: %.2 = struct_literal (%.loc7_19.1)
  511. // CHECK:STDOUT: %.loc7_20.2: ref %.1 = class_element_access file.%c.var, element0
  512. // CHECK:STDOUT: %.loc7_19.2: init %.1 = tuple_init () to %.loc7_20.2 [template = constants.%tuple]
  513. // CHECK:STDOUT: %.loc7_20.3: init %.1 = converted %.loc7_19.1, %.loc7_19.2 [template = constants.%tuple]
  514. // CHECK:STDOUT: %.loc7_20.4: init %C = class_init (%.loc7_20.3), file.%c.var [template = constants.%struct]
  515. // CHECK:STDOUT: %.loc7_21: init %C = converted %.loc7_20.1, %.loc7_20.4 [template = constants.%struct]
  516. // CHECK:STDOUT: assign file.%c.var, %.loc7_21
  517. // CHECK:STDOUT: return
  518. // CHECK:STDOUT: }
  519. // CHECK:STDOUT:
  520. // CHECK:STDOUT: --- use_export_copy.carbon
  521. // CHECK:STDOUT:
  522. // CHECK:STDOUT: constants {
  523. // CHECK:STDOUT: %C: type = class_type @C [template]
  524. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  525. // CHECK:STDOUT: %.2: type = struct_type {.x: %.1} [template]
  526. // CHECK:STDOUT: %.3: type = ptr_type %.2 [template]
  527. // CHECK:STDOUT: %tuple: %.1 = tuple_value () [template]
  528. // CHECK:STDOUT: %struct: %C = struct_value (%tuple) [template]
  529. // CHECK:STDOUT: }
  530. // CHECK:STDOUT:
  531. // CHECK:STDOUT: file {
  532. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  533. // CHECK:STDOUT: .C = %import_ref.1
  534. // CHECK:STDOUT: .c = %c
  535. // CHECK:STDOUT: }
  536. // CHECK:STDOUT: %import_ref.1: type = import_ref ir3, inst+1, loaded [template = constants.%C]
  537. // CHECK:STDOUT: %import_ref.2 = import_ref ir3, inst+2, unloaded
  538. // CHECK:STDOUT: %import_ref.3 = import_ref ir3, inst+7, unloaded
  539. // CHECK:STDOUT: %C.ref: type = name_ref C, %import_ref.1 [template = constants.%C]
  540. // CHECK:STDOUT: %c.var: ref %C = var c
  541. // CHECK:STDOUT: %c: ref %C = bind_name c, %c.var
  542. // CHECK:STDOUT: }
  543. // CHECK:STDOUT:
  544. // CHECK:STDOUT: class @C {
  545. // CHECK:STDOUT: !members:
  546. // CHECK:STDOUT: .Self = file.%import_ref.2
  547. // CHECK:STDOUT: .x = file.%import_ref.3
  548. // CHECK:STDOUT: }
  549. // CHECK:STDOUT:
  550. // CHECK:STDOUT: fn @__global_init() {
  551. // CHECK:STDOUT: !entry:
  552. // CHECK:STDOUT: %.loc7_19.1: %.1 = tuple_literal ()
  553. // CHECK:STDOUT: %.loc7_20.1: %.2 = struct_literal (%.loc7_19.1)
  554. // CHECK:STDOUT: %.loc7_20.2: ref %.1 = class_element_access file.%c.var, element0
  555. // CHECK:STDOUT: %.loc7_19.2: init %.1 = tuple_init () to %.loc7_20.2 [template = constants.%tuple]
  556. // CHECK:STDOUT: %.loc7_20.3: init %.1 = converted %.loc7_19.1, %.loc7_19.2 [template = constants.%tuple]
  557. // CHECK:STDOUT: %.loc7_20.4: init %C = class_init (%.loc7_20.3), file.%c.var [template = constants.%struct]
  558. // CHECK:STDOUT: %.loc7_21: init %C = converted %.loc7_20.1, %.loc7_20.4 [template = constants.%struct]
  559. // CHECK:STDOUT: assign file.%c.var, %.loc7_21
  560. // CHECK:STDOUT: return
  561. // CHECK:STDOUT: }
  562. // CHECK:STDOUT:
  563. // CHECK:STDOUT: --- fail_use_non_export.carbon
  564. // CHECK:STDOUT:
  565. // CHECK:STDOUT: file {
  566. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  567. // CHECK:STDOUT: .Local = %Local
  568. // CHECK:STDOUT: }
  569. // CHECK:STDOUT: %C.ref: <error> = name_ref C, <error> [template = <error>]
  570. // CHECK:STDOUT: %Local: <error> = bind_alias Local, <error> [template = <error>]
  571. // CHECK:STDOUT: }
  572. // CHECK:STDOUT:
  573. // CHECK:STDOUT: --- use_non_export_then_base.carbon
  574. // CHECK:STDOUT:
  575. // CHECK:STDOUT: constants {
  576. // CHECK:STDOUT: %C: type = class_type @C [template]
  577. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  578. // CHECK:STDOUT: %.2: type = struct_type {.x: %.1} [template]
  579. // CHECK:STDOUT: %.3: type = ptr_type %.2 [template]
  580. // CHECK:STDOUT: %tuple: %.1 = tuple_value () [template]
  581. // CHECK:STDOUT: %struct: %C = struct_value (%tuple) [template]
  582. // CHECK:STDOUT: }
  583. // CHECK:STDOUT:
  584. // CHECK:STDOUT: file {
  585. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  586. // CHECK:STDOUT: .C = %import_ref.1
  587. // CHECK:STDOUT: .c = %c
  588. // CHECK:STDOUT: }
  589. // CHECK:STDOUT: %import_ref.1: type = import_ref ir2, inst+1, loaded [template = constants.%C]
  590. // CHECK:STDOUT: %import_ref.2 = import_ref ir2, inst+2, unloaded
  591. // CHECK:STDOUT: %import_ref.3 = import_ref ir2, inst+7, unloaded
  592. // CHECK:STDOUT: %C.ref: type = name_ref C, %import_ref.1 [template = constants.%C]
  593. // CHECK:STDOUT: %c.var: ref %C = var c
  594. // CHECK:STDOUT: %c: ref %C = bind_name c, %c.var
  595. // CHECK:STDOUT: }
  596. // CHECK:STDOUT:
  597. // CHECK:STDOUT: class @C {
  598. // CHECK:STDOUT: !members:
  599. // CHECK:STDOUT: .Self = file.%import_ref.2
  600. // CHECK:STDOUT: .x = file.%import_ref.3
  601. // CHECK:STDOUT: }
  602. // CHECK:STDOUT:
  603. // CHECK:STDOUT: fn @__global_init() {
  604. // CHECK:STDOUT: !entry:
  605. // CHECK:STDOUT: %.loc7_19.1: %.1 = tuple_literal ()
  606. // CHECK:STDOUT: %.loc7_20.1: %.2 = struct_literal (%.loc7_19.1)
  607. // CHECK:STDOUT: %.loc7_20.2: ref %.1 = class_element_access file.%c.var, element0
  608. // CHECK:STDOUT: %.loc7_19.2: init %.1 = tuple_init () to %.loc7_20.2 [template = constants.%tuple]
  609. // CHECK:STDOUT: %.loc7_20.3: init %.1 = converted %.loc7_19.1, %.loc7_19.2 [template = constants.%tuple]
  610. // CHECK:STDOUT: %.loc7_20.4: init %C = class_init (%.loc7_20.3), file.%c.var [template = constants.%struct]
  611. // CHECK:STDOUT: %.loc7_21: init %C = converted %.loc7_20.1, %.loc7_20.4 [template = constants.%struct]
  612. // CHECK:STDOUT: assign file.%c.var, %.loc7_21
  613. // CHECK:STDOUT: return
  614. // CHECK:STDOUT: }
  615. // CHECK:STDOUT:
  616. // CHECK:STDOUT: --- indirect_use_non_export_then_base.carbon
  617. // CHECK:STDOUT:
  618. // CHECK:STDOUT: constants {
  619. // CHECK:STDOUT: %C: type = class_type @C [template]
  620. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  621. // CHECK:STDOUT: %.2: type = struct_type {.x: %.1} [template]
  622. // CHECK:STDOUT: %.3: type = ptr_type %.2 [template]
  623. // CHECK:STDOUT: %tuple: %.1 = tuple_value () [template]
  624. // CHECK:STDOUT: %struct: %C = struct_value (%tuple) [template]
  625. // CHECK:STDOUT: }
  626. // CHECK:STDOUT:
  627. // CHECK:STDOUT: file {
  628. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  629. // CHECK:STDOUT: .c = %import_ref.1
  630. // CHECK:STDOUT: .C = %import_ref.2
  631. // CHECK:STDOUT: .indirect_c = %indirect_c
  632. // CHECK:STDOUT: }
  633. // CHECK:STDOUT: %import_ref.1 = import_ref ir1, inst+13, unloaded
  634. // CHECK:STDOUT: %import_ref.2: type = import_ref ir2, inst+1, loaded [template = constants.%C]
  635. // CHECK:STDOUT: %import_ref.3 = import_ref ir2, inst+2, unloaded
  636. // CHECK:STDOUT: %import_ref.4 = import_ref ir2, inst+7, unloaded
  637. // CHECK:STDOUT: %C.ref: type = name_ref C, %import_ref.2 [template = constants.%C]
  638. // CHECK:STDOUT: %indirect_c.var: ref %C = var indirect_c
  639. // CHECK:STDOUT: %indirect_c: ref %C = bind_name indirect_c, %indirect_c.var
  640. // CHECK:STDOUT: }
  641. // CHECK:STDOUT:
  642. // CHECK:STDOUT: class @C {
  643. // CHECK:STDOUT: !members:
  644. // CHECK:STDOUT: .Self = file.%import_ref.3
  645. // CHECK:STDOUT: .x = file.%import_ref.4
  646. // CHECK:STDOUT: }
  647. // CHECK:STDOUT:
  648. // CHECK:STDOUT: fn @__global_init() {
  649. // CHECK:STDOUT: !entry:
  650. // CHECK:STDOUT: %.loc6_28.1: %.1 = tuple_literal ()
  651. // CHECK:STDOUT: %.loc6_29.1: %.2 = struct_literal (%.loc6_28.1)
  652. // CHECK:STDOUT: %.loc6_29.2: ref %.1 = class_element_access file.%indirect_c.var, element0
  653. // CHECK:STDOUT: %.loc6_28.2: init %.1 = tuple_init () to %.loc6_29.2 [template = constants.%tuple]
  654. // CHECK:STDOUT: %.loc6_29.3: init %.1 = converted %.loc6_28.1, %.loc6_28.2 [template = constants.%tuple]
  655. // CHECK:STDOUT: %.loc6_29.4: init %C = class_init (%.loc6_29.3), file.%indirect_c.var [template = constants.%struct]
  656. // CHECK:STDOUT: %.loc6_30: init %C = converted %.loc6_29.1, %.loc6_29.4 [template = constants.%struct]
  657. // CHECK:STDOUT: assign file.%indirect_c.var, %.loc6_30
  658. // CHECK:STDOUT: return
  659. // CHECK:STDOUT: }
  660. // CHECK:STDOUT: