import.carbon 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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/definition/import.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/definition/import.carbon
  10. // ============================================================================
  11. // Setup files
  12. // ============================================================================
  13. // --- fns.carbon
  14. library "fns";
  15. fn A() {}
  16. fn B(b: i32) -> i32 { return b; }
  17. fn C(c: (i32,)) -> {.c: i32} { return {.c = c[0]}; }
  18. fn D();
  19. // --- extern.carbon
  20. library "extern";
  21. extern fn A();
  22. // ============================================================================
  23. // Test files
  24. // ============================================================================
  25. // --- basics.carbon
  26. library "basics";
  27. import library "fns";
  28. var a: () = A();
  29. var b: i32 = B(1);
  30. var c: {.c: i32} = C((1,));
  31. // --- fail_def_ownership.carbon
  32. library "def_ownership";
  33. import library "fns";
  34. // CHECK:STDERR: fail_def_ownership.carbon:[[@LINE+10]]:1: ERROR: Only one library can declare `fn A` without `extern`.
  35. // CHECK:STDERR: fn A() {};
  36. // CHECK:STDERR: ^~~~~~~~
  37. // CHECK:STDERR: fail_def_ownership.carbon:[[@LINE-5]]:1: In import.
  38. // CHECK:STDERR: import library "fns";
  39. // CHECK:STDERR: ^~~~~~
  40. // CHECK:STDERR: fns.carbon:4:1: Previously declared here.
  41. // CHECK:STDERR: fn A() {}
  42. // CHECK:STDERR: ^~~~~~~~
  43. // CHECK:STDERR:
  44. fn A() {};
  45. // CHECK:STDERR: fail_def_ownership.carbon:[[@LINE+10]]:1: ERROR: Only one library can declare `fn B` without `extern`.
  46. // CHECK:STDERR: fn B(b: i32) -> i32;
  47. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~
  48. // CHECK:STDERR: fail_def_ownership.carbon:[[@LINE-16]]:1: In import.
  49. // CHECK:STDERR: import library "fns";
  50. // CHECK:STDERR: ^~~~~~
  51. // CHECK:STDERR: fns.carbon:5:1: Previously declared here.
  52. // CHECK:STDERR: fn B(b: i32) -> i32 { return b; }
  53. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~
  54. // CHECK:STDERR:
  55. fn B(b: i32) -> i32;
  56. // --- redecl_then_def.carbon
  57. library "redecl_then_def";
  58. import library "extern";
  59. fn A();
  60. fn A() {}
  61. // --- fail_mix_extern_decl.carbon
  62. library "mix_extern_decl";
  63. import library "fns";
  64. extern fn D();
  65. // CHECK:STDERR: fail_mix_extern_decl.carbon:[[@LINE+6]]:1: ERROR: Redeclarations of `fn D` in the same library must match use of `extern`.
  66. // CHECK:STDERR: fn D() {}
  67. // CHECK:STDERR: ^~~~~~~~
  68. // CHECK:STDERR: fail_mix_extern_decl.carbon:[[@LINE-4]]:1: Previously declared here.
  69. // CHECK:STDERR: extern fn D();
  70. // CHECK:STDERR: ^~~~~~~~~~~~~~
  71. fn D() {}
  72. // CHECK:STDOUT: --- fns.carbon
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: constants {
  75. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  76. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  77. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  78. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  79. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  80. // CHECK:STDOUT: %B.type: type = fn_type @B [template]
  81. // CHECK:STDOUT: %B: %B.type = struct_value () [template]
  82. // CHECK:STDOUT: %.2: type = tuple_type (type) [template]
  83. // CHECK:STDOUT: %.3: type = tuple_type (i32) [template]
  84. // CHECK:STDOUT: %.4: type = struct_type {.c: i32} [template]
  85. // CHECK:STDOUT: %C.type: type = fn_type @C [template]
  86. // CHECK:STDOUT: %C: %C.type = struct_value () [template]
  87. // CHECK:STDOUT: %.5: i32 = int_literal 0 [template]
  88. // CHECK:STDOUT: %D.type: type = fn_type @D [template]
  89. // CHECK:STDOUT: %D: %D.type = struct_value () [template]
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: imports {
  93. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  94. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  95. // CHECK:STDOUT: %import_ref.3: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  96. // CHECK:STDOUT: %import_ref.4: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: file {
  100. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  101. // CHECK:STDOUT: .Core = %Core
  102. // CHECK:STDOUT: .A = %A.decl
  103. // CHECK:STDOUT: .B = %B.decl
  104. // CHECK:STDOUT: .C = %C.decl
  105. // CHECK:STDOUT: .D = %D.decl
  106. // CHECK:STDOUT: }
  107. // CHECK:STDOUT: %Core.import = import Core
  108. // CHECK:STDOUT: %Core: <namespace> = namespace %Core.import, [template] {
  109. // CHECK:STDOUT: import Core//prelude
  110. // CHECK:STDOUT: import Core//prelude/operators
  111. // CHECK:STDOUT: import Core//prelude/types
  112. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  113. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  114. // CHECK:STDOUT: import Core//prelude/operators/comparison
  115. // CHECK:STDOUT: import Core//prelude/types/bool
  116. // CHECK:STDOUT: }
  117. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [template = constants.%A] {}
  118. // CHECK:STDOUT: %B.decl: %B.type = fn_decl @B [template = constants.%B] {
  119. // CHECK:STDOUT: %int.make_type_32.loc5_9: init type = call constants.%Int32() [template = i32]
  120. // CHECK:STDOUT: %.loc5_9.1: type = value_of_initializer %int.make_type_32.loc5_9 [template = i32]
  121. // CHECK:STDOUT: %.loc5_9.2: type = converted %int.make_type_32.loc5_9, %.loc5_9.1 [template = i32]
  122. // CHECK:STDOUT: %b.loc5_6.1: i32 = param b
  123. // CHECK:STDOUT: @B.%b: i32 = bind_name b, %b.loc5_6.1
  124. // CHECK:STDOUT: %int.make_type_32.loc5_17: init type = call constants.%Int32() [template = i32]
  125. // CHECK:STDOUT: %.loc5_17.1: type = value_of_initializer %int.make_type_32.loc5_17 [template = i32]
  126. // CHECK:STDOUT: %.loc5_17.2: type = converted %int.make_type_32.loc5_17, %.loc5_17.1 [template = i32]
  127. // CHECK:STDOUT: @B.%return: ref i32 = var <return slot>
  128. // CHECK:STDOUT: }
  129. // CHECK:STDOUT: %C.decl: %C.type = fn_decl @C [template = constants.%C] {
  130. // CHECK:STDOUT: %int.make_type_32.loc6_10: init type = call constants.%Int32() [template = i32]
  131. // CHECK:STDOUT: %.loc6_14.1: %.2 = tuple_literal (%int.make_type_32.loc6_10)
  132. // CHECK:STDOUT: %.loc6_14.2: type = value_of_initializer %int.make_type_32.loc6_10 [template = i32]
  133. // CHECK:STDOUT: %.loc6_14.3: type = converted %int.make_type_32.loc6_10, %.loc6_14.2 [template = i32]
  134. // CHECK:STDOUT: %.loc6_14.4: type = converted %.loc6_14.1, constants.%.3 [template = constants.%.3]
  135. // CHECK:STDOUT: %c.loc6_6.1: %.3 = param c
  136. // CHECK:STDOUT: @C.%c: %.3 = bind_name c, %c.loc6_6.1
  137. // CHECK:STDOUT: %int.make_type_32.loc6_25: init type = call constants.%Int32() [template = i32]
  138. // CHECK:STDOUT: %.loc6_25.1: type = value_of_initializer %int.make_type_32.loc6_25 [template = i32]
  139. // CHECK:STDOUT: %.loc6_25.2: type = converted %int.make_type_32.loc6_25, %.loc6_25.1 [template = i32]
  140. // CHECK:STDOUT: %.loc6_28: type = struct_type {.c: i32} [template = constants.%.4]
  141. // CHECK:STDOUT: @C.%return: ref %.4 = var <return slot>
  142. // CHECK:STDOUT: }
  143. // CHECK:STDOUT: %D.decl: %D.type = fn_decl @D [template = constants.%D] {}
  144. // CHECK:STDOUT: }
  145. // CHECK:STDOUT:
  146. // CHECK:STDOUT: fn @A() {
  147. // CHECK:STDOUT: !entry:
  148. // CHECK:STDOUT: return
  149. // CHECK:STDOUT: }
  150. // CHECK:STDOUT:
  151. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  152. // CHECK:STDOUT:
  153. // CHECK:STDOUT: fn @B(%b: i32) -> i32 {
  154. // CHECK:STDOUT: !entry:
  155. // CHECK:STDOUT: %b.ref: i32 = name_ref b, %b
  156. // CHECK:STDOUT: return %b.ref
  157. // CHECK:STDOUT: }
  158. // CHECK:STDOUT:
  159. // CHECK:STDOUT: fn @C(%c: %.3) -> %.4 {
  160. // CHECK:STDOUT: !entry:
  161. // CHECK:STDOUT: %c.ref: %.3 = name_ref c, %c
  162. // CHECK:STDOUT: %.loc6_47: i32 = int_literal 0 [template = constants.%.5]
  163. // CHECK:STDOUT: %.loc6_48: i32 = tuple_index %c.ref, %.loc6_47
  164. // CHECK:STDOUT: %.loc6_49: %.4 = struct_literal (%.loc6_48)
  165. // CHECK:STDOUT: %struct: %.4 = struct_value (%.loc6_48)
  166. // CHECK:STDOUT: %.loc6_50: %.4 = converted %.loc6_49, %struct
  167. // CHECK:STDOUT: return %.loc6_50
  168. // CHECK:STDOUT: }
  169. // CHECK:STDOUT:
  170. // CHECK:STDOUT: fn @D();
  171. // CHECK:STDOUT:
  172. // CHECK:STDOUT: --- extern.carbon
  173. // CHECK:STDOUT:
  174. // CHECK:STDOUT: constants {
  175. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  176. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  177. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  178. // CHECK:STDOUT: }
  179. // CHECK:STDOUT:
  180. // CHECK:STDOUT: file {
  181. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  182. // CHECK:STDOUT: .Core = %Core
  183. // CHECK:STDOUT: .A = %A.decl
  184. // CHECK:STDOUT: }
  185. // CHECK:STDOUT: %Core.import = import Core
  186. // CHECK:STDOUT: %Core: <namespace> = namespace %Core.import, [template] {
  187. // CHECK:STDOUT: import Core//prelude
  188. // CHECK:STDOUT: import Core//prelude/operators
  189. // CHECK:STDOUT: import Core//prelude/types
  190. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  191. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  192. // CHECK:STDOUT: import Core//prelude/operators/comparison
  193. // CHECK:STDOUT: import Core//prelude/types/bool
  194. // CHECK:STDOUT: }
  195. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [template = constants.%A] {}
  196. // CHECK:STDOUT: }
  197. // CHECK:STDOUT:
  198. // CHECK:STDOUT: extern fn @A();
  199. // CHECK:STDOUT:
  200. // CHECK:STDOUT: --- basics.carbon
  201. // CHECK:STDOUT:
  202. // CHECK:STDOUT: constants {
  203. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  204. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  205. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  206. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  207. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  208. // CHECK:STDOUT: %B.type: type = fn_type @B [template]
  209. // CHECK:STDOUT: %B: %B.type = struct_value () [template]
  210. // CHECK:STDOUT: %.2: i32 = int_literal 1 [template]
  211. // CHECK:STDOUT: %.3: type = struct_type {.c: i32} [template]
  212. // CHECK:STDOUT: %.4: type = tuple_type (i32) [template]
  213. // CHECK:STDOUT: %C.type: type = fn_type @C [template]
  214. // CHECK:STDOUT: %C: %C.type = struct_value () [template]
  215. // CHECK:STDOUT: %tuple: %.4 = tuple_value (%.2) [template]
  216. // CHECK:STDOUT: }
  217. // CHECK:STDOUT:
  218. // CHECK:STDOUT: imports {
  219. // CHECK:STDOUT: %import_ref.1: %A.type = import_ref Main//fns, inst+3, loaded [template = constants.%A]
  220. // CHECK:STDOUT: %import_ref.2: %B.type = import_ref Main//fns, inst+23, loaded [template = constants.%B]
  221. // CHECK:STDOUT: %import_ref.3: %C.type = import_ref Main//fns, inst+47, loaded [template = constants.%C]
  222. // CHECK:STDOUT: %import_ref.4 = import_ref Main//fns, inst+59, unloaded
  223. // CHECK:STDOUT: %import_ref.5: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  224. // CHECK:STDOUT: %import_ref.6: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  225. // CHECK:STDOUT: }
  226. // CHECK:STDOUT:
  227. // CHECK:STDOUT: file {
  228. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  229. // CHECK:STDOUT: .A = imports.%import_ref.1
  230. // CHECK:STDOUT: .B = imports.%import_ref.2
  231. // CHECK:STDOUT: .C = imports.%import_ref.3
  232. // CHECK:STDOUT: .D = imports.%import_ref.4
  233. // CHECK:STDOUT: .Core = %Core
  234. // CHECK:STDOUT: .a = %a
  235. // CHECK:STDOUT: .b = %b
  236. // CHECK:STDOUT: .c = %c
  237. // CHECK:STDOUT: }
  238. // CHECK:STDOUT: %Core.import = import Core
  239. // CHECK:STDOUT: %default.import = import <invalid>
  240. // CHECK:STDOUT: %Core: <namespace> = namespace %Core.import, [template] {
  241. // CHECK:STDOUT: import Core//prelude
  242. // CHECK:STDOUT: import Core//prelude/operators
  243. // CHECK:STDOUT: import Core//prelude/types
  244. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  245. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  246. // CHECK:STDOUT: import Core//prelude/operators/comparison
  247. // CHECK:STDOUT: import Core//prelude/types/bool
  248. // CHECK:STDOUT: }
  249. // CHECK:STDOUT: %.loc6_9.1: %.1 = tuple_literal ()
  250. // CHECK:STDOUT: %.loc6_9.2: type = converted %.loc6_9.1, constants.%.1 [template = constants.%.1]
  251. // CHECK:STDOUT: %a.var: ref %.1 = var a
  252. // CHECK:STDOUT: %a: ref %.1 = bind_name a, %a.var
  253. // CHECK:STDOUT: %int.make_type_32.loc7: init type = call constants.%Int32() [template = i32]
  254. // CHECK:STDOUT: %.loc7_8.1: type = value_of_initializer %int.make_type_32.loc7 [template = i32]
  255. // CHECK:STDOUT: %.loc7_8.2: type = converted %int.make_type_32.loc7, %.loc7_8.1 [template = i32]
  256. // CHECK:STDOUT: %b.var: ref i32 = var b
  257. // CHECK:STDOUT: %b: ref i32 = bind_name b, %b.var
  258. // CHECK:STDOUT: %int.make_type_32.loc8: init type = call constants.%Int32() [template = i32]
  259. // CHECK:STDOUT: %.loc8_13.1: type = value_of_initializer %int.make_type_32.loc8 [template = i32]
  260. // CHECK:STDOUT: %.loc8_13.2: type = converted %int.make_type_32.loc8, %.loc8_13.1 [template = i32]
  261. // CHECK:STDOUT: %.loc8_16: type = struct_type {.c: i32} [template = constants.%.3]
  262. // CHECK:STDOUT: %c.var: ref %.3 = var c
  263. // CHECK:STDOUT: %c: ref %.3 = bind_name c, %c.var
  264. // CHECK:STDOUT: }
  265. // CHECK:STDOUT:
  266. // CHECK:STDOUT: fn @A();
  267. // CHECK:STDOUT:
  268. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  269. // CHECK:STDOUT:
  270. // CHECK:STDOUT: fn @B(%b: i32) -> i32;
  271. // CHECK:STDOUT:
  272. // CHECK:STDOUT: fn @C(%c: %.4) -> %.3;
  273. // CHECK:STDOUT:
  274. // CHECK:STDOUT: fn @__global_init() {
  275. // CHECK:STDOUT: !entry:
  276. // CHECK:STDOUT: %A.ref: %A.type = name_ref A, imports.%import_ref.1 [template = constants.%A]
  277. // CHECK:STDOUT: %A.call: init %.1 = call %A.ref()
  278. // CHECK:STDOUT: assign file.%a.var, %A.call
  279. // CHECK:STDOUT: %B.ref: %B.type = name_ref B, imports.%import_ref.2 [template = constants.%B]
  280. // CHECK:STDOUT: %.loc7: i32 = int_literal 1 [template = constants.%.2]
  281. // CHECK:STDOUT: %B.call: init i32 = call %B.ref(%.loc7)
  282. // CHECK:STDOUT: assign file.%b.var, %B.call
  283. // CHECK:STDOUT: %C.ref: %C.type = name_ref C, imports.%import_ref.3 [template = constants.%C]
  284. // CHECK:STDOUT: %.loc8_23: i32 = int_literal 1 [template = constants.%.2]
  285. // CHECK:STDOUT: %.loc8_25: %.4 = tuple_literal (%.loc8_23)
  286. // CHECK:STDOUT: %tuple: %.4 = tuple_value (%.loc8_23) [template = constants.%tuple]
  287. // CHECK:STDOUT: %.loc8_21: %.4 = converted %.loc8_25, %tuple [template = constants.%tuple]
  288. // CHECK:STDOUT: %C.call: init %.3 = call %C.ref(%.loc8_21)
  289. // CHECK:STDOUT: assign file.%c.var, %C.call
  290. // CHECK:STDOUT: return
  291. // CHECK:STDOUT: }
  292. // CHECK:STDOUT:
  293. // CHECK:STDOUT: --- fail_def_ownership.carbon
  294. // CHECK:STDOUT:
  295. // CHECK:STDOUT: constants {
  296. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  297. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  298. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  299. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  300. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  301. // CHECK:STDOUT: %B.type: type = fn_type @B [template]
  302. // CHECK:STDOUT: %B: %B.type = struct_value () [template]
  303. // CHECK:STDOUT: }
  304. // CHECK:STDOUT:
  305. // CHECK:STDOUT: imports {
  306. // CHECK:STDOUT: %import_ref.1: %A.type = import_ref Main//fns, inst+3, loaded [template = constants.%A]
  307. // CHECK:STDOUT: %import_ref.2: %B.type = import_ref Main//fns, inst+23, loaded [template = constants.%B]
  308. // CHECK:STDOUT: %import_ref.3 = import_ref Main//fns, inst+47, unloaded
  309. // CHECK:STDOUT: %import_ref.4 = import_ref Main//fns, inst+59, unloaded
  310. // CHECK:STDOUT: %import_ref.5: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  311. // CHECK:STDOUT: %import_ref.6: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  312. // CHECK:STDOUT: }
  313. // CHECK:STDOUT:
  314. // CHECK:STDOUT: file {
  315. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  316. // CHECK:STDOUT: .A = %A.decl
  317. // CHECK:STDOUT: .B = %B.decl
  318. // CHECK:STDOUT: .C = imports.%import_ref.3
  319. // CHECK:STDOUT: .D = imports.%import_ref.4
  320. // CHECK:STDOUT: .Core = %Core
  321. // CHECK:STDOUT: }
  322. // CHECK:STDOUT: %Core.import = import Core
  323. // CHECK:STDOUT: %default.import = import <invalid>
  324. // CHECK:STDOUT: %Core: <namespace> = namespace %Core.import, [template] {
  325. // CHECK:STDOUT: import Core//prelude
  326. // CHECK:STDOUT: import Core//prelude/operators
  327. // CHECK:STDOUT: import Core//prelude/types
  328. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  329. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  330. // CHECK:STDOUT: import Core//prelude/operators/comparison
  331. // CHECK:STDOUT: import Core//prelude/types/bool
  332. // CHECK:STDOUT: }
  333. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [template = constants.%A] {}
  334. // CHECK:STDOUT: %B.decl: %B.type = fn_decl @B [template = constants.%B] {
  335. // CHECK:STDOUT: %int.make_type_32.loc27_9: init type = call constants.%Int32() [template = i32]
  336. // CHECK:STDOUT: %.loc27_9.1: type = value_of_initializer %int.make_type_32.loc27_9 [template = i32]
  337. // CHECK:STDOUT: %.loc27_9.2: type = converted %int.make_type_32.loc27_9, %.loc27_9.1 [template = i32]
  338. // CHECK:STDOUT: %b.loc27_6.1: i32 = param b
  339. // CHECK:STDOUT: %b.loc27_6.2: i32 = bind_name b, %b.loc27_6.1
  340. // CHECK:STDOUT: %int.make_type_32.loc27_17: init type = call constants.%Int32() [template = i32]
  341. // CHECK:STDOUT: %.loc27_17.1: type = value_of_initializer %int.make_type_32.loc27_17 [template = i32]
  342. // CHECK:STDOUT: %.loc27_17.2: type = converted %int.make_type_32.loc27_17, %.loc27_17.1 [template = i32]
  343. // CHECK:STDOUT: %return.var: ref i32 = var <return slot>
  344. // CHECK:STDOUT: }
  345. // CHECK:STDOUT: }
  346. // CHECK:STDOUT:
  347. // CHECK:STDOUT: fn @A() {
  348. // CHECK:STDOUT: !entry:
  349. // CHECK:STDOUT: return
  350. // CHECK:STDOUT: }
  351. // CHECK:STDOUT:
  352. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  353. // CHECK:STDOUT:
  354. // CHECK:STDOUT: fn @B(%b: i32) -> i32;
  355. // CHECK:STDOUT:
  356. // CHECK:STDOUT: --- redecl_then_def.carbon
  357. // CHECK:STDOUT:
  358. // CHECK:STDOUT: constants {
  359. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  360. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  361. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  362. // CHECK:STDOUT: }
  363. // CHECK:STDOUT:
  364. // CHECK:STDOUT: imports {
  365. // CHECK:STDOUT: %import_ref: %A.type = import_ref Main//extern, inst+3, loaded [template = constants.%A]
  366. // CHECK:STDOUT: }
  367. // CHECK:STDOUT:
  368. // CHECK:STDOUT: file {
  369. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  370. // CHECK:STDOUT: .A = %A.decl.loc6
  371. // CHECK:STDOUT: .Core = %Core
  372. // CHECK:STDOUT: }
  373. // CHECK:STDOUT: %Core.import = import Core
  374. // CHECK:STDOUT: %default.import = import <invalid>
  375. // CHECK:STDOUT: %Core: <namespace> = namespace %Core.import, [template] {
  376. // CHECK:STDOUT: import Core//prelude
  377. // CHECK:STDOUT: import Core//prelude/operators
  378. // CHECK:STDOUT: import Core//prelude/types
  379. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  380. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  381. // CHECK:STDOUT: import Core//prelude/operators/comparison
  382. // CHECK:STDOUT: import Core//prelude/types/bool
  383. // CHECK:STDOUT: }
  384. // CHECK:STDOUT: %A.decl.loc6: %A.type = fn_decl @A [template = constants.%A] {}
  385. // CHECK:STDOUT: %A.decl.loc7: %A.type = fn_decl @A [template = constants.%A] {}
  386. // CHECK:STDOUT: }
  387. // CHECK:STDOUT:
  388. // CHECK:STDOUT: fn @A() {
  389. // CHECK:STDOUT: !entry:
  390. // CHECK:STDOUT: return
  391. // CHECK:STDOUT: }
  392. // CHECK:STDOUT:
  393. // CHECK:STDOUT: --- fail_mix_extern_decl.carbon
  394. // CHECK:STDOUT:
  395. // CHECK:STDOUT: constants {
  396. // CHECK:STDOUT: %D.type: type = fn_type @D [template]
  397. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  398. // CHECK:STDOUT: %D: %D.type = struct_value () [template]
  399. // CHECK:STDOUT: }
  400. // CHECK:STDOUT:
  401. // CHECK:STDOUT: imports {
  402. // CHECK:STDOUT: %import_ref.1 = import_ref Main//fns, inst+3, unloaded
  403. // CHECK:STDOUT: %import_ref.2 = import_ref Main//fns, inst+23, unloaded
  404. // CHECK:STDOUT: %import_ref.3 = import_ref Main//fns, inst+47, unloaded
  405. // CHECK:STDOUT: %import_ref.4: %D.type = import_ref Main//fns, inst+59, loaded [template = constants.%D]
  406. // CHECK:STDOUT: }
  407. // CHECK:STDOUT:
  408. // CHECK:STDOUT: file {
  409. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  410. // CHECK:STDOUT: .A = imports.%import_ref.1
  411. // CHECK:STDOUT: .B = imports.%import_ref.2
  412. // CHECK:STDOUT: .C = imports.%import_ref.3
  413. // CHECK:STDOUT: .D = %D.decl.loc13
  414. // CHECK:STDOUT: .Core = %Core
  415. // CHECK:STDOUT: }
  416. // CHECK:STDOUT: %Core.import = import Core
  417. // CHECK:STDOUT: %default.import = import <invalid>
  418. // CHECK:STDOUT: %Core: <namespace> = namespace %Core.import, [template] {
  419. // CHECK:STDOUT: import Core//prelude
  420. // CHECK:STDOUT: import Core//prelude/operators
  421. // CHECK:STDOUT: import Core//prelude/types
  422. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  423. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  424. // CHECK:STDOUT: import Core//prelude/operators/comparison
  425. // CHECK:STDOUT: import Core//prelude/types/bool
  426. // CHECK:STDOUT: }
  427. // CHECK:STDOUT: %D.decl.loc6: %D.type = fn_decl @D [template = constants.%D] {}
  428. // CHECK:STDOUT: %D.decl.loc13: %D.type = fn_decl @D [template = constants.%D] {}
  429. // CHECK:STDOUT: }
  430. // CHECK:STDOUT:
  431. // CHECK:STDOUT: fn @D() {
  432. // CHECK:STDOUT: !entry:
  433. // CHECK:STDOUT: return
  434. // CHECK:STDOUT: }
  435. // CHECK:STDOUT: