import.carbon 2.2 KB

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