Skip to content

Frontend: Go back to emitting index data after IRGen #31752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions lib/FrontendTool/FrontendTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,9 +653,6 @@ static void debugFailWithCrash() {
LLVM_BUILTIN_TRAP;
}

static void emitIndexDataIfNeeded(SourceFile *PrimarySourceFile,
const CompilerInstance &Instance);

static void countStatsOfSourceFile(UnifiedStatsReporter &Stats,
const CompilerInstance &Instance,
SourceFile *SF) {
Expand Down Expand Up @@ -1115,13 +1112,16 @@ static bool performCompileStepsPostSema(CompilerInstance &Instance,
return result;
}

static void emitIndexDataForSourceFile(SourceFile *PrimarySourceFile,
const CompilerInstance &Instance);

/// Emits index data for all primary inputs, or the main module.
static void emitIndexData(const CompilerInstance &Instance) {
if (Instance.getPrimarySourceFiles().empty()) {
emitIndexDataIfNeeded(nullptr, Instance);
emitIndexDataForSourceFile(nullptr, Instance);
} else {
for (SourceFile *SF : Instance.getPrimarySourceFiles())
emitIndexDataIfNeeded(SF, Instance);
emitIndexDataForSourceFile(SF, Instance);
}
}

Expand Down Expand Up @@ -1288,12 +1288,13 @@ static bool performCompile(CompilerInstance &Instance,

SWIFT_DEFER {
// We might have freed the ASTContext already, but in that case we must have
// emitted the dependencies first.
if (Instance.hasASTContext())
// emitted the dependencies and index first.
if (Instance.hasASTContext()) {
emitReferenceDependenciesForAllPrimaryInputsIfNeeded(Instance);
emitIndexData(Instance);
}
};

emitIndexData(Instance);

if (Context.hadError())
return true;
Expand Down Expand Up @@ -1489,9 +1490,10 @@ static void freeASTContextIfPossible(CompilerInstance &Instance) {
return;
}

// Make sure we emit dependencies now, because we can't do it after the
// context is gone.
// Make sure we emit dependencies and index now, because we can't do it after
// the context is gone.
emitReferenceDependenciesForAllPrimaryInputsIfNeeded(Instance);
emitIndexData(Instance);

Instance.freeASTContext();
}
Expand Down Expand Up @@ -1664,8 +1666,8 @@ static bool performCompileStepsPostSILGen(CompilerInstance &Instance,
HadError;
}

static void emitIndexDataIfNeeded(SourceFile *PrimarySourceFile,
const CompilerInstance &Instance) {
static void emitIndexDataForSourceFile(SourceFile *PrimarySourceFile,
const CompilerInstance &Instance) {
const auto &Invocation = Instance.getInvocation();
const auto &opts = Invocation.getFrontendOptions();

Expand Down