instance_method.carbon 4.6 KB

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