Skip to content

Commit a301808

Browse files
committed
Frontend: Go back to emitting index data after IRGen
There's no longer a technical reason to do this, but it helps with crash analytics because AST crashes are less likely to end up happening during index emission.
1 parent 23cbd7f commit a301808

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

lib/FrontendTool/FrontendTool.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -653,9 +653,6 @@ static void debugFailWithCrash() {
653653
LLVM_BUILTIN_TRAP;
654654
}
655655

656-
static void emitIndexDataIfNeeded(SourceFile *PrimarySourceFile,
657-
const CompilerInstance &Instance);
658-
659656
static void countStatsOfSourceFile(UnifiedStatsReporter &Stats,
660657
const CompilerInstance &Instance,
661658
SourceFile *SF) {
@@ -1115,13 +1112,16 @@ static bool performCompileStepsPostSema(CompilerInstance &Instance,
11151112
return result;
11161113
}
11171114

1115+
static void emitIndexDataForSourceFile(SourceFile *PrimarySourceFile,
1116+
const CompilerInstance &Instance);
1117+
11181118
/// Emits index data for all primary inputs, or the main module.
11191119
static void emitIndexData(const CompilerInstance &Instance) {
11201120
if (Instance.getPrimarySourceFiles().empty()) {
1121-
emitIndexDataIfNeeded(nullptr, Instance);
1121+
emitIndexDataForSourceFile(nullptr, Instance);
11221122
} else {
11231123
for (SourceFile *SF : Instance.getPrimarySourceFiles())
1124-
emitIndexDataIfNeeded(SF, Instance);
1124+
emitIndexDataForSourceFile(SF, Instance);
11251125
}
11261126
}
11271127

@@ -1288,12 +1288,13 @@ static bool performCompile(CompilerInstance &Instance,
12881288

12891289
SWIFT_DEFER {
12901290
// We might have freed the ASTContext already, but in that case we must have
1291-
// emitted the dependencies first.
1292-
if (Instance.hasASTContext())
1291+
// emitted the dependencies and index first.
1292+
if (Instance.hasASTContext()) {
12931293
emitReferenceDependenciesForAllPrimaryInputsIfNeeded(Instance);
1294+
emitIndexData(Instance);
1295+
}
12941296
};
12951297

1296-
emitIndexData(Instance);
12971298

12981299
if (Context.hadError())
12991300
return true;
@@ -1489,9 +1490,10 @@ static void freeASTContextIfPossible(CompilerInstance &Instance) {
14891490
return;
14901491
}
14911492

1492-
// Make sure we emit dependencies now, because we can't do it after the
1493-
// context is gone.
1493+
// Make sure we emit dependencies and index now, because we can't do it after
1494+
// the context is gone.
14941495
emitReferenceDependenciesForAllPrimaryInputsIfNeeded(Instance);
1496+
emitIndexData(Instance);
14951497

14961498
Instance.freeASTContext();
14971499
}
@@ -1664,8 +1666,8 @@ static bool performCompileStepsPostSILGen(CompilerInstance &Instance,
16641666
HadError;
16651667
}
16661668

1667-
static void emitIndexDataIfNeeded(SourceFile *PrimarySourceFile,
1668-
const CompilerInstance &Instance) {
1669+
static void emitIndexDataForSourceFile(SourceFile *PrimarySourceFile,
1670+
const CompilerInstance &Instance) {
16691671
const auto &Invocation = Instance.getInvocation();
16701672
const auto &opts = Invocation.getFrontendOptions();
16711673

0 commit comments

Comments
 (0)