import.carbon 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/int.carbon
  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: %empty_tuple.type: type = tuple_type () [concrete]
  27. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  28. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  29. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  30. // CHECK:STDOUT: %int_42: Core.IntLiteral = int_value 42 [concrete]
  31. // CHECK:STDOUT: %array_type: type = array_type %int_42, %i32 [concrete]
  32. // CHECK:STDOUT: %ptr.830: type = ptr_type %array_type [concrete]
  33. // CHECK:STDOUT: %Destroy.type: type = facet_type <@Destroy> [concrete]
  34. // CHECK:STDOUT: %Op.type.bae: type = fn_type @Op.1 [concrete]
  35. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  36. // CHECK:STDOUT: %Op.type.bc9: type = fn_type @Op.3, @impl.49c(%T) [symbolic]
  37. // CHECK:STDOUT: %Op.46f: %Op.type.bc9 = struct_value () [symbolic]
  38. // CHECK:STDOUT: %Destroy.impl_witness.cc7: <witness> = impl_witness imports.%Destroy.impl_witness_table, @impl.49c(%array_type) [concrete]
  39. // CHECK:STDOUT: %Op.type.b8c: type = fn_type @Op.3, @impl.49c(%array_type) [concrete]
  40. // CHECK:STDOUT: %Op.552: %Op.type.b8c = struct_value () [concrete]
  41. // CHECK:STDOUT: %Destroy.facet: %Destroy.type = facet_value %array_type, (%Destroy.impl_witness.cc7) [concrete]
  42. // CHECK:STDOUT: %.1ca: type = fn_type_with_self_type %Op.type.bae, %Destroy.facet [concrete]
  43. // CHECK:STDOUT: %Op.specific_fn: <specific function> = specific_function %Op.552, @Op.3(%array_type) [concrete]
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: imports {
  47. // CHECK:STDOUT: %Main.F: %F.type = import_ref Main//library, F, loaded [concrete = constants.%F]
  48. // CHECK:STDOUT: %Core.import_ref.0b9: @impl.49c.%Op.type (%Op.type.bc9) = import_ref Core//prelude/parts/destroy, loc8_29, loaded [symbolic = @impl.49c.%Op (constants.%Op.46f)]
  49. // CHECK:STDOUT: %Destroy.impl_witness_table = impl_witness_table (%Core.import_ref.0b9), @impl.49c [concrete]
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT:
  52. // CHECK:STDOUT: fn @G(%n.param: %i32) -> %i32 {
  53. // CHECK:STDOUT: !entry:
  54. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, imports.%Main.F [concrete = constants.%F]
  55. // CHECK:STDOUT: %.loc6_12.1: ref %array_type = temporary_storage
  56. // CHECK:STDOUT: %F.call: init %array_type = call %F.ref() to %.loc6_12.1
  57. // CHECK:STDOUT: %n.ref: %i32 = name_ref n, %n
  58. // CHECK:STDOUT: %.loc6_12.2: ref %array_type = temporary %.loc6_12.1, %F.call
  59. // CHECK:STDOUT: %int_32.loc6: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  60. // CHECK:STDOUT: %i32.loc6: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  61. // CHECK:STDOUT: %.loc6_15.1: ref %i32 = array_index %.loc6_12.2, %n.ref
  62. // CHECK:STDOUT: %.loc6_15.2: %i32 = bind_value %.loc6_15.1
  63. // CHECK:STDOUT: %impl.elem0: %.1ca = impl_witness_access constants.%Destroy.impl_witness.cc7, element0 [concrete = constants.%Op.552]
  64. // CHECK:STDOUT: %bound_method.loc6_12.1: <bound method> = bound_method %.loc6_12.1, %impl.elem0
  65. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Op.3(constants.%array_type) [concrete = constants.%Op.specific_fn]
  66. // CHECK:STDOUT: %bound_method.loc6_12.2: <bound method> = bound_method %.loc6_12.1, %specific_fn
  67. // CHECK:STDOUT: %addr: %ptr.830 = addr_of %.loc6_12.1
  68. // CHECK:STDOUT: %no_op: init %empty_tuple.type = call %bound_method.loc6_12.2(%addr)
  69. // CHECK:STDOUT: return %.loc6_15.2
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT: