instance_method.carbon 4.5 KB

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