member_inline.carbon 6.8 KB

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