Skip to content

Commit a6a330c

Browse files
authored
Merge pull request #41912 from hyp/unify2
Recommit: [cxx-interop] start to emitting a unified header file for a Swift module
2 parents a45940c + 80bc75a commit a6a330c

32 files changed

+182
-223
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ ERROR(error_mode_cannot_emit_dependencies,none,
118118
ERROR(error_mode_cannot_emit_reference_dependencies,none,
119119
"this mode does not support emitting reference dependency files", ())
120120
ERROR(error_mode_cannot_emit_header,none,
121-
"this mode does not support emitting Objective-C headers", ())
122-
ERROR(error_mode_cannot_emit_cxx_header,none,
123-
"this mode does not support emitting C++ headers", ())
121+
"this mode does not support emitting Objective-C or C++ headers", ())
124122
ERROR(error_mode_cannot_emit_loaded_module_trace,none,
125123
"this mode does not support emitting the loaded module trace", ())
126124
ERROR(error_mode_cannot_emit_module,none,

include/swift/Basic/FileTypes.def

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ TYPE("raw-sib", RawSIB, "sib", "")
5959
TYPE("llvm-ir", LLVM_IR, "ll", "")
6060
TYPE("llvm-bc", LLVM_BC, "bc", "")
6161
TYPE("diagnostics", SerializedDiagnostics, "dia", "")
62-
TYPE("objc-header", ObjCHeader, "h", "")
63-
TYPE("cxx-header", CXXHeader, "h", "")
62+
TYPE("clang-header", ClangHeader, "h", "")
6463
TYPE("swift-dependencies", SwiftDeps, "swiftdeps", "")
6564
TYPE("external-swift-dependencies", ExternalSwiftDeps, "swiftdeps.external", "")
6665
TYPE("remap", Remapping, "remap", "")

include/swift/Basic/SupplementaryOutputPaths.h

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,17 @@
2020

2121
namespace swift {
2222
struct SupplementaryOutputPaths {
23-
/// The path to which we should emit an Objective-C header for the module.
23+
/// The path to which we should emit a header file that exposes the Swift
24+
/// declarations to C, Objective-C and C++ clients for the module.
2425
///
2526
/// Currently only makes sense when the compiler has whole module knowledge.
2627
/// The modes for which it makes sense incuide both WMO and the "merge
2728
/// modules" job that happens after the normal compilation jobs. That's where
2829
/// the header is emitted in single-file mode, since it needs whole-module
2930
/// information.
3031
///
31-
/// \sa swift::printAsObjC
32-
std::string ObjCHeaderOutputPath;
33-
34-
/// The path to which we should emit a C++ header for the module.
35-
///
36-
/// Currently only makes sense when the compiler has whole module knowledge.
37-
/// The modes for which it makes sense include both WMO and the "merge
38-
/// modules" job that happens after the normal compilation jobs. That's where
39-
/// the header is emitted in single-file mode, since it needs whole-module
40-
/// information.
41-
///
42-
/// \sa swift::printAsCXX
43-
std::string CxxHeaderOutputPath;
32+
/// \sa swift::printAsClangHeader
33+
std::string ClangHeaderOutputPath;
4434

4535
/// The path to which we should emit a serialized module.
4636
/// It is valid whenever there are any inputs.
@@ -170,10 +160,8 @@ struct SupplementaryOutputPaths {
170160

171161
/// Apply a given function for each existing (non-empty string) supplementary output
172162
void forEachSetOutput(llvm::function_ref<void(const std::string&)> fn) const {
173-
if (!ObjCHeaderOutputPath.empty())
174-
fn(ObjCHeaderOutputPath);
175-
if (!CxxHeaderOutputPath.empty())
176-
fn(CxxHeaderOutputPath);
163+
if (!ClangHeaderOutputPath.empty())
164+
fn(ClangHeaderOutputPath);
177165
if (!ModuleOutputPath.empty())
178166
fn(ModuleOutputPath);
179167
if (!ModuleSourceInfoOutputPath.empty())
@@ -209,9 +197,8 @@ struct SupplementaryOutputPaths {
209197
}
210198

211199
bool empty() const {
212-
return ObjCHeaderOutputPath.empty() && CxxHeaderOutputPath.empty() &&
213-
ModuleOutputPath.empty() && ModuleDocOutputPath.empty() &&
214-
DependenciesFilePath.empty() &&
200+
return ClangHeaderOutputPath.empty() && ModuleOutputPath.empty() &&
201+
ModuleDocOutputPath.empty() && DependenciesFilePath.empty() &&
215202
ReferenceDependenciesFilePath.empty() &&
216203
SerializedDiagnosticsPath.empty() && LoadedModuleTracePath.empty() &&
217204
TBDPath.empty() && ModuleInterfaceOutputPath.empty() &&

include/swift/Frontend/Frontend.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,7 @@ class CompilerInvocation {
392392

393393
std::string getOutputFilenameForAtMostOnePrimary() const;
394394
std::string getMainInputFilenameForDebugInfoForAtMostOnePrimary() const;
395-
std::string getObjCHeaderOutputPathForAtMostOnePrimary() const;
396-
std::string getCxxHeaderOutputPathForAtMostOnePrimary() const;
395+
std::string getClangHeaderOutputPathForAtMostOnePrimary() const;
397396
std::string getModuleOutputPathForAtMostOnePrimary() const;
398397
std::string
399398
getReferenceDependenciesFilePathForPrimary(StringRef filename) const;

include/swift/Frontend/FrontendInputsAndOutputs.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,7 @@ class FrontendInputsAndOutputs {
249249

250250
bool hasDependenciesPath() const;
251251
bool hasReferenceDependenciesPath() const;
252-
bool hasObjCHeaderOutputPath() const;
253-
bool hasCxxHeaderOutputPath() const;
252+
bool hasClangHeaderOutputPath() const;
254253
bool hasLoadedModuleTracePath() const;
255254
bool hasModuleOutputPath() const;
256255
bool hasModuleDocOutputPath() const;

include/swift/Frontend/FrontendOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,10 @@ class FrontendOptions {
378378
/// '.../lib/swift', otherwise '.../lib/swift_static'.
379379
bool UseSharedResourceFolder = true;
380380

381+
/// Indicates whether to expose all public declarations in the generated clang
382+
/// header.
383+
bool ExposePublicDeclsInClangHeader = false;
384+
381385
/// \return true if the given action only parses without doing other compilation steps.
382386
static bool shouldActionOnlyParse(ActionType);
383387

include/swift/Option/FrontendOptions.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,4 +1031,9 @@ def skip_import_in_public_interface:
10311031
HelpText<"Skip the import statement corresponding to a module name "
10321032
"when printing the public interface.">;
10331033

1034+
def clang_header_expose_public_decls:
1035+
Flag<["-"], "clang-header-expose-public-decls">,
1036+
HelpText<"Expose all public declarations in the generated clang header">,
1037+
Flags<[FrontendOption, HelpHidden]>;
1038+
10341039
} // end let Flags = [FrontendOption, NoDriverOption, HelpHidden]

include/swift/Option/Options.td

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -532,13 +532,11 @@ def emit_objc_header_path : Separate<["-"], "emit-objc-header-path">,
532532
SupplementaryOutput]>,
533533
MetaVarName<"<path>">, HelpText<"Emit an Objective-C header file to <path>">;
534534

535-
def emit_cxx_header : Flag<["-"], "emit-cxx-header">,
536-
Flags<[FrontendOption, NoInteractiveOption, SupplementaryOutput]>,
537-
HelpText<"Emit a C++ header file">;
538-
def emit_cxx_header_path : Separate<["-"], "emit-cxx-header-path">,
539-
Flags<[FrontendOption, NoInteractiveOption, ArgumentIsPath,
535+
def emit_clang_header_path : Separate<["-"], "emit-clang-header-path">,
536+
Flags<[FrontendOption, NoDriverOption, NoInteractiveOption, ArgumentIsPath,
540537
SupplementaryOutput]>,
541-
MetaVarName<"<path>">, HelpText<"Emit a C++ header file to <path>">;
538+
HelpText<"Emit an Objective-C and C++ header file to <path>">,
539+
Alias<emit_objc_header_path>;
542540

543541
def static : Flag<["-"], "static">,
544542
Flags<[FrontendOption, ModuleInterfaceOption, NoInteractiveOption]>,

include/swift/PrintAsClang/PrintAsClang.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,19 @@ namespace swift {
2121
class ModuleDecl;
2222
class ValueDecl;
2323

24-
/// Print the Objective-C-compatible declarations in a module as a Clang
25-
/// header.
24+
/// Print the exposed declarations in a module into a Clang header.
2625
///
27-
/// Returns true on error.
28-
bool printAsObjC(raw_ostream &out, ModuleDecl *M, StringRef bridgingHeader);
29-
30-
/// Print the C++-compatible declarations in a module as a Clang header.
26+
/// The Objective-C compatible declarations are printed into a block that
27+
/// ensures that those declarations are only usable when the header is
28+
/// compiled in Objective-C mode.
29+
/// The C++ compatible declarations are printed into a block that ensures
30+
/// that those declarations are only usable when the header is compiled in
31+
/// C++ mode.
3132
///
3233
/// Returns true on error.
33-
bool printAsCXX(raw_ostream &os, ModuleDecl *M);
34+
bool printAsClangHeader(raw_ostream &out, ModuleDecl *M,
35+
StringRef bridgingHeader,
36+
bool ExposePublicDeclsInClangHeader);
3437
}
3538

3639
#endif

lib/Basic/FileTypes.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ bool file_types::isTextual(ID Id) {
7373
case file_types::TY_ASTDump:
7474
case file_types::TY_RawSIL:
7575
case file_types::TY_LLVM_IR:
76-
case file_types::TY_ObjCHeader:
77-
case file_types::TY_CXXHeader:
76+
case file_types::TY_ClangHeader:
7877
case file_types::TY_AutolinkFile:
7978
case file_types::TY_ImportedModules:
8079
case file_types::TY_TBD:
@@ -132,8 +131,7 @@ bool file_types::isAfterLLVM(ID Id) {
132131
case file_types::TY_Dependencies:
133132
case file_types::TY_ASTDump:
134133
case file_types::TY_RawSIL:
135-
case file_types::TY_ObjCHeader:
136-
case file_types::TY_CXXHeader:
134+
case file_types::TY_ClangHeader:
137135
case file_types::TY_AutolinkFile:
138136
case file_types::TY_Image:
139137
case file_types::TY_dSYM:
@@ -183,8 +181,7 @@ bool file_types::isPartOfSwiftCompilation(ID Id) {
183181
case file_types::TY_LLVM_BC:
184182
case file_types::TY_Object:
185183
case file_types::TY_Dependencies:
186-
case file_types::TY_ObjCHeader:
187-
case file_types::TY_CXXHeader:
184+
case file_types::TY_ClangHeader:
188185
case file_types::TY_AutolinkFile:
189186
case file_types::TY_PCH:
190187
case file_types::TY_ImportedModules:

0 commit comments

Comments
 (0)