import.carbon 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247
  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/function/declaration/import.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/declaration/import.carbon
  10. // ============================================================================
  11. // Setup files
  12. // ============================================================================
  13. // --- api.carbon
  14. library "api";
  15. fn A();
  16. fn B(b: i32) -> i32;
  17. fn C(c: (i32,)) -> {.c: i32};
  18. extern fn D();
  19. namespace NS;
  20. fn NS.E();
  21. // --- extern_api.carbon
  22. library "extern_api";
  23. extern library "redecl_extern_api" fn A();
  24. extern library "redecl_extern_api" fn B(b: i32) -> i32;
  25. extern library "redecl_extern_api" fn C(c: (i32,)) -> {.c: i32};
  26. extern library "redecl_extern_api" fn D();
  27. namespace NS;
  28. extern library "redecl_extern_api" fn NS.E();
  29. // ============================================================================
  30. // Test files
  31. // ============================================================================
  32. // --- basics.carbon
  33. library "basics";
  34. import library "api";
  35. var a: () = A();
  36. var b: i32 = B(1);
  37. var c: {.c: i32} = C((1,));
  38. var d: () = D();
  39. var e: () = NS.E();
  40. // --- fail_redecl_api.carbon
  41. library "redecl_api";
  42. import library "api";
  43. // CHECK:STDERR: fail_redecl_api.carbon:[[@LINE+10]]:1: ERROR: Redeclarations of `fn A` must match use of `extern`.
  44. // CHECK:STDERR: extern fn A();
  45. // CHECK:STDERR: ^~~~~~~~~~~~~~
  46. // CHECK:STDERR: fail_redecl_api.carbon:[[@LINE-5]]:1: In import.
  47. // CHECK:STDERR: import library "api";
  48. // CHECK:STDERR: ^~~~~~
  49. // CHECK:STDERR: api.carbon:4:1: Previously declared here.
  50. // CHECK:STDERR: fn A();
  51. // CHECK:STDERR: ^~~~~~~
  52. // CHECK:STDERR:
  53. extern fn A();
  54. // CHECK:STDERR: fail_redecl_api.carbon:[[@LINE+10]]:1: ERROR: Redeclarations of `fn B` must match use of `extern`.
  55. // CHECK:STDERR: extern fn B(b: i32) -> i32;
  56. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  57. // CHECK:STDERR: fail_redecl_api.carbon:[[@LINE-16]]:1: In import.
  58. // CHECK:STDERR: import library "api";
  59. // CHECK:STDERR: ^~~~~~
  60. // CHECK:STDERR: api.carbon:5:1: Previously declared here.
  61. // CHECK:STDERR: fn B(b: i32) -> i32;
  62. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~
  63. // CHECK:STDERR:
  64. extern fn B(b: i32) -> i32;
  65. // CHECK:STDERR: fail_redecl_api.carbon:[[@LINE+10]]:1: ERROR: Redeclarations of `fn C` must match use of `extern`.
  66. // CHECK:STDERR: extern fn C(c: (i32,)) -> {.c: i32};
  67. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  68. // CHECK:STDERR: fail_redecl_api.carbon:[[@LINE-27]]:1: In import.
  69. // CHECK:STDERR: import library "api";
  70. // CHECK:STDERR: ^~~~~~
  71. // CHECK:STDERR: api.carbon:6:1: Previously declared here.
  72. // CHECK:STDERR: fn C(c: (i32,)) -> {.c: i32};
  73. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  74. // CHECK:STDERR:
  75. extern fn C(c: (i32,)) -> {.c: i32};
  76. // CHECK:STDERR: fail_redecl_api.carbon:[[@LINE+10]]:1: ERROR: Redeclaration of `fn D` is redundant.
  77. // CHECK:STDERR: extern fn D();
  78. // CHECK:STDERR: ^~~~~~~~~~~~~~
  79. // CHECK:STDERR: fail_redecl_api.carbon:[[@LINE-38]]:1: In import.
  80. // CHECK:STDERR: import library "api";
  81. // CHECK:STDERR: ^~~~~~
  82. // CHECK:STDERR: api.carbon:7:1: Previously declared here.
  83. // CHECK:STDERR: extern fn D();
  84. // CHECK:STDERR: ^~~~~~~~~~~~~~
  85. // CHECK:STDERR:
  86. extern fn D();
  87. // CHECK:STDERR: fail_redecl_api.carbon:[[@LINE+10]]:1: ERROR: Redeclarations of `fn E` must match use of `extern`.
  88. // CHECK:STDERR: extern fn NS.E();
  89. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  90. // CHECK:STDERR: fail_redecl_api.carbon:[[@LINE-49]]:1: In import.
  91. // CHECK:STDERR: import library "api";
  92. // CHECK:STDERR: ^~~~~~
  93. // CHECK:STDERR: api.carbon:10:1: Previously declared here.
  94. // CHECK:STDERR: fn NS.E();
  95. // CHECK:STDERR: ^~~~~~~~~~
  96. // CHECK:STDERR:
  97. extern fn NS.E();
  98. var a: () = A();
  99. var b: i32 = B(1);
  100. var c: {.c: i32} = C((1,));
  101. var d: () = D();
  102. var e: () = NS.E();
  103. // --- redecl_extern_api.carbon
  104. library "redecl_extern_api";
  105. import library "extern_api";
  106. extern fn A();
  107. extern fn B(b: i32) -> i32;
  108. extern fn C(c: (i32,)) -> {.c: i32};
  109. extern fn D();
  110. extern fn NS.E();
  111. var a: () = A();
  112. var b: i32 = B(1);
  113. var c: {.c: i32} = C((1,));
  114. var d: () = D();
  115. var e: () = NS.E();
  116. // --- fail_merge.carbon
  117. library "merge";
  118. // CHECK:STDERR: fail_merge.carbon:[[@LINE+65]]:1: In import.
  119. // CHECK:STDERR: import library "api";
  120. // CHECK:STDERR: ^~~~~~
  121. // CHECK:STDERR: extern_api.carbon:4:1: ERROR: Duplicate name being declared in the same scope.
  122. // CHECK:STDERR: extern library "redecl_extern_api" fn A();
  123. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  124. // CHECK:STDERR: fail_merge.carbon:[[@LINE+59]]:1: In import.
  125. // CHECK:STDERR: import library "api";
  126. // CHECK:STDERR: ^~~~~~
  127. // CHECK:STDERR: api.carbon:4:1: Name is previously declared here.
  128. // CHECK:STDERR: fn A();
  129. // CHECK:STDERR: ^~~~~~~
  130. // CHECK:STDERR:
  131. // CHECK:STDERR: fail_merge.carbon:[[@LINE+52]]:1: In import.
  132. // CHECK:STDERR: import library "api";
  133. // CHECK:STDERR: ^~~~~~
  134. // CHECK:STDERR: extern_api.carbon:5:1: ERROR: Duplicate name being declared in the same scope.
  135. // CHECK:STDERR: extern library "redecl_extern_api" fn B(b: i32) -> i32;
  136. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  137. // CHECK:STDERR: fail_merge.carbon:[[@LINE+46]]:1: In import.
  138. // CHECK:STDERR: import library "api";
  139. // CHECK:STDERR: ^~~~~~
  140. // CHECK:STDERR: api.carbon:5:1: Name is previously declared here.
  141. // CHECK:STDERR: fn B(b: i32) -> i32;
  142. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~
  143. // CHECK:STDERR:
  144. // CHECK:STDERR: fail_merge.carbon:[[@LINE+39]]:1: In import.
  145. // CHECK:STDERR: import library "api";
  146. // CHECK:STDERR: ^~~~~~
  147. // CHECK:STDERR: extern_api.carbon:6:1: ERROR: Duplicate name being declared in the same scope.
  148. // CHECK:STDERR: extern library "redecl_extern_api" fn C(c: (i32,)) -> {.c: i32};
  149. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  150. // CHECK:STDERR: fail_merge.carbon:[[@LINE+33]]:1: In import.
  151. // CHECK:STDERR: import library "api";
  152. // CHECK:STDERR: ^~~~~~
  153. // CHECK:STDERR: api.carbon:6:1: Name is previously declared here.
  154. // CHECK:STDERR: fn C(c: (i32,)) -> {.c: i32};
  155. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  156. // CHECK:STDERR:
  157. // CHECK:STDERR: fail_merge.carbon:[[@LINE+26]]:1: In import.
  158. // CHECK:STDERR: import library "api";
  159. // CHECK:STDERR: ^~~~~~
  160. // CHECK:STDERR: extern_api.carbon:7:1: ERROR: Duplicate name being declared in the same scope.
  161. // CHECK:STDERR: extern library "redecl_extern_api" fn D();
  162. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  163. // CHECK:STDERR: fail_merge.carbon:[[@LINE+20]]:1: In import.
  164. // CHECK:STDERR: import library "api";
  165. // CHECK:STDERR: ^~~~~~
  166. // CHECK:STDERR: api.carbon:7:1: Name is previously declared here.
  167. // CHECK:STDERR: extern fn D();
  168. // CHECK:STDERR: ^~~~~~~~~~~~~~
  169. // CHECK:STDERR:
  170. // CHECK:STDERR: fail_merge.carbon:[[@LINE+13]]:1: In import.
  171. // CHECK:STDERR: import library "api";
  172. // CHECK:STDERR: ^~~~~~
  173. // CHECK:STDERR: extern_api.carbon:10:1: ERROR: Duplicate name being declared in the same scope.
  174. // CHECK:STDERR: extern library "redecl_extern_api" fn NS.E();
  175. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  176. // CHECK:STDERR: fail_merge.carbon:[[@LINE+7]]:1: In import.
  177. // CHECK:STDERR: import library "api";
  178. // CHECK:STDERR: ^~~~~~
  179. // CHECK:STDERR: api.carbon:10:1: Name is previously declared here.
  180. // CHECK:STDERR: fn NS.E();
  181. // CHECK:STDERR: ^~~~~~~~~~
  182. // CHECK:STDERR:
  183. import library "api";
  184. import library "extern_api";
  185. var a: () = A();
  186. var b: i32 = B(1);
  187. var c: {.c: i32} = C((1,));
  188. var d: () = D();
  189. var e: () = NS.E();
  190. // --- fail_merge_reverse.carbon
  191. library "merge_reverse";
  192. // CHECK:STDERR: fail_merge_reverse.carbon:[[@LINE+64]]:1: In import.
  193. // CHECK:STDERR: import library "extern_api";
  194. // CHECK:STDERR: ^~~~~~
  195. // CHECK:STDERR: api.carbon:4:1: ERROR: Duplicate name being declared in the same scope.
  196. // CHECK:STDERR: fn A();
  197. // CHECK:STDERR: ^~~~~~~
  198. // CHECK:STDERR: fail_merge_reverse.carbon:[[@LINE+58]]:1: In import.
  199. // CHECK:STDERR: import library "extern_api";
  200. // CHECK:STDERR: ^~~~~~
  201. // CHECK:STDERR: extern_api.carbon:4:1: Name is previously declared here.
  202. // CHECK:STDERR: extern library "redecl_extern_api" fn A();
  203. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  204. // CHECK:STDERR:
  205. // CHECK:STDERR: fail_merge_reverse.carbon:[[@LINE+51]]:1: In import.
  206. // CHECK:STDERR: import library "extern_api";
  207. // CHECK:STDERR: ^~~~~~
  208. // CHECK:STDERR: api.carbon:5:1: ERROR: Duplicate name being declared in the same scope.
  209. // CHECK:STDERR: fn B(b: i32) -> i32;
  210. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~
  211. // CHECK:STDERR: fail_merge_reverse.carbon:[[@LINE+45]]:1: In import.
  212. // CHECK:STDERR: import library "extern_api";
  213. // CHECK:STDERR: ^~~~~~
  214. // CHECK:STDERR: extern_api.carbon:5:1: Name is previously declared here.
  215. // CHECK:STDERR: extern library "redecl_extern_api" fn B(b: i32) -> i32;
  216. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  217. // CHECK:STDERR:
  218. // CHECK:STDERR: fail_merge_reverse.carbon:[[@LINE+38]]:1: In import.
  219. // CHECK:STDERR: import library "extern_api";
  220. // CHECK:STDERR: ^~~~~~
  221. // CHECK:STDERR: api.carbon:6:1: ERROR: Duplicate name being declared in the same scope.
  222. // CHECK:STDERR: fn C(c: (i32,)) -> {.c: i32};
  223. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  224. // CHECK:STDERR: fail_merge_reverse.carbon:[[@LINE+32]]:1: In import.
  225. // CHECK:STDERR: import library "extern_api";
  226. // CHECK:STDERR: ^~~~~~
  227. // CHECK:STDERR: extern_api.carbon:6:1: Name is previously declared here.
  228. // CHECK:STDERR: extern library "redecl_extern_api" fn C(c: (i32,)) -> {.c: i32};
  229. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  230. // CHECK:STDERR:
  231. // CHECK:STDERR: fail_merge_reverse.carbon:[[@LINE+25]]:1: In import.
  232. // CHECK:STDERR: import library "extern_api";
  233. // CHECK:STDERR: ^~~~~~
  234. // CHECK:STDERR: api.carbon:7:1: ERROR: Duplicate name being declared in the same scope.
  235. // CHECK:STDERR: extern fn D();
  236. // CHECK:STDERR: ^~~~~~~~~~~~~~
  237. // CHECK:STDERR: fail_merge_reverse.carbon:[[@LINE+19]]:1: In import.
  238. // CHECK:STDERR: import library "extern_api";
  239. // CHECK:STDERR: ^~~~~~
  240. // CHECK:STDERR: extern_api.carbon:7:1: Name is previously declared here.
  241. // CHECK:STDERR: extern library "redecl_extern_api" fn D();
  242. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  243. // CHECK:STDERR:
  244. // CHECK:STDERR: fail_merge_reverse.carbon:[[@LINE+12]]:1: In import.
  245. // CHECK:STDERR: import library "extern_api";
  246. // CHECK:STDERR: ^~~~~~
  247. // CHECK:STDERR: api.carbon:10:1: ERROR: Duplicate name being declared in the same scope.
  248. // CHECK:STDERR: fn NS.E();
  249. // CHECK:STDERR: ^~~~~~~~~~
  250. // CHECK:STDERR: fail_merge_reverse.carbon:[[@LINE+6]]:1: In import.
  251. // CHECK:STDERR: import library "extern_api";
  252. // CHECK:STDERR: ^~~~~~
  253. // CHECK:STDERR: extern_api.carbon:10:1: Name is previously declared here.
  254. // CHECK:STDERR: extern library "redecl_extern_api" fn NS.E();
  255. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  256. import library "extern_api";
  257. import library "api";
  258. var a: () = A();
  259. var b: i32 = B(1);
  260. var c: {.c: i32} = C((1,));
  261. var d: () = D();
  262. var e: () = NS.E();
  263. // --- unloaded.carbon
  264. library "unloaded";
  265. import library "api";
  266. // --- unloaded_extern.carbon
  267. library "unloaded_extern";
  268. import library "extern_api";
  269. // CHECK:STDOUT: --- api.carbon
  270. // CHECK:STDOUT:
  271. // CHECK:STDOUT: constants {
  272. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  273. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  274. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  275. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  276. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  277. // CHECK:STDOUT: %B.type: type = fn_type @B [template]
  278. // CHECK:STDOUT: %B: %B.type = struct_value () [template]
  279. // CHECK:STDOUT: %.2: type = tuple_type (type) [template]
  280. // CHECK:STDOUT: %.3: type = tuple_type (i32) [template]
  281. // CHECK:STDOUT: %.4: type = struct_type {.c: i32} [template]
  282. // CHECK:STDOUT: %C.type: type = fn_type @C [template]
  283. // CHECK:STDOUT: %C: %C.type = struct_value () [template]
  284. // CHECK:STDOUT: %D.type: type = fn_type @D [template]
  285. // CHECK:STDOUT: %D: %D.type = struct_value () [template]
  286. // CHECK:STDOUT: %E.type: type = fn_type @E [template]
  287. // CHECK:STDOUT: %E: %E.type = struct_value () [template]
  288. // CHECK:STDOUT: }
  289. // CHECK:STDOUT:
  290. // CHECK:STDOUT: imports {
  291. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  292. // CHECK:STDOUT: .Int32 = %import_ref
  293. // CHECK:STDOUT: import Core//prelude
  294. // CHECK:STDOUT: import Core//prelude/operators
  295. // CHECK:STDOUT: import Core//prelude/types
  296. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  297. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  298. // CHECK:STDOUT: import Core//prelude/operators/comparison
  299. // CHECK:STDOUT: import Core//prelude/types/bool
  300. // CHECK:STDOUT: }
  301. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  302. // CHECK:STDOUT: }
  303. // CHECK:STDOUT:
  304. // CHECK:STDOUT: file {
  305. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  306. // CHECK:STDOUT: .Core = imports.%Core
  307. // CHECK:STDOUT: .A = %A.decl
  308. // CHECK:STDOUT: .B = %B.decl
  309. // CHECK:STDOUT: .C = %C.decl
  310. // CHECK:STDOUT: .D = %D.decl
  311. // CHECK:STDOUT: .NS = %NS
  312. // CHECK:STDOUT: }
  313. // CHECK:STDOUT: %Core.import = import Core
  314. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [template = constants.%A] {}
  315. // CHECK:STDOUT: %B.decl: %B.type = fn_decl @B [template = constants.%B] {
  316. // CHECK:STDOUT: %int.make_type_32.loc5_9: init type = call constants.%Int32() [template = i32]
  317. // CHECK:STDOUT: %.loc5_9.1: type = value_of_initializer %int.make_type_32.loc5_9 [template = i32]
  318. // CHECK:STDOUT: %.loc5_9.2: type = converted %int.make_type_32.loc5_9, %.loc5_9.1 [template = i32]
  319. // CHECK:STDOUT: %b.loc5_6.1: i32 = param b
  320. // CHECK:STDOUT: @B.%b: i32 = bind_name b, %b.loc5_6.1
  321. // CHECK:STDOUT: %int.make_type_32.loc5_17: init type = call constants.%Int32() [template = i32]
  322. // CHECK:STDOUT: %.loc5_17.1: type = value_of_initializer %int.make_type_32.loc5_17 [template = i32]
  323. // CHECK:STDOUT: %.loc5_17.2: type = converted %int.make_type_32.loc5_17, %.loc5_17.1 [template = i32]
  324. // CHECK:STDOUT: @B.%return: ref i32 = var <return slot>
  325. // CHECK:STDOUT: }
  326. // CHECK:STDOUT: %C.decl: %C.type = fn_decl @C [template = constants.%C] {
  327. // CHECK:STDOUT: %int.make_type_32.loc6_10: init type = call constants.%Int32() [template = i32]
  328. // CHECK:STDOUT: %.loc6_14.1: %.2 = tuple_literal (%int.make_type_32.loc6_10)
  329. // CHECK:STDOUT: %.loc6_14.2: type = value_of_initializer %int.make_type_32.loc6_10 [template = i32]
  330. // CHECK:STDOUT: %.loc6_14.3: type = converted %int.make_type_32.loc6_10, %.loc6_14.2 [template = i32]
  331. // CHECK:STDOUT: %.loc6_14.4: type = converted %.loc6_14.1, constants.%.3 [template = constants.%.3]
  332. // CHECK:STDOUT: %c.loc6_6.1: %.3 = param c
  333. // CHECK:STDOUT: @C.%c: %.3 = bind_name c, %c.loc6_6.1
  334. // CHECK:STDOUT: %int.make_type_32.loc6_25: init type = call constants.%Int32() [template = i32]
  335. // CHECK:STDOUT: %.loc6_25.1: type = value_of_initializer %int.make_type_32.loc6_25 [template = i32]
  336. // CHECK:STDOUT: %.loc6_25.2: type = converted %int.make_type_32.loc6_25, %.loc6_25.1 [template = i32]
  337. // CHECK:STDOUT: %.loc6_28: type = struct_type {.c: i32} [template = constants.%.4]
  338. // CHECK:STDOUT: @C.%return: ref %.4 = var <return slot>
  339. // CHECK:STDOUT: }
  340. // CHECK:STDOUT: %D.decl: %D.type = fn_decl @D [template = constants.%D] {}
  341. // CHECK:STDOUT: %NS: <namespace> = namespace [template] {
  342. // CHECK:STDOUT: .E = %E.decl
  343. // CHECK:STDOUT: }
  344. // CHECK:STDOUT: %E.decl: %E.type = fn_decl @E [template = constants.%E] {}
  345. // CHECK:STDOUT: }
  346. // CHECK:STDOUT:
  347. // CHECK:STDOUT: fn @A();
  348. // CHECK:STDOUT:
  349. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  350. // CHECK:STDOUT:
  351. // CHECK:STDOUT: fn @B(%b: i32) -> i32;
  352. // CHECK:STDOUT:
  353. // CHECK:STDOUT: fn @C(%c: %.3) -> %.4;
  354. // CHECK:STDOUT:
  355. // CHECK:STDOUT: extern fn @D();
  356. // CHECK:STDOUT:
  357. // CHECK:STDOUT: fn @E();
  358. // CHECK:STDOUT:
  359. // CHECK:STDOUT: --- extern_api.carbon
  360. // CHECK:STDOUT:
  361. // CHECK:STDOUT: constants {
  362. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  363. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  364. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  365. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  366. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  367. // CHECK:STDOUT: %B.type: type = fn_type @B [template]
  368. // CHECK:STDOUT: %B: %B.type = struct_value () [template]
  369. // CHECK:STDOUT: %.2: type = tuple_type (type) [template]
  370. // CHECK:STDOUT: %.3: type = tuple_type (i32) [template]
  371. // CHECK:STDOUT: %.4: type = struct_type {.c: i32} [template]
  372. // CHECK:STDOUT: %C.type: type = fn_type @C [template]
  373. // CHECK:STDOUT: %C: %C.type = struct_value () [template]
  374. // CHECK:STDOUT: %D.type: type = fn_type @D [template]
  375. // CHECK:STDOUT: %D: %D.type = struct_value () [template]
  376. // CHECK:STDOUT: %E.type: type = fn_type @E [template]
  377. // CHECK:STDOUT: %E: %E.type = struct_value () [template]
  378. // CHECK:STDOUT: }
  379. // CHECK:STDOUT:
  380. // CHECK:STDOUT: imports {
  381. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  382. // CHECK:STDOUT: .Int32 = %import_ref
  383. // CHECK:STDOUT: import Core//prelude
  384. // CHECK:STDOUT: import Core//prelude/operators
  385. // CHECK:STDOUT: import Core//prelude/types
  386. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  387. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  388. // CHECK:STDOUT: import Core//prelude/operators/comparison
  389. // CHECK:STDOUT: import Core//prelude/types/bool
  390. // CHECK:STDOUT: }
  391. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  392. // CHECK:STDOUT: }
  393. // CHECK:STDOUT:
  394. // CHECK:STDOUT: file {
  395. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  396. // CHECK:STDOUT: .Core = imports.%Core
  397. // CHECK:STDOUT: .A = %A.decl
  398. // CHECK:STDOUT: .B = %B.decl
  399. // CHECK:STDOUT: .C = %C.decl
  400. // CHECK:STDOUT: .D = %D.decl
  401. // CHECK:STDOUT: .NS = %NS
  402. // CHECK:STDOUT: }
  403. // CHECK:STDOUT: %Core.import = import Core
  404. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [template = constants.%A] {}
  405. // CHECK:STDOUT: %B.decl: %B.type = fn_decl @B [template = constants.%B] {
  406. // CHECK:STDOUT: %int.make_type_32.loc5_44: init type = call constants.%Int32() [template = i32]
  407. // CHECK:STDOUT: %.loc5_44.1: type = value_of_initializer %int.make_type_32.loc5_44 [template = i32]
  408. // CHECK:STDOUT: %.loc5_44.2: type = converted %int.make_type_32.loc5_44, %.loc5_44.1 [template = i32]
  409. // CHECK:STDOUT: %b.loc5_41.1: i32 = param b
  410. // CHECK:STDOUT: @B.%b: i32 = bind_name b, %b.loc5_41.1
  411. // CHECK:STDOUT: %int.make_type_32.loc5_52: init type = call constants.%Int32() [template = i32]
  412. // CHECK:STDOUT: %.loc5_52.1: type = value_of_initializer %int.make_type_32.loc5_52 [template = i32]
  413. // CHECK:STDOUT: %.loc5_52.2: type = converted %int.make_type_32.loc5_52, %.loc5_52.1 [template = i32]
  414. // CHECK:STDOUT: @B.%return: ref i32 = var <return slot>
  415. // CHECK:STDOUT: }
  416. // CHECK:STDOUT: %C.decl: %C.type = fn_decl @C [template = constants.%C] {
  417. // CHECK:STDOUT: %int.make_type_32.loc6_45: init type = call constants.%Int32() [template = i32]
  418. // CHECK:STDOUT: %.loc6_49.1: %.2 = tuple_literal (%int.make_type_32.loc6_45)
  419. // CHECK:STDOUT: %.loc6_49.2: type = value_of_initializer %int.make_type_32.loc6_45 [template = i32]
  420. // CHECK:STDOUT: %.loc6_49.3: type = converted %int.make_type_32.loc6_45, %.loc6_49.2 [template = i32]
  421. // CHECK:STDOUT: %.loc6_49.4: type = converted %.loc6_49.1, constants.%.3 [template = constants.%.3]
  422. // CHECK:STDOUT: %c.loc6_41.1: %.3 = param c
  423. // CHECK:STDOUT: @C.%c: %.3 = bind_name c, %c.loc6_41.1
  424. // CHECK:STDOUT: %int.make_type_32.loc6_60: init type = call constants.%Int32() [template = i32]
  425. // CHECK:STDOUT: %.loc6_60.1: type = value_of_initializer %int.make_type_32.loc6_60 [template = i32]
  426. // CHECK:STDOUT: %.loc6_60.2: type = converted %int.make_type_32.loc6_60, %.loc6_60.1 [template = i32]
  427. // CHECK:STDOUT: %.loc6_63: type = struct_type {.c: i32} [template = constants.%.4]
  428. // CHECK:STDOUT: @C.%return: ref %.4 = var <return slot>
  429. // CHECK:STDOUT: }
  430. // CHECK:STDOUT: %D.decl: %D.type = fn_decl @D [template = constants.%D] {}
  431. // CHECK:STDOUT: %NS: <namespace> = namespace [template] {
  432. // CHECK:STDOUT: .E = %E.decl
  433. // CHECK:STDOUT: }
  434. // CHECK:STDOUT: %E.decl: %E.type = fn_decl @E [template = constants.%E] {}
  435. // CHECK:STDOUT: }
  436. // CHECK:STDOUT:
  437. // CHECK:STDOUT: extern fn @A();
  438. // CHECK:STDOUT:
  439. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  440. // CHECK:STDOUT:
  441. // CHECK:STDOUT: extern fn @B(%b: i32) -> i32;
  442. // CHECK:STDOUT:
  443. // CHECK:STDOUT: extern fn @C(%c: %.3) -> %.4;
  444. // CHECK:STDOUT:
  445. // CHECK:STDOUT: extern fn @D();
  446. // CHECK:STDOUT:
  447. // CHECK:STDOUT: extern fn @E();
  448. // CHECK:STDOUT:
  449. // CHECK:STDOUT: --- basics.carbon
  450. // CHECK:STDOUT:
  451. // CHECK:STDOUT: constants {
  452. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  453. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  454. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  455. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  456. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  457. // CHECK:STDOUT: %B.type: type = fn_type @B [template]
  458. // CHECK:STDOUT: %B: %B.type = struct_value () [template]
  459. // CHECK:STDOUT: %.2: i32 = int_literal 1 [template]
  460. // CHECK:STDOUT: %.3: type = struct_type {.c: i32} [template]
  461. // CHECK:STDOUT: %C.type: type = fn_type @C [template]
  462. // CHECK:STDOUT: %C: %C.type = struct_value () [template]
  463. // CHECK:STDOUT: %.4: type = tuple_type (i32) [template]
  464. // CHECK:STDOUT: %tuple: %.4 = tuple_value (%.2) [template]
  465. // CHECK:STDOUT: %D.type: type = fn_type @D [template]
  466. // CHECK:STDOUT: %D: %D.type = struct_value () [template]
  467. // CHECK:STDOUT: %E.type: type = fn_type @E [template]
  468. // CHECK:STDOUT: %E: %E.type = struct_value () [template]
  469. // CHECK:STDOUT: }
  470. // CHECK:STDOUT:
  471. // CHECK:STDOUT: imports {
  472. // CHECK:STDOUT: %import_ref.1: %A.type = import_ref Main//api, inst+3, loaded [template = constants.%A]
  473. // CHECK:STDOUT: %import_ref.2: %B.type = import_ref Main//api, inst+21, loaded [template = constants.%B]
  474. // CHECK:STDOUT: %import_ref.3: %C.type = import_ref Main//api, inst+41, loaded [template = constants.%C]
  475. // CHECK:STDOUT: %import_ref.4: %D.type = import_ref Main//api, inst+44, loaded [template = constants.%D]
  476. // CHECK:STDOUT: %import_ref.5: <namespace> = import_ref Main//api, inst+47, loaded
  477. // CHECK:STDOUT: %NS: <namespace> = namespace %import_ref.5, [template] {
  478. // CHECK:STDOUT: .E = %import_ref.6
  479. // CHECK:STDOUT: }
  480. // CHECK:STDOUT: %import_ref.6: %E.type = import_ref Main//api, inst+48, loaded [template = constants.%E]
  481. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  482. // CHECK:STDOUT: .Int32 = %import_ref.7
  483. // CHECK:STDOUT: import Core//prelude
  484. // CHECK:STDOUT: import Core//prelude/operators
  485. // CHECK:STDOUT: import Core//prelude/types
  486. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  487. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  488. // CHECK:STDOUT: import Core//prelude/operators/comparison
  489. // CHECK:STDOUT: import Core//prelude/types/bool
  490. // CHECK:STDOUT: }
  491. // CHECK:STDOUT: %import_ref.7: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  492. // CHECK:STDOUT: }
  493. // CHECK:STDOUT:
  494. // CHECK:STDOUT: file {
  495. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  496. // CHECK:STDOUT: .A = imports.%import_ref.1
  497. // CHECK:STDOUT: .B = imports.%import_ref.2
  498. // CHECK:STDOUT: .C = imports.%import_ref.3
  499. // CHECK:STDOUT: .D = imports.%import_ref.4
  500. // CHECK:STDOUT: .NS = imports.%NS
  501. // CHECK:STDOUT: .Core = imports.%Core
  502. // CHECK:STDOUT: .a = %a
  503. // CHECK:STDOUT: .b = %b
  504. // CHECK:STDOUT: .c = %c
  505. // CHECK:STDOUT: .d = %d
  506. // CHECK:STDOUT: .e = %e
  507. // CHECK:STDOUT: }
  508. // CHECK:STDOUT: %Core.import = import Core
  509. // CHECK:STDOUT: %default.import = import <invalid>
  510. // CHECK:STDOUT: %.loc6_9.1: %.1 = tuple_literal ()
  511. // CHECK:STDOUT: %.loc6_9.2: type = converted %.loc6_9.1, constants.%.1 [template = constants.%.1]
  512. // CHECK:STDOUT: %a.var: ref %.1 = var a
  513. // CHECK:STDOUT: %a: ref %.1 = bind_name a, %a.var
  514. // CHECK:STDOUT: %int.make_type_32.loc7: init type = call constants.%Int32() [template = i32]
  515. // CHECK:STDOUT: %.loc7_8.1: type = value_of_initializer %int.make_type_32.loc7 [template = i32]
  516. // CHECK:STDOUT: %.loc7_8.2: type = converted %int.make_type_32.loc7, %.loc7_8.1 [template = i32]
  517. // CHECK:STDOUT: %b.var: ref i32 = var b
  518. // CHECK:STDOUT: %b: ref i32 = bind_name b, %b.var
  519. // CHECK:STDOUT: %int.make_type_32.loc8: init type = call constants.%Int32() [template = i32]
  520. // CHECK:STDOUT: %.loc8_13.1: type = value_of_initializer %int.make_type_32.loc8 [template = i32]
  521. // CHECK:STDOUT: %.loc8_13.2: type = converted %int.make_type_32.loc8, %.loc8_13.1 [template = i32]
  522. // CHECK:STDOUT: %.loc8_16: type = struct_type {.c: i32} [template = constants.%.3]
  523. // CHECK:STDOUT: %c.var: ref %.3 = var c
  524. // CHECK:STDOUT: %c: ref %.3 = bind_name c, %c.var
  525. // CHECK:STDOUT: %.loc9_9.1: %.1 = tuple_literal ()
  526. // CHECK:STDOUT: %.loc9_9.2: type = converted %.loc9_9.1, constants.%.1 [template = constants.%.1]
  527. // CHECK:STDOUT: %d.var: ref %.1 = var d
  528. // CHECK:STDOUT: %d: ref %.1 = bind_name d, %d.var
  529. // CHECK:STDOUT: %.loc10_9.1: %.1 = tuple_literal ()
  530. // CHECK:STDOUT: %.loc10_9.2: type = converted %.loc10_9.1, constants.%.1 [template = constants.%.1]
  531. // CHECK:STDOUT: %e.var: ref %.1 = var e
  532. // CHECK:STDOUT: %e: ref %.1 = bind_name e, %e.var
  533. // CHECK:STDOUT: }
  534. // CHECK:STDOUT:
  535. // CHECK:STDOUT: fn @A();
  536. // CHECK:STDOUT:
  537. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  538. // CHECK:STDOUT:
  539. // CHECK:STDOUT: fn @B(%b: i32) -> i32;
  540. // CHECK:STDOUT:
  541. // CHECK:STDOUT: fn @C(%c: %.4) -> %.3;
  542. // CHECK:STDOUT:
  543. // CHECK:STDOUT: extern fn @D();
  544. // CHECK:STDOUT:
  545. // CHECK:STDOUT: fn @E();
  546. // CHECK:STDOUT:
  547. // CHECK:STDOUT: fn @__global_init() {
  548. // CHECK:STDOUT: !entry:
  549. // CHECK:STDOUT: %A.ref: %A.type = name_ref A, imports.%import_ref.1 [template = constants.%A]
  550. // CHECK:STDOUT: %A.call: init %.1 = call %A.ref()
  551. // CHECK:STDOUT: assign file.%a.var, %A.call
  552. // CHECK:STDOUT: %B.ref: %B.type = name_ref B, imports.%import_ref.2 [template = constants.%B]
  553. // CHECK:STDOUT: %.loc7: i32 = int_literal 1 [template = constants.%.2]
  554. // CHECK:STDOUT: %B.call: init i32 = call %B.ref(%.loc7)
  555. // CHECK:STDOUT: assign file.%b.var, %B.call
  556. // CHECK:STDOUT: %C.ref: %C.type = name_ref C, imports.%import_ref.3 [template = constants.%C]
  557. // CHECK:STDOUT: %.loc8_23: i32 = int_literal 1 [template = constants.%.2]
  558. // CHECK:STDOUT: %.loc8_25: %.4 = tuple_literal (%.loc8_23)
  559. // CHECK:STDOUT: %tuple: %.4 = tuple_value (%.loc8_23) [template = constants.%tuple]
  560. // CHECK:STDOUT: %.loc8_21: %.4 = converted %.loc8_25, %tuple [template = constants.%tuple]
  561. // CHECK:STDOUT: %C.call: init %.3 = call %C.ref(%.loc8_21)
  562. // CHECK:STDOUT: assign file.%c.var, %C.call
  563. // CHECK:STDOUT: %D.ref: %D.type = name_ref D, imports.%import_ref.4 [template = constants.%D]
  564. // CHECK:STDOUT: %D.call: init %.1 = call %D.ref()
  565. // CHECK:STDOUT: assign file.%d.var, %D.call
  566. // CHECK:STDOUT: %NS.ref: <namespace> = name_ref NS, imports.%NS [template = imports.%NS]
  567. // CHECK:STDOUT: %E.ref: %E.type = name_ref E, imports.%import_ref.6 [template = constants.%E]
  568. // CHECK:STDOUT: %E.call: init %.1 = call %E.ref()
  569. // CHECK:STDOUT: assign file.%e.var, %E.call
  570. // CHECK:STDOUT: return
  571. // CHECK:STDOUT: }
  572. // CHECK:STDOUT:
  573. // CHECK:STDOUT: --- fail_redecl_api.carbon
  574. // CHECK:STDOUT:
  575. // CHECK:STDOUT: constants {
  576. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  577. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  578. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  579. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  580. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  581. // CHECK:STDOUT: %B.type: type = fn_type @B [template]
  582. // CHECK:STDOUT: %B: %B.type = struct_value () [template]
  583. // CHECK:STDOUT: %.2: type = tuple_type (type) [template]
  584. // CHECK:STDOUT: %.3: type = tuple_type (i32) [template]
  585. // CHECK:STDOUT: %.4: type = struct_type {.c: i32} [template]
  586. // CHECK:STDOUT: %C.type: type = fn_type @C [template]
  587. // CHECK:STDOUT: %C: %C.type = struct_value () [template]
  588. // CHECK:STDOUT: %D.type: type = fn_type @D [template]
  589. // CHECK:STDOUT: %D: %D.type = struct_value () [template]
  590. // CHECK:STDOUT: %E.type: type = fn_type @E [template]
  591. // CHECK:STDOUT: %E: %E.type = struct_value () [template]
  592. // CHECK:STDOUT: %.5: i32 = int_literal 1 [template]
  593. // CHECK:STDOUT: %tuple: %.3 = tuple_value (%.5) [template]
  594. // CHECK:STDOUT: }
  595. // CHECK:STDOUT:
  596. // CHECK:STDOUT: imports {
  597. // CHECK:STDOUT: %import_ref.1: %A.type = import_ref Main//api, inst+3, loaded [template = constants.%A]
  598. // CHECK:STDOUT: %import_ref.2: %B.type = import_ref Main//api, inst+21, loaded [template = constants.%B]
  599. // CHECK:STDOUT: %import_ref.3: %C.type = import_ref Main//api, inst+41, loaded [template = constants.%C]
  600. // CHECK:STDOUT: %import_ref.4: %D.type = import_ref Main//api, inst+44, loaded [template = constants.%D]
  601. // CHECK:STDOUT: %import_ref.5: <namespace> = import_ref Main//api, inst+47, loaded
  602. // CHECK:STDOUT: %NS: <namespace> = namespace %import_ref.5, [template] {
  603. // CHECK:STDOUT: .E = file.%E.decl
  604. // CHECK:STDOUT: }
  605. // CHECK:STDOUT: %import_ref.6: %E.type = import_ref Main//api, inst+48, loaded [template = constants.%E]
  606. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  607. // CHECK:STDOUT: .Int32 = %import_ref.7
  608. // CHECK:STDOUT: import Core//prelude
  609. // CHECK:STDOUT: import Core//prelude/operators
  610. // CHECK:STDOUT: import Core//prelude/types
  611. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  612. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  613. // CHECK:STDOUT: import Core//prelude/operators/comparison
  614. // CHECK:STDOUT: import Core//prelude/types/bool
  615. // CHECK:STDOUT: }
  616. // CHECK:STDOUT: %import_ref.7: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  617. // CHECK:STDOUT: }
  618. // CHECK:STDOUT:
  619. // CHECK:STDOUT: file {
  620. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  621. // CHECK:STDOUT: .A = %A.decl
  622. // CHECK:STDOUT: .B = %B.decl
  623. // CHECK:STDOUT: .C = %C.decl
  624. // CHECK:STDOUT: .D = %D.decl
  625. // CHECK:STDOUT: .NS = imports.%NS
  626. // CHECK:STDOUT: .Core = imports.%Core
  627. // CHECK:STDOUT: .a = %a
  628. // CHECK:STDOUT: .b = %b.loc63
  629. // CHECK:STDOUT: .c = %c.loc64
  630. // CHECK:STDOUT: .d = %d
  631. // CHECK:STDOUT: .e = %e
  632. // CHECK:STDOUT: }
  633. // CHECK:STDOUT: %Core.import = import Core
  634. // CHECK:STDOUT: %default.import = import <invalid>
  635. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [template = constants.%A] {}
  636. // CHECK:STDOUT: %B.decl: %B.type = fn_decl @B [template = constants.%B] {
  637. // CHECK:STDOUT: %int.make_type_32.loc27_16: init type = call constants.%Int32() [template = i32]
  638. // CHECK:STDOUT: %.loc27_16.1: type = value_of_initializer %int.make_type_32.loc27_16 [template = i32]
  639. // CHECK:STDOUT: %.loc27_16.2: type = converted %int.make_type_32.loc27_16, %.loc27_16.1 [template = i32]
  640. // CHECK:STDOUT: %b.loc27_13.1: i32 = param b
  641. // CHECK:STDOUT: %b.loc27_13.2: i32 = bind_name b, %b.loc27_13.1
  642. // CHECK:STDOUT: %int.make_type_32.loc27_24: init type = call constants.%Int32() [template = i32]
  643. // CHECK:STDOUT: %.loc27_24.1: type = value_of_initializer %int.make_type_32.loc27_24 [template = i32]
  644. // CHECK:STDOUT: %.loc27_24.2: type = converted %int.make_type_32.loc27_24, %.loc27_24.1 [template = i32]
  645. // CHECK:STDOUT: %return.var.loc27: ref i32 = var <return slot>
  646. // CHECK:STDOUT: }
  647. // CHECK:STDOUT: %C.decl: %C.type = fn_decl @C [template = constants.%C] {
  648. // CHECK:STDOUT: %int.make_type_32.loc38_17: init type = call constants.%Int32() [template = i32]
  649. // CHECK:STDOUT: %.loc38_21.1: %.2 = tuple_literal (%int.make_type_32.loc38_17)
  650. // CHECK:STDOUT: %.loc38_21.2: type = value_of_initializer %int.make_type_32.loc38_17 [template = i32]
  651. // CHECK:STDOUT: %.loc38_21.3: type = converted %int.make_type_32.loc38_17, %.loc38_21.2 [template = i32]
  652. // CHECK:STDOUT: %.loc38_21.4: type = converted %.loc38_21.1, constants.%.3 [template = constants.%.3]
  653. // CHECK:STDOUT: %c.loc38_13.1: %.3 = param c
  654. // CHECK:STDOUT: %c.loc38_13.2: %.3 = bind_name c, %c.loc38_13.1
  655. // CHECK:STDOUT: %int.make_type_32.loc38_32: init type = call constants.%Int32() [template = i32]
  656. // CHECK:STDOUT: %.loc38_32.1: type = value_of_initializer %int.make_type_32.loc38_32 [template = i32]
  657. // CHECK:STDOUT: %.loc38_32.2: type = converted %int.make_type_32.loc38_32, %.loc38_32.1 [template = i32]
  658. // CHECK:STDOUT: %.loc38_35: type = struct_type {.c: i32} [template = constants.%.4]
  659. // CHECK:STDOUT: %return.var.loc38: ref %.4 = var <return slot>
  660. // CHECK:STDOUT: }
  661. // CHECK:STDOUT: %D.decl: %D.type = fn_decl @D [template = constants.%D] {}
  662. // CHECK:STDOUT: %E.decl: %E.type = fn_decl @E [template = constants.%E] {}
  663. // CHECK:STDOUT: %.loc62_9.1: %.1 = tuple_literal ()
  664. // CHECK:STDOUT: %.loc62_9.2: type = converted %.loc62_9.1, constants.%.1 [template = constants.%.1]
  665. // CHECK:STDOUT: %a.var: ref %.1 = var a
  666. // CHECK:STDOUT: %a: ref %.1 = bind_name a, %a.var
  667. // CHECK:STDOUT: %int.make_type_32.loc63: init type = call constants.%Int32() [template = i32]
  668. // CHECK:STDOUT: %.loc63_8.1: type = value_of_initializer %int.make_type_32.loc63 [template = i32]
  669. // CHECK:STDOUT: %.loc63_8.2: type = converted %int.make_type_32.loc63, %.loc63_8.1 [template = i32]
  670. // CHECK:STDOUT: %b.var: ref i32 = var b
  671. // CHECK:STDOUT: %b.loc63: ref i32 = bind_name b, %b.var
  672. // CHECK:STDOUT: %int.make_type_32.loc64: init type = call constants.%Int32() [template = i32]
  673. // CHECK:STDOUT: %.loc64_13.1: type = value_of_initializer %int.make_type_32.loc64 [template = i32]
  674. // CHECK:STDOUT: %.loc64_13.2: type = converted %int.make_type_32.loc64, %.loc64_13.1 [template = i32]
  675. // CHECK:STDOUT: %.loc64_16: type = struct_type {.c: i32} [template = constants.%.4]
  676. // CHECK:STDOUT: %c.var: ref %.4 = var c
  677. // CHECK:STDOUT: %c.loc64: ref %.4 = bind_name c, %c.var
  678. // CHECK:STDOUT: %.loc65_9.1: %.1 = tuple_literal ()
  679. // CHECK:STDOUT: %.loc65_9.2: type = converted %.loc65_9.1, constants.%.1 [template = constants.%.1]
  680. // CHECK:STDOUT: %d.var: ref %.1 = var d
  681. // CHECK:STDOUT: %d: ref %.1 = bind_name d, %d.var
  682. // CHECK:STDOUT: %.loc66_9.1: %.1 = tuple_literal ()
  683. // CHECK:STDOUT: %.loc66_9.2: type = converted %.loc66_9.1, constants.%.1 [template = constants.%.1]
  684. // CHECK:STDOUT: %e.var: ref %.1 = var e
  685. // CHECK:STDOUT: %e: ref %.1 = bind_name e, %e.var
  686. // CHECK:STDOUT: }
  687. // CHECK:STDOUT:
  688. // CHECK:STDOUT: extern fn @A();
  689. // CHECK:STDOUT:
  690. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  691. // CHECK:STDOUT:
  692. // CHECK:STDOUT: extern fn @B(%b: i32) -> i32;
  693. // CHECK:STDOUT:
  694. // CHECK:STDOUT: extern fn @C(%c: %.3) -> %.4;
  695. // CHECK:STDOUT:
  696. // CHECK:STDOUT: extern fn @D();
  697. // CHECK:STDOUT:
  698. // CHECK:STDOUT: extern fn @E();
  699. // CHECK:STDOUT:
  700. // CHECK:STDOUT: fn @__global_init() {
  701. // CHECK:STDOUT: !entry:
  702. // CHECK:STDOUT: %A.ref: %A.type = name_ref A, file.%A.decl [template = constants.%A]
  703. // CHECK:STDOUT: %A.call: init %.1 = call %A.ref()
  704. // CHECK:STDOUT: assign file.%a.var, %A.call
  705. // CHECK:STDOUT: %B.ref: %B.type = name_ref B, file.%B.decl [template = constants.%B]
  706. // CHECK:STDOUT: %.loc63: i32 = int_literal 1 [template = constants.%.5]
  707. // CHECK:STDOUT: %B.call: init i32 = call %B.ref(%.loc63)
  708. // CHECK:STDOUT: assign file.%b.var, %B.call
  709. // CHECK:STDOUT: %C.ref: %C.type = name_ref C, file.%C.decl [template = constants.%C]
  710. // CHECK:STDOUT: %.loc64_23: i32 = int_literal 1 [template = constants.%.5]
  711. // CHECK:STDOUT: %.loc64_25: %.3 = tuple_literal (%.loc64_23)
  712. // CHECK:STDOUT: %tuple: %.3 = tuple_value (%.loc64_23) [template = constants.%tuple]
  713. // CHECK:STDOUT: %.loc64_21: %.3 = converted %.loc64_25, %tuple [template = constants.%tuple]
  714. // CHECK:STDOUT: %C.call: init %.4 = call %C.ref(%.loc64_21)
  715. // CHECK:STDOUT: assign file.%c.var, %C.call
  716. // CHECK:STDOUT: %D.ref: %D.type = name_ref D, file.%D.decl [template = constants.%D]
  717. // CHECK:STDOUT: %D.call: init %.1 = call %D.ref()
  718. // CHECK:STDOUT: assign file.%d.var, %D.call
  719. // CHECK:STDOUT: %NS.ref: <namespace> = name_ref NS, imports.%NS [template = imports.%NS]
  720. // CHECK:STDOUT: %E.ref: %E.type = name_ref E, file.%E.decl [template = constants.%E]
  721. // CHECK:STDOUT: %E.call: init %.1 = call %E.ref()
  722. // CHECK:STDOUT: assign file.%e.var, %E.call
  723. // CHECK:STDOUT: return
  724. // CHECK:STDOUT: }
  725. // CHECK:STDOUT:
  726. // CHECK:STDOUT: --- redecl_extern_api.carbon
  727. // CHECK:STDOUT:
  728. // CHECK:STDOUT: constants {
  729. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  730. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  731. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  732. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  733. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  734. // CHECK:STDOUT: %B.type: type = fn_type @B [template]
  735. // CHECK:STDOUT: %B: %B.type = struct_value () [template]
  736. // CHECK:STDOUT: %.2: type = tuple_type (type) [template]
  737. // CHECK:STDOUT: %.3: type = tuple_type (i32) [template]
  738. // CHECK:STDOUT: %.4: type = struct_type {.c: i32} [template]
  739. // CHECK:STDOUT: %C.type: type = fn_type @C [template]
  740. // CHECK:STDOUT: %C: %C.type = struct_value () [template]
  741. // CHECK:STDOUT: %D.type: type = fn_type @D [template]
  742. // CHECK:STDOUT: %D: %D.type = struct_value () [template]
  743. // CHECK:STDOUT: %E.type: type = fn_type @E [template]
  744. // CHECK:STDOUT: %E: %E.type = struct_value () [template]
  745. // CHECK:STDOUT: %.5: i32 = int_literal 1 [template]
  746. // CHECK:STDOUT: %tuple: %.3 = tuple_value (%.5) [template]
  747. // CHECK:STDOUT: }
  748. // CHECK:STDOUT:
  749. // CHECK:STDOUT: imports {
  750. // CHECK:STDOUT: %import_ref.1: %A.type = import_ref Main//extern_api, inst+3, loaded [template = constants.%A]
  751. // CHECK:STDOUT: %import_ref.2: %B.type = import_ref Main//extern_api, inst+21, loaded [template = constants.%B]
  752. // CHECK:STDOUT: %import_ref.3: %C.type = import_ref Main//extern_api, inst+41, loaded [template = constants.%C]
  753. // CHECK:STDOUT: %import_ref.4: %D.type = import_ref Main//extern_api, inst+44, loaded [template = constants.%D]
  754. // CHECK:STDOUT: %import_ref.5: <namespace> = import_ref Main//extern_api, inst+47, loaded
  755. // CHECK:STDOUT: %NS: <namespace> = namespace %import_ref.5, [template] {
  756. // CHECK:STDOUT: .E = file.%E.decl
  757. // CHECK:STDOUT: }
  758. // CHECK:STDOUT: %import_ref.6: %E.type = import_ref Main//extern_api, inst+48, loaded [template = constants.%E]
  759. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  760. // CHECK:STDOUT: .Int32 = %import_ref.7
  761. // CHECK:STDOUT: import Core//prelude
  762. // CHECK:STDOUT: import Core//prelude/operators
  763. // CHECK:STDOUT: import Core//prelude/types
  764. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  765. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  766. // CHECK:STDOUT: import Core//prelude/operators/comparison
  767. // CHECK:STDOUT: import Core//prelude/types/bool
  768. // CHECK:STDOUT: }
  769. // CHECK:STDOUT: %import_ref.7: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  770. // CHECK:STDOUT: }
  771. // CHECK:STDOUT:
  772. // CHECK:STDOUT: file {
  773. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  774. // CHECK:STDOUT: .A = %A.decl
  775. // CHECK:STDOUT: .B = %B.decl
  776. // CHECK:STDOUT: .C = %C.decl
  777. // CHECK:STDOUT: .D = %D.decl
  778. // CHECK:STDOUT: .NS = imports.%NS
  779. // CHECK:STDOUT: .Core = imports.%Core
  780. // CHECK:STDOUT: .a = %a
  781. // CHECK:STDOUT: .b = %b.loc13
  782. // CHECK:STDOUT: .c = %c.loc14
  783. // CHECK:STDOUT: .d = %d
  784. // CHECK:STDOUT: .e = %e
  785. // CHECK:STDOUT: }
  786. // CHECK:STDOUT: %Core.import = import Core
  787. // CHECK:STDOUT: %default.import = import <invalid>
  788. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [template = constants.%A] {}
  789. // CHECK:STDOUT: %B.decl: %B.type = fn_decl @B [template = constants.%B] {
  790. // CHECK:STDOUT: %int.make_type_32.loc7_16: init type = call constants.%Int32() [template = i32]
  791. // CHECK:STDOUT: %.loc7_16.1: type = value_of_initializer %int.make_type_32.loc7_16 [template = i32]
  792. // CHECK:STDOUT: %.loc7_16.2: type = converted %int.make_type_32.loc7_16, %.loc7_16.1 [template = i32]
  793. // CHECK:STDOUT: %b.loc7_13.1: i32 = param b
  794. // CHECK:STDOUT: %b.loc7_13.2: i32 = bind_name b, %b.loc7_13.1
  795. // CHECK:STDOUT: %int.make_type_32.loc7_24: init type = call constants.%Int32() [template = i32]
  796. // CHECK:STDOUT: %.loc7_24.1: type = value_of_initializer %int.make_type_32.loc7_24 [template = i32]
  797. // CHECK:STDOUT: %.loc7_24.2: type = converted %int.make_type_32.loc7_24, %.loc7_24.1 [template = i32]
  798. // CHECK:STDOUT: %return.var.loc7: ref i32 = var <return slot>
  799. // CHECK:STDOUT: }
  800. // CHECK:STDOUT: %C.decl: %C.type = fn_decl @C [template = constants.%C] {
  801. // CHECK:STDOUT: %int.make_type_32.loc8_17: init type = call constants.%Int32() [template = i32]
  802. // CHECK:STDOUT: %.loc8_21.1: %.2 = tuple_literal (%int.make_type_32.loc8_17)
  803. // CHECK:STDOUT: %.loc8_21.2: type = value_of_initializer %int.make_type_32.loc8_17 [template = i32]
  804. // CHECK:STDOUT: %.loc8_21.3: type = converted %int.make_type_32.loc8_17, %.loc8_21.2 [template = i32]
  805. // CHECK:STDOUT: %.loc8_21.4: type = converted %.loc8_21.1, constants.%.3 [template = constants.%.3]
  806. // CHECK:STDOUT: %c.loc8_13.1: %.3 = param c
  807. // CHECK:STDOUT: %c.loc8_13.2: %.3 = bind_name c, %c.loc8_13.1
  808. // CHECK:STDOUT: %int.make_type_32.loc8_32: init type = call constants.%Int32() [template = i32]
  809. // CHECK:STDOUT: %.loc8_32.1: type = value_of_initializer %int.make_type_32.loc8_32 [template = i32]
  810. // CHECK:STDOUT: %.loc8_32.2: type = converted %int.make_type_32.loc8_32, %.loc8_32.1 [template = i32]
  811. // CHECK:STDOUT: %.loc8_35: type = struct_type {.c: i32} [template = constants.%.4]
  812. // CHECK:STDOUT: %return.var.loc8: ref %.4 = var <return slot>
  813. // CHECK:STDOUT: }
  814. // CHECK:STDOUT: %D.decl: %D.type = fn_decl @D [template = constants.%D] {}
  815. // CHECK:STDOUT: %E.decl: %E.type = fn_decl @E [template = constants.%E] {}
  816. // CHECK:STDOUT: %.loc12_9.1: %.1 = tuple_literal ()
  817. // CHECK:STDOUT: %.loc12_9.2: type = converted %.loc12_9.1, constants.%.1 [template = constants.%.1]
  818. // CHECK:STDOUT: %a.var: ref %.1 = var a
  819. // CHECK:STDOUT: %a: ref %.1 = bind_name a, %a.var
  820. // CHECK:STDOUT: %int.make_type_32.loc13: init type = call constants.%Int32() [template = i32]
  821. // CHECK:STDOUT: %.loc13_8.1: type = value_of_initializer %int.make_type_32.loc13 [template = i32]
  822. // CHECK:STDOUT: %.loc13_8.2: type = converted %int.make_type_32.loc13, %.loc13_8.1 [template = i32]
  823. // CHECK:STDOUT: %b.var: ref i32 = var b
  824. // CHECK:STDOUT: %b.loc13: ref i32 = bind_name b, %b.var
  825. // CHECK:STDOUT: %int.make_type_32.loc14: init type = call constants.%Int32() [template = i32]
  826. // CHECK:STDOUT: %.loc14_13.1: type = value_of_initializer %int.make_type_32.loc14 [template = i32]
  827. // CHECK:STDOUT: %.loc14_13.2: type = converted %int.make_type_32.loc14, %.loc14_13.1 [template = i32]
  828. // CHECK:STDOUT: %.loc14_16: type = struct_type {.c: i32} [template = constants.%.4]
  829. // CHECK:STDOUT: %c.var: ref %.4 = var c
  830. // CHECK:STDOUT: %c.loc14: ref %.4 = bind_name c, %c.var
  831. // CHECK:STDOUT: %.loc15_9.1: %.1 = tuple_literal ()
  832. // CHECK:STDOUT: %.loc15_9.2: type = converted %.loc15_9.1, constants.%.1 [template = constants.%.1]
  833. // CHECK:STDOUT: %d.var: ref %.1 = var d
  834. // CHECK:STDOUT: %d: ref %.1 = bind_name d, %d.var
  835. // CHECK:STDOUT: %.loc16_9.1: %.1 = tuple_literal ()
  836. // CHECK:STDOUT: %.loc16_9.2: type = converted %.loc16_9.1, constants.%.1 [template = constants.%.1]
  837. // CHECK:STDOUT: %e.var: ref %.1 = var e
  838. // CHECK:STDOUT: %e: ref %.1 = bind_name e, %e.var
  839. // CHECK:STDOUT: }
  840. // CHECK:STDOUT:
  841. // CHECK:STDOUT: extern fn @A();
  842. // CHECK:STDOUT:
  843. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  844. // CHECK:STDOUT:
  845. // CHECK:STDOUT: extern fn @B(%b: i32) -> i32;
  846. // CHECK:STDOUT:
  847. // CHECK:STDOUT: extern fn @C(%c: %.3) -> %.4;
  848. // CHECK:STDOUT:
  849. // CHECK:STDOUT: extern fn @D();
  850. // CHECK:STDOUT:
  851. // CHECK:STDOUT: extern fn @E();
  852. // CHECK:STDOUT:
  853. // CHECK:STDOUT: fn @__global_init() {
  854. // CHECK:STDOUT: !entry:
  855. // CHECK:STDOUT: %A.ref: %A.type = name_ref A, file.%A.decl [template = constants.%A]
  856. // CHECK:STDOUT: %A.call: init %.1 = call %A.ref()
  857. // CHECK:STDOUT: assign file.%a.var, %A.call
  858. // CHECK:STDOUT: %B.ref: %B.type = name_ref B, file.%B.decl [template = constants.%B]
  859. // CHECK:STDOUT: %.loc13: i32 = int_literal 1 [template = constants.%.5]
  860. // CHECK:STDOUT: %B.call: init i32 = call %B.ref(%.loc13)
  861. // CHECK:STDOUT: assign file.%b.var, %B.call
  862. // CHECK:STDOUT: %C.ref: %C.type = name_ref C, file.%C.decl [template = constants.%C]
  863. // CHECK:STDOUT: %.loc14_23: i32 = int_literal 1 [template = constants.%.5]
  864. // CHECK:STDOUT: %.loc14_25: %.3 = tuple_literal (%.loc14_23)
  865. // CHECK:STDOUT: %tuple: %.3 = tuple_value (%.loc14_23) [template = constants.%tuple]
  866. // CHECK:STDOUT: %.loc14_21: %.3 = converted %.loc14_25, %tuple [template = constants.%tuple]
  867. // CHECK:STDOUT: %C.call: init %.4 = call %C.ref(%.loc14_21)
  868. // CHECK:STDOUT: assign file.%c.var, %C.call
  869. // CHECK:STDOUT: %D.ref: %D.type = name_ref D, file.%D.decl [template = constants.%D]
  870. // CHECK:STDOUT: %D.call: init %.1 = call %D.ref()
  871. // CHECK:STDOUT: assign file.%d.var, %D.call
  872. // CHECK:STDOUT: %NS.ref: <namespace> = name_ref NS, imports.%NS [template = imports.%NS]
  873. // CHECK:STDOUT: %E.ref: %E.type = name_ref E, file.%E.decl [template = constants.%E]
  874. // CHECK:STDOUT: %E.call: init %.1 = call %E.ref()
  875. // CHECK:STDOUT: assign file.%e.var, %E.call
  876. // CHECK:STDOUT: return
  877. // CHECK:STDOUT: }
  878. // CHECK:STDOUT:
  879. // CHECK:STDOUT: --- fail_merge.carbon
  880. // CHECK:STDOUT:
  881. // CHECK:STDOUT: constants {
  882. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  883. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  884. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  885. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  886. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  887. // CHECK:STDOUT: %B.type: type = fn_type @B [template]
  888. // CHECK:STDOUT: %B: %B.type = struct_value () [template]
  889. // CHECK:STDOUT: %.2: i32 = int_literal 1 [template]
  890. // CHECK:STDOUT: %.3: type = struct_type {.c: i32} [template]
  891. // CHECK:STDOUT: %C.type: type = fn_type @C [template]
  892. // CHECK:STDOUT: %C: %C.type = struct_value () [template]
  893. // CHECK:STDOUT: %.4: type = tuple_type (i32) [template]
  894. // CHECK:STDOUT: %tuple: %.4 = tuple_value (%.2) [template]
  895. // CHECK:STDOUT: %D.type: type = fn_type @D [template]
  896. // CHECK:STDOUT: %D: %D.type = struct_value () [template]
  897. // CHECK:STDOUT: %E.type: type = fn_type @E [template]
  898. // CHECK:STDOUT: %E: %E.type = struct_value () [template]
  899. // CHECK:STDOUT: }
  900. // CHECK:STDOUT:
  901. // CHECK:STDOUT: imports {
  902. // CHECK:STDOUT: %import_ref.1: %A.type = import_ref Main//api, inst+3, loaded [template = constants.%A]
  903. // CHECK:STDOUT: %import_ref.2: %B.type = import_ref Main//api, inst+21, loaded [template = constants.%B]
  904. // CHECK:STDOUT: %import_ref.3: %C.type = import_ref Main//api, inst+41, loaded [template = constants.%C]
  905. // CHECK:STDOUT: %import_ref.4: %D.type = import_ref Main//api, inst+44, loaded [template = constants.%D]
  906. // CHECK:STDOUT: %import_ref.5: <namespace> = import_ref Main//api, inst+47, loaded
  907. // CHECK:STDOUT: %NS: <namespace> = namespace %import_ref.5, [template] {
  908. // CHECK:STDOUT: .E = %import_ref.6
  909. // CHECK:STDOUT: }
  910. // CHECK:STDOUT: %import_ref.6: %E.type = import_ref Main//api, inst+48, loaded [template = constants.%E]
  911. // CHECK:STDOUT: %import_ref.7 = import_ref Main//extern_api, inst+3, unloaded
  912. // CHECK:STDOUT: %import_ref.8 = import_ref Main//extern_api, inst+21, unloaded
  913. // CHECK:STDOUT: %import_ref.9 = import_ref Main//extern_api, inst+41, unloaded
  914. // CHECK:STDOUT: %import_ref.10 = import_ref Main//extern_api, inst+44, unloaded
  915. // CHECK:STDOUT: %import_ref.11 = import_ref Main//extern_api, inst+48, unloaded
  916. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  917. // CHECK:STDOUT: .Int32 = %import_ref.12
  918. // CHECK:STDOUT: import Core//prelude
  919. // CHECK:STDOUT: import Core//prelude/operators
  920. // CHECK:STDOUT: import Core//prelude/types
  921. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  922. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  923. // CHECK:STDOUT: import Core//prelude/operators/comparison
  924. // CHECK:STDOUT: import Core//prelude/types/bool
  925. // CHECK:STDOUT: }
  926. // CHECK:STDOUT: %import_ref.12: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  927. // CHECK:STDOUT: }
  928. // CHECK:STDOUT:
  929. // CHECK:STDOUT: file {
  930. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  931. // CHECK:STDOUT: .A = imports.%import_ref.1
  932. // CHECK:STDOUT: .B = imports.%import_ref.2
  933. // CHECK:STDOUT: .C = imports.%import_ref.3
  934. // CHECK:STDOUT: .D = imports.%import_ref.4
  935. // CHECK:STDOUT: .NS = imports.%NS
  936. // CHECK:STDOUT: .Core = imports.%Core
  937. // CHECK:STDOUT: .a = %a
  938. // CHECK:STDOUT: .b = %b
  939. // CHECK:STDOUT: .c = %c
  940. // CHECK:STDOUT: .d = %d
  941. // CHECK:STDOUT: .e = %e
  942. // CHECK:STDOUT: }
  943. // CHECK:STDOUT: %Core.import = import Core
  944. // CHECK:STDOUT: %default.import = import <invalid>
  945. // CHECK:STDOUT: %.loc72_9.1: %.1 = tuple_literal ()
  946. // CHECK:STDOUT: %.loc72_9.2: type = converted %.loc72_9.1, constants.%.1 [template = constants.%.1]
  947. // CHECK:STDOUT: %a.var: ref %.1 = var a
  948. // CHECK:STDOUT: %a: ref %.1 = bind_name a, %a.var
  949. // CHECK:STDOUT: %int.make_type_32.loc73: init type = call constants.%Int32() [template = i32]
  950. // CHECK:STDOUT: %.loc73_8.1: type = value_of_initializer %int.make_type_32.loc73 [template = i32]
  951. // CHECK:STDOUT: %.loc73_8.2: type = converted %int.make_type_32.loc73, %.loc73_8.1 [template = i32]
  952. // CHECK:STDOUT: %b.var: ref i32 = var b
  953. // CHECK:STDOUT: %b: ref i32 = bind_name b, %b.var
  954. // CHECK:STDOUT: %int.make_type_32.loc74: init type = call constants.%Int32() [template = i32]
  955. // CHECK:STDOUT: %.loc74_13.1: type = value_of_initializer %int.make_type_32.loc74 [template = i32]
  956. // CHECK:STDOUT: %.loc74_13.2: type = converted %int.make_type_32.loc74, %.loc74_13.1 [template = i32]
  957. // CHECK:STDOUT: %.loc74_16: type = struct_type {.c: i32} [template = constants.%.3]
  958. // CHECK:STDOUT: %c.var: ref %.3 = var c
  959. // CHECK:STDOUT: %c: ref %.3 = bind_name c, %c.var
  960. // CHECK:STDOUT: %.loc75_9.1: %.1 = tuple_literal ()
  961. // CHECK:STDOUT: %.loc75_9.2: type = converted %.loc75_9.1, constants.%.1 [template = constants.%.1]
  962. // CHECK:STDOUT: %d.var: ref %.1 = var d
  963. // CHECK:STDOUT: %d: ref %.1 = bind_name d, %d.var
  964. // CHECK:STDOUT: %.loc76_9.1: %.1 = tuple_literal ()
  965. // CHECK:STDOUT: %.loc76_9.2: type = converted %.loc76_9.1, constants.%.1 [template = constants.%.1]
  966. // CHECK:STDOUT: %e.var: ref %.1 = var e
  967. // CHECK:STDOUT: %e: ref %.1 = bind_name e, %e.var
  968. // CHECK:STDOUT: }
  969. // CHECK:STDOUT:
  970. // CHECK:STDOUT: fn @A();
  971. // CHECK:STDOUT:
  972. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  973. // CHECK:STDOUT:
  974. // CHECK:STDOUT: fn @B(%b: i32) -> i32;
  975. // CHECK:STDOUT:
  976. // CHECK:STDOUT: fn @C(%c: %.4) -> %.3;
  977. // CHECK:STDOUT:
  978. // CHECK:STDOUT: extern fn @D();
  979. // CHECK:STDOUT:
  980. // CHECK:STDOUT: fn @E();
  981. // CHECK:STDOUT:
  982. // CHECK:STDOUT: fn @__global_init() {
  983. // CHECK:STDOUT: !entry:
  984. // CHECK:STDOUT: %A.ref: %A.type = name_ref A, imports.%import_ref.1 [template = constants.%A]
  985. // CHECK:STDOUT: %A.call: init %.1 = call %A.ref()
  986. // CHECK:STDOUT: assign file.%a.var, %A.call
  987. // CHECK:STDOUT: %B.ref: %B.type = name_ref B, imports.%import_ref.2 [template = constants.%B]
  988. // CHECK:STDOUT: %.loc73: i32 = int_literal 1 [template = constants.%.2]
  989. // CHECK:STDOUT: %B.call: init i32 = call %B.ref(%.loc73)
  990. // CHECK:STDOUT: assign file.%b.var, %B.call
  991. // CHECK:STDOUT: %C.ref: %C.type = name_ref C, imports.%import_ref.3 [template = constants.%C]
  992. // CHECK:STDOUT: %.loc74_23: i32 = int_literal 1 [template = constants.%.2]
  993. // CHECK:STDOUT: %.loc74_25: %.4 = tuple_literal (%.loc74_23)
  994. // CHECK:STDOUT: %tuple: %.4 = tuple_value (%.loc74_23) [template = constants.%tuple]
  995. // CHECK:STDOUT: %.loc74_21: %.4 = converted %.loc74_25, %tuple [template = constants.%tuple]
  996. // CHECK:STDOUT: %C.call: init %.3 = call %C.ref(%.loc74_21)
  997. // CHECK:STDOUT: assign file.%c.var, %C.call
  998. // CHECK:STDOUT: %D.ref: %D.type = name_ref D, imports.%import_ref.4 [template = constants.%D]
  999. // CHECK:STDOUT: %D.call: init %.1 = call %D.ref()
  1000. // CHECK:STDOUT: assign file.%d.var, %D.call
  1001. // CHECK:STDOUT: %NS.ref: <namespace> = name_ref NS, imports.%NS [template = imports.%NS]
  1002. // CHECK:STDOUT: %E.ref: %E.type = name_ref E, imports.%import_ref.6 [template = constants.%E]
  1003. // CHECK:STDOUT: %E.call: init %.1 = call %E.ref()
  1004. // CHECK:STDOUT: assign file.%e.var, %E.call
  1005. // CHECK:STDOUT: return
  1006. // CHECK:STDOUT: }
  1007. // CHECK:STDOUT:
  1008. // CHECK:STDOUT: --- fail_merge_reverse.carbon
  1009. // CHECK:STDOUT:
  1010. // CHECK:STDOUT: constants {
  1011. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  1012. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  1013. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  1014. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  1015. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  1016. // CHECK:STDOUT: %B.type: type = fn_type @B [template]
  1017. // CHECK:STDOUT: %B: %B.type = struct_value () [template]
  1018. // CHECK:STDOUT: %.2: i32 = int_literal 1 [template]
  1019. // CHECK:STDOUT: %.3: type = struct_type {.c: i32} [template]
  1020. // CHECK:STDOUT: %C.type: type = fn_type @C [template]
  1021. // CHECK:STDOUT: %C: %C.type = struct_value () [template]
  1022. // CHECK:STDOUT: %.4: type = tuple_type (i32) [template]
  1023. // CHECK:STDOUT: %tuple: %.4 = tuple_value (%.2) [template]
  1024. // CHECK:STDOUT: %D.type: type = fn_type @D [template]
  1025. // CHECK:STDOUT: %D: %D.type = struct_value () [template]
  1026. // CHECK:STDOUT: %E.type: type = fn_type @E [template]
  1027. // CHECK:STDOUT: %E: %E.type = struct_value () [template]
  1028. // CHECK:STDOUT: }
  1029. // CHECK:STDOUT:
  1030. // CHECK:STDOUT: imports {
  1031. // CHECK:STDOUT: %import_ref.1: %A.type = import_ref Main//extern_api, inst+3, loaded [template = constants.%A]
  1032. // CHECK:STDOUT: %import_ref.2: %B.type = import_ref Main//extern_api, inst+21, loaded [template = constants.%B]
  1033. // CHECK:STDOUT: %import_ref.3: %C.type = import_ref Main//extern_api, inst+41, loaded [template = constants.%C]
  1034. // CHECK:STDOUT: %import_ref.4: %D.type = import_ref Main//extern_api, inst+44, loaded [template = constants.%D]
  1035. // CHECK:STDOUT: %import_ref.5: <namespace> = import_ref Main//extern_api, inst+47, loaded
  1036. // CHECK:STDOUT: %NS: <namespace> = namespace %import_ref.5, [template] {
  1037. // CHECK:STDOUT: .E = %import_ref.6
  1038. // CHECK:STDOUT: }
  1039. // CHECK:STDOUT: %import_ref.6: %E.type = import_ref Main//extern_api, inst+48, loaded [template = constants.%E]
  1040. // CHECK:STDOUT: %import_ref.7 = import_ref Main//api, inst+3, unloaded
  1041. // CHECK:STDOUT: %import_ref.8 = import_ref Main//api, inst+21, unloaded
  1042. // CHECK:STDOUT: %import_ref.9 = import_ref Main//api, inst+41, unloaded
  1043. // CHECK:STDOUT: %import_ref.10 = import_ref Main//api, inst+44, unloaded
  1044. // CHECK:STDOUT: %import_ref.11 = import_ref Main//api, inst+48, unloaded
  1045. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  1046. // CHECK:STDOUT: .Int32 = %import_ref.12
  1047. // CHECK:STDOUT: import Core//prelude
  1048. // CHECK:STDOUT: import Core//prelude/operators
  1049. // CHECK:STDOUT: import Core//prelude/types
  1050. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  1051. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  1052. // CHECK:STDOUT: import Core//prelude/operators/comparison
  1053. // CHECK:STDOUT: import Core//prelude/types/bool
  1054. // CHECK:STDOUT: }
  1055. // CHECK:STDOUT: %import_ref.12: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  1056. // CHECK:STDOUT: }
  1057. // CHECK:STDOUT:
  1058. // CHECK:STDOUT: file {
  1059. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  1060. // CHECK:STDOUT: .A = imports.%import_ref.1
  1061. // CHECK:STDOUT: .B = imports.%import_ref.2
  1062. // CHECK:STDOUT: .C = imports.%import_ref.3
  1063. // CHECK:STDOUT: .D = imports.%import_ref.4
  1064. // CHECK:STDOUT: .NS = imports.%NS
  1065. // CHECK:STDOUT: .Core = imports.%Core
  1066. // CHECK:STDOUT: .a = %a
  1067. // CHECK:STDOUT: .b = %b
  1068. // CHECK:STDOUT: .c = %c
  1069. // CHECK:STDOUT: .d = %d
  1070. // CHECK:STDOUT: .e = %e
  1071. // CHECK:STDOUT: }
  1072. // CHECK:STDOUT: %Core.import = import Core
  1073. // CHECK:STDOUT: %default.import = import <invalid>
  1074. // CHECK:STDOUT: %.loc71_9.1: %.1 = tuple_literal ()
  1075. // CHECK:STDOUT: %.loc71_9.2: type = converted %.loc71_9.1, constants.%.1 [template = constants.%.1]
  1076. // CHECK:STDOUT: %a.var: ref %.1 = var a
  1077. // CHECK:STDOUT: %a: ref %.1 = bind_name a, %a.var
  1078. // CHECK:STDOUT: %int.make_type_32.loc72: init type = call constants.%Int32() [template = i32]
  1079. // CHECK:STDOUT: %.loc72_8.1: type = value_of_initializer %int.make_type_32.loc72 [template = i32]
  1080. // CHECK:STDOUT: %.loc72_8.2: type = converted %int.make_type_32.loc72, %.loc72_8.1 [template = i32]
  1081. // CHECK:STDOUT: %b.var: ref i32 = var b
  1082. // CHECK:STDOUT: %b: ref i32 = bind_name b, %b.var
  1083. // CHECK:STDOUT: %int.make_type_32.loc73: init type = call constants.%Int32() [template = i32]
  1084. // CHECK:STDOUT: %.loc73_13.1: type = value_of_initializer %int.make_type_32.loc73 [template = i32]
  1085. // CHECK:STDOUT: %.loc73_13.2: type = converted %int.make_type_32.loc73, %.loc73_13.1 [template = i32]
  1086. // CHECK:STDOUT: %.loc73_16: type = struct_type {.c: i32} [template = constants.%.3]
  1087. // CHECK:STDOUT: %c.var: ref %.3 = var c
  1088. // CHECK:STDOUT: %c: ref %.3 = bind_name c, %c.var
  1089. // CHECK:STDOUT: %.loc74_9.1: %.1 = tuple_literal ()
  1090. // CHECK:STDOUT: %.loc74_9.2: type = converted %.loc74_9.1, constants.%.1 [template = constants.%.1]
  1091. // CHECK:STDOUT: %d.var: ref %.1 = var d
  1092. // CHECK:STDOUT: %d: ref %.1 = bind_name d, %d.var
  1093. // CHECK:STDOUT: %.loc75_9.1: %.1 = tuple_literal ()
  1094. // CHECK:STDOUT: %.loc75_9.2: type = converted %.loc75_9.1, constants.%.1 [template = constants.%.1]
  1095. // CHECK:STDOUT: %e.var: ref %.1 = var e
  1096. // CHECK:STDOUT: %e: ref %.1 = bind_name e, %e.var
  1097. // CHECK:STDOUT: }
  1098. // CHECK:STDOUT:
  1099. // CHECK:STDOUT: extern fn @A();
  1100. // CHECK:STDOUT:
  1101. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  1102. // CHECK:STDOUT:
  1103. // CHECK:STDOUT: extern fn @B(%b: i32) -> i32;
  1104. // CHECK:STDOUT:
  1105. // CHECK:STDOUT: extern fn @C(%c: %.4) -> %.3;
  1106. // CHECK:STDOUT:
  1107. // CHECK:STDOUT: extern fn @D();
  1108. // CHECK:STDOUT:
  1109. // CHECK:STDOUT: extern fn @E();
  1110. // CHECK:STDOUT:
  1111. // CHECK:STDOUT: fn @__global_init() {
  1112. // CHECK:STDOUT: !entry:
  1113. // CHECK:STDOUT: %A.ref: %A.type = name_ref A, imports.%import_ref.1 [template = constants.%A]
  1114. // CHECK:STDOUT: %A.call: init %.1 = call %A.ref()
  1115. // CHECK:STDOUT: assign file.%a.var, %A.call
  1116. // CHECK:STDOUT: %B.ref: %B.type = name_ref B, imports.%import_ref.2 [template = constants.%B]
  1117. // CHECK:STDOUT: %.loc72: i32 = int_literal 1 [template = constants.%.2]
  1118. // CHECK:STDOUT: %B.call: init i32 = call %B.ref(%.loc72)
  1119. // CHECK:STDOUT: assign file.%b.var, %B.call
  1120. // CHECK:STDOUT: %C.ref: %C.type = name_ref C, imports.%import_ref.3 [template = constants.%C]
  1121. // CHECK:STDOUT: %.loc73_23: i32 = int_literal 1 [template = constants.%.2]
  1122. // CHECK:STDOUT: %.loc73_25: %.4 = tuple_literal (%.loc73_23)
  1123. // CHECK:STDOUT: %tuple: %.4 = tuple_value (%.loc73_23) [template = constants.%tuple]
  1124. // CHECK:STDOUT: %.loc73_21: %.4 = converted %.loc73_25, %tuple [template = constants.%tuple]
  1125. // CHECK:STDOUT: %C.call: init %.3 = call %C.ref(%.loc73_21)
  1126. // CHECK:STDOUT: assign file.%c.var, %C.call
  1127. // CHECK:STDOUT: %D.ref: %D.type = name_ref D, imports.%import_ref.4 [template = constants.%D]
  1128. // CHECK:STDOUT: %D.call: init %.1 = call %D.ref()
  1129. // CHECK:STDOUT: assign file.%d.var, %D.call
  1130. // CHECK:STDOUT: %NS.ref: <namespace> = name_ref NS, imports.%NS [template = imports.%NS]
  1131. // CHECK:STDOUT: %E.ref: %E.type = name_ref E, imports.%import_ref.6 [template = constants.%E]
  1132. // CHECK:STDOUT: %E.call: init %.1 = call %E.ref()
  1133. // CHECK:STDOUT: assign file.%e.var, %E.call
  1134. // CHECK:STDOUT: return
  1135. // CHECK:STDOUT: }
  1136. // CHECK:STDOUT:
  1137. // CHECK:STDOUT: --- unloaded.carbon
  1138. // CHECK:STDOUT:
  1139. // CHECK:STDOUT: imports {
  1140. // CHECK:STDOUT: %import_ref.1 = import_ref Main//api, inst+3, unloaded
  1141. // CHECK:STDOUT: %import_ref.2 = import_ref Main//api, inst+21, unloaded
  1142. // CHECK:STDOUT: %import_ref.3 = import_ref Main//api, inst+41, unloaded
  1143. // CHECK:STDOUT: %import_ref.4 = import_ref Main//api, inst+44, unloaded
  1144. // CHECK:STDOUT: %import_ref.5: <namespace> = import_ref Main//api, inst+47, loaded
  1145. // CHECK:STDOUT: %NS: <namespace> = namespace %import_ref.5, [template] {
  1146. // CHECK:STDOUT: .E = %import_ref.6
  1147. // CHECK:STDOUT: }
  1148. // CHECK:STDOUT: %import_ref.6 = import_ref Main//api, inst+48, unloaded
  1149. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  1150. // CHECK:STDOUT: import Core//prelude
  1151. // CHECK:STDOUT: import Core//prelude/operators
  1152. // CHECK:STDOUT: import Core//prelude/types
  1153. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  1154. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  1155. // CHECK:STDOUT: import Core//prelude/operators/comparison
  1156. // CHECK:STDOUT: import Core//prelude/types/bool
  1157. // CHECK:STDOUT: }
  1158. // CHECK:STDOUT: }
  1159. // CHECK:STDOUT:
  1160. // CHECK:STDOUT: file {
  1161. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  1162. // CHECK:STDOUT: .A = imports.%import_ref.1
  1163. // CHECK:STDOUT: .B = imports.%import_ref.2
  1164. // CHECK:STDOUT: .C = imports.%import_ref.3
  1165. // CHECK:STDOUT: .D = imports.%import_ref.4
  1166. // CHECK:STDOUT: .NS = imports.%NS
  1167. // CHECK:STDOUT: .Core = imports.%Core
  1168. // CHECK:STDOUT: }
  1169. // CHECK:STDOUT: %Core.import = import Core
  1170. // CHECK:STDOUT: %default.import = import <invalid>
  1171. // CHECK:STDOUT: }
  1172. // CHECK:STDOUT:
  1173. // CHECK:STDOUT: --- unloaded_extern.carbon
  1174. // CHECK:STDOUT:
  1175. // CHECK:STDOUT: imports {
  1176. // CHECK:STDOUT: %import_ref.1 = import_ref Main//extern_api, inst+3, unloaded
  1177. // CHECK:STDOUT: %import_ref.2 = import_ref Main//extern_api, inst+21, unloaded
  1178. // CHECK:STDOUT: %import_ref.3 = import_ref Main//extern_api, inst+41, unloaded
  1179. // CHECK:STDOUT: %import_ref.4 = import_ref Main//extern_api, inst+44, unloaded
  1180. // CHECK:STDOUT: %import_ref.5: <namespace> = import_ref Main//extern_api, inst+47, loaded
  1181. // CHECK:STDOUT: %NS: <namespace> = namespace %import_ref.5, [template] {
  1182. // CHECK:STDOUT: .E = %import_ref.6
  1183. // CHECK:STDOUT: }
  1184. // CHECK:STDOUT: %import_ref.6 = import_ref Main//extern_api, inst+48, unloaded
  1185. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  1186. // CHECK:STDOUT: import Core//prelude
  1187. // CHECK:STDOUT: import Core//prelude/operators
  1188. // CHECK:STDOUT: import Core//prelude/types
  1189. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  1190. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  1191. // CHECK:STDOUT: import Core//prelude/operators/comparison
  1192. // CHECK:STDOUT: import Core//prelude/types/bool
  1193. // CHECK:STDOUT: }
  1194. // CHECK:STDOUT: }
  1195. // CHECK:STDOUT:
  1196. // CHECK:STDOUT: file {
  1197. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  1198. // CHECK:STDOUT: .A = imports.%import_ref.1
  1199. // CHECK:STDOUT: .B = imports.%import_ref.2
  1200. // CHECK:STDOUT: .C = imports.%import_ref.3
  1201. // CHECK:STDOUT: .D = imports.%import_ref.4
  1202. // CHECK:STDOUT: .NS = imports.%NS
  1203. // CHECK:STDOUT: .Core = imports.%Core
  1204. // CHECK:STDOUT: }
  1205. // CHECK:STDOUT: %Core.import = import Core
  1206. // CHECK:STDOUT: %default.import = import <invalid>
  1207. // CHECK:STDOUT: }
  1208. // CHECK:STDOUT: