import_constraint_decl.carbon 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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/none.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/named_constraint/import_constraint_decl.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/named_constraint/import_constraint_decl.carbon
  12. // --- a.carbon
  13. library "[[@TEST_NAME]]";
  14. constraint A;
  15. // --- a.impl.carbon
  16. //@include-in-dumps
  17. impl library "[[@TEST_NAME]]";
  18. // --- b.carbon
  19. library "[[@TEST_NAME]]";
  20. interface I {}
  21. constraint B {
  22. extend require impls I;
  23. }
  24. // --- b.impl.carbon
  25. //@include-in-dumps
  26. impl library "[[@TEST_NAME]]";
  27. fn F(T:! B) {}
  28. // --- fail_import_not_identified.carbon
  29. library "[[@TEST_NAME]]";
  30. import library "a";
  31. class C {}
  32. // CHECK:STDERR: fail_import_not_identified.carbon:[[@LINE+8]]:1: error: facet type `A` cannot be identified in `impl as` [ImplOfUnidentifiedFacetType]
  33. // CHECK:STDERR: impl C as A;
  34. // CHECK:STDERR: ^~~~~~~~~~~~
  35. // CHECK:STDERR: fail_import_not_identified.carbon:[[@LINE-6]]:1: in import [InImport]
  36. // CHECK:STDERR: a.carbon:3:1: note: constraint was forward declared here [NamedConstraintForwardDeclaredHere]
  37. // CHECK:STDERR: constraint A;
  38. // CHECK:STDERR: ^~~~~~~~~~~~~
  39. // CHECK:STDERR:
  40. impl C as A;
  41. // --- import_complete.carbon
  42. library "[[@TEST_NAME]]";
  43. import library "b";
  44. class C {}
  45. // This requires that B is identified.
  46. impl C as B;
  47. // This requires that B is complete.
  48. impl C as B {}
  49. // CHECK:STDOUT: --- a.impl.carbon
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: imports {
  52. // CHECK:STDOUT: %Main.A = import_ref Main//a, A, unloaded
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: file {
  56. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  57. // CHECK:STDOUT: .A = imports.%Main.A
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: %default.import.loc2_17.1 = import <none>
  60. // CHECK:STDOUT: %default.import.loc2_17.2 = import <none>
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: --- b.impl.carbon
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: constants {
  66. // CHECK:STDOUT: %type: type = facet_type <type> [concrete]
  67. // CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self]
  68. // CHECK:STDOUT: %B.type: type = facet_type <@B> [concrete]
  69. // CHECK:STDOUT: %Self.861: %B.type = symbolic_binding Self, 0 [symbolic]
  70. // CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
  71. // CHECK:STDOUT: %Self.binding.as_type: type = symbolic_binding_type Self, 0, %Self.861 [symbolic]
  72. // CHECK:STDOUT: %T: %B.type = symbolic_binding T, 0 [symbolic]
  73. // CHECK:STDOUT: %pattern_type: type = pattern_type %B.type [concrete]
  74. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  75. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: imports {
  79. // CHECK:STDOUT: %Main.I = import_ref Main//b, I, unloaded
  80. // CHECK:STDOUT: %Main.B: type = import_ref Main//b, B, loaded [concrete = constants.%B.type]
  81. // CHECK:STDOUT: %Main.import_ref.8df = import_ref Main//b, loc3_13, unloaded
  82. // CHECK:STDOUT: %Main.import_ref.b7c: type = import_ref Main//b, loc5_18, loaded [symbolic = @B.require0.%Self.binding.as_type (constants.%Self.binding.as_type)]
  83. // CHECK:STDOUT: %Main.import_ref.301: type = import_ref Main//b, loc5_24, loaded [concrete = constants.%I.type]
  84. // CHECK:STDOUT: %Main.import_ref.dec: %B.type = import_ref Main//b, loc4_14, loaded [symbolic = constants.%Self.861]
  85. // CHECK:STDOUT: %Main.import_ref.cae = import_ref Main//b, loc4_14, unloaded
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT:
  88. // CHECK:STDOUT: file {
  89. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  90. // CHECK:STDOUT: .I = imports.%Main.I
  91. // CHECK:STDOUT: .B = imports.%Main.B
  92. // CHECK:STDOUT: .F = %F.decl
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT: %default.import.loc2_17.1 = import <none>
  95. // CHECK:STDOUT: %default.import.loc2_17.2 = import <none>
  96. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  97. // CHECK:STDOUT: %T.patt: %pattern_type = symbolic_binding_pattern T, 0 [concrete]
  98. // CHECK:STDOUT: } {
  99. // CHECK:STDOUT: %.loc4: type = splice_block %B.ref [concrete = constants.%B.type] {
  100. // CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self = constants.%.Self]
  101. // CHECK:STDOUT: %B.ref: type = name_ref B, imports.%Main.B [concrete = constants.%B.type]
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT: %T.loc4_6.2: %B.type = symbolic_binding T, 0 [symbolic = %T.loc4_6.1 (constants.%T)]
  104. // CHECK:STDOUT: }
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: interface @I [from "b.carbon"] {
  108. // CHECK:STDOUT: !members:
  109. // CHECK:STDOUT: .Self = imports.%Main.import_ref.8df
  110. // CHECK:STDOUT: witness = ()
  111. // CHECK:STDOUT:
  112. // CHECK:STDOUT: !requires:
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT:
  115. // CHECK:STDOUT: constraint @B [from "b.carbon"] {
  116. // CHECK:STDOUT: !members:
  117. // CHECK:STDOUT: .Self = imports.%Main.import_ref.cae
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: !requires:
  120. // CHECK:STDOUT: @B.require0 {
  121. // CHECK:STDOUT: require imports.%Main.import_ref.b7c impls imports.%Main.import_ref.301
  122. // CHECK:STDOUT: }
  123. // CHECK:STDOUT: }
  124. // CHECK:STDOUT:
  125. // CHECK:STDOUT: generic require @B.require0(imports.%Main.import_ref.dec: %B.type) [from "b.carbon"] {
  126. // CHECK:STDOUT: %Self: %B.type = symbolic_binding Self, 0 [symbolic = %Self (constants.%Self.861)]
  127. // CHECK:STDOUT: %Self.binding.as_type: type = symbolic_binding_type Self, 0, %Self [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)]
  128. // CHECK:STDOUT: }
  129. // CHECK:STDOUT:
  130. // CHECK:STDOUT: generic fn @F(%T.loc4_6.2: %B.type) {
  131. // CHECK:STDOUT: %T.loc4_6.1: %B.type = symbolic_binding T, 0 [symbolic = %T.loc4_6.1 (constants.%T)]
  132. // CHECK:STDOUT:
  133. // CHECK:STDOUT: !definition:
  134. // CHECK:STDOUT:
  135. // CHECK:STDOUT: fn() {
  136. // CHECK:STDOUT: !entry:
  137. // CHECK:STDOUT: return
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT:
  141. // CHECK:STDOUT: specific @B.require0(constants.%Self.861) {
  142. // CHECK:STDOUT: %Self => constants.%Self.861
  143. // CHECK:STDOUT: %Self.binding.as_type => constants.%Self.binding.as_type
  144. // CHECK:STDOUT: }
  145. // CHECK:STDOUT:
  146. // CHECK:STDOUT: specific @F(constants.%T) {
  147. // CHECK:STDOUT: %T.loc4_6.1 => constants.%T
  148. // CHECK:STDOUT: }
  149. // CHECK:STDOUT: