alias.carbon 4.0 KB

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