method.carbon 5.5 KB

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