alias.carbon 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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/namespace/alias.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/namespace/alias.carbon
  10. namespace NS;
  11. alias ns = NS;
  12. fn NS.A() -> i32 { return 0; }
  13. fn B() -> i32 { return ns.A(); }
  14. alias C = NS.A;
  15. fn D() -> i32 { return C(); }
  16. // CHECK:STDOUT: --- alias.carbon
  17. // CHECK:STDOUT:
  18. // CHECK:STDOUT: constants {
  19. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  20. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  21. // CHECK:STDOUT: %A.type: type = fn_type @A [concrete]
  22. // CHECK:STDOUT: %A: %A.type = struct_value () [concrete]
  23. // CHECK:STDOUT: %int_0.5c6: Core.IntLiteral = int_value 0 [concrete]
  24. // CHECK:STDOUT: %ImplicitAs.type.205: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete]
  25. // CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [concrete]
  26. // CHECK:STDOUT: %impl_witness.d39: <witness> = impl_witness (imports.%Core.import_ref.a5b), @impl.4f9(%int_32) [concrete]
  27. // CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.4f9(%int_32) [concrete]
  28. // CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [concrete]
  29. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.205 = facet_value Core.IntLiteral, (%impl_witness.d39) [concrete]
  30. // CHECK:STDOUT: %.be7: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet [concrete]
  31. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_0.5c6, %Convert.956 [concrete]
  32. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.956, @Convert.2(%int_32) [concrete]
  33. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %int_0.5c6, %Convert.specific_fn [concrete]
  34. // CHECK:STDOUT: %int_0.6a9: %i32 = int_value 0 [concrete]
  35. // CHECK:STDOUT: %B.type: type = fn_type @B [concrete]
  36. // CHECK:STDOUT: %B: %B.type = struct_value () [concrete]
  37. // CHECK:STDOUT: %D.type: type = fn_type @D [concrete]
  38. // CHECK:STDOUT: %D: %D.type = struct_value () [concrete]
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: imports {
  42. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  43. // CHECK:STDOUT: .Int = %Core.Int
  44. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  45. // CHECK:STDOUT: import Core//prelude
  46. // CHECK:STDOUT: import Core//prelude/...
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT:
  50. // CHECK:STDOUT: file {
  51. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  52. // CHECK:STDOUT: .Core = imports.%Core
  53. // CHECK:STDOUT: .NS = %NS
  54. // CHECK:STDOUT: .ns = %ns
  55. // CHECK:STDOUT: .B = %B.decl
  56. // CHECK:STDOUT: .C = %C
  57. // CHECK:STDOUT: .D = %D.decl
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: %Core.import = import Core
  60. // CHECK:STDOUT: %NS: <namespace> = namespace [concrete] {
  61. // CHECK:STDOUT: .A = %A.decl
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT: %NS.ref.loc13: <namespace> = name_ref NS, %NS [concrete = %NS]
  64. // CHECK:STDOUT: %ns: <namespace> = bind_alias ns, %NS [concrete = %NS]
  65. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [concrete = constants.%A] {
  66. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  67. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, call_param0
  68. // CHECK:STDOUT: } {
  69. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  70. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  71. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param0
  72. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT: %B.decl: %B.type = fn_decl @B [concrete = constants.%B] {
  75. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  76. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, call_param0
  77. // CHECK:STDOUT: } {
  78. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  79. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  80. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param0
  81. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT: %NS.ref.loc19: <namespace> = name_ref NS, %NS [concrete = %NS]
  84. // CHECK:STDOUT: %A.ref: %A.type = name_ref A, %A.decl [concrete = constants.%A]
  85. // CHECK:STDOUT: %C: %A.type = bind_alias C, %A.decl [concrete = constants.%A]
  86. // CHECK:STDOUT: %D.decl: %D.type = fn_decl @D [concrete = constants.%D] {
  87. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  88. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, call_param0
  89. // CHECK:STDOUT: } {
  90. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  91. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  92. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param0
  93. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: fn @A() -> %i32 {
  98. // CHECK:STDOUT: !entry:
  99. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [concrete = constants.%int_0.5c6]
  100. // CHECK:STDOUT: %impl.elem0: %.be7 = impl_witness_access constants.%impl_witness.d39, element0 [concrete = constants.%Convert.956]
  101. // CHECK:STDOUT: %bound_method.loc15_28.1: <bound method> = bound_method %int_0, %impl.elem0 [concrete = constants.%Convert.bound]
  102. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
  103. // CHECK:STDOUT: %bound_method.loc15_28.2: <bound method> = bound_method %int_0, %specific_fn [concrete = constants.%bound_method]
  104. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %bound_method.loc15_28.2(%int_0) [concrete = constants.%int_0.6a9]
  105. // CHECK:STDOUT: %.loc15_28.1: %i32 = value_of_initializer %int.convert_checked [concrete = constants.%int_0.6a9]
  106. // CHECK:STDOUT: %.loc15_28.2: %i32 = converted %int_0, %.loc15_28.1 [concrete = constants.%int_0.6a9]
  107. // CHECK:STDOUT: return %.loc15_28.2
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT:
  110. // CHECK:STDOUT: fn @B() -> %i32 {
  111. // CHECK:STDOUT: !entry:
  112. // CHECK:STDOUT: %ns.ref: <namespace> = name_ref ns, file.%ns [concrete = file.%NS]
  113. // CHECK:STDOUT: %A.ref: %A.type = name_ref A, file.%A.decl [concrete = constants.%A]
  114. // CHECK:STDOUT: %A.call: init %i32 = call %A.ref()
  115. // CHECK:STDOUT: %.loc17_30.1: %i32 = value_of_initializer %A.call
  116. // CHECK:STDOUT: %.loc17_30.2: %i32 = converted %A.call, %.loc17_30.1
  117. // CHECK:STDOUT: return %.loc17_30.2
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT:
  120. // CHECK:STDOUT: fn @D() -> %i32 {
  121. // CHECK:STDOUT: !entry:
  122. // CHECK:STDOUT: %C.ref: %A.type = name_ref C, file.%C [concrete = constants.%A]
  123. // CHECK:STDOUT: %A.call: init %i32 = call %C.ref()
  124. // CHECK:STDOUT: %.loc21_27.1: %i32 = value_of_initializer %A.call
  125. // CHECK:STDOUT: %.loc21_27.2: %i32 = converted %A.call, %.loc21_27.1
  126. // CHECK:STDOUT: return %.loc21_27.2
  127. // CHECK:STDOUT: }
  128. // CHECK:STDOUT: