extend_impl.carbon 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. // AUTOUPDATE
  6. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/impl/extend_impl.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/extend_impl.carbon
  10. interface HasF {
  11. fn F();
  12. }
  13. class C {
  14. extend impl as HasF {
  15. fn F() {}
  16. }
  17. }
  18. fn G(c: C) {
  19. C.F();
  20. c.F();
  21. }
  22. // CHECK:STDOUT: --- extend_impl.carbon
  23. // CHECK:STDOUT:
  24. // CHECK:STDOUT: constants {
  25. // CHECK:STDOUT: %.1: type = interface_type @HasF [template]
  26. // CHECK:STDOUT: %Self: %.1 = bind_symbolic_name Self, 0 [symbolic]
  27. // CHECK:STDOUT: %F.type.1: type = fn_type @F.1 [template]
  28. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  29. // CHECK:STDOUT: %F.1: %F.type.1 = struct_value () [template]
  30. // CHECK:STDOUT: %.3: type = assoc_entity_type %.1, %F.type.1 [template]
  31. // CHECK:STDOUT: %.4: %.3 = assoc_entity element0, @HasF.%F.decl [template]
  32. // CHECK:STDOUT: %C: type = class_type @C [template]
  33. // CHECK:STDOUT: %F.type.2: type = fn_type @F.2 [template]
  34. // CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [template]
  35. // CHECK:STDOUT: %.5: <witness> = interface_witness (%F.2) [template]
  36. // CHECK:STDOUT: %.6: type = struct_type {} [template]
  37. // CHECK:STDOUT: %.7: <witness> = complete_type_witness %.6 [template]
  38. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  39. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  40. // CHECK:STDOUT: %.8: type = ptr_type %.6 [template]
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT:
  43. // CHECK:STDOUT: imports {
  44. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  45. // CHECK:STDOUT: import Core//prelude
  46. // CHECK:STDOUT: import Core//prelude/operators
  47. // CHECK:STDOUT: import Core//prelude/types
  48. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  49. // CHECK:STDOUT: import Core//prelude/operators/as
  50. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  51. // CHECK:STDOUT: import Core//prelude/operators/comparison
  52. // CHECK:STDOUT: import Core//prelude/types/bool
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: file {
  57. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  58. // CHECK:STDOUT: .Core = imports.%Core
  59. // CHECK:STDOUT: .HasF = %HasF.decl
  60. // CHECK:STDOUT: .C = %C.decl
  61. // CHECK:STDOUT: .G = %G.decl
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT: %Core.import = import Core
  64. // CHECK:STDOUT: %HasF.decl: type = interface_decl @HasF [template = constants.%.1] {} {}
  65. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  66. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  67. // CHECK:STDOUT: %c.patt: %C = binding_pattern c
  68. // CHECK:STDOUT: } {
  69. // CHECK:STDOUT: %C.ref.loc21: type = name_ref C, file.%C.decl [template = constants.%C]
  70. // CHECK:STDOUT: %c.param: %C = param c, runtime_param0
  71. // CHECK:STDOUT: %c: %C = bind_name c, %c.param
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: interface @HasF {
  76. // CHECK:STDOUT: %Self: %.1 = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
  77. // CHECK:STDOUT: %F.decl: %F.type.1 = fn_decl @F.1 [template = constants.%F.1] {} {}
  78. // CHECK:STDOUT: %.loc12: %.3 = assoc_entity element0, %F.decl [template = constants.%.4]
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: !members:
  81. // CHECK:STDOUT: .Self = %Self
  82. // CHECK:STDOUT: .F = %.loc12
  83. // CHECK:STDOUT: witness = (%F.decl)
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: impl @impl: %Self.ref as %HasF.ref {
  87. // CHECK:STDOUT: %F.decl: %F.type.2 = fn_decl @F.2 [template = constants.%F.2] {} {}
  88. // CHECK:STDOUT: %.loc16: <witness> = interface_witness (%F.decl) [template = constants.%.5]
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: !members:
  91. // CHECK:STDOUT: .F = %F.decl
  92. // CHECK:STDOUT: witness = %.loc16
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: class @C {
  96. // CHECK:STDOUT: impl_decl @impl [template] {} {
  97. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [template = constants.%C]
  98. // CHECK:STDOUT: %HasF.ref: type = name_ref HasF, file.%HasF.decl [template = constants.%.1]
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT: %.loc19: <witness> = complete_type_witness %.6 [template = constants.%.7]
  101. // CHECK:STDOUT:
  102. // CHECK:STDOUT: !members:
  103. // CHECK:STDOUT: .Self = constants.%C
  104. // CHECK:STDOUT: extend name_scope2
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: generic fn @F.1(@HasF.%Self: %.1) {
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: fn();
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT:
  112. // CHECK:STDOUT: fn @F.2() {
  113. // CHECK:STDOUT: !entry:
  114. // CHECK:STDOUT: return
  115. // CHECK:STDOUT: }
  116. // CHECK:STDOUT:
  117. // CHECK:STDOUT: fn @G(%c: %C) {
  118. // CHECK:STDOUT: !entry:
  119. // CHECK:STDOUT: %C.ref.loc22: type = name_ref C, file.%C.decl [template = constants.%C]
  120. // CHECK:STDOUT: %F.ref.loc22: %.3 = name_ref F, @HasF.%.loc12 [template = constants.%.4]
  121. // CHECK:STDOUT: %.loc22: %F.type.1 = interface_witness_access constants.%.5, element0 [template = constants.%F.2]
  122. // CHECK:STDOUT: %F.call.loc22: init %.2 = call %.loc22()
  123. // CHECK:STDOUT: %c.ref: %C = name_ref c, %c
  124. // CHECK:STDOUT: %F.ref.loc23: %.3 = name_ref F, @HasF.%.loc12 [template = constants.%.4]
  125. // CHECK:STDOUT: %.loc23: %F.type.1 = interface_witness_access constants.%.5, element0 [template = constants.%F.2]
  126. // CHECK:STDOUT: %F.call.loc23: init %.2 = call %.loc23()
  127. // CHECK:STDOUT: return
  128. // CHECK:STDOUT: }
  129. // CHECK:STDOUT:
  130. // CHECK:STDOUT: specific @F.1(constants.%Self) {}
  131. // CHECK:STDOUT:
  132. // CHECK:STDOUT: specific @F.1(constants.%C) {}
  133. // CHECK:STDOUT: