Skip to content

Commit b53334e

Browse files
authored
Merge pull request swiftlang#32243 from hamishknight/whole-module-population
2 parents 059fe23 + 55cf78b commit b53334e

File tree

13 files changed

+192
-153
lines changed

13 files changed

+192
-153
lines changed

include/swift/AST/SourceFile.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class SourceFile final : public FileUnit {
105105
/// decl.
106106
///
107107
/// FIXME: When condition evaluation moves to a later phase, remove this
108-
/// and adjust the client call 'performParseOnly'.
108+
/// and the associated language option.
109109
DisablePoundIfEvaluation = 1 << 1,
110110

111111
/// Whether to build a syntax tree.
@@ -490,7 +490,7 @@ class SourceFile final : public FileUnit {
490490
}
491491

492492
SWIFT_DEBUG_DUMP;
493-
void dump(raw_ostream &os) const;
493+
void dump(raw_ostream &os, bool parseIfNeeded = false) const;
494494

495495
/// Pretty-print the contents of this source file.
496496
///

include/swift/Basic/LangOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ namespace swift {
335335
/// Whether to verify the parsed syntax tree and emit related diagnostics.
336336
bool VerifySyntaxTree = false;
337337

338+
/// Whether to disable the evaluation of '#if' decls, such that the bodies
339+
/// of active clauses aren't hoisted into the enclosing scope.
340+
bool DisablePoundIfEvaluation = false;
341+
338342
/// Instead of hashing tokens inside of NominalType and ExtensionBodies into
339343
/// the interface hash, hash them into per-iterable-decl-context
340344
/// fingerprints. Fine-grained dependency types won't dirty every provides

include/swift/Frontend/Frontend.h

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,9 @@ class CompilerInstance {
441441
std::vector<unsigned> InputSourceCodeBufferIDs;
442442

443443
/// Contains \c MemoryBuffers for partial serialized module files and
444-
/// corresponding partial serialized module documentation files.
445-
std::vector<ModuleBuffers> PartialModules;
444+
/// corresponding partial serialized module documentation files. This is
445+
/// \c mutable as it is consumed by \c loadPartialModulesAndImplicitImports.
446+
mutable std::vector<ModuleBuffers> PartialModules;
446447

447448
enum : unsigned { NO_SUCH_BUFFER = ~0U };
448449
unsigned MainBufferID = NO_SUCH_BUFFER;
@@ -460,7 +461,7 @@ class CompilerInstance {
460461
/// If \p BufID is already in the set, do nothing.
461462
void recordPrimaryInputBuffer(unsigned BufID);
462463

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

465466
public:
466467
// Out of line to avoid having to import SILModule.h.
@@ -615,10 +616,6 @@ class CompilerInstance {
615616
/// Parses and type-checks all input files.
616617
void performSema();
617618

618-
/// Parses the input file but does no type-checking or module imports.
619-
void performParseOnly(bool EvaluateConditionals = false,
620-
bool CanDelayBodies = true);
621-
622619
/// Parses and performs import resolution on all input files.
623620
///
624621
/// This is similar to a parse-only invocation, but module imports will also
@@ -631,10 +628,15 @@ class CompilerInstance {
631628
bool performSILProcessing(SILModule *silModule);
632629

633630
private:
634-
SourceFile *
635-
createSourceFileForMainModule(SourceFileKind FileKind,
636-
Optional<unsigned> BufferID,
637-
SourceFile::ParsingOptions options = {});
631+
/// Creates a new source file for the main module.
632+
SourceFile *createSourceFileForMainModule(ModuleDecl *mod,
633+
SourceFileKind FileKind,
634+
Optional<unsigned> BufferID) const;
635+
636+
/// Creates all the files to be added to the main module, appending them to
637+
/// \p files. If a loading error occurs, returns \c true.
638+
bool createFilesForMainModule(ModuleDecl *mod,
639+
SmallVectorImpl<FileUnit *> &files) const;
638640

639641
public:
640642
void freeASTContext();
@@ -644,14 +646,17 @@ class CompilerInstance {
644646
bool loadStdlibIfNeeded();
645647

646648
private:
649+
/// Compute the parsing options for a source file in the main module.
650+
SourceFile::ParsingOptions getSourceFileParsingOptions(bool forPrimary) const;
651+
647652
/// Retrieve a description of which modules should be implicitly imported.
648653
ImplicitImportInfo getImplicitImportInfo() const;
649654

650-
void performSemaUpTo(SourceFile::ASTStage_t LimitStage,
651-
SourceFile::ParsingOptions POpts = {});
652-
653-
/// Return true if had load error
654-
bool loadPartialModulesAndImplicitImports();
655+
/// For any serialized AST inputs, loads them in as partial module files,
656+
/// appending them to \p partialModules. If a loading error occurs, returns
657+
/// \c true.
658+
bool loadPartialModulesAndImplicitImports(
659+
ModuleDecl *mod, SmallVectorImpl<FileUnit *> &partialModules) const;
655660

656661
void forEachFileToTypeCheck(llvm::function_ref<void(SourceFile &)> fn);
657662

lib/AST/ASTDumper.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,13 @@ void SourceFile::dump() const {
14201420
dump(llvm::errs());
14211421
}
14221422

1423-
void SourceFile::dump(llvm::raw_ostream &OS) const {
1423+
void SourceFile::dump(llvm::raw_ostream &OS, bool parseIfNeeded) const {
1424+
// If we're allowed to parse the SourceFile, do so now. We need to force the
1425+
// parsing request as by default the dumping logic tries not to kick any
1426+
// requests.
1427+
if (parseIfNeeded)
1428+
(void)getTopLevelDecls();
1429+
14241430
PrintDecl(OS).visitSourceFile(*this);
14251431
llvm::errs() << '\n';
14261432
}

lib/AST/Module.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,6 +2233,8 @@ SourceFile::SourceFile(ModuleDecl &M, SourceFileKind K,
22332233
SourceFile::ParsingOptions
22342234
SourceFile::getDefaultParsingOptions(const LangOptions &langOpts) {
22352235
ParsingOptions opts;
2236+
if (langOpts.DisablePoundIfEvaluation)
2237+
opts |= ParsingFlags::DisablePoundIfEvaluation;
22362238
if (langOpts.BuildSyntaxTree)
22372239
opts |= ParsingFlags::BuildSyntaxTree;
22382240
if (langOpts.CollectParsedToken)

0 commit comments

Comments
 (0)