compound.carbon 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 Simple {
  7. fn F();
  8. fn G[self: Self]();
  9. }
  10. impl i32 as Simple {
  11. fn F();
  12. fn G[self: i32]();
  13. }
  14. fn NonInstanceCall(n: i32) {
  15. n.(Simple.F)();
  16. }
  17. fn InstanceCall(n: i32) {
  18. n.(Simple.G)();
  19. }
  20. fn NonInstanceCallIndirect(p: i32*) {
  21. p->(Simple.F)();
  22. }
  23. fn InstanceCallIndirect(p: i32*) {
  24. p->(Simple.G)();
  25. }
  26. // CHECK:STDOUT: --- compound.carbon
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: constants {
  29. // CHECK:STDOUT: %.1: type = interface_type @Simple [template]
  30. // CHECK:STDOUT: %.2: type = assoc_entity_type @Simple, <function> [template]
  31. // CHECK:STDOUT: %.3: <associated <function> in Simple> = assoc_entity element0, @Simple.%F [template]
  32. // CHECK:STDOUT: %.4: <associated <function> in Simple> = assoc_entity element1, @Simple.%G [template]
  33. // CHECK:STDOUT: %.5: <witness> = interface_witness (@impl.%F, @impl.%G) [template]
  34. // CHECK:STDOUT: %.6: type = tuple_type () [template]
  35. // CHECK:STDOUT: %.7: type = ptr_type i32 [template]
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: file {
  39. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  40. // CHECK:STDOUT: .Simple = %Simple.decl
  41. // CHECK:STDOUT: .NonInstanceCall = %NonInstanceCall
  42. // CHECK:STDOUT: .InstanceCall = %InstanceCall
  43. // CHECK:STDOUT: .NonInstanceCallIndirect = %NonInstanceCallIndirect
  44. // CHECK:STDOUT: .InstanceCallIndirect = %InstanceCallIndirect
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT: %Simple.decl: type = interface_decl @Simple [template = constants.%.1] {}
  47. // CHECK:STDOUT: impl_decl @impl {
  48. // CHECK:STDOUT: %Simple.ref: type = name_ref Simple, %Simple.decl [template = constants.%.1]
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT: %NonInstanceCall: <function> = fn_decl @NonInstanceCall [template] {
  51. // CHECK:STDOUT: %n.loc17_20.1: i32 = param n
  52. // CHECK:STDOUT: @NonInstanceCall.%n: i32 = bind_name n, %n.loc17_20.1
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: %InstanceCall: <function> = fn_decl @InstanceCall [template] {
  55. // CHECK:STDOUT: %n.loc21_17.1: i32 = param n
  56. // CHECK:STDOUT: @InstanceCall.%n: i32 = bind_name n, %n.loc21_17.1
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT: %NonInstanceCallIndirect: <function> = fn_decl @NonInstanceCallIndirect [template] {
  59. // CHECK:STDOUT: %.loc25: type = ptr_type i32 [template = constants.%.7]
  60. // CHECK:STDOUT: %p.loc25_28.1: i32* = param p
  61. // CHECK:STDOUT: @NonInstanceCallIndirect.%p: i32* = bind_name p, %p.loc25_28.1
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT: %InstanceCallIndirect: <function> = fn_decl @InstanceCallIndirect [template] {
  64. // CHECK:STDOUT: %.loc29: type = ptr_type i32 [template = constants.%.7]
  65. // CHECK:STDOUT: %p.loc29_25.1: i32* = param p
  66. // CHECK:STDOUT: @InstanceCallIndirect.%p: i32* = bind_name p, %p.loc29_25.1
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: interface @Simple {
  71. // CHECK:STDOUT: %Self: Simple = bind_symbolic_name Self [symbolic]
  72. // CHECK:STDOUT: %F: <function> = fn_decl @F.1 [template] {}
  73. // CHECK:STDOUT: %.loc8: <associated <function> in Simple> = assoc_entity element0, %F [template = constants.%.3]
  74. // CHECK:STDOUT: %G: <function> = fn_decl @G.1 [template] {
  75. // CHECK:STDOUT: %Self.ref: Simple = name_ref Self, %Self [symbolic = %Self]
  76. // CHECK:STDOUT: %.loc9_14.1: type = facet_type_access %Self.ref [symbolic = %Self]
  77. // CHECK:STDOUT: %.loc9_14.2: type = converted %Self.ref, %.loc9_14.1 [symbolic = %Self]
  78. // CHECK:STDOUT: %self.loc9_8.1: Self = param self
  79. // CHECK:STDOUT: %self.loc9_8.2: Self = bind_name self, %self.loc9_8.1
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT: %.loc9_21: <associated <function> in Simple> = assoc_entity element1, %G [template = constants.%.4]
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: !members:
  84. // CHECK:STDOUT: .Self = %Self
  85. // CHECK:STDOUT: .F = %.loc8
  86. // CHECK:STDOUT: .G = %.loc9_21
  87. // CHECK:STDOUT: witness = (%F, %G)
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: impl @impl: i32 as Simple {
  91. // CHECK:STDOUT: %F: <function> = fn_decl @F.2 [template] {}
  92. // CHECK:STDOUT: %G: <function> = fn_decl @G.2 [template] {
  93. // CHECK:STDOUT: %self.loc14_8.1: i32 = param self
  94. // CHECK:STDOUT: %self.loc14_8.2: i32 = bind_name self, %self.loc14_8.1
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT: %.1: <witness> = interface_witness (%F, %G) [template = constants.%.5]
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: !members:
  99. // CHECK:STDOUT: .F = %F
  100. // CHECK:STDOUT: .G = %G
  101. // CHECK:STDOUT: witness = %.1
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: fn @F.1();
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: fn @G.1[@Simple.%self.loc9_8.2: Self]();
  107. // CHECK:STDOUT:
  108. // CHECK:STDOUT: fn @F.2();
  109. // CHECK:STDOUT:
  110. // CHECK:STDOUT: fn @G.2[@impl.%self.loc14_8.2: i32]();
  111. // CHECK:STDOUT:
  112. // CHECK:STDOUT: fn @NonInstanceCall(%n: i32) {
  113. // CHECK:STDOUT: !entry:
  114. // CHECK:STDOUT: %n.ref: i32 = name_ref n, %n
  115. // CHECK:STDOUT: %Simple.ref: type = name_ref Simple, file.%Simple.decl [template = constants.%.1]
  116. // CHECK:STDOUT: %F.ref: <associated <function> in Simple> = name_ref F, @Simple.%.loc8 [template = constants.%.3]
  117. // CHECK:STDOUT: %.1: <function> = interface_witness_access @impl.%.1, element0 [template = @impl.%F]
  118. // CHECK:STDOUT: %.loc18: init () = call %.1()
  119. // CHECK:STDOUT: return
  120. // CHECK:STDOUT: }
  121. // CHECK:STDOUT:
  122. // CHECK:STDOUT: fn @InstanceCall(%n: i32) {
  123. // CHECK:STDOUT: !entry:
  124. // CHECK:STDOUT: %n.ref: i32 = name_ref n, %n
  125. // CHECK:STDOUT: %Simple.ref: type = name_ref Simple, file.%Simple.decl [template = constants.%.1]
  126. // CHECK:STDOUT: %G.ref: <associated <function> in Simple> = name_ref G, @Simple.%.loc9_21 [template = constants.%.4]
  127. // CHECK:STDOUT: %.1: <function> = interface_witness_access @impl.%.1, element1 [template = @impl.%G]
  128. // CHECK:STDOUT: %.loc22_4: <bound method> = bound_method %n.ref, %.1
  129. // CHECK:STDOUT: %.loc22_15: init () = call %.loc22_4(%n.ref)
  130. // CHECK:STDOUT: return
  131. // CHECK:STDOUT: }
  132. // CHECK:STDOUT:
  133. // CHECK:STDOUT: fn @NonInstanceCallIndirect(%p: i32*) {
  134. // CHECK:STDOUT: !entry:
  135. // CHECK:STDOUT: %p.ref: i32* = name_ref p, %p
  136. // CHECK:STDOUT: %Simple.ref: type = name_ref Simple, file.%Simple.decl [template = constants.%.1]
  137. // CHECK:STDOUT: %F.ref: <associated <function> in Simple> = name_ref F, @Simple.%.loc8 [template = constants.%.3]
  138. // CHECK:STDOUT: %.loc26_4: ref i32 = deref %p.ref
  139. // CHECK:STDOUT: %.1: <function> = interface_witness_access @impl.%.1, element0 [template = @impl.%F]
  140. // CHECK:STDOUT: %.loc26_16: init () = call %.1()
  141. // CHECK:STDOUT: return
  142. // CHECK:STDOUT: }
  143. // CHECK:STDOUT:
  144. // CHECK:STDOUT: fn @InstanceCallIndirect(%p: i32*) {
  145. // CHECK:STDOUT: !entry:
  146. // CHECK:STDOUT: %p.ref: i32* = name_ref p, %p
  147. // CHECK:STDOUT: %Simple.ref: type = name_ref Simple, file.%Simple.decl [template = constants.%.1]
  148. // CHECK:STDOUT: %G.ref: <associated <function> in Simple> = name_ref G, @Simple.%.loc9_21 [template = constants.%.4]
  149. // CHECK:STDOUT: %.loc30_4.1: ref i32 = deref %p.ref
  150. // CHECK:STDOUT: %.1: <function> = interface_witness_access @impl.%.1, element1 [template = @impl.%G]
  151. // CHECK:STDOUT: %.loc30_4.2: <bound method> = bound_method %.loc30_4.1, %.1
  152. // CHECK:STDOUT: %.loc30_4.3: i32 = bind_value %.loc30_4.1
  153. // CHECK:STDOUT: %.loc30_16: init () = call %.loc30_4.2(%.loc30_4.3)
  154. // CHECK:STDOUT: return
  155. // CHECK:STDOUT: }
  156. // CHECK:STDOUT: