import.carbon 63 KB

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