Skip to content

Commit 553dadd

Browse files
committed
[Frontend] dumpAPI at the end of the pipeline
This allows us to remove another condition that was previously preventing the ASTContext from being freed before LLVM.
1 parent 4ca6732 commit 553dadd

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

lib/FrontendTool/FrontendTool.cpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,9 +1224,12 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
12241224
return hadAnyError;
12251225
}
12261226

1227-
/// Returns true if an error occurred.
1228-
static bool dumpAPI(ModuleDecl *Mod, StringRef OutDir) {
1227+
static void dumpAPIIfNeeded(const CompilerInstance &Instance) {
12291228
using namespace llvm::sys;
1229+
const auto &Invocation = Instance.getInvocation();
1230+
StringRef OutDir = Invocation.getFrontendOptions().DumpAPIPath;
1231+
if (OutDir.empty())
1232+
return;
12301233

12311234
auto getOutPath = [&](SourceFile *SF) -> std::string {
12321235
SmallString<256> Path = OutDir;
@@ -1274,16 +1277,14 @@ static bool dumpAPI(ModuleDecl *Mod, StringRef OutDir) {
12741277
if (EC) {
12751278
llvm::errs() << "error creating directory '" << OutDir << "': "
12761279
<< EC.message() << '\n';
1277-
return true;
1280+
return;
12781281
}
12791282

1280-
for (auto *FU : Mod->getFiles()) {
1283+
for (auto *FU : Instance.getMainModule()->getFiles()) {
12811284
if (auto *SF = dyn_cast<SourceFile>(FU))
12821285
if (dumpFile(SF))
1283-
return true;
1286+
return;
12841287
}
1285-
1286-
return false;
12871288
}
12881289

12891290
/// Perform any actions that must have access to the ASTContext, and need to be
@@ -1330,6 +1331,8 @@ static void performEndOfPipelineActions(CompilerInstance &Instance) {
13301331
Instance.getMainModule(), Instance.getDependencyTracker(), opts);
13311332

13321333
emitAnyWholeModulePostTypeCheckSupplementaryOutputs(Instance);
1334+
1335+
dumpAPIIfNeeded(Instance);
13331336
}
13341337

13351338
// Verify reference dependencies of the current compilation job. Note this
@@ -1623,12 +1626,7 @@ static void freeASTContextIfPossible(CompilerInstance &Instance) {
16231626
return;
16241627
}
16251628

1626-
// If we're going to dump the API of the module, we cannot tear down
1627-
// the ASTContext, as that would cause the module to be freed prematurely.
16281629
const auto &opts = Instance.getInvocation().getFrontendOptions();
1629-
if (!opts.DumpAPIPath.empty()) {
1630-
return;
1631-
}
16321630

16331631
// If there are multiple primary inputs it is too soon to free
16341632
// the ASTContext, etc.. OTOH, if this compilation generates code for > 1
@@ -2230,10 +2228,6 @@ int swift::performFrontend(ArrayRef<const char *> Args,
22302228

22312229
int ReturnValue = 0;
22322230
bool HadError = performCompile(*Instance, Args, ReturnValue, observer);
2233-
if (!HadError && !Invocation.getFrontendOptions().DumpAPIPath.empty()) {
2234-
HadError = dumpAPI(Instance->getMainModule(),
2235-
Invocation.getFrontendOptions().DumpAPIPath);
2236-
}
22372231

22382232
if (verifierEnabled) {
22392233
DiagnosticEngine &diags = Instance->getDiags();

0 commit comments

Comments
 (0)