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