extend_impl.carbon 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. interface HasF {
  7. fn F();
  8. }
  9. class C {
  10. extend impl as HasF {
  11. fn F() {}
  12. }
  13. }
  14. fn G(c: C) {
  15. C.F();
  16. c.F();
  17. }
  18. // CHECK:STDOUT: --- extend_impl.carbon
  19. // CHECK:STDOUT:
  20. // CHECK:STDOUT: constants {
  21. // CHECK:STDOUT: %.1: type = interface_type @HasF [template]
  22. // CHECK:STDOUT: %.2: type = assoc_entity_type @HasF, <function> [template]
  23. // CHECK:STDOUT: %.3: <associated <function> in HasF> = assoc_entity element0, @HasF.%F [template]
  24. // CHECK:STDOUT: %C: type = class_type @C [template]
  25. // CHECK:STDOUT: %.4: <witness> = interface_witness (@impl.%F) [template]
  26. // CHECK:STDOUT: %.5: type = struct_type {} [template]
  27. // CHECK:STDOUT: %.6: type = tuple_type () [template]
  28. // CHECK:STDOUT: %.7: type = ptr_type {} [template]
  29. // CHECK:STDOUT: }
  30. // CHECK:STDOUT:
  31. // CHECK:STDOUT: file {
  32. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  33. // CHECK:STDOUT: .HasF = %HasF.decl
  34. // CHECK:STDOUT: .C = %C.decl
  35. // CHECK:STDOUT: .G = %G
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT: %HasF.decl: type = interface_decl @HasF [template = constants.%.1] {}
  38. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  39. // CHECK:STDOUT: %G: <function> = fn_decl @G [template] {
  40. // CHECK:STDOUT: %C.ref: type = name_ref C, %C.decl [template = constants.%C]
  41. // CHECK:STDOUT: %c.loc17_6.1: C = param c
  42. // CHECK:STDOUT: @G.%c: C = bind_name c, %c.loc17_6.1
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: interface @HasF {
  47. // CHECK:STDOUT: %Self: HasF = bind_symbolic_name Self [symbolic]
  48. // CHECK:STDOUT: %F: <function> = fn_decl @F.1 [template] {}
  49. // CHECK:STDOUT: %.loc8: <associated <function> in HasF> = assoc_entity element0, %F [template = constants.%.3]
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: !members:
  52. // CHECK:STDOUT: .Self = %Self
  53. // CHECK:STDOUT: .F = %.loc8
  54. // CHECK:STDOUT: witness = (%F)
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: impl @impl: C as HasF {
  58. // CHECK:STDOUT: %F: <function> = fn_decl @F.2 [template] {}
  59. // CHECK:STDOUT: %.1: <witness> = interface_witness (%F) [template = constants.%.4]
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: !members:
  62. // CHECK:STDOUT: .F = %F
  63. // CHECK:STDOUT: witness = %.1
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: class @C {
  67. // CHECK:STDOUT: impl_decl @impl {
  68. // CHECK:STDOUT: %HasF.ref: type = name_ref HasF, file.%HasF.decl [template = constants.%.1]
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: !members:
  72. // CHECK:STDOUT: .Self = constants.%C
  73. // CHECK:STDOUT: extend name_scope1
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: fn @F.1();
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: fn @F.2() {
  79. // CHECK:STDOUT: !entry:
  80. // CHECK:STDOUT: return
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: fn @G(%c: C) {
  84. // CHECK:STDOUT: !entry:
  85. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  86. // CHECK:STDOUT: %F.ref.loc18: <associated <function> in HasF> = name_ref F, @HasF.%.loc8 [template = constants.%.3]
  87. // CHECK:STDOUT: %.1: <function> = interface_witness_access @impl.%.1, element0 [template = @impl.%F]
  88. // CHECK:STDOUT: %.loc18: init () = call %.1()
  89. // CHECK:STDOUT: %c.ref: C = name_ref c, %c
  90. // CHECK:STDOUT: %F.ref.loc19: <associated <function> in HasF> = name_ref F, @HasF.%.loc8 [template = constants.%.3]
  91. // CHECK:STDOUT: %.2: <function> = interface_witness_access @impl.%.1, element0 [template = @impl.%F]
  92. // CHECK:STDOUT: %.loc19: init () = call %.2()
  93. // CHECK:STDOUT: return
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT: