import.carbon 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. // EXTRA-ARGS: --dump-sem-ir-ranges=only
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/array/import.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/array/import.carbon
  12. // --- library.carbon
  13. library "[[@TEST_NAME]]";
  14. fn F() -> array(i32, 42);
  15. // --- user.carbon
  16. import library "library";
  17. fn G(n: i32) -> i32 {
  18. //@dump-sem-ir-begin
  19. return F()[n];
  20. //@dump-sem-ir-end
  21. }
  22. // CHECK:STDOUT: --- user.carbon
  23. // CHECK:STDOUT:
  24. // CHECK:STDOUT: constants {
  25. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  26. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  27. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  28. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  29. // CHECK:STDOUT: %int_42: Core.IntLiteral = int_value 42 [concrete]
  30. // CHECK:STDOUT: %array_type: type = array_type %int_42, %i32 [concrete]
  31. // CHECK:STDOUT: }
  32. // CHECK:STDOUT:
  33. // CHECK:STDOUT: imports {
  34. // CHECK:STDOUT: %Main.F: %F.type = import_ref Main//library, F, loaded [concrete = constants.%F]
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: fn @G(%n.param: %i32) -> %i32 {
  38. // CHECK:STDOUT: !entry:
  39. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, imports.%Main.F [concrete = constants.%F]
  40. // CHECK:STDOUT: %.loc6_12.1: ref %array_type = temporary_storage
  41. // CHECK:STDOUT: %F.call: init %array_type = call %F.ref() to %.loc6_12.1
  42. // CHECK:STDOUT: %n.ref: %i32 = name_ref n, %n
  43. // CHECK:STDOUT: %.loc6_12.2: ref %array_type = temporary %.loc6_12.1, %F.call
  44. // CHECK:STDOUT: %int_32.loc6: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  45. // CHECK:STDOUT: %i32.loc6: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  46. // CHECK:STDOUT: %.loc6_15.1: ref %i32 = array_index %.loc6_12.2, %n.ref
  47. // CHECK:STDOUT: %.loc6_15.2: %i32 = bind_value %.loc6_15.1
  48. // CHECK:STDOUT: return %.loc6_15.2
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT: