import.carbon 22 KB

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