alias.carbon 6.7 KB

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