Skip to content

Commit d328e44

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-rebranch
2 parents ee15a40 + 6efcff6 commit d328e44

File tree

10 files changed

+271
-249
lines changed

10 files changed

+271
-249
lines changed

include/swift/AST/ASTScope.h

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,10 @@ class ASTScopeImpl {
177177
void addChild(ASTScopeImpl *child, ASTContext &);
178178
std::vector<ASTScopeImpl *> rescueYoungestChildren(unsigned count);
179179

180-
virtual std::vector<ASTScopeImpl *> rescueScopesToReuse();
181-
virtual void addReusedScopes(ArrayRef<ASTScopeImpl *>);
180+
/// When reexpanding, do we always create a new body?
181+
virtual NullablePtr<ASTScopeImpl> getParentOfRescuedScopes();
182+
std::vector<ASTScopeImpl *> rescueScopesToReuse();
183+
void addReusedScopes(ArrayRef<ASTScopeImpl *>);
182184

183185
private:
184186
void removeChildren();
@@ -201,7 +203,8 @@ class ASTScopeImpl {
201203
/// InterpolatedStringLiteralExprs and EditorPlaceHolders respond to
202204
/// getSourceRange with the starting point. But we might be asked to lookup an
203205
/// identifer within one of them. So, find the real source range of them here.
204-
/// /// FIXME: Alter how these are parsed so getSourceRange is enough.
206+
///
207+
/// FIXME: Alter how these are parsed so getSourceRange is enough.
205208
SourceRange getEffectiveSourceRange(ASTNode) const;
206209

207210
void cacheSourceRangeOfMeAndDescendants(bool omitAssertions = false) const;
@@ -303,6 +306,12 @@ class ASTScopeImpl {
303306
virtual void beCurrent();
304307
virtual bool isCurrent() const;
305308

309+
/// Some scopes can be expanded lazily.
310+
/// Such scopes must: not change their source ranges after expansion, and
311+
/// their expansion must return an insertion point outside themselves.
312+
virtual NullablePtr<ASTScopeImpl> insertionPointForDeferredExpansion();
313+
virtual SourceRange sourceRangeForDeferredExpansion() const;
314+
306315
public:
307316
// Some nodes (VarDecls and Accessors) are created directly from
308317
// pattern scope code and should neither be deferred nor should
@@ -548,6 +557,10 @@ class Portion {
548557

549558
virtual void beCurrent(IterableTypeScope *) const;
550559
virtual bool isCurrent(const IterableTypeScope *) const;
560+
virtual NullablePtr<ASTScopeImpl>
561+
insertionPointForDeferredExpansion(IterableTypeScope *) const;
562+
virtual SourceRange
563+
sourceRangeForDeferredExpansion(const IterableTypeScope *) const;
551564
};
552565

553566
// For the whole Decl scope of a GenericType or an Extension
@@ -623,6 +636,10 @@ class IterableTypeBodyPortion final
623636

624637
void beCurrent(IterableTypeScope *) const override;
625638
bool isCurrent(const IterableTypeScope *) const override;
639+
NullablePtr<ASTScopeImpl>
640+
insertionPointForDeferredExpansion(IterableTypeScope *) const override;
641+
SourceRange
642+
sourceRangeForDeferredExpansion(const IterableTypeScope *) const override;
626643
};
627644

628645
/// GenericType or Extension scope
@@ -702,7 +719,6 @@ class IterableTypeScope : public GenericTypeScope {
702719
/// Because of \c parseDelayedDecl members can get added after the tree is
703720
/// constructed, and they can be out of order. Detect this happening by
704721
/// remembering the member count.
705-
/// TODO: unify with \c numberOfDeclsAlreadySeen
706722
unsigned memberCount = 0;
707723

708724
public:
@@ -721,6 +737,8 @@ class IterableTypeScope : public GenericTypeScope {
721737
public:
722738
void makeBodyCurrent();
723739
bool isBodyCurrent() const;
740+
NullablePtr<ASTScopeImpl> insertionPointForDeferredExpansion() override;
741+
SourceRange sourceRangeForDeferredExpansion() const override;
724742
};
725743

726744
class NominalTypeScope final : public IterableTypeScope {
@@ -958,8 +976,7 @@ class AbstractFunctionBodyScope : public ASTScopeImpl {
958976
Decl *getDecl() const { return decl; }
959977
static bool isAMethod(const AbstractFunctionDecl *);
960978

961-
std::vector<ASTScopeImpl *> rescueScopesToReuse() override;
962-
void addReusedScopes(ArrayRef<ASTScopeImpl *>) override;
979+
NullablePtr<ASTScopeImpl> getParentOfRescuedScopes() override;
963980

964981
protected:
965982
bool lookupLocalsOrMembers(ArrayRef<const ASTScopeImpl *>,
@@ -1122,7 +1139,6 @@ class PatternEntryDeclScope final : public AbstractPatternEntryScope {
11221139
SourceRange
11231140
getChildlessSourceRange(bool omitAssertions = false) const override;
11241141

1125-
static bool isHandledSpecially(const ASTNode n);
11261142
NullablePtr<const void> getReferrent() const override;
11271143

11281144
protected:
@@ -1372,8 +1388,7 @@ class TopLevelCodeScope final : public ASTScopeImpl {
13721388
Decl *getDecl() const { return decl; }
13731389
NullablePtr<const void> getReferrent() const override;
13741390

1375-
std::vector<ASTScopeImpl *> rescueScopesToReuse() override;
1376-
void addReusedScopes(ArrayRef<ASTScopeImpl *>) override;
1391+
NullablePtr<ASTScopeImpl> getParentOfRescuedScopes() override;
13771392
};
13781393

13791394
/// The \c _@specialize attribute.

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ namespace swift {
268268
/// whether it is. The warning is useful for testing.
269269
bool WarnIfASTScopeLookup = false;
270270

271+
/// Build the ASTScope tree lazily
272+
bool LazyASTScopes = false;
273+
271274
/// Whether to use the import as member inference system
272275
///
273276
/// When importing a global, try to infer whether we can import it as a

include/swift/Option/FrontendOptions.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ def compare_to_astscope_lookup : Flag<["-"], "compare-to-astscope-lookup">,
127127

128128
def warn_if_astscope_lookup : Flag<["-"], "warn-if-astscope-lookup">,
129129
HelpText<"Print a warning if ASTScope lookup is used">;
130+
131+
def lazy_astscopes : Flag<["-"], "lazy-astscopes">,
132+
HelpText<"Build ASTScopes lazily">;
130133

131134
def print_clang_stats : Flag<["-"], "print-clang-stats">,
132135
HelpText<"Print Clang importer statistics">;

0 commit comments

Comments
 (0)