mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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.
This commit is contained in:
@@ -809,6 +809,36 @@ static bool writeTBDIfNeeded(CompilerInstance &Instance) {
|
||||
Instance.getOutputBackend(), tbdOpts);
|
||||
}
|
||||
|
||||
static bool writeAPIDescriptor(ModuleDecl *M, StringRef OutputPath,
|
||||
llvm::vfs::OutputBackend &Backend,
|
||||
bool PrettyPrinted) {
|
||||
return withOutputPath(M->getDiags(), Backend, OutputPath,
|
||||
[&](raw_ostream &OS) -> bool {
|
||||
writeAPIJSONFile(M, OS, PrettyPrinted);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
static bool writeAPIDescriptorIfNeeded(CompilerInstance &Instance) {
|
||||
const auto &Invocation = Instance.getInvocation();
|
||||
const auto &frontendOpts = Invocation.getFrontendOptions();
|
||||
if (!frontendOpts.InputsAndOutputs.hasAPIDescriptorOutputPath())
|
||||
return false;
|
||||
|
||||
if (!frontendOpts.InputsAndOutputs.isWholeModule()) {
|
||||
Instance.getDiags().diagnose(
|
||||
SourceLoc(), diag::api_descriptor_only_supported_in_whole_module);
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string &APIDescriptorPath =
|
||||
Invocation.getAPIDescriptorPathForWholeModule();
|
||||
|
||||
// FIXME: Need a frontend flag for pretty printing
|
||||
return writeAPIDescriptor(Instance.getMainModule(), APIDescriptorPath,
|
||||
Instance.getOutputBackend(), true);
|
||||
}
|
||||
|
||||
static bool performCompileStepsPostSILGen(CompilerInstance &Instance,
|
||||
std::unique_ptr<SILModule> SM,
|
||||
ModuleOrSourceFile MSF,
|
||||
@@ -975,6 +1005,10 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
|
||||
hadAnyError |= writeTBDIfNeeded(Instance);
|
||||
}
|
||||
|
||||
{
|
||||
hadAnyError |= writeAPIDescriptorIfNeeded(Instance);
|
||||
}
|
||||
|
||||
{
|
||||
hadAnyError |= writeModuleSemanticInfoIfNeeded(Instance);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user