export_name.carbon 4.2 KB

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