import.carbon 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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/builtin/no_prelude/import.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/builtin/no_prelude/import.carbon
  10. // --- core.carbon
  11. package Core library "[[@TEST_NAME]]";
  12. fn Int32() -> type = "int.make_type_32";
  13. fn TestAdd(a: i32, b: i32) -> i32 = "int.sadd";
  14. // --- use.carbon
  15. import Core library "core";
  16. var arr: [i32; Core.TestAdd(1, 2)] = (1, 2, 3);
  17. // CHECK:STDOUT: --- core.carbon
  18. // CHECK:STDOUT:
  19. // CHECK:STDOUT: constants {
  20. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  21. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  22. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  23. // CHECK:STDOUT: %TestAdd.type: type = fn_type @TestAdd [template]
  24. // CHECK:STDOUT: %TestAdd: %TestAdd.type = struct_value () [template]
  25. // CHECK:STDOUT: }
  26. // CHECK:STDOUT:
  27. // CHECK:STDOUT: file {
  28. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  29. // CHECK:STDOUT: .Int32 = %Int32.decl
  30. // CHECK:STDOUT: .TestAdd = %TestAdd.decl
  31. // CHECK:STDOUT: }
  32. // CHECK:STDOUT: %Int32.decl: %Int32.type = fn_decl @Int32 [template = constants.%Int32] {} {
  33. // CHECK:STDOUT: %return: ref type = var <return slot>
  34. // CHECK:STDOUT: }
  35. // CHECK:STDOUT: %TestAdd.decl: %TestAdd.type = fn_decl @TestAdd [template = constants.%TestAdd] {
  36. // CHECK:STDOUT: %a.patt: i32 = binding_pattern a
  37. // CHECK:STDOUT: %b.patt: i32 = binding_pattern b
  38. // CHECK:STDOUT: } {
  39. // CHECK:STDOUT: %int.make_type_32.loc5_15: init type = call constants.%Int32() [template = i32]
  40. // CHECK:STDOUT: %.loc5_15.1: type = value_of_initializer %int.make_type_32.loc5_15 [template = i32]
  41. // CHECK:STDOUT: %.loc5_15.2: type = converted %int.make_type_32.loc5_15, %.loc5_15.1 [template = i32]
  42. // CHECK:STDOUT: %a.param: i32 = param a, runtime_param0
  43. // CHECK:STDOUT: %a: i32 = bind_name a, %a.param
  44. // CHECK:STDOUT: %int.make_type_32.loc5_23: init type = call constants.%Int32() [template = i32]
  45. // CHECK:STDOUT: %.loc5_23.1: type = value_of_initializer %int.make_type_32.loc5_23 [template = i32]
  46. // CHECK:STDOUT: %.loc5_23.2: type = converted %int.make_type_32.loc5_23, %.loc5_23.1 [template = i32]
  47. // CHECK:STDOUT: %b.param: i32 = param b, runtime_param1
  48. // CHECK:STDOUT: %b: i32 = bind_name b, %b.param
  49. // CHECK:STDOUT: %int.make_type_32.loc5_31: init type = call constants.%Int32() [template = i32]
  50. // CHECK:STDOUT: %.loc5_31.1: type = value_of_initializer %int.make_type_32.loc5_31 [template = i32]
  51. // CHECK:STDOUT: %.loc5_31.2: type = converted %int.make_type_32.loc5_31, %.loc5_31.1 [template = i32]
  52. // CHECK:STDOUT: %return: ref i32 = var <return slot>
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: fn @TestAdd(%a: i32, %b: i32) -> i32 = "int.sadd";
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: --- use.carbon
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: constants {
  63. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  64. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  65. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  66. // CHECK:STDOUT: %TestAdd.type: type = fn_type @TestAdd [template]
  67. // CHECK:STDOUT: %TestAdd: %TestAdd.type = struct_value () [template]
  68. // CHECK:STDOUT: %.2: i32 = int_literal 1 [template]
  69. // CHECK:STDOUT: %.3: i32 = int_literal 2 [template]
  70. // CHECK:STDOUT: %.4: i32 = int_literal 3 [template]
  71. // CHECK:STDOUT: %.5: type = array_type %.4, i32 [template]
  72. // CHECK:STDOUT: %.6: type = ptr_type %.5 [template]
  73. // CHECK:STDOUT: %.7: type = tuple_type (i32, i32, i32) [template]
  74. // CHECK:STDOUT: %.8: i32 = int_literal 0 [template]
  75. // CHECK:STDOUT: %array: %.5 = tuple_value (%.2, %.3, %.4) [template]
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: imports {
  79. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  80. // CHECK:STDOUT: .Int32 = %import_ref.1
  81. // CHECK:STDOUT: .TestAdd = %import_ref.2
  82. // CHECK:STDOUT: import Core//core
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref Core//core, inst+2, loaded [template = constants.%Int32]
  85. // CHECK:STDOUT: %import_ref.2: %TestAdd.type = import_ref Core//core, inst+22, loaded [template = constants.%TestAdd]
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT:
  88. // CHECK:STDOUT: file {
  89. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  90. // CHECK:STDOUT: .Core = imports.%Core
  91. // CHECK:STDOUT: .arr = %arr
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT: %Core.import = import Core
  94. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  95. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, imports.%Core [template = imports.%Core]
  96. // CHECK:STDOUT: %TestAdd.ref: %TestAdd.type = name_ref TestAdd, imports.%import_ref.2 [template = constants.%TestAdd]
  97. // CHECK:STDOUT: %.loc4_29: i32 = int_literal 1 [template = constants.%.2]
  98. // CHECK:STDOUT: %.loc4_32: i32 = int_literal 2 [template = constants.%.3]
  99. // CHECK:STDOUT: %int.sadd: init i32 = call %TestAdd.ref(%.loc4_29, %.loc4_32) [template = constants.%.4]
  100. // CHECK:STDOUT: %.loc4_11.1: type = value_of_initializer %int.make_type_32 [template = i32]
  101. // CHECK:STDOUT: %.loc4_11.2: type = converted %int.make_type_32, %.loc4_11.1 [template = i32]
  102. // CHECK:STDOUT: %.loc4_34: type = array_type %int.sadd, i32 [template = constants.%.5]
  103. // CHECK:STDOUT: %arr.var: ref %.5 = var arr
  104. // CHECK:STDOUT: %arr: ref %.5 = bind_name arr, %arr.var
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: fn @TestAdd(%a: i32, %b: i32) -> i32 = "int.sadd";
  110. // CHECK:STDOUT:
  111. // CHECK:STDOUT: fn @__global_init() {
  112. // CHECK:STDOUT: !entry:
  113. // CHECK:STDOUT: %.loc4_39: i32 = int_literal 1 [template = constants.%.2]
  114. // CHECK:STDOUT: %.loc4_42: i32 = int_literal 2 [template = constants.%.3]
  115. // CHECK:STDOUT: %.loc4_45: i32 = int_literal 3 [template = constants.%.4]
  116. // CHECK:STDOUT: %.loc4_46.1: %.7 = tuple_literal (%.loc4_39, %.loc4_42, %.loc4_45)
  117. // CHECK:STDOUT: %.loc4_46.2: i32 = int_literal 0 [template = constants.%.8]
  118. // CHECK:STDOUT: %.loc4_46.3: ref i32 = array_index file.%arr.var, %.loc4_46.2
  119. // CHECK:STDOUT: %.loc4_46.4: init i32 = initialize_from %.loc4_39 to %.loc4_46.3 [template = constants.%.2]
  120. // CHECK:STDOUT: %.loc4_46.5: i32 = int_literal 1 [template = constants.%.2]
  121. // CHECK:STDOUT: %.loc4_46.6: ref i32 = array_index file.%arr.var, %.loc4_46.5
  122. // CHECK:STDOUT: %.loc4_46.7: init i32 = initialize_from %.loc4_42 to %.loc4_46.6 [template = constants.%.3]
  123. // CHECK:STDOUT: %.loc4_46.8: i32 = int_literal 2 [template = constants.%.3]
  124. // CHECK:STDOUT: %.loc4_46.9: ref i32 = array_index file.%arr.var, %.loc4_46.8
  125. // CHECK:STDOUT: %.loc4_46.10: init i32 = initialize_from %.loc4_45 to %.loc4_46.9 [template = constants.%.4]
  126. // CHECK:STDOUT: %.loc4_46.11: init %.5 = array_init (%.loc4_46.4, %.loc4_46.7, %.loc4_46.10) to file.%arr.var [template = constants.%array]
  127. // CHECK:STDOUT: %.loc4_47: init %.5 = converted %.loc4_46.1, %.loc4_46.11 [template = constants.%array]
  128. // CHECK:STDOUT: assign file.%arr.var, %.loc4_47
  129. // CHECK:STDOUT: return
  130. // CHECK:STDOUT: }
  131. // CHECK:STDOUT: