[Parse] Check the SourceFile to see if bodies can be delayed

Remove the `DelayBodyParsing` flag from the parser
and instead query the source file.
This commit is contained in:
Hamish Knight
2020-02-11 15:30:34 -08:00
parent 2ec619caf7
commit 2724cf6f65
8 changed files with 53 additions and 62 deletions

View File

@@ -569,6 +569,10 @@ public:
bool isSuitableForASTScopes() const { return canBeParsedInFull(); }
/// Whether the bodies of types and functions within this file can be lazily
/// parsed.
bool hasDelayedBodyParsing() const;
syntax::SourceFileSyntax getSyntaxRoot() const;
void setSyntaxRoot(syntax::SourceFileSyntax &&Root);
bool hasSyntaxRoot() const;

View File

@@ -173,9 +173,9 @@ public:
LocalContext *CurLocalContext = nullptr;
bool isDelayedParsingEnabled() const {
return DelayBodyParsing || isCodeCompletionFirstPass();
}
/// Whether we should delay parsing nominal type, extension, and function
/// bodies.
bool isDelayedParsingEnabled() const;
void setCodeCompletionCallbacks(CodeCompletionCallbacks *Callbacks) {
CodeCompletion = Callbacks;
@@ -213,16 +213,6 @@ public:
/// Always empty if !SF.shouldBuildSyntaxTree().
ParsedTrivia TrailingTrivia;
/// Whether we should delay parsing nominal type and extension bodies,
/// and skip function bodies.
///
/// This is false in primary files, since we want to type check all
/// declarations and function bodies.
///
/// This is true for non-primary files, where declarations only need to be
/// lazily parsed and type checked.
bool DelayBodyParsing;
/// Whether to evaluate the conditions of #if decls, meaning that the bodies
/// of any active clauses are hoisted such that they become sibling nodes with
/// the #if decl.
@@ -408,16 +398,16 @@ public:
SILParserTUStateBase *SIL,
PersistentParserState *PersistentState,
std::shared_ptr<SyntaxParseActions> SPActions = nullptr,
bool DelayBodyParsing = true, bool EvaluateConditionals = true);
bool EvaluateConditionals = true);
Parser(unsigned BufferID, SourceFile &SF, SILParserTUStateBase *SIL,
PersistentParserState *PersistentState = nullptr,
std::shared_ptr<SyntaxParseActions> SPActions = nullptr,
bool DelayBodyParsing = true, bool EvaluateConditionals = true);
bool EvaluateConditionals = true);
Parser(std::unique_ptr<Lexer> Lex, SourceFile &SF,
SILParserTUStateBase *SIL = nullptr,
PersistentParserState *PersistentState = nullptr,
std::shared_ptr<SyntaxParseActions> SPActions = nullptr,
bool DelayBodyParsing = true, bool EvaluateConditionals = true);
bool EvaluateConditionals = true);
~Parser();
/// Returns true if the buffer being parsed is allowed to contain SIL.

View File

@@ -108,11 +108,7 @@ namespace swift {
/// \param SF The file within the module being parsed.
///
/// \param BufferID The buffer to parse from.
///
/// \param DelayBodyParsing Whether parsing of type and function bodies can be
/// delayed.
void parseIntoSourceFile(SourceFile &SF, unsigned BufferID,
bool DelayBodyParsing = true,
bool EvaluateConditionals = true);
/// Parse a source file's SIL declarations into a given SIL module.