export_name.carbon 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  6. // EXTRA-ARGS: --no-prelude-import --dump-sem-ir-ranges=if-present
  7. //
  8. // AUTOUPDATE
  9. // TIP: To test this file alone, run:
  10. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/function/declaration/export_name.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/declaration/export_name.carbon
  13. // ============================================================================
  14. // Setup files
  15. // ============================================================================
  16. // --- base.carbon
  17. library "[[@TEST_NAME]]";
  18. fn F();
  19. // --- export.carbon
  20. library "[[@TEST_NAME]]";
  21. import library "base";
  22. export F;
  23. // ============================================================================
  24. // Test files
  25. // ============================================================================
  26. // --- use_export.carbon
  27. library "[[@TEST_NAME]]";
  28. import library "export";
  29. var f: () = F();
  30. // CHECK:STDOUT: --- base.carbon
  31. // CHECK:STDOUT:
  32. // CHECK:STDOUT: constants {
  33. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  34. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: file {
  38. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  39. // CHECK:STDOUT: .F = %F.decl
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: fn @F();
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: --- export.carbon
  47. // CHECK:STDOUT:
  48. // CHECK:STDOUT: constants {
  49. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  50. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: imports {
  54. // CHECK:STDOUT: %Main.F: %F.type = import_ref Main//base, F, loaded [concrete = constants.%F]
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: file {
  58. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  59. // CHECK:STDOUT: .F = %F
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT: %default.import = import <none>
  62. // CHECK:STDOUT: %F: %F.type = export F, imports.%Main.F [concrete = constants.%F]
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: fn @F [from "base.carbon"];
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: --- use_export.carbon
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: constants {
  70. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  71. // CHECK:STDOUT: %pattern_type: type = pattern_type %empty_tuple.type [concrete]
  72. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  73. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: imports {
  77. // CHECK:STDOUT: %Main.F: %F.type = import_ref Main//export, F, loaded [concrete = constants.%F]
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: file {
  81. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  82. // CHECK:STDOUT: .F = imports.%Main.F
  83. // CHECK:STDOUT: .f = %f
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT: %default.import = import <none>
  86. // CHECK:STDOUT: name_binding_decl {
  87. // CHECK:STDOUT: %f.patt: %pattern_type = binding_pattern f [concrete]
  88. // CHECK:STDOUT: %f.var_patt: %pattern_type = var_pattern %f.patt [concrete]
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT: %f.var: ref %empty_tuple.type = var %f.var_patt [concrete]
  91. // CHECK:STDOUT: %.loc6_9.1: type = splice_block %.loc6_9.3 [concrete = constants.%empty_tuple.type] {
  92. // CHECK:STDOUT: %.loc6_9.2: %empty_tuple.type = tuple_literal ()
  93. // CHECK:STDOUT: %.loc6_9.3: type = converted %.loc6_9.2, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT: %f: ref %empty_tuple.type = bind_name f, %f.var [concrete = %f.var]
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: fn @F [from "export.carbon"];
  99. // CHECK:STDOUT:
  100. // CHECK:STDOUT: fn @__global_init() {
  101. // CHECK:STDOUT: !entry:
  102. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, imports.%Main.F [concrete = constants.%F]
  103. // CHECK:STDOUT: %F.call: init %empty_tuple.type = call %F.ref()
  104. // CHECK:STDOUT: assign file.%f.var, %F.call
  105. // CHECK:STDOUT: return
  106. // CHECK:STDOUT: }
  107. // CHECK:STDOUT: