Skip to content

Commit 8755ced

Browse files
authored
Merge pull request #31426 from slavapestov/index-before-silgen
Frontend: Write out index before SILGen
2 parents bbe2f6e + fd9ffe7 commit 8755ced

File tree

1 file changed

+26
-49
lines changed

1 file changed

+26
-49
lines changed

lib/FrontendTool/FrontendTool.cpp

Lines changed: 26 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,7 @@ static void debugFailWithCrash() {
653653
LLVM_BUILTIN_TRAP;
654654
}
655655

656-
/// \return true on error.
657-
static bool emitIndexDataIfNeeded(SourceFile *PrimarySourceFile,
656+
static void emitIndexDataIfNeeded(SourceFile *PrimarySourceFile,
658657
const CompilerInvocation &Invocation,
659658
const CompilerInstance &Instance);
660659

@@ -1144,15 +1143,14 @@ static bool performCompileStepsPostSema(const CompilerInvocation &Invocation,
11441143
}
11451144

11461145
/// Emits index data for all primary inputs, or the main module.
1147-
static bool
1146+
static void
11481147
emitIndexData(const CompilerInvocation &Invocation, const CompilerInstance &Instance) {
1149-
bool hadEmitIndexDataError = false;
11501148
if (Instance.getPrimarySourceFiles().empty())
1151-
return emitIndexDataIfNeeded(nullptr, Invocation, Instance);
1152-
for (SourceFile *SF : Instance.getPrimarySourceFiles())
1153-
hadEmitIndexDataError = emitIndexDataIfNeeded(SF, Invocation, Instance) ||
1154-
hadEmitIndexDataError;
1155-
return hadEmitIndexDataError;
1149+
emitIndexDataIfNeeded(nullptr, Invocation, Instance);
1150+
else {
1151+
for (SourceFile *SF : Instance.getPrimarySourceFiles())
1152+
emitIndexDataIfNeeded(SF, Invocation, Instance);
1153+
}
11561154
}
11571155

11581156
/// Emits all "one-per-module" supplementary outputs that don't depend on
@@ -1317,19 +1315,16 @@ static bool performCompile(CompilerInstance &Instance,
13171315
emitSwiftRangesForAllPrimaryInputsIfNeeded(Invocation, Instance);
13181316
emitCompiledSourceForAllPrimaryInputsIfNeeded(Invocation, Instance);
13191317

1320-
if (Context.hadError()) {
1321-
// Emit the index store data even if there were compiler errors.
1322-
(void)emitIndexData(Invocation, Instance);
1318+
emitIndexData(Invocation, Instance);
1319+
1320+
if (Context.hadError())
13231321
return true;
1324-
}
13251322

13261323
(void)emitLoadedModuleTraceForAllPrimariesIfNeeded(
13271324
Instance.getMainModule(), Instance.getDependencyTracker(), opts);
13281325

13291326
// We've just been told to perform a typecheck, so we can return now.
13301327
if (Action == FrontendOptions::ActionType::Typecheck) {
1331-
if (emitIndexData(Invocation, Instance))
1332-
return true;
13331328
// FIXME: Whole-module outputs with a non-whole-module -typecheck ought to
13341329
// be disallowed, but the driver implements -index-file mode by generating a
13351330
// regular whole-module frontend command line and modifying it to index just
@@ -1641,17 +1636,10 @@ static bool performCompileStepsPostSILGen(CompilerInstance &Instance,
16411636
if (Action == FrontendOptions::ActionType::EmitSIB)
16421637
return serializeSIB(SM.get(), PSPs, Context, MSF);
16431638

1644-
{
1645-
if (PSPs.haveModuleOrModuleDocOutputPaths()) {
1646-
if (Action == FrontendOptions::ActionType::MergeModules ||
1647-
Action == FrontendOptions::ActionType::EmitModuleOnly) {
1648-
// What if MSF is a module?
1649-
// emitIndexDataIfNeeded already handles that case;
1650-
// it'll index everything.
1651-
return emitIndexDataIfNeeded(MSF.dyn_cast<SourceFile *>(), Invocation,
1652-
Instance) ||
1653-
Context.hadError();
1654-
}
1639+
if (PSPs.haveModuleOrModuleDocOutputPaths()) {
1640+
if (Action == FrontendOptions::ActionType::MergeModules ||
1641+
Action == FrontendOptions::ActionType::EmitModuleOnly) {
1642+
return Context.hadError();
16551643
}
16561644
}
16571645

@@ -1703,11 +1691,6 @@ static bool performCompileStepsPostSILGen(CompilerInstance &Instance,
17031691
IRGenOpts, std::move(SM), PSPs, OutputFilename, MSF, HashGlobal,
17041692
ParallelOutputFilenames, LinkerDirectives);
17051693

1706-
// Walk the AST for indexing after IR generation. Walking it before seems
1707-
// to cause miscompilation issues.
1708-
if (emitIndexDataIfNeeded(MSF.dyn_cast<SourceFile *>(), Invocation, Instance))
1709-
return true;
1710-
17111694
// Just because we had an AST error it doesn't mean we can't performLLVM.
17121695
bool HadError = Instance.getASTContext().hadError();
17131696

@@ -1726,13 +1709,13 @@ static bool performCompileStepsPostSILGen(CompilerInstance &Instance,
17261709
HadError;
17271710
}
17281711

1729-
static bool emitIndexDataIfNeeded(SourceFile *PrimarySourceFile,
1712+
static void emitIndexDataIfNeeded(SourceFile *PrimarySourceFile,
17301713
const CompilerInvocation &Invocation,
17311714
const CompilerInstance &Instance) {
17321715
const FrontendOptions &opts = Invocation.getFrontendOptions();
17331716

17341717
if (opts.IndexStorePath.empty())
1735-
return false;
1718+
return;
17361719

17371720
// FIXME: provide index unit token(s) explicitly and only use output file
17381721
// paths as a fallback.
@@ -1753,29 +1736,23 @@ static bool emitIndexDataIfNeeded(SourceFile *PrimarySourceFile,
17531736
const PrimarySpecificPaths &PSPs =
17541737
opts.InputsAndOutputs.getPrimarySpecificPathsForPrimary(
17551738
PrimarySourceFile->getFilename());
1756-
if (index::indexAndRecord(PrimarySourceFile, PSPs.OutputFilename,
1757-
opts.IndexStorePath, opts.IndexSystemModules,
1758-
opts.IndexIgnoreStdlib, isDebugCompilation,
1759-
Invocation.getTargetTriple(),
1760-
*Instance.getDependencyTracker())) {
1761-
return true;
1762-
}
1739+
(void) index::indexAndRecord(PrimarySourceFile, PSPs.OutputFilename,
1740+
opts.IndexStorePath, opts.IndexSystemModules,
1741+
opts.IndexIgnoreStdlib, isDebugCompilation,
1742+
Invocation.getTargetTriple(),
1743+
*Instance.getDependencyTracker());
17631744
} else {
17641745
std::string moduleToken =
17651746
Invocation.getModuleOutputPathForAtMostOnePrimary();
17661747
if (moduleToken.empty())
17671748
moduleToken = opts.InputsAndOutputs.getSingleOutputFilename();
17681749

1769-
if (index::indexAndRecord(Instance.getMainModule(), opts.InputsAndOutputs.copyOutputFilenames(),
1770-
moduleToken, opts.IndexStorePath,
1771-
opts.IndexSystemModules, opts.IndexIgnoreStdlib,
1772-
isDebugCompilation, Invocation.getTargetTriple(),
1773-
*Instance.getDependencyTracker())) {
1774-
return true;
1775-
}
1750+
(void) index::indexAndRecord(Instance.getMainModule(), opts.InputsAndOutputs.copyOutputFilenames(),
1751+
moduleToken, opts.IndexStorePath,
1752+
opts.IndexSystemModules, opts.IndexIgnoreStdlib,
1753+
isDebugCompilation, Invocation.getTargetTriple(),
1754+
*Instance.getDependencyTracker());
17761755
}
1777-
1778-
return false;
17791756
}
17801757

17811758
/// Returns true if an error occurred.

0 commit comments

Comments
 (0)