import.carbon 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. // --- fail_todo_symbolic_decl.carbon
  23. library "[[@TEST_NAME]]";
  24. interface I {
  25. let val:! array(i32, 1);
  26. }
  27. class C {}
  28. // CHECK:STDERR: fail_todo_symbolic_decl.carbon:[[@LINE+4]]:26: error: expression is runtime; expected constant [EvalRequiresConstantValue]
  29. // CHECK:STDERR: impl C as I where .val = (1,) {}
  30. // CHECK:STDERR: ^~~~
  31. // CHECK:STDERR:
  32. impl C as I where .val = (1,) {}
  33. // --- fail_todo_import_symbolic_decl.carbon
  34. library "[[@TEST_NAME]]";
  35. import library "symbolic_decl";
  36. fn F() -> array(i32, 1) {
  37. //@dump-sem-ir-begin
  38. // CHECK:STDERR: fail_todo_import_symbolic_decl.carbon:[[@LINE+4]]:11: error: cannot convert type `C` into type implementing `I` [ConversionFailureTypeToFacet]
  39. // CHECK:STDERR: return (C as I).val;
  40. // CHECK:STDERR: ^~~~~~
  41. // CHECK:STDERR:
  42. return (C as I).val;
  43. //@dump-sem-ir-end
  44. }
  45. // CHECK:STDOUT: --- user.carbon
  46. // CHECK:STDOUT:
  47. // CHECK:STDOUT: constants {
  48. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  49. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  50. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  51. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  52. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  53. // CHECK:STDOUT: %int_42: Core.IntLiteral = int_value 42 [concrete]
  54. // CHECK:STDOUT: %array_type: type = array_type %int_42, %i32 [concrete]
  55. // CHECK:STDOUT: %ptr.830: type = ptr_type %array_type [concrete]
  56. // CHECK:STDOUT: %T.as.Destroy.impl.Op.type.886: type = fn_type @T.as.Destroy.impl.Op, @T.as.Destroy.impl(%array_type) [concrete]
  57. // CHECK:STDOUT: %T.as.Destroy.impl.Op.923: %T.as.Destroy.impl.Op.type.886 = struct_value () [concrete]
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: imports {
  61. // CHECK:STDOUT: %Main.F: %F.type = import_ref Main//library, F, loaded [concrete = constants.%F]
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: fn @G(%n.param: %i32) -> %i32 {
  65. // CHECK:STDOUT: !entry:
  66. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, imports.%Main.F [concrete = constants.%F]
  67. // CHECK:STDOUT: %.loc6_12.1: ref %array_type = temporary_storage
  68. // CHECK:STDOUT: %F.call: init %array_type = call %F.ref() to %.loc6_12.1
  69. // CHECK:STDOUT: %n.ref: %i32 = name_ref n, %n
  70. // CHECK:STDOUT: %.loc6_12.2: ref %array_type = temporary %.loc6_12.1, %F.call
  71. // CHECK:STDOUT: %int_32.loc6: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  72. // CHECK:STDOUT: %i32.loc6: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  73. // CHECK:STDOUT: %.loc6_15.1: ref %i32 = array_index %.loc6_12.2, %n.ref
  74. // CHECK:STDOUT: %.loc6_15.2: %i32 = bind_value %.loc6_15.1
  75. // CHECK:STDOUT: %T.as.Destroy.impl.Op.bound: <bound method> = bound_method %.loc6_12.2, constants.%T.as.Destroy.impl.Op.923
  76. // CHECK:STDOUT: <elided>
  77. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %.loc6_12.2, %T.as.Destroy.impl.Op.specific_fn
  78. // CHECK:STDOUT: %addr: %ptr.830 = addr_of %.loc6_12.2
  79. // CHECK:STDOUT: %T.as.Destroy.impl.Op.call: init %empty_tuple.type = call %bound_method(%addr)
  80. // CHECK:STDOUT: return %.loc6_15.2
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: --- fail_todo_import_symbolic_decl.carbon
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: constants {
  86. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  87. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  88. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete]
  89. // CHECK:STDOUT: %array_type: type = array_type %int_1, %i32 [concrete]
  90. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  91. // CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: imports {
  95. // CHECK:STDOUT: %Main.I: type = import_ref Main//symbolic_decl, I, loaded [concrete = constants.%I.type]
  96. // CHECK:STDOUT: %Main.C: type = import_ref Main//symbolic_decl, C, loaded [concrete = constants.%C]
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: fn @F() -> %return.param: %array_type {
  100. // CHECK:STDOUT: !entry:
  101. // CHECK:STDOUT: %C.ref: type = name_ref C, imports.%Main.C [concrete = constants.%C]
  102. // CHECK:STDOUT: %I.ref: type = name_ref I, imports.%Main.I [concrete = constants.%I.type]
  103. // CHECK:STDOUT: %val.ref: <error> = name_ref val, <error> [concrete = <error>]
  104. // CHECK:STDOUT: return <error> to %return
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT: