instance_method.carbon 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. class C;
  7. interface I {
  8. // TODO: Use `Self` once we perform substitution for it.
  9. fn F[self: C]() -> i32;
  10. }
  11. class C {
  12. extend impl as I {
  13. fn F[self: C]() -> i32;
  14. }
  15. }
  16. fn F(c: C) -> i32 {
  17. return c.F();
  18. }
  19. // CHECK:STDOUT: --- instance_method.carbon
  20. // CHECK:STDOUT:
  21. // CHECK:STDOUT: constants {
  22. // CHECK:STDOUT: %C: type = class_type @C [template]
  23. // CHECK:STDOUT: %.1: type = interface_type @I [template]
  24. // CHECK:STDOUT: %.2: type = assoc_entity_type @I, <function> [template]
  25. // CHECK:STDOUT: %.3: <associated <function> in I> = assoc_entity element0, @I.%F [template]
  26. // CHECK:STDOUT: %.4: <witness> = interface_witness (@impl.%F) [template]
  27. // CHECK:STDOUT: %.5: type = struct_type {} [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: .C = %C.decl.loc7
  35. // CHECK:STDOUT: .I = %I.decl
  36. // CHECK:STDOUT: .F = %F
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT: %C.decl.loc7: type = class_decl @C [template = constants.%C] {}
  39. // CHECK:STDOUT: %I.decl: type = interface_decl @I [template = constants.%.1] {}
  40. // CHECK:STDOUT: %C.decl.loc14: type = class_decl @C [template = constants.%C] {}
  41. // CHECK:STDOUT: %F: <function> = fn_decl @F.3 [template] {
  42. // CHECK:STDOUT: %C.ref: type = name_ref C, %C.decl.loc7 [template = constants.%C]
  43. // CHECK:STDOUT: %c.loc20_6.1: C = param c
  44. // CHECK:STDOUT: @F.3.%c: C = bind_name c, %c.loc20_6.1
  45. // CHECK:STDOUT: %return.var: ref i32 = var <return slot>
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: interface @I {
  50. // CHECK:STDOUT: %Self: I = bind_symbolic_name Self [symbolic]
  51. // CHECK:STDOUT: %F: <function> = fn_decl @F.1 [template] {
  52. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl.loc7 [template = constants.%C]
  53. // CHECK:STDOUT: %self.loc11_8.1: C = param self
  54. // CHECK:STDOUT: %self.loc11_8.2: C = bind_name self, %self.loc11_8.1
  55. // CHECK:STDOUT: %return.var: ref i32 = var <return slot>
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT: %.loc11: <associated <function> in I> = assoc_entity element0, %F [template = constants.%.3]
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: !members:
  60. // CHECK:STDOUT: .Self = %Self
  61. // CHECK:STDOUT: .F = %.loc11
  62. // CHECK:STDOUT: witness = (%F)
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: impl @impl: C as I {
  66. // CHECK:STDOUT: %F: <function> = fn_decl @F.2 [template] {
  67. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl.loc7 [template = constants.%C]
  68. // CHECK:STDOUT: %self.loc16_10.1: C = param self
  69. // CHECK:STDOUT: %self.loc16_10.2: C = bind_name self, %self.loc16_10.1
  70. // CHECK:STDOUT: %return.var: ref i32 = var <return slot>
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT: %.1: <witness> = interface_witness (%F) [template = constants.%.4]
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: !members:
  75. // CHECK:STDOUT: .F = %F
  76. // CHECK:STDOUT: witness = %.1
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: class @C {
  80. // CHECK:STDOUT: impl_decl @impl {
  81. // CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [template = constants.%.1]
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: !members:
  85. // CHECK:STDOUT: .Self = constants.%C
  86. // CHECK:STDOUT: extend name_scope1
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: fn @F.1[@I.%self.loc11_8.2: C]() -> i32;
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: fn @F.2[@impl.%self.loc16_10.2: C]() -> i32;
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: fn @F.3(%c: C) -> i32 {
  94. // CHECK:STDOUT: !entry:
  95. // CHECK:STDOUT: %c.ref: C = name_ref c, %c
  96. // CHECK:STDOUT: %F.ref: <associated <function> in I> = name_ref F, @I.%.loc11 [template = constants.%.3]
  97. // CHECK:STDOUT: %.1: <function> = interface_witness_access @impl.%.1, element0 [template = @impl.%F]
  98. // CHECK:STDOUT: %.loc21_11: <bound method> = bound_method %c.ref, %.1
  99. // CHECK:STDOUT: %.loc21_13.1: init i32 = call %.loc21_11(%c.ref)
  100. // CHECK:STDOUT: %.loc21_15: i32 = value_of_initializer %.loc21_13.1
  101. // CHECK:STDOUT: %.loc21_13.2: i32 = converted %.loc21_13.1, %.loc21_15
  102. // CHECK:STDOUT: return %.loc21_13.2
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT: