base_function_unqualified.carbon 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/convert.carbon
  6. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  7. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/base_function_unqualified.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/base_function_unqualified.carbon
  14. base class Base {
  15. fn F();
  16. }
  17. class Derived {
  18. extend base: Base;
  19. fn G() { F(); }
  20. fn H();
  21. }
  22. fn Derived.H() {
  23. F();
  24. }
  25. // CHECK:STDOUT: --- base_function_unqualified.carbon
  26. // CHECK:STDOUT:
  27. // CHECK:STDOUT: constants {
  28. // CHECK:STDOUT: %Base: type = class_type @Base [concrete]
  29. // CHECK:STDOUT: %Base.F.type: type = fn_type @Base.F [concrete]
  30. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  31. // CHECK:STDOUT: %Base.F: %Base.F.type = struct_value () [concrete]
  32. // CHECK:STDOUT: %Destroy.type: type = facet_type <@Destroy> [concrete]
  33. // CHECK:STDOUT: %pattern_type.f6d: type = pattern_type auto [concrete]
  34. // CHECK:STDOUT: %Destroy.impl_witness.31c: <witness> = impl_witness @Base.%Destroy.impl_witness_table [concrete]
  35. // CHECK:STDOUT: %ptr.11f: type = ptr_type %Base [concrete]
  36. // CHECK:STDOUT: %pattern_type.1b9: type = pattern_type %ptr.11f [concrete]
  37. // CHECK:STDOUT: %Base.as.Destroy.impl.Op.type: type = fn_type @Base.as.Destroy.impl.Op [concrete]
  38. // CHECK:STDOUT: %Base.as.Destroy.impl.Op: %Base.as.Destroy.impl.Op.type = struct_value () [concrete]
  39. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  40. // CHECK:STDOUT: %complete_type.357: <witness> = complete_type_witness %empty_struct_type [concrete]
  41. // CHECK:STDOUT: %Derived: type = class_type @Derived [concrete]
  42. // CHECK:STDOUT: %Derived.elem: type = unbound_element_type %Derived, %Base [concrete]
  43. // CHECK:STDOUT: %Derived.G.type: type = fn_type @Derived.G [concrete]
  44. // CHECK:STDOUT: %Derived.G: %Derived.G.type = struct_value () [concrete]
  45. // CHECK:STDOUT: %Derived.H.type: type = fn_type @Derived.H [concrete]
  46. // CHECK:STDOUT: %Derived.H: %Derived.H.type = struct_value () [concrete]
  47. // CHECK:STDOUT: %Destroy.impl_witness.62a: <witness> = impl_witness @Derived.%Destroy.impl_witness_table [concrete]
  48. // CHECK:STDOUT: %ptr.404: type = ptr_type %Derived [concrete]
  49. // CHECK:STDOUT: %pattern_type.605: type = pattern_type %ptr.404 [concrete]
  50. // CHECK:STDOUT: %Derived.as.Destroy.impl.Op.type: type = fn_type @Derived.as.Destroy.impl.Op [concrete]
  51. // CHECK:STDOUT: %Derived.as.Destroy.impl.Op: %Derived.as.Destroy.impl.Op.type = struct_value () [concrete]
  52. // CHECK:STDOUT: %struct_type.base: type = struct_type {.base: %Base} [concrete]
  53. // CHECK:STDOUT: %complete_type.15c: <witness> = complete_type_witness %struct_type.base [concrete]
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: imports {
  57. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  58. // CHECK:STDOUT: .Destroy = %Core.Destroy
  59. // CHECK:STDOUT: import Core//prelude
  60. // CHECK:STDOUT: import Core//prelude/...
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT: %Core.Destroy: type = import_ref Core//prelude/parts/destroy, Destroy, loaded [concrete = constants.%Destroy.type]
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: file {
  66. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  67. // CHECK:STDOUT: .Core = imports.%Core
  68. // CHECK:STDOUT: .Base = %Base.decl
  69. // CHECK:STDOUT: .Derived = %Derived.decl
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT: %Core.import = import Core
  72. // CHECK:STDOUT: %Base.decl: type = class_decl @Base [concrete = constants.%Base] {} {}
  73. // CHECK:STDOUT: %Derived.decl: type = class_decl @Derived [concrete = constants.%Derived] {} {}
  74. // CHECK:STDOUT: %Derived.H.decl: %Derived.H.type = fn_decl @Derived.H [concrete = constants.%Derived.H] {} {}
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: impl @Base.as.Destroy.impl: @Base.%Self.ref as constants.%Destroy.type {
  78. // CHECK:STDOUT: %Base.as.Destroy.impl.Op.decl: %Base.as.Destroy.impl.Op.type = fn_decl @Base.as.Destroy.impl.Op [concrete = constants.%Base.as.Destroy.impl.Op] {
  79. // CHECK:STDOUT: %self.patt: %pattern_type.1b9 = binding_pattern self [concrete]
  80. // CHECK:STDOUT: %self.param_patt: %pattern_type.1b9 = value_param_pattern %self.patt, call_param0 [concrete]
  81. // CHECK:STDOUT: %.loc15: %pattern_type.f6d = addr_pattern %self.param_patt [concrete]
  82. // CHECK:STDOUT: } {
  83. // CHECK:STDOUT: %self.param: %ptr.11f = value_param call_param0
  84. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%Base [concrete = constants.%Base]
  85. // CHECK:STDOUT: %self: %ptr.11f = bind_name self, %self.param
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT:
  88. // CHECK:STDOUT: !members:
  89. // CHECK:STDOUT: .Op = %Base.as.Destroy.impl.Op.decl
  90. // CHECK:STDOUT: witness = @Base.%Destroy.impl_witness
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: impl @Derived.as.Destroy.impl: @Derived.%Self.ref as constants.%Destroy.type {
  94. // CHECK:STDOUT: %Derived.as.Destroy.impl.Op.decl: %Derived.as.Destroy.impl.Op.type = fn_decl @Derived.as.Destroy.impl.Op [concrete = constants.%Derived.as.Destroy.impl.Op] {
  95. // CHECK:STDOUT: %self.patt: %pattern_type.605 = binding_pattern self [concrete]
  96. // CHECK:STDOUT: %self.param_patt: %pattern_type.605 = value_param_pattern %self.patt, call_param0 [concrete]
  97. // CHECK:STDOUT: %.loc19: %pattern_type.f6d = addr_pattern %self.param_patt [concrete]
  98. // CHECK:STDOUT: } {
  99. // CHECK:STDOUT: %self.param: %ptr.404 = value_param call_param0
  100. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%Derived [concrete = constants.%Derived]
  101. // CHECK:STDOUT: %self: %ptr.404 = bind_name self, %self.param
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: !members:
  105. // CHECK:STDOUT: .Op = %Derived.as.Destroy.impl.Op.decl
  106. // CHECK:STDOUT: witness = @Derived.%Destroy.impl_witness
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: class @Base {
  110. // CHECK:STDOUT: %Base.F.decl: %Base.F.type = fn_decl @Base.F [concrete = constants.%Base.F] {} {}
  111. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%Base [concrete = constants.%Base]
  112. // CHECK:STDOUT: impl_decl @Base.as.Destroy.impl [concrete] {} {}
  113. // CHECK:STDOUT: %Destroy.impl_witness_table = impl_witness_table (@Base.as.Destroy.impl.%Base.as.Destroy.impl.Op.decl), @Base.as.Destroy.impl [concrete]
  114. // CHECK:STDOUT: %Destroy.impl_witness: <witness> = impl_witness %Destroy.impl_witness_table [concrete = constants.%Destroy.impl_witness.31c]
  115. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type.357]
  116. // CHECK:STDOUT: complete_type_witness = %complete_type
  117. // CHECK:STDOUT:
  118. // CHECK:STDOUT: !members:
  119. // CHECK:STDOUT: .Self = constants.%Base
  120. // CHECK:STDOUT: .F = %Base.F.decl
  121. // CHECK:STDOUT: }
  122. // CHECK:STDOUT:
  123. // CHECK:STDOUT: class @Derived {
  124. // CHECK:STDOUT: %Base.ref: type = name_ref Base, file.%Base.decl [concrete = constants.%Base]
  125. // CHECK:STDOUT: %.loc20: %Derived.elem = base_decl %Base.ref, element0 [concrete]
  126. // CHECK:STDOUT: %Derived.G.decl: %Derived.G.type = fn_decl @Derived.G [concrete = constants.%Derived.G] {} {}
  127. // CHECK:STDOUT: %Derived.H.decl: %Derived.H.type = fn_decl @Derived.H [concrete = constants.%Derived.H] {} {}
  128. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%Derived [concrete = constants.%Derived]
  129. // CHECK:STDOUT: impl_decl @Derived.as.Destroy.impl [concrete] {} {}
  130. // CHECK:STDOUT: %Destroy.impl_witness_table = impl_witness_table (@Derived.as.Destroy.impl.%Derived.as.Destroy.impl.Op.decl), @Derived.as.Destroy.impl [concrete]
  131. // CHECK:STDOUT: %Destroy.impl_witness: <witness> = impl_witness %Destroy.impl_witness_table [concrete = constants.%Destroy.impl_witness.62a]
  132. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%struct_type.base [concrete = constants.%complete_type.15c]
  133. // CHECK:STDOUT: complete_type_witness = %complete_type
  134. // CHECK:STDOUT:
  135. // CHECK:STDOUT: !members:
  136. // CHECK:STDOUT: .Self = constants.%Derived
  137. // CHECK:STDOUT: .Base = <poisoned>
  138. // CHECK:STDOUT: .base = %.loc20
  139. // CHECK:STDOUT: .G = %Derived.G.decl
  140. // CHECK:STDOUT: .H = %Derived.H.decl
  141. // CHECK:STDOUT: .F = <poisoned>
  142. // CHECK:STDOUT: extend %Base.ref
  143. // CHECK:STDOUT: }
  144. // CHECK:STDOUT:
  145. // CHECK:STDOUT: fn @Base.F();
  146. // CHECK:STDOUT:
  147. // CHECK:STDOUT: fn @Base.as.Destroy.impl.Op(%self.param: %ptr.11f) = "no_op";
  148. // CHECK:STDOUT:
  149. // CHECK:STDOUT: fn @Derived.G() {
  150. // CHECK:STDOUT: !entry:
  151. // CHECK:STDOUT: %F.ref: %Base.F.type = name_ref F, @Base.%Base.F.decl [concrete = constants.%Base.F]
  152. // CHECK:STDOUT: %Base.F.call: init %empty_tuple.type = call %F.ref()
  153. // CHECK:STDOUT: return
  154. // CHECK:STDOUT: }
  155. // CHECK:STDOUT:
  156. // CHECK:STDOUT: fn @Derived.H() {
  157. // CHECK:STDOUT: !entry:
  158. // CHECK:STDOUT: %F.ref: %Base.F.type = name_ref F, @Base.%Base.F.decl [concrete = constants.%Base.F]
  159. // CHECK:STDOUT: %Base.F.call: init %empty_tuple.type = call %F.ref()
  160. // CHECK:STDOUT: return
  161. // CHECK:STDOUT: }
  162. // CHECK:STDOUT:
  163. // CHECK:STDOUT: fn @Derived.as.Destroy.impl.Op(%self.param: %ptr.404) = "no_op";
  164. // CHECK:STDOUT: