import.carbon 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  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 [RedeclRedundant]
  35. // CHECK:STDERR: fn A() {};
  36. // CHECK:STDERR: ^~~~~~~~
  37. // CHECK:STDERR: fail_def_ownership.carbon:[[@LINE-5]]:1: in import [InImport]
  38. // CHECK:STDERR: fns.carbon:4:1: note: previously declared here [RedeclPrevDecl]
  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 [RedeclRedundant]
  44. // CHECK:STDERR: fn B(b: i32) -> i32;
  45. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~
  46. // CHECK:STDERR: fail_def_ownership.carbon:[[@LINE-14]]:1: in import [InImport]
  47. // CHECK:STDERR: fns.carbon:5:1: note: previously declared here [RedeclPrevDecl]
  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` [RedeclExternMismatch]
  56. // CHECK:STDERR: fn A();
  57. // CHECK:STDERR: ^~~~~~~
  58. // CHECK:STDERR: fail_redecl_then_def.carbon:[[@LINE-5]]:1: in import [InImport]
  59. // CHECK:STDERR: extern.carbon:4:1: note: previously declared here [RedeclPrevDecl]
  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` [RedeclExternMismatch]
  65. // CHECK:STDERR: fn A() {}
  66. // CHECK:STDERR: ^~~~~~~~
  67. // CHECK:STDERR: fail_redecl_then_def.carbon:[[@LINE-15]]:1: in import [InImport]
  68. // CHECK:STDERR: extern.carbon:4:1: note: previously declared here [RedeclPrevDecl]
  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` [RedeclExternMismatch]
  77. // CHECK:STDERR: extern fn D();
  78. // CHECK:STDERR: ^~~~~~~~~~~~~~
  79. // CHECK:STDERR: fail_mix_extern_decl.carbon:[[@LINE-5]]:1: in import [InImport]
  80. // CHECK:STDERR: fns.carbon:7:1: note: previously declared here [RedeclPrevDecl]
  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: %A: %A.type = struct_value () [template]
  90. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  91. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  92. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  93. // CHECK:STDOUT: %i32: type = int_type signed, %int_32 [template]
  94. // CHECK:STDOUT: %B.type: type = fn_type @B [template]
  95. // CHECK:STDOUT: %B: %B.type = struct_value () [template]
  96. // CHECK:STDOUT: %tuple.type.1: type = tuple_type (type) [template]
  97. // CHECK:STDOUT: %tuple.type.2: type = tuple_type (%i32) [template]
  98. // CHECK:STDOUT: %struct_type.c: type = struct_type {.c: %i32} [template]
  99. // CHECK:STDOUT: %C.type: type = fn_type @C [template]
  100. // CHECK:STDOUT: %C: %C.type = struct_value () [template]
  101. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [template]
  102. // CHECK:STDOUT: %D.type: type = fn_type @D [template]
  103. // CHECK:STDOUT: %D: %D.type = struct_value () [template]
  104. // CHECK:STDOUT: }
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: imports {
  107. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  108. // CHECK:STDOUT: .Int = %import_ref
  109. // CHECK:STDOUT: import Core//prelude
  110. // CHECK:STDOUT: import Core//prelude/...
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: file {
  115. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  116. // CHECK:STDOUT: .Core = imports.%Core
  117. // CHECK:STDOUT: .A = %A.decl
  118. // CHECK:STDOUT: .B = %B.decl
  119. // CHECK:STDOUT: .C = %C.decl
  120. // CHECK:STDOUT: .D = %D.decl
  121. // CHECK:STDOUT: }
  122. // CHECK:STDOUT: %Core.import = import Core
  123. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [template = constants.%A] {} {}
  124. // CHECK:STDOUT: %B.decl: %B.type = fn_decl @B [template = constants.%B] {
  125. // CHECK:STDOUT: %b.patt: %i32 = binding_pattern b
  126. // CHECK:STDOUT: %b.param_patt: %i32 = value_param_pattern %b.patt, runtime_param0
  127. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  128. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param1
  129. // CHECK:STDOUT: } {
  130. // CHECK:STDOUT: %int_32.loc5_9: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  131. // CHECK:STDOUT: %int.make_type_signed.loc5_9: init type = call constants.%Int(%int_32.loc5_9) [template = constants.%i32]
  132. // CHECK:STDOUT: %.loc5_9.1: type = value_of_initializer %int.make_type_signed.loc5_9 [template = constants.%i32]
  133. // CHECK:STDOUT: %.loc5_9.2: type = converted %int.make_type_signed.loc5_9, %.loc5_9.1 [template = constants.%i32]
  134. // CHECK:STDOUT: %int_32.loc5_17: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  135. // CHECK:STDOUT: %int.make_type_signed.loc5_17: init type = call constants.%Int(%int_32.loc5_17) [template = constants.%i32]
  136. // CHECK:STDOUT: %.loc5_17.1: type = value_of_initializer %int.make_type_signed.loc5_17 [template = constants.%i32]
  137. // CHECK:STDOUT: %.loc5_17.2: type = converted %int.make_type_signed.loc5_17, %.loc5_17.1 [template = constants.%i32]
  138. // CHECK:STDOUT: %b.param: %i32 = value_param runtime_param0
  139. // CHECK:STDOUT: %b: %i32 = bind_name b, %b.param
  140. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param1
  141. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  142. // CHECK:STDOUT: }
  143. // CHECK:STDOUT: %C.decl: %C.type = fn_decl @C [template = constants.%C] {
  144. // CHECK:STDOUT: %c.patt: %tuple.type.2 = binding_pattern c
  145. // CHECK:STDOUT: %c.param_patt: %tuple.type.2 = value_param_pattern %c.patt, runtime_param0
  146. // CHECK:STDOUT: %return.patt: %struct_type.c = return_slot_pattern
  147. // CHECK:STDOUT: %return.param_patt: %struct_type.c = out_param_pattern %return.patt, runtime_param1
  148. // CHECK:STDOUT: } {
  149. // CHECK:STDOUT: %int_32.loc6_10: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  150. // CHECK:STDOUT: %int.make_type_signed.loc6_10: init type = call constants.%Int(%int_32.loc6_10) [template = constants.%i32]
  151. // CHECK:STDOUT: %.loc6_14.1: %tuple.type.1 = tuple_literal (%int.make_type_signed.loc6_10)
  152. // CHECK:STDOUT: %.loc6_14.2: type = value_of_initializer %int.make_type_signed.loc6_10 [template = constants.%i32]
  153. // CHECK:STDOUT: %.loc6_14.3: type = converted %int.make_type_signed.loc6_10, %.loc6_14.2 [template = constants.%i32]
  154. // CHECK:STDOUT: %.loc6_14.4: type = converted %.loc6_14.1, constants.%tuple.type.2 [template = constants.%tuple.type.2]
  155. // CHECK:STDOUT: %int_32.loc6_25: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  156. // CHECK:STDOUT: %int.make_type_signed.loc6_25: init type = call constants.%Int(%int_32.loc6_25) [template = constants.%i32]
  157. // CHECK:STDOUT: %.loc6_25.1: type = value_of_initializer %int.make_type_signed.loc6_25 [template = constants.%i32]
  158. // CHECK:STDOUT: %.loc6_25.2: type = converted %int.make_type_signed.loc6_25, %.loc6_25.1 [template = constants.%i32]
  159. // CHECK:STDOUT: %struct_type.c: type = struct_type {.c: %i32} [template = constants.%struct_type.c]
  160. // CHECK:STDOUT: %c.param: %tuple.type.2 = value_param runtime_param0
  161. // CHECK:STDOUT: %c: %tuple.type.2 = bind_name c, %c.param
  162. // CHECK:STDOUT: %return.param: ref %struct_type.c = out_param runtime_param1
  163. // CHECK:STDOUT: %return: ref %struct_type.c = return_slot %return.param
  164. // CHECK:STDOUT: }
  165. // CHECK:STDOUT: %D.decl: %D.type = fn_decl @D [template = constants.%D] {} {}
  166. // CHECK:STDOUT: }
  167. // CHECK:STDOUT:
  168. // CHECK:STDOUT: fn @A() {
  169. // CHECK:STDOUT: !entry:
  170. // CHECK:STDOUT: return
  171. // CHECK:STDOUT: }
  172. // CHECK:STDOUT:
  173. // CHECK:STDOUT: fn @B(%b.param_patt: %i32) -> %i32 {
  174. // CHECK:STDOUT: !entry:
  175. // CHECK:STDOUT: %b.ref: %i32 = name_ref b, %b
  176. // CHECK:STDOUT: return %b.ref
  177. // CHECK:STDOUT: }
  178. // CHECK:STDOUT:
  179. // CHECK:STDOUT: fn @C(%c.param_patt: %tuple.type.2) -> %struct_type.c {
  180. // CHECK:STDOUT: !entry:
  181. // CHECK:STDOUT: %c.ref: %tuple.type.2 = name_ref c, %c
  182. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [template = constants.%int_0]
  183. // CHECK:STDOUT: %tuple.elem0: %i32 = tuple_access %c.ref, element0
  184. // CHECK:STDOUT: %.loc6_48: %struct_type.c = struct_literal (%tuple.elem0)
  185. // CHECK:STDOUT: %struct: %struct_type.c = struct_value (%tuple.elem0)
  186. // CHECK:STDOUT: %.loc6_49: %struct_type.c = converted %.loc6_48, %struct
  187. // CHECK:STDOUT: return %.loc6_49
  188. // CHECK:STDOUT: }
  189. // CHECK:STDOUT:
  190. // CHECK:STDOUT: fn @D();
  191. // CHECK:STDOUT:
  192. // CHECK:STDOUT: --- extern.carbon
  193. // CHECK:STDOUT:
  194. // CHECK:STDOUT: constants {
  195. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  196. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  197. // CHECK:STDOUT: }
  198. // CHECK:STDOUT:
  199. // CHECK:STDOUT: imports {
  200. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  201. // CHECK:STDOUT: import Core//prelude
  202. // CHECK:STDOUT: import Core//prelude/...
  203. // CHECK:STDOUT: }
  204. // CHECK:STDOUT: }
  205. // CHECK:STDOUT:
  206. // CHECK:STDOUT: file {
  207. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  208. // CHECK:STDOUT: .Core = imports.%Core
  209. // CHECK:STDOUT: .A = %A.decl
  210. // CHECK:STDOUT: }
  211. // CHECK:STDOUT: %Core.import = import Core
  212. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [template = constants.%A] {} {}
  213. // CHECK:STDOUT: }
  214. // CHECK:STDOUT:
  215. // CHECK:STDOUT: extern fn @A();
  216. // CHECK:STDOUT:
  217. // CHECK:STDOUT: --- basics.carbon
  218. // CHECK:STDOUT:
  219. // CHECK:STDOUT: constants {
  220. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
  221. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  222. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  223. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  224. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  225. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  226. // CHECK:STDOUT: %i32: type = int_type signed, %int_32 [template]
  227. // CHECK:STDOUT: %B.type: type = fn_type @B [template]
  228. // CHECK:STDOUT: %B: %B.type = struct_value () [template]
  229. // CHECK:STDOUT: %int_1.1: Core.IntLiteral = int_value 1 [template]
  230. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  231. // CHECK:STDOUT: %Convert.type.14: type = fn_type @Convert.2, @impl.1(%int_32) [template]
  232. // CHECK:STDOUT: %Convert.14: %Convert.type.14 = struct_value () [template]
  233. // CHECK:STDOUT: %interface.9: <witness> = interface_witness (%Convert.14) [template]
  234. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_1.1, %Convert.14 [template]
  235. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.2(%int_32) [template]
  236. // CHECK:STDOUT: %int_1.2: %i32 = int_value 1 [template]
  237. // CHECK:STDOUT: %struct_type.c: type = struct_type {.c: %i32} [template]
  238. // CHECK:STDOUT: %C.type: type = fn_type @C [template]
  239. // CHECK:STDOUT: %C: %C.type = struct_value () [template]
  240. // CHECK:STDOUT: %tuple.type.1: type = tuple_type (%i32) [template]
  241. // CHECK:STDOUT: %tuple.type.2: type = tuple_type (Core.IntLiteral) [template]
  242. // CHECK:STDOUT: %tuple: %tuple.type.1 = tuple_value (%int_1.2) [template]
  243. // CHECK:STDOUT: }
  244. // CHECK:STDOUT:
  245. // CHECK:STDOUT: imports {
  246. // CHECK:STDOUT: %import_ref.1: %A.type = import_ref Main//fns, inst+3, loaded [template = constants.%A]
  247. // CHECK:STDOUT: %import_ref.2: %B.type = import_ref Main//fns, inst+34, loaded [template = constants.%B]
  248. // CHECK:STDOUT: %import_ref.3: %C.type = import_ref Main//fns, inst+61, loaded [template = constants.%C]
  249. // CHECK:STDOUT: %import_ref.4 = import_ref Main//fns, inst+72, unloaded
  250. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  251. // CHECK:STDOUT: .Int = %import_ref.5
  252. // CHECK:STDOUT: .ImplicitAs = %import_ref.6
  253. // CHECK:STDOUT: import Core//prelude
  254. // CHECK:STDOUT: import Core//prelude/...
  255. // CHECK:STDOUT: }
  256. // CHECK:STDOUT: }
  257. // CHECK:STDOUT:
  258. // CHECK:STDOUT: file {
  259. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  260. // CHECK:STDOUT: .A = imports.%import_ref.1
  261. // CHECK:STDOUT: .B = imports.%import_ref.2
  262. // CHECK:STDOUT: .C = imports.%import_ref.3
  263. // CHECK:STDOUT: .D = imports.%import_ref.4
  264. // CHECK:STDOUT: .Core = imports.%Core
  265. // CHECK:STDOUT: .a = %a
  266. // CHECK:STDOUT: .b = %b
  267. // CHECK:STDOUT: .c = %c
  268. // CHECK:STDOUT: }
  269. // CHECK:STDOUT: %Core.import = import Core
  270. // CHECK:STDOUT: %default.import = import <invalid>
  271. // CHECK:STDOUT: %.loc6_9.1: %empty_tuple.type = tuple_literal ()
  272. // CHECK:STDOUT: %.loc6_9.2: type = converted %.loc6_9.1, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
  273. // CHECK:STDOUT: %a.var: ref %empty_tuple.type = var a
  274. // CHECK:STDOUT: %a: ref %empty_tuple.type = bind_name a, %a.var
  275. // CHECK:STDOUT: %int_32.loc7: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  276. // CHECK:STDOUT: %int.make_type_signed.loc7: init type = call constants.%Int(%int_32.loc7) [template = constants.%i32]
  277. // CHECK:STDOUT: %.loc7_8.1: type = value_of_initializer %int.make_type_signed.loc7 [template = constants.%i32]
  278. // CHECK:STDOUT: %.loc7_8.2: type = converted %int.make_type_signed.loc7, %.loc7_8.1 [template = constants.%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_32.loc8: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  282. // CHECK:STDOUT: %int.make_type_signed.loc8: init type = call constants.%Int(%int_32.loc8) [template = constants.%i32]
  283. // CHECK:STDOUT: %.loc8_13.1: type = value_of_initializer %int.make_type_signed.loc8 [template = constants.%i32]
  284. // CHECK:STDOUT: %.loc8_13.2: type = converted %int.make_type_signed.loc8, %.loc8_13.1 [template = constants.%i32]
  285. // CHECK:STDOUT: %struct_type.c: type = struct_type {.c: %i32} [template = constants.%struct_type.c]
  286. // CHECK:STDOUT: %c.var: ref %struct_type.c = var c
  287. // CHECK:STDOUT: %c: ref %struct_type.c = bind_name c, %c.var
  288. // CHECK:STDOUT: }
  289. // CHECK:STDOUT:
  290. // CHECK:STDOUT: fn @A();
  291. // CHECK:STDOUT:
  292. // CHECK:STDOUT: fn @B(%b.param_patt: %i32) -> %i32;
  293. // CHECK:STDOUT:
  294. // CHECK:STDOUT: fn @C(%c.param_patt: %tuple.type.1) -> %struct_type.c;
  295. // CHECK:STDOUT:
  296. // CHECK:STDOUT: fn @__global_init() {
  297. // CHECK:STDOUT: !entry:
  298. // CHECK:STDOUT: %A.ref: %A.type = name_ref A, imports.%import_ref.1 [template = constants.%A]
  299. // CHECK:STDOUT: %A.call: init %empty_tuple.type = call %A.ref()
  300. // CHECK:STDOUT: assign file.%a.var, %A.call
  301. // CHECK:STDOUT: %B.ref: %B.type = name_ref B, imports.%import_ref.2 [template = constants.%B]
  302. // CHECK:STDOUT: %int_1.loc7: Core.IntLiteral = int_value 1 [template = constants.%int_1.1]
  303. // CHECK:STDOUT: %impl.elem0.loc7: %Convert.type.2 = interface_witness_access constants.%interface.9, element0 [template = constants.%Convert.14]
  304. // CHECK:STDOUT: %Convert.bound.loc7: <bound method> = bound_method %int_1.loc7, %impl.elem0.loc7 [template = constants.%Convert.bound]
  305. // CHECK:STDOUT: %Convert.specific_fn.loc7: <specific function> = specific_function %Convert.bound.loc7, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn]
  306. // CHECK:STDOUT: %int.convert_checked.loc7: init %i32 = call %Convert.specific_fn.loc7(%int_1.loc7) [template = constants.%int_1.2]
  307. // CHECK:STDOUT: %.loc7_16.1: %i32 = value_of_initializer %int.convert_checked.loc7 [template = constants.%int_1.2]
  308. // CHECK:STDOUT: %.loc7_16.2: %i32 = converted %int_1.loc7, %.loc7_16.1 [template = constants.%int_1.2]
  309. // CHECK:STDOUT: %B.call: init %i32 = call %B.ref(%.loc7_16.2)
  310. // CHECK:STDOUT: assign file.%b.var, %B.call
  311. // CHECK:STDOUT: %C.ref: %C.type = name_ref C, imports.%import_ref.3 [template = constants.%C]
  312. // CHECK:STDOUT: %int_1.loc8: Core.IntLiteral = int_value 1 [template = constants.%int_1.1]
  313. // CHECK:STDOUT: %.loc8_25.1: %tuple.type.2 = tuple_literal (%int_1.loc8)
  314. // CHECK:STDOUT: %impl.elem0.loc8: %Convert.type.2 = interface_witness_access constants.%interface.9, element0 [template = constants.%Convert.14]
  315. // CHECK:STDOUT: %Convert.bound.loc8: <bound method> = bound_method %int_1.loc8, %impl.elem0.loc8 [template = constants.%Convert.bound]
  316. // CHECK:STDOUT: %Convert.specific_fn.loc8: <specific function> = specific_function %Convert.bound.loc8, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn]
  317. // CHECK:STDOUT: %int.convert_checked.loc8: init %i32 = call %Convert.specific_fn.loc8(%int_1.loc8) [template = constants.%int_1.2]
  318. // CHECK:STDOUT: %.loc8_25.2: %i32 = value_of_initializer %int.convert_checked.loc8 [template = constants.%int_1.2]
  319. // CHECK:STDOUT: %.loc8_25.3: %i32 = converted %int_1.loc8, %.loc8_25.2 [template = constants.%int_1.2]
  320. // CHECK:STDOUT: %tuple: %tuple.type.1 = tuple_value (%.loc8_25.3) [template = constants.%tuple]
  321. // CHECK:STDOUT: %.loc8_25.4: %tuple.type.1 = converted %.loc8_25.1, %tuple [template = constants.%tuple]
  322. // CHECK:STDOUT: %C.call: init %struct_type.c = call %C.ref(%.loc8_25.4)
  323. // CHECK:STDOUT: assign file.%c.var, %C.call
  324. // CHECK:STDOUT: return
  325. // CHECK:STDOUT: }
  326. // CHECK:STDOUT:
  327. // CHECK:STDOUT: --- fail_def_ownership.carbon
  328. // CHECK:STDOUT:
  329. // CHECK:STDOUT: constants {
  330. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  331. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  332. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  333. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  334. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  335. // CHECK:STDOUT: %i32: type = int_type signed, %int_32 [template]
  336. // CHECK:STDOUT: %B.type: type = fn_type @B [template]
  337. // CHECK:STDOUT: %B: %B.type = struct_value () [template]
  338. // CHECK:STDOUT: }
  339. // CHECK:STDOUT:
  340. // CHECK:STDOUT: imports {
  341. // CHECK:STDOUT: %import_ref.3 = import_ref Main//fns, inst+61, unloaded
  342. // CHECK:STDOUT: %import_ref.4 = import_ref Main//fns, inst+72, unloaded
  343. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  344. // CHECK:STDOUT: .Int = %import_ref.5
  345. // CHECK:STDOUT: import Core//prelude
  346. // CHECK:STDOUT: import Core//prelude/...
  347. // CHECK:STDOUT: }
  348. // CHECK:STDOUT: }
  349. // CHECK:STDOUT:
  350. // CHECK:STDOUT: file {
  351. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  352. // CHECK:STDOUT: .A = %A.decl
  353. // CHECK:STDOUT: .B = %B.decl
  354. // CHECK:STDOUT: .C = imports.%import_ref.3
  355. // CHECK:STDOUT: .D = imports.%import_ref.4
  356. // CHECK:STDOUT: .Core = imports.%Core
  357. // CHECK:STDOUT: }
  358. // CHECK:STDOUT: %Core.import = import Core
  359. // CHECK:STDOUT: %default.import = import <invalid>
  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: %int_32.loc23_9: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  363. // CHECK:STDOUT: %int.make_type_signed.loc23_9: init type = call constants.%Int(%int_32.loc23_9) [template = constants.%i32]
  364. // CHECK:STDOUT: %.loc23_9.1: type = value_of_initializer %int.make_type_signed.loc23_9 [template = constants.%i32]
  365. // CHECK:STDOUT: %.loc23_9.2: type = converted %int.make_type_signed.loc23_9, %.loc23_9.1 [template = constants.%i32]
  366. // CHECK:STDOUT: %int_32.loc23_17: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  367. // CHECK:STDOUT: %int.make_type_signed.loc23_17: init type = call constants.%Int(%int_32.loc23_17) [template = constants.%i32]
  368. // CHECK:STDOUT: %.loc23_17.1: type = value_of_initializer %int.make_type_signed.loc23_17 [template = constants.%i32]
  369. // CHECK:STDOUT: %.loc23_17.2: type = converted %int.make_type_signed.loc23_17, %.loc23_17.1 [template = constants.%i32]
  370. // CHECK:STDOUT: %b.param: %i32 = value_param runtime_param0
  371. // CHECK:STDOUT: %b: %i32 = bind_name b, %b.param
  372. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param1
  373. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  374. // CHECK:STDOUT: }
  375. // CHECK:STDOUT: }
  376. // CHECK:STDOUT:
  377. // CHECK:STDOUT: fn @A() {
  378. // CHECK:STDOUT: !entry:
  379. // CHECK:STDOUT: return
  380. // CHECK:STDOUT: }
  381. // CHECK:STDOUT:
  382. // CHECK:STDOUT: fn @B(%b.param_patt: %i32) -> %i32;
  383. // CHECK:STDOUT:
  384. // CHECK:STDOUT: --- fail_redecl_then_def.carbon
  385. // CHECK:STDOUT:
  386. // CHECK:STDOUT: constants {
  387. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  388. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  389. // CHECK:STDOUT: }
  390. // CHECK:STDOUT:
  391. // CHECK:STDOUT: imports {
  392. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  393. // CHECK:STDOUT: import Core//prelude
  394. // CHECK:STDOUT: import Core//prelude/...
  395. // CHECK:STDOUT: }
  396. // CHECK:STDOUT: }
  397. // CHECK:STDOUT:
  398. // CHECK:STDOUT: file {
  399. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  400. // CHECK:STDOUT: .A = %A.decl.loc14
  401. // CHECK:STDOUT: .Core = imports.%Core
  402. // CHECK:STDOUT: }
  403. // CHECK:STDOUT: %Core.import = import Core
  404. // CHECK:STDOUT: %default.import = import <invalid>
  405. // CHECK:STDOUT: %A.decl.loc14: %A.type = fn_decl @A [template = constants.%A] {} {}
  406. // CHECK:STDOUT: %A.decl.loc24: %A.type = fn_decl @A [template = constants.%A] {} {}
  407. // CHECK:STDOUT: }
  408. // CHECK:STDOUT:
  409. // CHECK:STDOUT: extern fn @A() {
  410. // CHECK:STDOUT: !entry:
  411. // CHECK:STDOUT: return
  412. // CHECK:STDOUT: }
  413. // CHECK:STDOUT:
  414. // CHECK:STDOUT: --- fail_mix_extern_decl.carbon
  415. // CHECK:STDOUT:
  416. // CHECK:STDOUT: constants {
  417. // CHECK:STDOUT: %D.type: type = fn_type @D [template]
  418. // CHECK:STDOUT: %D: %D.type = struct_value () [template]
  419. // CHECK:STDOUT: }
  420. // CHECK:STDOUT:
  421. // CHECK:STDOUT: imports {
  422. // CHECK:STDOUT: %import_ref.1 = import_ref Main//fns, inst+3, unloaded
  423. // CHECK:STDOUT: %import_ref.2 = import_ref Main//fns, inst+34, unloaded
  424. // CHECK:STDOUT: %import_ref.3 = import_ref Main//fns, inst+61, unloaded
  425. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  426. // CHECK:STDOUT: import Core//prelude
  427. // CHECK:STDOUT: import Core//prelude/...
  428. // CHECK:STDOUT: }
  429. // CHECK:STDOUT: }
  430. // CHECK:STDOUT:
  431. // CHECK:STDOUT: file {
  432. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  433. // CHECK:STDOUT: .A = imports.%import_ref.1
  434. // CHECK:STDOUT: .B = imports.%import_ref.2
  435. // CHECK:STDOUT: .C = imports.%import_ref.3
  436. // CHECK:STDOUT: .D = %D.decl.loc13
  437. // CHECK:STDOUT: .Core = imports.%Core
  438. // CHECK:STDOUT: }
  439. // CHECK:STDOUT: %Core.import = import Core
  440. // CHECK:STDOUT: %default.import = import <invalid>
  441. // CHECK:STDOUT: %D.decl.loc13: %D.type = fn_decl @D [template = constants.%D] {} {}
  442. // CHECK:STDOUT: %D.decl.loc15: %D.type = fn_decl @D [template = constants.%D] {} {}
  443. // CHECK:STDOUT: }
  444. // CHECK:STDOUT:
  445. // CHECK:STDOUT: fn @D() {
  446. // CHECK:STDOUT: !entry:
  447. // CHECK:STDOUT: return
  448. // CHECK:STDOUT: }
  449. // CHECK:STDOUT: