convert_interface.carbon 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  6. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  7. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/convert.carbon
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/facet/convert_interface.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/facet/convert_interface.carbon
  14. interface Eats {}
  15. interface Animal {}
  16. // TODO: This may be rejected in the future.
  17. // https://github.com/carbon-language/carbon-lang/issues/4853
  18. impl Animal as Eats {}
  19. fn F(e: Eats) {}
  20. fn G() { F(Animal); }
  21. // CHECK:STDOUT: --- convert_interface.carbon
  22. // CHECK:STDOUT:
  23. // CHECK:STDOUT: constants {
  24. // CHECK:STDOUT: %Eats.type: type = facet_type <@Eats> [concrete]
  25. // CHECK:STDOUT: %Self.267: %Eats.type = symbolic_binding Self, 0 [symbolic]
  26. // CHECK:STDOUT: %Animal.type: type = facet_type <@Animal> [concrete]
  27. // CHECK:STDOUT: %Self.84c: %Animal.type = symbolic_binding Self, 0 [symbolic]
  28. // CHECK:STDOUT: %Eats.impl_witness: <witness> = impl_witness file.%Eats.impl_witness_table [concrete]
  29. // CHECK:STDOUT: %pattern_type: type = pattern_type %Eats.type [concrete]
  30. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  31. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  32. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  33. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  34. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  35. // CHECK:STDOUT: %Eats.facet: %Eats.type = facet_value %Animal.type, (%Eats.impl_witness) [concrete]
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: imports {
  39. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  40. // CHECK:STDOUT: import Core//prelude
  41. // CHECK:STDOUT: import Core//prelude/...
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: file {
  46. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  47. // CHECK:STDOUT: .Core = imports.%Core
  48. // CHECK:STDOUT: .Eats = %Eats.decl
  49. // CHECK:STDOUT: .Animal = %Animal.decl
  50. // CHECK:STDOUT: .F = %F.decl
  51. // CHECK:STDOUT: .G = %G.decl
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT: %Core.import = import Core
  54. // CHECK:STDOUT: %Eats.decl: type = interface_decl @Eats [concrete = constants.%Eats.type] {} {}
  55. // CHECK:STDOUT: %Animal.decl: type = interface_decl @Animal [concrete = constants.%Animal.type] {} {}
  56. // CHECK:STDOUT: impl_decl @Animal.type.as.Eats.impl [concrete] {} {
  57. // CHECK:STDOUT: %Animal.ref: type = name_ref Animal, file.%Animal.decl [concrete = constants.%Animal.type]
  58. // CHECK:STDOUT: %Eats.ref: type = name_ref Eats, file.%Eats.decl [concrete = constants.%Eats.type]
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT: %Eats.impl_witness_table = impl_witness_table (), @Animal.type.as.Eats.impl [concrete]
  61. // CHECK:STDOUT: %Eats.impl_witness: <witness> = impl_witness %Eats.impl_witness_table [concrete = constants.%Eats.impl_witness]
  62. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  63. // CHECK:STDOUT: %e.patt: %pattern_type = value_binding_pattern e [concrete]
  64. // CHECK:STDOUT: %e.param_patt: %pattern_type = value_param_pattern %e.patt, call_param0 [concrete]
  65. // CHECK:STDOUT: } {
  66. // CHECK:STDOUT: %e.param: %Eats.type = value_param call_param0
  67. // CHECK:STDOUT: %Eats.ref: type = name_ref Eats, file.%Eats.decl [concrete = constants.%Eats.type]
  68. // CHECK:STDOUT: %e: %Eats.type = value_binding e, %e.param
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {} {}
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: interface @Eats {
  74. // CHECK:STDOUT: %Self: %Eats.type = symbolic_binding Self, 0 [symbolic = constants.%Self.267]
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: !members:
  77. // CHECK:STDOUT: .Self = %Self
  78. // CHECK:STDOUT: witness = ()
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: !requires:
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: interface @Animal {
  84. // CHECK:STDOUT: %Self: %Animal.type = symbolic_binding Self, 0 [symbolic = constants.%Self.84c]
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: !members:
  87. // CHECK:STDOUT: .Self = %Self
  88. // CHECK:STDOUT: witness = ()
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: !requires:
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: impl @Animal.type.as.Eats.impl: %Animal.ref as %Eats.ref {
  94. // CHECK:STDOUT: !members:
  95. // CHECK:STDOUT: witness = file.%Eats.impl_witness
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: fn @F(%e.param: %Eats.type) {
  99. // CHECK:STDOUT: !entry:
  100. // CHECK:STDOUT: return
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: fn @G() {
  104. // CHECK:STDOUT: !entry:
  105. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [concrete = constants.%F]
  106. // CHECK:STDOUT: %Animal.ref: type = name_ref Animal, file.%Animal.decl [concrete = constants.%Animal.type]
  107. // CHECK:STDOUT: %Eats.facet: %Eats.type = facet_value %Animal.ref, (constants.%Eats.impl_witness) [concrete = constants.%Eats.facet]
  108. // CHECK:STDOUT: %.loc23: %Eats.type = converted %Animal.ref, %Eats.facet [concrete = constants.%Eats.facet]
  109. // CHECK:STDOUT: %F.call: init %empty_tuple.type = call %F.ref(%.loc23)
  110. // CHECK:STDOUT: return
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT: