alias.carbon 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  6. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  7. //
  8. // AUTOUPDATE
  9. // TIP: To test this file alone, run:
  10. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/impl/lookup/alias.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/lookup/alias.carbon
  13. interface HasF {
  14. fn F();
  15. }
  16. class C {
  17. alias G = HasF.F;
  18. }
  19. impl C as HasF {
  20. fn F() {}
  21. }
  22. fn G(c: C) {
  23. C.G();
  24. c.G();
  25. }
  26. // CHECK:STDOUT: --- alias.carbon
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: constants {
  29. // CHECK:STDOUT: %HasF.type: type = facet_type <@HasF> [concrete]
  30. // CHECK:STDOUT: %Self: %HasF.type = bind_symbolic_name Self, 0 [symbolic]
  31. // CHECK:STDOUT: %F.type.b7b: type = fn_type @F.1 [concrete]
  32. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  33. // CHECK:STDOUT: %F.f50: %F.type.b7b = struct_value () [concrete]
  34. // CHECK:STDOUT: %HasF.assoc_type: type = assoc_entity_type @HasF [concrete]
  35. // CHECK:STDOUT: %assoc0: %HasF.assoc_type = assoc_entity element0, @HasF.%F.decl [concrete]
  36. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  37. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  38. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  39. // CHECK:STDOUT: %HasF.impl_witness: <witness> = impl_witness file.%HasF.impl_witness_table [concrete]
  40. // CHECK:STDOUT: %F.type.a02: type = fn_type @F.2 [concrete]
  41. // CHECK:STDOUT: %F.dc7: %F.type.a02 = struct_value () [concrete]
  42. // CHECK:STDOUT: %HasF.facet: %HasF.type = facet_value %C, (%HasF.impl_witness) [concrete]
  43. // CHECK:STDOUT: %pattern_type: type = pattern_type %C [concrete]
  44. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  45. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  46. // CHECK:STDOUT: %.fec: type = fn_type_with_self_type %F.type.b7b, %HasF.facet [concrete]
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: imports {
  50. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  51. // CHECK:STDOUT: import Core//prelude
  52. // CHECK:STDOUT: import Core//prelude/...
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: file {
  57. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  58. // CHECK:STDOUT: .Core = imports.%Core
  59. // CHECK:STDOUT: .HasF = %HasF.decl
  60. // CHECK:STDOUT: .C = %C.decl
  61. // CHECK:STDOUT: .G = %G.decl
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT: %Core.import = import Core
  64. // CHECK:STDOUT: %HasF.decl: type = interface_decl @HasF [concrete = constants.%HasF.type] {} {}
  65. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  66. // CHECK:STDOUT: impl_decl @impl [concrete] {} {
  67. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  68. // CHECK:STDOUT: %HasF.ref: type = name_ref HasF, file.%HasF.decl [concrete = constants.%HasF.type]
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT: %HasF.impl_witness_table = impl_witness_table (@impl.%F.decl), @impl [concrete]
  71. // CHECK:STDOUT: %HasF.impl_witness: <witness> = impl_witness %HasF.impl_witness_table [concrete = constants.%HasF.impl_witness]
  72. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {
  73. // CHECK:STDOUT: %c.patt: %pattern_type = binding_pattern c [concrete]
  74. // CHECK:STDOUT: %c.param_patt: %pattern_type = value_param_pattern %c.patt, call_param0 [concrete]
  75. // CHECK:STDOUT: } {
  76. // CHECK:STDOUT: %c.param: %C = value_param call_param0
  77. // CHECK:STDOUT: %C.ref.loc26: type = name_ref C, file.%C.decl [concrete = constants.%C]
  78. // CHECK:STDOUT: %c: %C = bind_name c, %c.param
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: interface @HasF {
  83. // CHECK:STDOUT: %Self: %HasF.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
  84. // CHECK:STDOUT: %F.decl: %F.type.b7b = fn_decl @F.1 [concrete = constants.%F.f50] {} {}
  85. // CHECK:STDOUT: %assoc0: %HasF.assoc_type = assoc_entity element0, %F.decl [concrete = constants.%assoc0]
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: !members:
  88. // CHECK:STDOUT: .Self = %Self
  89. // CHECK:STDOUT: .F = %assoc0
  90. // CHECK:STDOUT: witness = (%F.decl)
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: impl @impl: %C.ref as %HasF.ref {
  94. // CHECK:STDOUT: %F.decl: %F.type.a02 = fn_decl @F.2 [concrete = constants.%F.dc7] {} {}
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: !members:
  97. // CHECK:STDOUT: .F = %F.decl
  98. // CHECK:STDOUT: witness = file.%HasF.impl_witness
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: class @C {
  102. // CHECK:STDOUT: %HasF.ref: type = name_ref HasF, file.%HasF.decl [concrete = constants.%HasF.type]
  103. // CHECK:STDOUT: %F.ref: %HasF.assoc_type = name_ref F, @HasF.%assoc0 [concrete = constants.%assoc0]
  104. // CHECK:STDOUT: %G: %HasF.assoc_type = bind_alias G, @HasF.%assoc0 [concrete = constants.%assoc0]
  105. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  106. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
  107. // CHECK:STDOUT: complete_type_witness = %complete_type
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: !members:
  110. // CHECK:STDOUT: .Self = constants.%C
  111. // CHECK:STDOUT: .HasF = <poisoned>
  112. // CHECK:STDOUT: .G = %G
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT:
  115. // CHECK:STDOUT: generic fn @F.1(@HasF.%Self: %HasF.type) {
  116. // CHECK:STDOUT: fn();
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: fn @F.2() {
  120. // CHECK:STDOUT: !entry:
  121. // CHECK:STDOUT: return
  122. // CHECK:STDOUT: }
  123. // CHECK:STDOUT:
  124. // CHECK:STDOUT: fn @G(%c.param: %C) {
  125. // CHECK:STDOUT: !entry:
  126. // CHECK:STDOUT: %C.ref.loc27: type = name_ref C, file.%C.decl [concrete = constants.%C]
  127. // CHECK:STDOUT: %G.ref.loc27: %HasF.assoc_type = name_ref G, @C.%G [concrete = constants.%assoc0]
  128. // CHECK:STDOUT: %impl.elem0.loc27: %.fec = impl_witness_access constants.%HasF.impl_witness, element0 [concrete = constants.%F.dc7]
  129. // CHECK:STDOUT: %F.call.loc27: init %empty_tuple.type = call %impl.elem0.loc27()
  130. // CHECK:STDOUT: %c.ref: %C = name_ref c, %c
  131. // CHECK:STDOUT: %G.ref.loc28: %HasF.assoc_type = name_ref G, @C.%G [concrete = constants.%assoc0]
  132. // CHECK:STDOUT: %impl.elem0.loc28: %.fec = impl_witness_access constants.%HasF.impl_witness, element0 [concrete = constants.%F.dc7]
  133. // CHECK:STDOUT: %F.call.loc28: init %empty_tuple.type = call %impl.elem0.loc28()
  134. // CHECK:STDOUT: return
  135. // CHECK:STDOUT: }
  136. // CHECK:STDOUT:
  137. // CHECK:STDOUT: specific @F.1(constants.%Self) {}
  138. // CHECK:STDOUT:
  139. // CHECK:STDOUT: specific @F.1(constants.%HasF.facet) {}
  140. // CHECK:STDOUT: