method.carbon 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 I {
  7. fn F[self: Self](other: Self) -> Self;
  8. }
  9. impl i32 as I {
  10. fn F[self: i32](other: i32) -> i32 = "int.sadd";
  11. }
  12. var arr: [i32; 1.(I.F)(2)];
  13. // CHECK:STDOUT: --- method.carbon
  14. // CHECK:STDOUT:
  15. // CHECK:STDOUT: constants {
  16. // CHECK:STDOUT: %.1: type = interface_type @I [template]
  17. // CHECK:STDOUT: %.2: type = assoc_entity_type @I, <function> [template]
  18. // CHECK:STDOUT: %.3: <associated <function> in I> = assoc_entity element0, @I.%F [template]
  19. // CHECK:STDOUT: %.4: <witness> = interface_witness (@impl.%F) [template]
  20. // CHECK:STDOUT: %.5: i32 = int_literal 1 [template]
  21. // CHECK:STDOUT: %.6: <bound method> = bound_method %.5, @impl.%F [template]
  22. // CHECK:STDOUT: %.7: i32 = int_literal 2 [template]
  23. // CHECK:STDOUT: %.8: i32 = int_literal 3 [template]
  24. // CHECK:STDOUT: %.9: type = array_type %.8, i32 [template]
  25. // CHECK:STDOUT: %.10: type = ptr_type [i32; 3] [template]
  26. // CHECK:STDOUT: }
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: file {
  29. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  30. // CHECK:STDOUT: .Core = %Core
  31. // CHECK:STDOUT: .I = %I.decl
  32. // CHECK:STDOUT: .arr = %arr
  33. // CHECK:STDOUT: }
  34. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  35. // CHECK:STDOUT: %I.decl: type = interface_decl @I [template = constants.%.1] {}
  36. // CHECK:STDOUT: impl_decl @impl {
  37. // CHECK:STDOUT: %I.ref.loc11: type = name_ref I, %I.decl [template = constants.%.1]
  38. // CHECK:STDOUT: }
  39. // CHECK:STDOUT: %.loc15_16: i32 = int_literal 1 [template = constants.%.5]
  40. // CHECK:STDOUT: %I.ref.loc15: type = name_ref I, %I.decl [template = constants.%.1]
  41. // CHECK:STDOUT: %F.ref: <associated <function> in I> = name_ref F, @I.%.loc8_40 [template = constants.%.3]
  42. // CHECK:STDOUT: %.1: <function> = interface_witness_access @impl.%.1, element0 [template = @impl.%F]
  43. // CHECK:STDOUT: %.loc15_17: <bound method> = bound_method %.loc15_16, %.1 [template = constants.%.6]
  44. // CHECK:STDOUT: %.loc15_24: i32 = int_literal 2 [template = constants.%.7]
  45. // CHECK:STDOUT: %int.sadd: init i32 = call %.loc15_17(%.loc15_16, %.loc15_24) [template = constants.%.8]
  46. // CHECK:STDOUT: %.loc15_26: type = array_type %int.sadd, i32 [template = constants.%.9]
  47. // CHECK:STDOUT: %arr.var: ref [i32; 3] = var arr
  48. // CHECK:STDOUT: %arr: ref [i32; 3] = bind_name arr, %arr.var
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: interface @I {
  52. // CHECK:STDOUT: %Self: I = bind_symbolic_name Self [symbolic]
  53. // CHECK:STDOUT: %F: <function> = fn_decl @F.1 [template] {
  54. // CHECK:STDOUT: %Self.ref.loc8_14: I = name_ref Self, %Self [symbolic = %Self]
  55. // CHECK:STDOUT: %.loc8_14.1: type = facet_type_access %Self.ref.loc8_14 [symbolic = %Self]
  56. // CHECK:STDOUT: %.loc8_14.2: type = converted %Self.ref.loc8_14, %.loc8_14.1 [symbolic = %Self]
  57. // CHECK:STDOUT: %self.loc8_8.1: Self = param self
  58. // CHECK:STDOUT: %self.loc8_8.2: Self = bind_name self, %self.loc8_8.1
  59. // CHECK:STDOUT: %Self.ref.loc8_27: I = name_ref Self, %Self [symbolic = %Self]
  60. // CHECK:STDOUT: %.loc8_27.1: type = facet_type_access %Self.ref.loc8_27 [symbolic = %Self]
  61. // CHECK:STDOUT: %.loc8_27.2: type = converted %Self.ref.loc8_27, %.loc8_27.1 [symbolic = %Self]
  62. // CHECK:STDOUT: %other.loc8_20.1: Self = param other
  63. // CHECK:STDOUT: %other.loc8_20.2: Self = bind_name other, %other.loc8_20.1
  64. // CHECK:STDOUT: %Self.ref.loc8_36: I = name_ref Self, %Self [symbolic = %Self]
  65. // CHECK:STDOUT: %.loc8_36.1: type = facet_type_access %Self.ref.loc8_36 [symbolic = %Self]
  66. // CHECK:STDOUT: %.loc8_36.2: type = converted %Self.ref.loc8_36, %.loc8_36.1 [symbolic = %Self]
  67. // CHECK:STDOUT: %return.var: ref Self = var <return slot>
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT: %.loc8_40: <associated <function> in I> = assoc_entity element0, %F [template = constants.%.3]
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: !members:
  72. // CHECK:STDOUT: .Self = %Self
  73. // CHECK:STDOUT: .F = %.loc8_40
  74. // CHECK:STDOUT: witness = (%F)
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: impl @impl: i32 as I {
  78. // CHECK:STDOUT: %F: <function> = fn_decl @F.2 [template] {
  79. // CHECK:STDOUT: %self.loc12_8.1: i32 = param self
  80. // CHECK:STDOUT: %self.loc12_8.2: i32 = bind_name self, %self.loc12_8.1
  81. // CHECK:STDOUT: %other.loc12_19.1: i32 = param other
  82. // CHECK:STDOUT: %other.loc12_19.2: i32 = bind_name other, %other.loc12_19.1
  83. // CHECK:STDOUT: %return.var: ref i32 = var <return slot>
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT: %.1: <witness> = interface_witness (%F) [template = constants.%.4]
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: !members:
  88. // CHECK:STDOUT: .F = %F
  89. // CHECK:STDOUT: witness = %.1
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: fn @F.1[@I.%self.loc8_8.2: Self](@I.%other.loc8_20.2: Self) -> Self;
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: fn @F.2[@impl.%self.loc12_8.2: i32](@impl.%other.loc12_19.2: i32) -> i32 = "int.sadd";
  95. // CHECK:STDOUT: