generic_method.carbon 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/generic_method.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/generic_method.carbon
  10. class Class(T:! type) {
  11. var a: T;
  12. fn F[self: Self](n: T);
  13. }
  14. fn Class(T:! type).F[self: Self](n: T) {}
  15. // CHECK:STDOUT: --- generic_method.carbon
  16. // CHECK:STDOUT:
  17. // CHECK:STDOUT: constants {
  18. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  19. // CHECK:STDOUT: %Class.type: type = generic_class_type @Class [template]
  20. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  21. // CHECK:STDOUT: %Class.1: %Class.type = struct_value () [template]
  22. // CHECK:STDOUT: %Class.2: type = class_type @Class, @Class(%T) [symbolic]
  23. // CHECK:STDOUT: %.2: type = unbound_element_type %Class.2, %T [symbolic]
  24. // CHECK:STDOUT: %F.type: type = fn_type @F, @Class(%T) [symbolic]
  25. // CHECK:STDOUT: %F: %F.type = struct_value () [symbolic]
  26. // CHECK:STDOUT: %.3: type = struct_type {.a: %T} [symbolic]
  27. // CHECK:STDOUT: %.4: type = ptr_type %.3 [symbolic]
  28. // CHECK:STDOUT: }
  29. // CHECK:STDOUT:
  30. // CHECK:STDOUT: imports {
  31. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  32. // CHECK:STDOUT: import Core//prelude
  33. // CHECK:STDOUT: import Core//prelude/operators
  34. // CHECK:STDOUT: import Core//prelude/types
  35. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  36. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  37. // CHECK:STDOUT: import Core//prelude/operators/comparison
  38. // CHECK:STDOUT: import Core//prelude/types/bool
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: file {
  43. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  44. // CHECK:STDOUT: .Core = imports.%Core
  45. // CHECK:STDOUT: .Class = %Class.decl
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT: %Core.import = import Core
  48. // CHECK:STDOUT: %Class.decl: %Class.type = class_decl @Class [template = constants.%Class.1] {
  49. // CHECK:STDOUT: %T.loc11_13.1: type = param T
  50. // CHECK:STDOUT: %T.loc11_13.2: type = bind_symbolic_name T 0, %T.loc11_13.1 [symbolic = @Class.%T (constants.%T)]
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [symbolic = constants.%F] {
  53. // CHECK:STDOUT: %T.loc16_10.1: type = param T
  54. // CHECK:STDOUT: %T.loc16_10.2: type = bind_symbolic_name T 0, %T.loc16_10.1 [symbolic = constants.%T]
  55. // CHECK:STDOUT: %.loc16: type = specific_constant constants.%Class.2, @Class(constants.%T) [symbolic = constants.%Class.2]
  56. // CHECK:STDOUT: %Self.ref: type = name_ref Self, %.loc16 [symbolic = constants.%Class.2]
  57. // CHECK:STDOUT: %self.loc16_22.1: %Class.2 = param self
  58. // CHECK:STDOUT: @F.%self: %Class.2 = bind_name self, %self.loc16_22.1
  59. // CHECK:STDOUT: %T.ref: type = name_ref T, %T.loc16_10.2 [symbolic = constants.%T]
  60. // CHECK:STDOUT: %n.loc16_34.1: %T = param n
  61. // CHECK:STDOUT: @F.%n: %T = bind_name n, %n.loc16_34.1
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: generic class @Class(file.%T.loc11_13.2: type) {
  66. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: !definition:
  69. // CHECK:STDOUT: %Class: type = class_type @Class, @Class(%T) [symbolic = %Class (constants.%Class.2)]
  70. // CHECK:STDOUT: %.1: type = unbound_element_type @Class.%Class (%Class.2), @Class.%T (%T) [symbolic = %.1 (constants.%.2)]
  71. // CHECK:STDOUT: %F.type: type = fn_type @F, @Class(%T) [symbolic = %F.type (constants.%F.type)]
  72. // CHECK:STDOUT: %F: @Class.%F.type (%F.type) = struct_value () [symbolic = %F (constants.%F)]
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: class {
  75. // CHECK:STDOUT: %T.ref.loc12: type = name_ref T, file.%T.loc11_13.2 [symbolic = %T (constants.%T)]
  76. // CHECK:STDOUT: %.loc12: @Class.%.1 (%.2) = field_decl a, element0 [template]
  77. // CHECK:STDOUT: %F.decl: @Class.%F.type (%F.type) = fn_decl @F [symbolic = %F (constants.%F)] {
  78. // CHECK:STDOUT: %.loc13: type = specific_constant constants.%Class.2, @Class(constants.%T) [symbolic = @F.%Class (constants.%Class.2)]
  79. // CHECK:STDOUT: %Self.ref: type = name_ref Self, %.loc13 [symbolic = @F.%Class (constants.%Class.2)]
  80. // CHECK:STDOUT: %self.loc13_8.1: @F.%Class (%Class.2) = param self
  81. // CHECK:STDOUT: %self.loc13_8.2: @F.%Class (%Class.2) = bind_name self, %self.loc13_8.1
  82. // CHECK:STDOUT: %T.ref.loc13: type = name_ref T, file.%T.loc11_13.2 [symbolic = @F.%T (constants.%T)]
  83. // CHECK:STDOUT: %n.loc13_20.1: @F.%T (%T) = param n
  84. // CHECK:STDOUT: %n.loc13_20.2: @F.%T (%T) = bind_name n, %n.loc13_20.1
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: !members:
  88. // CHECK:STDOUT: .Self = constants.%Class.2
  89. // CHECK:STDOUT: .a = %.loc12
  90. // CHECK:STDOUT: .F = %F.decl
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: generic fn @F(file.%T.loc11_13.2: type) {
  95. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  96. // CHECK:STDOUT: %Class: type = class_type @Class, @Class(%T) [symbolic = %Class (constants.%Class.2)]
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: !definition:
  99. // CHECK:STDOUT:
  100. // CHECK:STDOUT: fn[%self: %Class.2](%n: %T) {
  101. // CHECK:STDOUT: !entry:
  102. // CHECK:STDOUT: return
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT: }
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: specific @Class(constants.%T) {
  107. // CHECK:STDOUT: %T => constants.%T
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: !definition:
  110. // CHECK:STDOUT: %Class => constants.%Class.2
  111. // CHECK:STDOUT: %.1 => constants.%.2
  112. // CHECK:STDOUT: %F.type => constants.%F.type
  113. // CHECK:STDOUT: %F => constants.%F
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT:
  116. // CHECK:STDOUT: specific @Class(@F.%T) {
  117. // CHECK:STDOUT: %T => constants.%T
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT:
  120. // CHECK:STDOUT: specific @F(constants.%T) {
  121. // CHECK:STDOUT: %T => constants.%T
  122. // CHECK:STDOUT: %Class => constants.%Class.2
  123. // CHECK:STDOUT: }
  124. // CHECK:STDOUT:
  125. // CHECK:STDOUT: specific @Class(@Class.%T) {
  126. // CHECK:STDOUT: %T => constants.%T
  127. // CHECK:STDOUT: }
  128. // CHECK:STDOUT: