require_import.carbon 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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/facet/require_import.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/facet/require_import.carbon
  12. // --- a.carbon
  13. library "[[@TEST_NAME]]";
  14. interface Z {}
  15. interface Y {
  16. require impls Z;
  17. }
  18. constraint X {
  19. extend require impls Z;
  20. }
  21. // --- a.impl.carbon
  22. //@include-in-dumps
  23. impl library "[[@TEST_NAME]]";
  24. fn F(A:! X, B:! Y) {}
  25. // CHECK:STDOUT: --- a.impl.carbon
  26. // CHECK:STDOUT:
  27. // CHECK:STDOUT: constants {
  28. // CHECK:STDOUT: %type: type = facet_type <type> [concrete]
  29. // CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self]
  30. // CHECK:STDOUT: %X.type: type = facet_type <@X> [concrete]
  31. // CHECK:STDOUT: %Self.861: %X.type = symbolic_binding Self, 0 [symbolic]
  32. // CHECK:STDOUT: %Z.type: type = facet_type <@Z> [concrete]
  33. // CHECK:STDOUT: %Self.binding.as_type.1a1: type = symbolic_binding_type Self, 0, %Self.861 [symbolic]
  34. // CHECK:STDOUT: %A: %X.type = symbolic_binding A, 0 [symbolic]
  35. // CHECK:STDOUT: %pattern_type.e25: type = pattern_type %X.type [concrete]
  36. // CHECK:STDOUT: %Y.type: type = facet_type <@Y> [concrete]
  37. // CHECK:STDOUT: %Self.29b: %Y.type = symbolic_binding Self, 0 [symbolic]
  38. // CHECK:STDOUT: %Self.binding.as_type.384: type = symbolic_binding_type Self, 0, %Self.29b [symbolic]
  39. // CHECK:STDOUT: %B: %Y.type = symbolic_binding B, 1 [symbolic]
  40. // CHECK:STDOUT: %pattern_type.6e5: type = pattern_type %Y.type [concrete]
  41. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  42. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: imports {
  46. // CHECK:STDOUT: %Main.Z = import_ref Main//a, Z, unloaded
  47. // CHECK:STDOUT: %Main.Y: type = import_ref Main//a, Y, loaded [concrete = constants.%Y.type]
  48. // CHECK:STDOUT: %Main.X: type = import_ref Main//a, X, loaded [concrete = constants.%X.type]
  49. // CHECK:STDOUT: %Main.import_ref.462 = import_ref Main//a, loc3_13, unloaded
  50. // CHECK:STDOUT: %Main.import_ref.b7c: type = import_ref Main//a, loc10_18, loaded [symbolic = @X.require0.%Self.binding.as_type (constants.%Self.binding.as_type.1a1)]
  51. // CHECK:STDOUT: %Main.import_ref.df1cc4.1: type = import_ref Main//a, loc10_24, loaded [concrete = constants.%Z.type]
  52. // CHECK:STDOUT: %Main.import_ref.dec: %X.type = import_ref Main//a, loc9_14, loaded [symbolic = constants.%Self.861]
  53. // CHECK:STDOUT: %Main.import_ref.cae = import_ref Main//a, loc9_14, unloaded
  54. // CHECK:STDOUT: %Main.import_ref.3e6: type = import_ref Main//a, loc6_11, loaded [symbolic = @Y.require1.%Self.binding.as_type (constants.%Self.binding.as_type.384)]
  55. // CHECK:STDOUT: %Main.import_ref.df1cc4.2: type = import_ref Main//a, loc6_17, loaded [concrete = constants.%Z.type]
  56. // CHECK:STDOUT: %Main.import_ref.35b: %Y.type = import_ref Main//a, loc5_13, loaded [symbolic = constants.%Self.29b]
  57. // CHECK:STDOUT: %Main.import_ref.581 = import_ref Main//a, loc5_13, unloaded
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: file {
  61. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  62. // CHECK:STDOUT: .Z = imports.%Main.Z
  63. // CHECK:STDOUT: .Y = imports.%Main.Y
  64. // CHECK:STDOUT: .X = imports.%Main.X
  65. // CHECK:STDOUT: .F = %F.decl
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT: %default.import.loc2_17.1 = import <none>
  68. // CHECK:STDOUT: %default.import.loc2_17.2 = import <none>
  69. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  70. // CHECK:STDOUT: %A.patt: %pattern_type.e25 = symbolic_binding_pattern A, 0 [concrete]
  71. // CHECK:STDOUT: %B.patt: %pattern_type.6e5 = symbolic_binding_pattern B, 1 [concrete]
  72. // CHECK:STDOUT: } {
  73. // CHECK:STDOUT: %.loc4_10: type = splice_block %X.ref [concrete = constants.%X.type] {
  74. // CHECK:STDOUT: %.Self.2: %type = symbolic_binding .Self [symbolic_self = constants.%.Self]
  75. // CHECK:STDOUT: %X.ref: type = name_ref X, imports.%Main.X [concrete = constants.%X.type]
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT: %A.loc4_6.2: %X.type = symbolic_binding A, 0 [symbolic = %A.loc4_6.1 (constants.%A)]
  78. // CHECK:STDOUT: %.loc4_17: type = splice_block %Y.ref [concrete = constants.%Y.type] {
  79. // CHECK:STDOUT: %.Self.1: %type = symbolic_binding .Self [symbolic_self = constants.%.Self]
  80. // CHECK:STDOUT: %Y.ref: type = name_ref Y, imports.%Main.Y [concrete = constants.%Y.type]
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT: %B.loc4_13.2: %Y.type = symbolic_binding B, 1 [symbolic = %B.loc4_13.1 (constants.%B)]
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: interface @Z [from "a.carbon"] {
  87. // CHECK:STDOUT: !members:
  88. // CHECK:STDOUT: .Self = imports.%Main.import_ref.462
  89. // CHECK:STDOUT: witness = ()
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: !requires:
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: interface @Y [from "a.carbon"] {
  95. // CHECK:STDOUT: !members:
  96. // CHECK:STDOUT: .Self = imports.%Main.import_ref.581
  97. // CHECK:STDOUT: witness = ()
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: !requires:
  100. // CHECK:STDOUT: @Y.require1 {
  101. // CHECK:STDOUT: require imports.%Main.import_ref.3e6 impls imports.%Main.import_ref.df1cc4.2
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT:
  105. // CHECK:STDOUT: constraint @X [from "a.carbon"] {
  106. // CHECK:STDOUT: !members:
  107. // CHECK:STDOUT: .Self = imports.%Main.import_ref.cae
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: !requires:
  110. // CHECK:STDOUT: @X.require0 {
  111. // CHECK:STDOUT: require imports.%Main.import_ref.b7c impls imports.%Main.import_ref.df1cc4.1
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT:
  115. // CHECK:STDOUT: generic require @X.require0(imports.%Main.import_ref.dec: %X.type) [from "a.carbon"] {
  116. // CHECK:STDOUT: %Self: %X.type = symbolic_binding Self, 0 [symbolic = %Self (constants.%Self.861)]
  117. // CHECK:STDOUT: %Self.binding.as_type: type = symbolic_binding_type Self, 0, %Self [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type.1a1)]
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT:
  120. // CHECK:STDOUT: generic require @Y.require1(imports.%Main.import_ref.35b: %Y.type) [from "a.carbon"] {
  121. // CHECK:STDOUT: %Self: %Y.type = symbolic_binding Self, 0 [symbolic = %Self (constants.%Self.29b)]
  122. // CHECK:STDOUT: %Self.binding.as_type: type = symbolic_binding_type Self, 0, %Self [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type.384)]
  123. // CHECK:STDOUT: }
  124. // CHECK:STDOUT:
  125. // CHECK:STDOUT: generic fn @F(%A.loc4_6.2: %X.type, %B.loc4_13.2: %Y.type) {
  126. // CHECK:STDOUT: %A.loc4_6.1: %X.type = symbolic_binding A, 0 [symbolic = %A.loc4_6.1 (constants.%A)]
  127. // CHECK:STDOUT: %B.loc4_13.1: %Y.type = symbolic_binding B, 1 [symbolic = %B.loc4_13.1 (constants.%B)]
  128. // CHECK:STDOUT:
  129. // CHECK:STDOUT: !definition:
  130. // CHECK:STDOUT:
  131. // CHECK:STDOUT: fn() {
  132. // CHECK:STDOUT: !entry:
  133. // CHECK:STDOUT: return
  134. // CHECK:STDOUT: }
  135. // CHECK:STDOUT: }
  136. // CHECK:STDOUT:
  137. // CHECK:STDOUT: specific @X.require0(constants.%Self.861) {
  138. // CHECK:STDOUT: %Self => constants.%Self.861
  139. // CHECK:STDOUT: %Self.binding.as_type => constants.%Self.binding.as_type.1a1
  140. // CHECK:STDOUT: }
  141. // CHECK:STDOUT:
  142. // CHECK:STDOUT: specific @Y.require1(constants.%Self.29b) {
  143. // CHECK:STDOUT: %Self => constants.%Self.29b
  144. // CHECK:STDOUT: %Self.binding.as_type => constants.%Self.binding.as_type.384
  145. // CHECK:STDOUT: }
  146. // CHECK:STDOUT:
  147. // CHECK:STDOUT: specific @F(constants.%A, constants.%B) {
  148. // CHECK:STDOUT: %A.loc4_6.1 => constants.%A
  149. // CHECK:STDOUT: %B.loc4_13.1 => constants.%B
  150. // CHECK:STDOUT: }
  151. // CHECK:STDOUT: