method.carbon 4.9 KB

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