import.carbon 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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: %N: Core.IntLiteral = bind_symbolic_name N, 0 [symbolic]
  51. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  52. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  53. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  54. // CHECK:STDOUT: %int_42: Core.IntLiteral = int_value 42 [concrete]
  55. // CHECK:STDOUT: %array_type: type = array_type %int_42, %i32 [concrete]
  56. // CHECK:STDOUT: %ptr.830: type = ptr_type %array_type [concrete]
  57. // CHECK:STDOUT: %Copy.type: type = facet_type <@Copy> [concrete]
  58. // CHECK:STDOUT: %Copy.Op.type: type = fn_type @Copy.Op [concrete]
  59. // CHECK:STDOUT: %Int.as.Copy.impl.Op.type.afd: type = fn_type @Int.as.Copy.impl.Op, @Int.as.Copy.impl(%N) [symbolic]
  60. // CHECK:STDOUT: %Int.as.Copy.impl.Op.6cd: %Int.as.Copy.impl.Op.type.afd = struct_value () [symbolic]
  61. // CHECK:STDOUT: %Copy.impl_witness.a32: <witness> = impl_witness imports.%Copy.impl_witness_table.1ed, @Int.as.Copy.impl(%int_32) [concrete]
  62. // CHECK:STDOUT: %Int.as.Copy.impl.Op.type.276: type = fn_type @Int.as.Copy.impl.Op, @Int.as.Copy.impl(%int_32) [concrete]
  63. // CHECK:STDOUT: %Int.as.Copy.impl.Op.f59: %Int.as.Copy.impl.Op.type.276 = struct_value () [concrete]
  64. // CHECK:STDOUT: %Copy.facet: %Copy.type = facet_value %i32, (%Copy.impl_witness.a32) [concrete]
  65. // CHECK:STDOUT: %.7fa: type = fn_type_with_self_type %Copy.Op.type, %Copy.facet [concrete]
  66. // CHECK:STDOUT: %Int.as.Copy.impl.Op.specific_fn: <specific function> = specific_function %Int.as.Copy.impl.Op.f59, @Int.as.Copy.impl.Op(%int_32) [concrete]
  67. // CHECK:STDOUT: %type_where: type = facet_type <type where .Self impls <CanDestroy>> [concrete]
  68. // CHECK:STDOUT: %facet_value: %type_where = facet_value %array_type, () [concrete]
  69. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.type.4f7: type = fn_type @DestroyT.binding.as_type.as.Destroy.impl.Op, @DestroyT.binding.as_type.as.Destroy.impl(%facet_value) [concrete]
  70. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.ce8: %DestroyT.binding.as_type.as.Destroy.impl.Op.type.4f7 = struct_value () [concrete]
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: imports {
  74. // CHECK:STDOUT: %Main.F: %F.type = import_ref Main//library, F, loaded [concrete = constants.%F]
  75. // CHECK:STDOUT: %Core.import_ref.d0f6: @Int.as.Copy.impl.%Int.as.Copy.impl.Op.type (%Int.as.Copy.impl.Op.type.afd) = import_ref Core//prelude/parts/int, loc{{\d+_\d+}}, loaded [symbolic = @Int.as.Copy.impl.%Int.as.Copy.impl.Op (constants.%Int.as.Copy.impl.Op.6cd)]
  76. // CHECK:STDOUT: %Copy.impl_witness_table.1ed = impl_witness_table (%Core.import_ref.d0f6), @Int.as.Copy.impl [concrete]
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: fn @G(%n.param: %i32) -> %i32 {
  80. // CHECK:STDOUT: !entry:
  81. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, imports.%Main.F [concrete = constants.%F]
  82. // CHECK:STDOUT: %.loc6_12.1: ref %array_type = temporary_storage
  83. // CHECK:STDOUT: %F.call: init %array_type = call %F.ref() to %.loc6_12.1
  84. // CHECK:STDOUT: %n.ref: %i32 = name_ref n, %n
  85. // CHECK:STDOUT: %.loc6_12.2: ref %array_type = temporary %.loc6_12.1, %F.call
  86. // CHECK:STDOUT: %int_32.loc6: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  87. // CHECK:STDOUT: %i32.loc6: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  88. // CHECK:STDOUT: %.loc6_15.1: ref %i32 = array_index %.loc6_12.2, %n.ref
  89. // CHECK:STDOUT: %.loc6_15.2: %i32 = bind_value %.loc6_15.1
  90. // CHECK:STDOUT: %impl.elem0: %.7fa = impl_witness_access constants.%Copy.impl_witness.a32, element0 [concrete = constants.%Int.as.Copy.impl.Op.f59]
  91. // CHECK:STDOUT: %bound_method.loc6_15.1: <bound method> = bound_method %.loc6_15.2, %impl.elem0
  92. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Int.as.Copy.impl.Op(constants.%int_32) [concrete = constants.%Int.as.Copy.impl.Op.specific_fn]
  93. // CHECK:STDOUT: %bound_method.loc6_15.2: <bound method> = bound_method %.loc6_15.2, %specific_fn
  94. // CHECK:STDOUT: %Int.as.Copy.impl.Op.call: init %i32 = call %bound_method.loc6_15.2(%.loc6_15.2)
  95. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.bound: <bound method> = bound_method %.loc6_12.2, constants.%DestroyT.binding.as_type.as.Destroy.impl.Op.ce8
  96. // CHECK:STDOUT: <elided>
  97. // CHECK:STDOUT: %bound_method.loc6_12: <bound method> = bound_method %.loc6_12.2, %DestroyT.binding.as_type.as.Destroy.impl.Op.specific_fn
  98. // CHECK:STDOUT: %addr: %ptr.830 = addr_of %.loc6_12.2
  99. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.call: init %empty_tuple.type = call %bound_method.loc6_12(%addr)
  100. // CHECK:STDOUT: return %Int.as.Copy.impl.Op.call to %return
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: --- fail_todo_import_symbolic_decl.carbon
  104. // CHECK:STDOUT:
  105. // CHECK:STDOUT: constants {
  106. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  107. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  108. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete]
  109. // CHECK:STDOUT: %array_type: type = array_type %int_1, %i32 [concrete]
  110. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  111. // CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: imports {
  115. // CHECK:STDOUT: %Main.I: type = import_ref Main//symbolic_decl, I, loaded [concrete = constants.%I.type]
  116. // CHECK:STDOUT: %Main.C: type = import_ref Main//symbolic_decl, C, loaded [concrete = constants.%C]
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: fn @F() -> %return.param: %array_type {
  120. // CHECK:STDOUT: !entry:
  121. // CHECK:STDOUT: %C.ref: type = name_ref C, imports.%Main.C [concrete = constants.%C]
  122. // CHECK:STDOUT: %I.ref: type = name_ref I, imports.%Main.I [concrete = constants.%I.type]
  123. // CHECK:STDOUT: %val.ref: <error> = name_ref val, <error> [concrete = <error>]
  124. // CHECK:STDOUT: return <error> to %return
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT: