Skip to content

Commit 00dd637

Browse files
committed
[Frontend] Factor out getSourceFileParsingOptions
1 parent 5d72c46 commit 00dd637

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

include/swift/Frontend/Frontend.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ class CompilerInstance {
460460
/// If \p BufID is already in the set, do nothing.
461461
void recordPrimaryInputBuffer(unsigned BufID);
462462

463-
bool isWholeModuleCompilation() { return PrimaryBufferIDs.empty(); }
463+
bool isWholeModuleCompilation() const { return PrimaryBufferIDs.empty(); }
464464

465465
public:
466466
// Out of line to avoid having to import SILModule.h.
@@ -642,6 +642,9 @@ class CompilerInstance {
642642
bool loadStdlibIfNeeded();
643643

644644
private:
645+
/// Compute the parsing options for a source file in the main module.
646+
SourceFile::ParsingOptions getSourceFileParsingOptions(bool forPrimary) const;
647+
645648
/// Retrieve a description of which modules should be implicitly imported.
646649
ImplicitImportInfo getImplicitImportInfo() const;
647650

lib/Frontend/Frontend.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -889,10 +889,8 @@ void CompilerInstance::finishTypeChecking() {
889889
});
890890
}
891891

892-
SourceFile *CompilerInstance::createSourceFileForMainModule(
893-
SourceFileKind fileKind, Optional<unsigned> bufferID) {
894-
ModuleDecl *mainModule = getMainModule();
895-
892+
SourceFile::ParsingOptions
893+
CompilerInstance::getSourceFileParsingOptions(bool forPrimary) const {
896894
const auto &frontendOpts = Invocation.getFrontendOptions();
897895
const auto action = frontendOpts.RequestedAction;
898896

@@ -912,9 +910,8 @@ SourceFile *CompilerInstance::createSourceFileForMainModule(
912910
opts |= SourceFile::ParsingFlags::DisableDelayedBodies;
913911
}
914912

915-
auto isPrimary = bufferID && isPrimaryInput(*bufferID);
916-
if (isPrimary || isWholeModuleCompilation()) {
917-
// Disable delayed body parsing for primaries.
913+
if (forPrimary || isWholeModuleCompilation()) {
914+
// Disable delayed body parsing for primaries and in WMO.
918915
opts |= SourceFile::ParsingFlags::DisableDelayedBodies;
919916
} else {
920917
// Suppress parse warnings for non-primaries, as they'll get parsed multiple
@@ -924,9 +921,18 @@ SourceFile *CompilerInstance::createSourceFileForMainModule(
924921

925922
// Enable interface hash computation for primaries, but not in WMO, as it's
926923
// only currently needed for incremental mode.
927-
if (isPrimary) {
924+
if (forPrimary) {
928925
opts |= SourceFile::ParsingFlags::EnableInterfaceHash;
929926
}
927+
return opts;
928+
}
929+
930+
SourceFile *CompilerInstance::createSourceFileForMainModule(
931+
SourceFileKind fileKind, Optional<unsigned> bufferID) {
932+
ModuleDecl *mainModule = getMainModule();
933+
934+
auto isPrimary = bufferID && isPrimaryInput(*bufferID);
935+
auto opts = getSourceFileParsingOptions(isPrimary);
930936

931937
auto *inputFile = new (*Context)
932938
SourceFile(*mainModule, fileKind, bufferID, opts, isPrimary);

0 commit comments

Comments
 (0)