import.carbon 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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() -> [i32; 42];
  13. // --- user.carbon
  14. import library "library";
  15. fn G(n: i32) -> i32 {
  16. return F()[n];
  17. }
  18. // CHECK:STDOUT: --- library.carbon
  19. // CHECK:STDOUT:
  20. // CHECK:STDOUT: constants {
  21. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  22. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  23. // CHECK:STDOUT: %int_42: Core.IntLiteral = int_value 42 [concrete]
  24. // CHECK:STDOUT: %array_type: type = array_type %int_42, %i32 [concrete]
  25. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  26. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  27. // CHECK:STDOUT: }
  28. // CHECK:STDOUT:
  29. // CHECK:STDOUT: imports {
  30. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  31. // CHECK:STDOUT: .Int = %Core.Int
  32. // CHECK:STDOUT: import Core//prelude
  33. // CHECK:STDOUT: import Core//prelude/...
  34. // CHECK:STDOUT: }
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: file {
  38. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  39. // CHECK:STDOUT: .Core = imports.%Core
  40. // CHECK:STDOUT: .F = %F.decl
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT: %Core.import = import Core
  43. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  44. // CHECK:STDOUT: %return.patt: %array_type = return_slot_pattern
  45. // CHECK:STDOUT: %return.param_patt: %array_type = out_param_pattern %return.patt, runtime_param0
  46. // CHECK:STDOUT: } {
  47. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  48. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  49. // CHECK:STDOUT: %int_42: Core.IntLiteral = int_value 42 [concrete = constants.%int_42]
  50. // CHECK:STDOUT: %array_type: type = array_type %int_42, %i32 [concrete = constants.%array_type]
  51. // CHECK:STDOUT: %return.param: ref %array_type = out_param runtime_param0
  52. // CHECK:STDOUT: %return: ref %array_type = return_slot %return.param
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: fn @F() -> %array_type;
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: --- user.carbon
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: constants {
  61. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  62. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  63. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  64. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  65. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  66. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  67. // CHECK:STDOUT: %int_42: Core.IntLiteral = int_value 42 [concrete]
  68. // CHECK:STDOUT: %array_type: type = array_type %int_42, %i32 [concrete]
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: imports {
  72. // CHECK:STDOUT: %Main.F: %F.type = import_ref Main//library, F, loaded [concrete = constants.%F]
  73. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  74. // CHECK:STDOUT: .Int = %Core.Int
  75. // CHECK:STDOUT: import Core//prelude
  76. // CHECK:STDOUT: import Core//prelude/...
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: file {
  81. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  82. // CHECK:STDOUT: .F = imports.%Main.F
  83. // CHECK:STDOUT: .Core = imports.%Core
  84. // CHECK:STDOUT: .G = %G.decl
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT: %Core.import = import Core
  87. // CHECK:STDOUT: %default.import = import <none>
  88. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {
  89. // CHECK:STDOUT: %n.patt: %i32 = binding_pattern n
  90. // CHECK:STDOUT: %n.param_patt: %i32 = value_param_pattern %n.patt, runtime_param0
  91. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  92. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param1
  93. // CHECK:STDOUT: } {
  94. // CHECK:STDOUT: %int_32.loc4_17: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  95. // CHECK:STDOUT: %i32.loc4_17: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  96. // CHECK:STDOUT: %n.param: %i32 = value_param runtime_param0
  97. // CHECK:STDOUT: %.loc4: type = splice_block %i32.loc4_9 [concrete = constants.%i32] {
  98. // CHECK:STDOUT: %int_32.loc4_9: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  99. // CHECK:STDOUT: %i32.loc4_9: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT: %n: %i32 = bind_name n, %n.param
  102. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param1
  103. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  104. // CHECK:STDOUT: }
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: fn @G(%n.param_patt: %i32) -> %i32 {
  108. // CHECK:STDOUT: !entry:
  109. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, imports.%Main.F [concrete = constants.%F]
  110. // CHECK:STDOUT: %.loc5_12.1: ref %array_type = temporary_storage
  111. // CHECK:STDOUT: %F.call: init %array_type = call %F.ref() to %.loc5_12.1
  112. // CHECK:STDOUT: %n.ref: %i32 = name_ref n, %n
  113. // CHECK:STDOUT: %.loc5_12.2: ref %array_type = temporary %.loc5_12.1, %F.call
  114. // CHECK:STDOUT: %int_32.loc5: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  115. // CHECK:STDOUT: %i32.loc5: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  116. // CHECK:STDOUT: %.loc5_15.1: ref %i32 = array_index %.loc5_12.2, %n.ref
  117. // CHECK:STDOUT: %.loc5_15.2: %i32 = bind_value %.loc5_15.1
  118. // CHECK:STDOUT: return %.loc5_15.2
  119. // CHECK:STDOUT: }
  120. // CHECK:STDOUT:
  121. // CHECK:STDOUT: fn @F() -> %array_type [from "library.carbon"];
  122. // CHECK:STDOUT: