compound.carbon 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. // CHECK:STDOUT: --- compound.carbon
  21. // CHECK:STDOUT:
  22. // CHECK:STDOUT: constants {
  23. // CHECK:STDOUT: %.1: type = interface_type @Simple [template]
  24. // CHECK:STDOUT: %.2: type = assoc_entity_type @Simple, <function> [template]
  25. // CHECK:STDOUT: %.3: <associated <function> in Simple> = assoc_entity element0, @Simple.%F [template]
  26. // CHECK:STDOUT: %.4: <associated <function> in Simple> = assoc_entity element1, @Simple.%G [template]
  27. // CHECK:STDOUT: %.5: <witness> = interface_witness (@impl.%F, @impl.%G) [template]
  28. // CHECK:STDOUT: %.6: type = tuple_type () [template]
  29. // CHECK:STDOUT: }
  30. // CHECK:STDOUT:
  31. // CHECK:STDOUT: file {
  32. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  33. // CHECK:STDOUT: .Simple = %Simple.decl
  34. // CHECK:STDOUT: .NonInstanceCall = %NonInstanceCall
  35. // CHECK:STDOUT: .InstanceCall = %InstanceCall
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT: %Simple.decl: type = interface_decl @Simple [template = constants.%.1] {}
  38. // CHECK:STDOUT: impl_decl @impl {
  39. // CHECK:STDOUT: %Simple.ref: type = name_ref Simple, %Simple.decl [template = constants.%.1]
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT: %NonInstanceCall: <function> = fn_decl @NonInstanceCall [template] {
  42. // CHECK:STDOUT: %n.loc17_20.1: i32 = param n
  43. // CHECK:STDOUT: @NonInstanceCall.%n: i32 = bind_name n, %n.loc17_20.1
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT: %InstanceCall: <function> = fn_decl @InstanceCall [template] {
  46. // CHECK:STDOUT: %n.loc21_17.1: i32 = param n
  47. // CHECK:STDOUT: @InstanceCall.%n: i32 = bind_name n, %n.loc21_17.1
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: interface @Simple {
  52. // CHECK:STDOUT: %Self: Simple = bind_symbolic_name Self [symbolic]
  53. // CHECK:STDOUT: %F: <function> = fn_decl @F.1 [template] {}
  54. // CHECK:STDOUT: %.loc8: <associated <function> in Simple> = assoc_entity element0, %F [template = constants.%.3]
  55. // CHECK:STDOUT: %G: <function> = fn_decl @G.1 [template] {
  56. // CHECK:STDOUT: %Self.ref: Simple = name_ref Self, %Self [symbolic = %Self]
  57. // CHECK:STDOUT: %.loc9_14.1: type = facet_type_access %Self.ref [symbolic = %Self]
  58. // CHECK:STDOUT: %.loc9_14.2: type = converted %Self.ref, %.loc9_14.1 [symbolic = %Self]
  59. // CHECK:STDOUT: %self.loc9_8.1: Self = param self
  60. // CHECK:STDOUT: %self.loc9_8.2: Self = bind_name self, %self.loc9_8.1
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT: %.loc9_21: <associated <function> in Simple> = assoc_entity element1, %G [template = constants.%.4]
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: !members:
  65. // CHECK:STDOUT: .Self = %Self
  66. // CHECK:STDOUT: .F = %.loc8
  67. // CHECK:STDOUT: .G = %.loc9_21
  68. // CHECK:STDOUT: witness = (%F, %G)
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: impl @impl: i32 as Simple {
  72. // CHECK:STDOUT: %F: <function> = fn_decl @F.2 [template] {}
  73. // CHECK:STDOUT: %G: <function> = fn_decl @G.2 [template] {
  74. // CHECK:STDOUT: %self.loc14_8.1: i32 = param self
  75. // CHECK:STDOUT: %self.loc14_8.2: i32 = bind_name self, %self.loc14_8.1
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT: %.1: <witness> = interface_witness (%F, %G) [template = constants.%.5]
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: !members:
  80. // CHECK:STDOUT: .F = %F
  81. // CHECK:STDOUT: .G = %G
  82. // CHECK:STDOUT: witness = %.1
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: fn @F.1();
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: fn @G.1[@Simple.%self.loc9_8.2: Self]();
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: fn @F.2();
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: fn @G.2[@impl.%self.loc14_8.2: i32]();
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: fn @NonInstanceCall(%n: i32) {
  94. // CHECK:STDOUT: !entry:
  95. // CHECK:STDOUT: %n.ref: i32 = name_ref n, %n
  96. // CHECK:STDOUT: %Simple.ref: type = name_ref Simple, file.%Simple.decl [template = constants.%.1]
  97. // CHECK:STDOUT: %F.ref: <associated <function> in Simple> = name_ref F, @Simple.%.loc8 [template = constants.%.3]
  98. // CHECK:STDOUT: %.1: <function> = interface_witness_access @impl.%.1, element0 [template = @impl.%F]
  99. // CHECK:STDOUT: %.loc18: init () = call %.1()
  100. // CHECK:STDOUT: return
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: fn @InstanceCall(%n: i32) {
  104. // CHECK:STDOUT: !entry:
  105. // CHECK:STDOUT: %n.ref: i32 = name_ref n, %n
  106. // CHECK:STDOUT: %Simple.ref: type = name_ref Simple, file.%Simple.decl [template = constants.%.1]
  107. // CHECK:STDOUT: %G.ref: <associated <function> in Simple> = name_ref G, @Simple.%.loc9_21 [template = constants.%.4]
  108. // CHECK:STDOUT: %.1: <function> = interface_witness_access @impl.%.1, element1 [template = @impl.%G]
  109. // CHECK:STDOUT: %.loc22_4: <bound method> = bound_method %n.ref, %.1
  110. // CHECK:STDOUT: %.loc22_15: init () = call %.loc22_4(%n.ref)
  111. // CHECK:STDOUT: return
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT: