Skip to content

Commit 8adee83

Browse files
committed
[Frontend] Split off loadAccessNotesIfNeeded
This ought to be requestified, but for now let's split it into its own function.
1 parent 5755fb2 commit 8adee83

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

include/swift/Frontend/Frontend.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,11 @@ class CompilerInstance {
781781
/// Parses and type-checks all input files.
782782
void performSema();
783783

784+
/// Loads any access notes for the main module.
785+
///
786+
/// FIXME: This should be requestified.
787+
void loadAccessNotesIfNeeded();
788+
784789
/// Parses and performs import resolution on all input files.
785790
///
786791
/// This is similar to a parse-only invocation, but module imports will also

lib/Frontend/Frontend.cpp

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,33 +1543,40 @@ void CompilerInstance::setMainModule(ModuleDecl *newMod) {
15431543
Context->MainModule = newMod;
15441544
}
15451545

1546+
void CompilerInstance::loadAccessNotesIfNeeded() {
1547+
if (Invocation.getFrontendOptions().AccessNotesPath.empty())
1548+
return;
1549+
1550+
auto *mainModule = getMainModule();
1551+
1552+
auto accessNotesPath = Invocation.getFrontendOptions().AccessNotesPath;
1553+
1554+
auto bufferOrError =
1555+
swift::vfs::getFileOrSTDIN(getFileSystem(), accessNotesPath);
1556+
if (bufferOrError) {
1557+
int sourceID = SourceMgr.addNewSourceBuffer(std::move(bufferOrError.get()));
1558+
auto buffer = SourceMgr.getLLVMSourceMgr().getMemoryBuffer(sourceID);
1559+
1560+
if (auto accessNotesFile = AccessNotesFile::load(*Context, buffer))
1561+
mainModule->getAccessNotes() = *accessNotesFile;
1562+
} else {
1563+
Diagnostics.diagnose(SourceLoc(), diag::access_notes_file_io_error,
1564+
accessNotesPath, bufferOrError.getError().message());
1565+
}
1566+
}
1567+
15461568
bool CompilerInstance::performParseAndResolveImportsOnly() {
15471569
FrontendStatsTracer tracer(getStatsReporter(), "parse-and-resolve-imports");
15481570

1549-
auto *mainModule = getMainModule();
1571+
// NOTE: Do not add new logic to this function, use the request evaluator to
1572+
// lazily evaluate instead. Once the below computations are requestified we
1573+
// ought to be able to remove this function.
15501574

15511575
// Load access notes.
1552-
if (!Invocation.getFrontendOptions().AccessNotesPath.empty()) {
1553-
auto accessNotesPath = Invocation.getFrontendOptions().AccessNotesPath;
1554-
1555-
auto bufferOrError =
1556-
swift::vfs::getFileOrSTDIN(getFileSystem(), accessNotesPath);
1557-
if (bufferOrError) {
1558-
int sourceID =
1559-
SourceMgr.addNewSourceBuffer(std::move(bufferOrError.get()));
1560-
auto buffer =
1561-
SourceMgr.getLLVMSourceMgr().getMemoryBuffer(sourceID);
1562-
1563-
if (auto accessNotesFile = AccessNotesFile::load(*Context, buffer))
1564-
mainModule->getAccessNotes() = *accessNotesFile;
1565-
}
1566-
else {
1567-
Diagnostics.diagnose(SourceLoc(), diag::access_notes_file_io_error,
1568-
accessNotesPath, bufferOrError.getError().message());
1569-
}
1570-
}
1576+
loadAccessNotesIfNeeded();
15711577

15721578
// Resolve imports for all the source files in the module.
1579+
auto *mainModule = getMainModule();
15731580
performImportResolution(mainModule);
15741581

15751582
bindExtensions(*mainModule);

0 commit comments

Comments
 (0)