alias.carbon 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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/destroy.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/function/call/alias.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/call/alias.carbon
  14. fn A() -> () { return (); }
  15. alias B = A;
  16. fn Main() {
  17. var b: () = B();
  18. }
  19. // CHECK:STDOUT: --- alias.carbon
  20. // CHECK:STDOUT:
  21. // CHECK:STDOUT: constants {
  22. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  23. // CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [concrete]
  24. // CHECK:STDOUT: %pattern_type.cb1: type = pattern_type %empty_tuple.type [concrete]
  25. // CHECK:STDOUT: %A.type: type = fn_type @A [concrete]
  26. // CHECK:STDOUT: %A: %A.type = struct_value () [concrete]
  27. // CHECK:STDOUT: %Main.type: type = fn_type @Main [concrete]
  28. // CHECK:STDOUT: %Main: %Main.type = struct_value () [concrete]
  29. // CHECK:STDOUT: %Destroy.type: type = facet_type <@Destroy> [concrete]
  30. // CHECK:STDOUT: %type_where: type = facet_type <type where .Self impls <CanDestroy>> [concrete]
  31. // CHECK:STDOUT: %facet_value: %type_where = facet_value %empty_tuple.type, () [concrete]
  32. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.type.bb8: type = fn_type @DestroyT.binding.as_type.as.Destroy.impl.Op, @DestroyT.binding.as_type.as.Destroy.impl(%facet_value) [concrete]
  33. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.72f: %DestroyT.binding.as_type.as.Destroy.impl.Op.type.bb8 = struct_value () [concrete]
  34. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.specific_fn: <specific function> = specific_function %DestroyT.binding.as_type.as.Destroy.impl.Op.72f, @DestroyT.binding.as_type.as.Destroy.impl.Op(%facet_value) [concrete]
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: imports {
  38. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  39. // CHECK:STDOUT: .Destroy = %Core.Destroy
  40. // CHECK:STDOUT: import Core//prelude
  41. // CHECK:STDOUT: import Core//prelude/...
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT: %Core.Destroy: type = import_ref Core//prelude/parts/destroy, Destroy, loaded [concrete = constants.%Destroy.type]
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: file {
  47. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  48. // CHECK:STDOUT: .Core = imports.%Core
  49. // CHECK:STDOUT: .A = %A.decl
  50. // CHECK:STDOUT: .B = %B
  51. // CHECK:STDOUT: .Main = %Main.decl
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT: %Core.import = import Core
  54. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [concrete = constants.%A] {
  55. // CHECK:STDOUT: %return.patt: %pattern_type.cb1 = return_slot_pattern [concrete]
  56. // CHECK:STDOUT: %return.param_patt: %pattern_type.cb1 = out_param_pattern %return.patt, call_param0 [concrete]
  57. // CHECK:STDOUT: } {
  58. // CHECK:STDOUT: %.loc15_12.1: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
  59. // CHECK:STDOUT: %.loc15_12.2: type = converted %.loc15_12.1, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  60. // CHECK:STDOUT: %return.param: ref %empty_tuple.type = out_param call_param0
  61. // CHECK:STDOUT: %return: ref %empty_tuple.type = return_slot %return.param
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT: %A.ref: %A.type = name_ref A, %A.decl [concrete = constants.%A]
  64. // CHECK:STDOUT: %B: %A.type = alias_binding B, %A.decl [concrete = constants.%A]
  65. // CHECK:STDOUT: %Main.decl: %Main.type = fn_decl @Main [concrete = constants.%Main] {} {}
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: fn @A() -> %empty_tuple.type {
  69. // CHECK:STDOUT: !entry:
  70. // CHECK:STDOUT: %.loc15_24.1: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
  71. // CHECK:STDOUT: %.loc15_24.2: init %empty_tuple.type = tuple_init () to %return [concrete = constants.%empty_tuple]
  72. // CHECK:STDOUT: %.loc15_25: init %empty_tuple.type = converted %.loc15_24.1, %.loc15_24.2 [concrete = constants.%empty_tuple]
  73. // CHECK:STDOUT: return %.loc15_25 to %return
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: fn @Main() {
  77. // CHECK:STDOUT: !entry:
  78. // CHECK:STDOUT: name_binding_decl {
  79. // CHECK:STDOUT: %b.patt: %pattern_type.cb1 = ref_binding_pattern b [concrete]
  80. // CHECK:STDOUT: %b.var_patt: %pattern_type.cb1 = var_pattern %b.patt [concrete]
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT: %b.var: ref %empty_tuple.type = var %b.var_patt
  83. // CHECK:STDOUT: %B.ref: %A.type = name_ref B, file.%B [concrete = constants.%A]
  84. // CHECK:STDOUT: %A.call: init %empty_tuple.type = call %B.ref()
  85. // CHECK:STDOUT: assign %b.var, %A.call
  86. // CHECK:STDOUT: %.loc20_11.1: type = splice_block %.loc20_11.3 [concrete = constants.%empty_tuple.type] {
  87. // CHECK:STDOUT: %.loc20_11.2: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
  88. // CHECK:STDOUT: %.loc20_11.3: type = converted %.loc20_11.2, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT: %b: ref %empty_tuple.type = ref_binding b, %b.var
  91. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.bound: <bound method> = bound_method %b.var, constants.%DestroyT.binding.as_type.as.Destroy.impl.Op.72f
  92. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.specific_fn: <specific function> = specific_function constants.%DestroyT.binding.as_type.as.Destroy.impl.Op.72f, @DestroyT.binding.as_type.as.Destroy.impl.Op(constants.%facet_value) [concrete = constants.%DestroyT.binding.as_type.as.Destroy.impl.Op.specific_fn]
  93. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %b.var, %DestroyT.binding.as_type.as.Destroy.impl.Op.specific_fn
  94. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.call: init %empty_tuple.type = call %bound_method(%b.var)
  95. // CHECK:STDOUT: return
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT: