cross_package_export.carbon 29 KB

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