alias.carbon 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 [template]
  20. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  21. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  22. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  23. // CHECK:STDOUT: %int_0.5c6: Core.IntLiteral = int_value 0 [template]
  24. // CHECK:STDOUT: %Convert.type.cd1: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  25. // CHECK:STDOUT: %impl_witness.5b0: <witness> = impl_witness (imports.%import_ref.723), @impl.1(%int_32) [template]
  26. // CHECK:STDOUT: %Convert.type.466: type = fn_type @Convert.2, @impl.1(%int_32) [template]
  27. // CHECK:STDOUT: %Convert.925: %Convert.type.466 = struct_value () [template]
  28. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_0.5c6, %Convert.925 [template]
  29. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.2(%int_32) [template]
  30. // CHECK:STDOUT: %int_0.f61: %i32 = int_value 0 [template]
  31. // CHECK:STDOUT: %B.type: type = fn_type @B [template]
  32. // CHECK:STDOUT: %B: %B.type = struct_value () [template]
  33. // CHECK:STDOUT: %D.type: type = fn_type @D [template]
  34. // CHECK:STDOUT: %D: %D.type = struct_value () [template]
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: imports {
  38. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  39. // CHECK:STDOUT: .Int = %import_ref.187
  40. // CHECK:STDOUT: .ImplicitAs = %import_ref.a69
  41. // CHECK:STDOUT: import Core//prelude
  42. // CHECK:STDOUT: import Core//prelude/...
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: file {
  47. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  48. // CHECK:STDOUT: .Core = imports.%Core
  49. // CHECK:STDOUT: .NS = %NS
  50. // CHECK:STDOUT: .ns = %ns
  51. // CHECK:STDOUT: .B = %B.decl
  52. // CHECK:STDOUT: .C = %C
  53. // CHECK:STDOUT: .D = %D.decl
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT: %Core.import = import Core
  56. // CHECK:STDOUT: %NS: <namespace> = namespace [template] {
  57. // CHECK:STDOUT: .A = %A.decl
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: %NS.ref.loc13: <namespace> = name_ref NS, %NS [template = %NS]
  60. // CHECK:STDOUT: %ns: <namespace> = bind_alias ns, %NS [template = %NS]
  61. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [template = constants.%A] {
  62. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  63. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param0
  64. // CHECK:STDOUT: } {
  65. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  66. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  67. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param0
  68. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT: %B.decl: %B.type = fn_decl @B [template = constants.%B] {
  71. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  72. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param0
  73. // CHECK:STDOUT: } {
  74. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  75. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  76. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param0
  77. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT: %NS.ref.loc19: <namespace> = name_ref NS, %NS [template = %NS]
  80. // CHECK:STDOUT: %A.ref: %A.type = name_ref A, %A.decl [template = constants.%A]
  81. // CHECK:STDOUT: %C: %A.type = bind_alias C, %A.decl [template = constants.%A]
  82. // CHECK:STDOUT: %D.decl: %D.type = fn_decl @D [template = constants.%D] {
  83. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  84. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param0
  85. // CHECK:STDOUT: } {
  86. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  87. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  88. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param0
  89. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: fn @A() -> %i32 {
  94. // CHECK:STDOUT: !entry:
  95. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [template = constants.%int_0.5c6]
  96. // CHECK:STDOUT: %impl.elem0: %Convert.type.cd1 = impl_witness_access constants.%impl_witness.5b0, element0 [template = constants.%Convert.925]
  97. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_0, %impl.elem0 [template = constants.%Convert.bound]
  98. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn]
  99. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %Convert.specific_fn(%int_0) [template = constants.%int_0.f61]
  100. // CHECK:STDOUT: %.loc15_28.1: %i32 = value_of_initializer %int.convert_checked [template = constants.%int_0.f61]
  101. // CHECK:STDOUT: %.loc15_28.2: %i32 = converted %int_0, %.loc15_28.1 [template = constants.%int_0.f61]
  102. // CHECK:STDOUT: return %.loc15_28.2
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT:
  105. // CHECK:STDOUT: fn @B() -> %i32 {
  106. // CHECK:STDOUT: !entry:
  107. // CHECK:STDOUT: %ns.ref: <namespace> = name_ref ns, file.%ns [template = file.%NS]
  108. // CHECK:STDOUT: %A.ref: %A.type = name_ref A, file.%A.decl [template = constants.%A]
  109. // CHECK:STDOUT: %A.call: init %i32 = call %A.ref()
  110. // CHECK:STDOUT: %.loc17_30.1: %i32 = value_of_initializer %A.call
  111. // CHECK:STDOUT: %.loc17_30.2: %i32 = converted %A.call, %.loc17_30.1
  112. // CHECK:STDOUT: return %.loc17_30.2
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT:
  115. // CHECK:STDOUT: fn @D() -> %i32 {
  116. // CHECK:STDOUT: !entry:
  117. // CHECK:STDOUT: %C.ref: %A.type = name_ref C, file.%C [template = constants.%A]
  118. // CHECK:STDOUT: %A.call: init %i32 = call %C.ref()
  119. // CHECK:STDOUT: %.loc21_27.1: %i32 = value_of_initializer %A.call
  120. // CHECK:STDOUT: %.loc21_27.2: %i32 = converted %A.call, %.loc21_27.1
  121. // CHECK:STDOUT: return %.loc21_27.2
  122. // CHECK:STDOUT: }
  123. // CHECK:STDOUT: