Skip to content

Commit e1f2e25

Browse files
committed
Frontend: Introduce -emit-api-descriptor flag.
An "API descriptor" file is JSON describing the externally accessible symbols of a module and metadata associated with those symbols like availability and SPI status. This output was previously only generated by the `swift-api-extract` alias of `swift-frontend`, which is desgined to take an already built module as input. Post-processing a built module to extract this information is inefficient because the module and the module's dependencies need to be deserialized in order to visit the entire AST. We can generate this output more efficiently as a supplementary output of the -emit-module job that originally produced the module (since the AST is already available in-memory). The -emit-api-descriptor flag can be used to request this output. This change lays the groundwork by introducing frontend flags. Follow up changes are needed to make API descriptor emission during -emit-module functional. Part of rdar://110916764.
1 parent d58943a commit e1f2e25

17 files changed

+141
-3
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ ERROR(error_mode_cannot_emit_module_summary,none,
152152
ERROR(error_mode_cannot_emit_symbol_graph,none,
153153
"this mode does not support emitting symbol graph files", ())
154154
ERROR(error_mode_cannot_emit_abi_descriptor,none,
155-
"this mode does not support emitting ABI descriptor", ())
155+
"this mode does not support emitting ABI descriptor files", ())
156+
ERROR(error_mode_cannot_emit_api_descriptor,none,
157+
"this mode does not support emitting API descriptor files", ())
156158
ERROR(error_mode_cannot_emit_const_values,none,
157159
"this mode does not support emitting extracted const values", ())
158160
ERROR(error_mode_cannot_emit_module_semantic_info,none,

include/swift/Basic/FileTypes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ TYPE("pch", PCH, "pch", "")
9898
TYPE("none", Nothing, "", "")
9999

100100
TYPE("abi-baseline-json", SwiftABIDescriptor, "abi.json", "")
101+
TYPE("api-json", SwiftAPIDescriptor, "", "")
101102
TYPE("fixit", SwiftFixIt, "", "")
102103
TYPE("module-semantic-info", ModuleSemanticInfo, "", "")
103104
TYPE("cached-diagnostics", CachedDiagnostics, "", "")

include/swift/Basic/SupplementaryOutputPaths.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ OUTPUT(ModuleSummaryOutputPath, TY_SwiftModuleSummaryFile)
143143
/// The output path to generate ABI baseline.
144144
OUTPUT(ABIDescriptorOutputPath, TY_SwiftABIDescriptor)
145145

146+
/// The output path to the module's API description.
147+
OUTPUT(APIDescriptorOutputPath, TY_SwiftAPIDescriptor)
148+
146149
/// The output path for extracted compile-time-known value information
147150
OUTPUT(ConstValuesOutputPath, TY_ConstValues)
148151

include/swift/Frontend/Frontend.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,11 @@ class CompilerInvocation {
428428
std::string getModuleInterfaceOutputPathForWholeModule() const;
429429
std::string getPrivateModuleInterfaceOutputPathForWholeModule() const;
430430

431+
/// APIDescriptorPath only makes sense in whole module compilation mode,
432+
/// so return the APIDescriptorPath when in that mode and fail an assert
433+
/// if not in that mode.
434+
std::string getAPIDescriptorPathForWholeModule() const;
435+
431436
public:
432437
/// Given the current configuration of this frontend invocation, a set of
433438
/// supplementary output paths, and a module, compute the appropriate set of

include/swift/Frontend/FrontendInputsAndOutputs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ class FrontendInputsAndOutputs {
265265
bool hasModuleInterfaceOutputPath() const;
266266
bool hasPrivateModuleInterfaceOutputPath() const;
267267
bool hasABIDescriptorOutputPath() const;
268+
bool hasAPIDescriptorOutputPath() const;
268269
bool hasConstValuesOutputPath() const;
269270
bool hasModuleSemanticInfoOutputPath() const;
270271
bool hasModuleSummaryOutputPath() const;

include/swift/Frontend/FrontendOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ class FrontendOptions {
569569
static bool canActionEmitModuleSummary(ActionType);
570570
static bool canActionEmitInterface(ActionType);
571571
static bool canActionEmitABIDescriptor(ActionType);
572+
static bool canActionEmitAPIDescriptor(ActionType);
572573
static bool canActionEmitConstValues(ActionType);
573574
static bool canActionEmitModuleSemanticInfo(ActionType);
574575

include/swift/Option/Options.td

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,19 @@ def emit_const_values :
626626
def emit_const_values_path : Separate<["-"], "emit-const-values-path">,
627627
Flags<[FrontendOption, NoInteractiveOption, ArgumentIsPath,
628628
SupplementaryOutput, CacheInvariant]>,
629-
MetaVarName<"<path>">, HelpText<"Emit the extracted compile-time known values to <path>">;
629+
MetaVarName<"<path>">,
630+
HelpText<"Emit the extracted compile-time known values to <path>">;
631+
632+
def emit_api_descriptor :
633+
Flag<["-"], "emit-api-descriptor">,
634+
Flags<[NoInteractiveOption, SupplementaryOutput, CacheInvariant]>,
635+
HelpText<"Output a JSON file describing the module's API">;
636+
def emit_api_descriptor_path :
637+
Separate<["-"], "emit-api-descriptor-path">,
638+
Flags<[FrontendOption, NoInteractiveOption, ArgumentIsPath,
639+
SupplementaryOutput, CacheInvariant]>,
640+
MetaVarName<"<path>">,
641+
HelpText<"Output a JSON file describing the module's API to <path>">;
630642

631643
def emit_objc_header : Flag<["-"], "emit-objc-header">,
632644
Flags<[FrontendOption, NoInteractiveOption, SupplementaryOutput, CacheInvariant]>,

lib/Basic/FileTypes.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ bool file_types::isTextual(ID Id) {
8686
case file_types::TY_JSONDependencies:
8787
case file_types::TY_JSONFeatures:
8888
case file_types::TY_SwiftABIDescriptor:
89+
case file_types::TY_SwiftAPIDescriptor:
8990
case file_types::TY_ConstValues:
9091
return true;
9192
case file_types::TY_Image:
@@ -164,6 +165,7 @@ bool file_types::isAfterLLVM(ID Id) {
164165
case file_types::TY_JSONFeatures:
165166
case file_types::TY_IndexUnitOutputPath:
166167
case file_types::TY_SwiftABIDescriptor:
168+
case file_types::TY_SwiftAPIDescriptor:
167169
case file_types::TY_ConstValues:
168170
case file_types::TY_SwiftFixIt:
169171
case file_types::TY_ModuleSemanticInfo:
@@ -220,6 +222,7 @@ bool file_types::isPartOfSwiftCompilation(ID Id) {
220222
case file_types::TY_JSONFeatures:
221223
case file_types::TY_IndexUnitOutputPath:
222224
case file_types::TY_SwiftABIDescriptor:
225+
case file_types::TY_SwiftAPIDescriptor:
223226
case file_types::TY_ConstValues:
224227
case file_types::TY_SwiftFixIt:
225228
case file_types::TY_ModuleSemanticInfo:

lib/Driver/Driver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,6 +2090,7 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
20902090
case file_types::TY_JSONDependencies:
20912091
case file_types::TY_JSONFeatures:
20922092
case file_types::TY_SwiftABIDescriptor:
2093+
case file_types::TY_SwiftAPIDescriptor:
20932094
case file_types::TY_ConstValues:
20942095
case file_types::TY_SwiftFixIt:
20952096
case file_types::TY_ModuleSemanticInfo:

lib/Driver/ToolChains.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ const char *ToolChain::JobContext::computeFrontendModeForCompile() const {
733733
case file_types::TY_SwiftOverlayFile:
734734
case file_types::TY_IndexUnitOutputPath:
735735
case file_types::TY_SwiftABIDescriptor:
736+
case file_types::TY_SwiftAPIDescriptor:
736737
case file_types::TY_ConstValues:
737738
case file_types::TY_SwiftFixIt:
738739
case file_types::TY_ModuleSemanticInfo:
@@ -997,6 +998,7 @@ ToolChain::constructInvocation(const BackendJobAction &job,
997998
case file_types::TY_SwiftOverlayFile:
998999
case file_types::TY_IndexUnitOutputPath:
9991000
case file_types::TY_SwiftABIDescriptor:
1001+
case file_types::TY_SwiftAPIDescriptor:
10001002
case file_types::TY_ConstValues:
10011003
case file_types::TY_SwiftFixIt:
10021004
case file_types::TY_ModuleSemanticInfo:

0 commit comments

Comments
 (0)