instance_method.carbon 5.1 KB

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