alias.carbon 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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: %Int32.type: type = fn_type @Int32 [template]
  20. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  21. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  22. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  23. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  24. // CHECK:STDOUT: %.2: i32 = int_literal 0 [template]
  25. // CHECK:STDOUT: %B.type: type = fn_type @B [template]
  26. // CHECK:STDOUT: %B: %B.type = struct_value () [template]
  27. // CHECK:STDOUT: %D.type: type = fn_type @D [template]
  28. // CHECK:STDOUT: %D: %D.type = struct_value () [template]
  29. // CHECK:STDOUT: }
  30. // CHECK:STDOUT:
  31. // CHECK:STDOUT: file {
  32. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  33. // CHECK:STDOUT: .Core = %Core
  34. // CHECK:STDOUT: .NS = %NS
  35. // CHECK:STDOUT: .ns = %ns
  36. // CHECK:STDOUT: .B = %B.decl
  37. // CHECK:STDOUT: .C = %C
  38. // CHECK:STDOUT: .D = %D.decl
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  41. // CHECK:STDOUT: %NS: <namespace> = namespace [template] {
  42. // CHECK:STDOUT: .A = %A.decl
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT: %NS.ref.loc13: <namespace> = name_ref NS, %NS [template = %NS]
  45. // CHECK:STDOUT: %ns: <namespace> = bind_alias ns, %NS [template = %NS]
  46. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  47. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [template = constants.%A] {
  48. // CHECK:STDOUT: %int.make_type_32.loc15: init type = call constants.%Int32() [template = i32]
  49. // CHECK:STDOUT: %.loc15_14.1: type = value_of_initializer %int.make_type_32.loc15 [template = i32]
  50. // CHECK:STDOUT: %.loc15_14.2: type = converted %int.make_type_32.loc15, %.loc15_14.1 [template = i32]
  51. // CHECK:STDOUT: @A.%return: ref i32 = var <return slot>
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  54. // CHECK:STDOUT: %B.decl: %B.type = fn_decl @B [template = constants.%B] {
  55. // CHECK:STDOUT: %int.make_type_32.loc17: init type = call constants.%Int32() [template = i32]
  56. // CHECK:STDOUT: %.loc17_11.1: type = value_of_initializer %int.make_type_32.loc17 [template = i32]
  57. // CHECK:STDOUT: %.loc17_11.2: type = converted %int.make_type_32.loc17, %.loc17_11.1 [template = i32]
  58. // CHECK:STDOUT: @B.%return: ref i32 = var <return slot>
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT: %NS.ref.loc19: <namespace> = name_ref NS, %NS [template = %NS]
  61. // CHECK:STDOUT: %A.ref: %A.type = name_ref A, %A.decl [template = constants.%A]
  62. // CHECK:STDOUT: %C: %A.type = bind_alias C, %A.decl [template = constants.%A]
  63. // CHECK:STDOUT: %import_ref.3: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  64. // CHECK:STDOUT: %D.decl: %D.type = fn_decl @D [template = constants.%D] {
  65. // CHECK:STDOUT: %int.make_type_32.loc21: init type = call constants.%Int32() [template = i32]
  66. // CHECK:STDOUT: %.loc21_11.1: type = value_of_initializer %int.make_type_32.loc21 [template = i32]
  67. // CHECK:STDOUT: %.loc21_11.2: type = converted %int.make_type_32.loc21, %.loc21_11.1 [template = i32]
  68. // CHECK:STDOUT: @D.%return: ref i32 = var <return slot>
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: fn @A() -> i32 {
  75. // CHECK:STDOUT: !entry:
  76. // CHECK:STDOUT: %.loc15: i32 = int_literal 0 [template = constants.%.2]
  77. // CHECK:STDOUT: return %.loc15
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: fn @B() -> i32 {
  81. // CHECK:STDOUT: !entry:
  82. // CHECK:STDOUT: %ns.ref: <namespace> = name_ref ns, file.%ns [template = file.%NS]
  83. // CHECK:STDOUT: %A.ref: %A.type = name_ref A, file.%A.decl [template = constants.%A]
  84. // CHECK:STDOUT: %A.call: init i32 = call %A.ref()
  85. // CHECK:STDOUT: %.loc17_30.1: i32 = value_of_initializer %A.call
  86. // CHECK:STDOUT: %.loc17_30.2: i32 = converted %A.call, %.loc17_30.1
  87. // CHECK:STDOUT: return %.loc17_30.2
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: fn @D() -> i32 {
  91. // CHECK:STDOUT: !entry:
  92. // CHECK:STDOUT: %C.ref: %A.type = name_ref C, file.%C [template = constants.%A]
  93. // CHECK:STDOUT: %A.call: init i32 = call %C.ref()
  94. // CHECK:STDOUT: %.loc21_27.1: i32 = value_of_initializer %A.call
  95. // CHECK:STDOUT: %.loc21_27.2: i32 = converted %A.call, %.loc21_27.1
  96. // CHECK:STDOUT: return %.loc21_27.2
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT: