Skip to content

Commit 5e14ed3

Browse files
author
David Ungar
authored
Merge pull request #26859 from davidungar/A-8-15-astscope-off
[NameLookup ASTScopes] Still off-by-default, but much closer to turning on
2 parents e56743e + 7992e1c commit 5e14ed3

File tree

12 files changed

+599
-954
lines changed

12 files changed

+599
-954
lines changed

include/swift/AST/ASTScope.h

Lines changed: 77 additions & 54 deletions
Large diffs are not rendered by default.

include/swift/Basic/Statistics.def

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,22 @@ FRONTEND_STATISTIC(AST, NumUnqualifiedLookup)
160160
/// AnyObject lookup.
161161
FRONTEND_STATISTIC(AST, NumModuleLookupClassMember)
162162

163+
/// Number of body scopes for iterable types
164+
FRONTEND_STATISTIC(AST, NumIterableTypeBodyASTScopes)
165+
166+
/// Number of expansions of body scopes for iterable types
167+
FRONTEND_STATISTIC(AST, NumIterableTypeBodyASTScopeExpansions)
168+
169+
/// Number of brace statment scopes for iterable types
170+
FRONTEND_STATISTIC(AST, NumBraceStmtASTScopes)
171+
172+
/// Number of expansions of brace statement scopes for iterable types
173+
FRONTEND_STATISTIC(AST, NumBraceStmtASTScopeExpansions)
174+
175+
/// Number of ASTScope lookups
176+
FRONTEND_STATISTIC(AST, NumASTScopeLookups)
177+
178+
163179
/// Number of full function bodies parsed.
164180
FRONTEND_STATISTIC(Parse, NumFunctionsParsed)
165181

include/swift/Frontend/Frontend.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ class CompilerInvocation {
297297
/// Called from lldb, see rdar://53971116
298298
void disableASTScopeLookup() {
299299
LangOpts.EnableASTScopeLookup = false;
300+
LangOpts.LazyASTScopes = false;
300301
}
301302

302303
CodeCompletionCallbacksFactory *getCodeCompletionFactory() const {

lib/AST/ASTScope.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ llvm::SmallVector<const ASTScopeImpl *, 0> ASTScope::unqualifiedLookup(
4141
SourceFile *SF, DeclName name, SourceLoc loc,
4242
const DeclContext *startingContext,
4343
namelookup::AbstractASTScopeDeclConsumer &consumer) {
44+
if (auto *s = SF->getASTContext().Stats)
45+
++s->getFrontendCounters().NumASTScopeLookups;
4446
return ASTScopeImpl::unqualifiedLookup(SF, name, loc, startingContext,
4547
consumer);
4648
}
@@ -82,7 +84,7 @@ AbstractClosureScope::getClosureIfClosureScope() const {
8284

8385
// Conservative, because using precise info would be circular
8486
SourceRange
85-
AttachedPropertyWrapperScope::getSourceRangeFor(const VarDecl *const vd) {
87+
AttachedPropertyWrapperScope::getSourceRangeOfVarDecl(const VarDecl *const vd) {
8688
SourceRange sr;
8789
for (auto *attr : vd->getAttrs().getAttributes<CustomAttr>()) {
8890
if (sr.isInvalid())

lib/AST/ASTScopeCreation.cpp

Lines changed: 298 additions & 260 deletions
Large diffs are not rendered by default.

lib/AST/ASTScopeLookup.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const ASTScopeImpl *ASTScopeImpl::findStartingScopeForLookup(
5858

5959
auto *const fileScope = sourceFile->getScope().impl;
6060
// Parser may have added decls to source file, since previous lookup
61-
sourceFile->getScope().impl->addNewDeclsToTree();
61+
sourceFile->getScope().impl->addNewDeclsToScopeTree();
6262
if (name.isOperator())
6363
return fileScope; // operators always at file scope
6464

@@ -119,8 +119,8 @@ const ASTScopeImpl *ASTScopeImpl::findInnermostEnclosingScopeImpl(
119119
scopeCreator);
120120
}
121121

122-
bool ASTScopeImpl::checkChildlessSourceRange() const {
123-
const auto r = getChildlessSourceRange();
122+
bool ASTScopeImpl::checkSourceRangeOfThisASTNode() const {
123+
const auto r = getSourceRangeOfThisASTNode();
124124
(void)r;
125125
assert(!getSourceManager().isBeforeInBuffer(r.End, r.Start));
126126
return true;
@@ -134,19 +134,21 @@ ASTScopeImpl::findChildContaining(SourceLoc loc,
134134
SourceManager &sourceMgr;
135135

136136
bool operator()(const ASTScopeImpl *scope, SourceLoc loc) {
137-
assert(scope->checkChildlessSourceRange());
138-
return sourceMgr.isBeforeInBuffer(scope->getSourceRange().End, loc);
137+
assert(scope->checkSourceRangeOfThisASTNode());
138+
return sourceMgr.isBeforeInBuffer(scope->getSourceRangeOfScope().End,
139+
loc);
139140
}
140141
bool operator()(SourceLoc loc, const ASTScopeImpl *scope) {
141-
assert(scope->checkChildlessSourceRange());
142-
return sourceMgr.isBeforeInBuffer(loc, scope->getSourceRange().End);
142+
assert(scope->checkSourceRangeOfThisASTNode());
143+
return sourceMgr.isBeforeInBuffer(loc,
144+
scope->getSourceRangeOfScope().End);
143145
}
144146
};
145147
auto *const *child = std::lower_bound(
146148
getChildren().begin(), getChildren().end(), loc, CompareLocs{sourceMgr});
147149

148150
if (child != getChildren().end() &&
149-
sourceMgr.rangeContainsTokenLoc((*child)->getSourceRange(), loc))
151+
sourceMgr.rangeContainsTokenLoc((*child)->getSourceRangeOfScope(), loc))
150152
return *child;
151153

152154
return nullptr;

lib/AST/ASTScopePrinting.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static void printSourceRange(llvm::raw_ostream &out, const SourceRange range,
126126
void ASTScopeImpl::printRange(llvm::raw_ostream &out) const {
127127
if (!isSourceRangeCached(true))
128128
out << "(uncached) ";
129-
SourceRange range = getUncachedSourceRange(/*omitAssertions=*/true);
129+
SourceRange range = computeSourceRangeOfScope(/*omitAssertions=*/true);
130130
printSourceRange(out, range, getSourceManager());
131131
}
132132

@@ -151,10 +151,11 @@ NullablePtr<const void> ASTScopeImpl::addressForPrinting() const {
151151
void GenericTypeOrExtensionScope::printSpecifics(llvm::raw_ostream &out) const {
152152
if (shouldHaveABody() && !doesDeclHaveABody())
153153
out << "<no body>";
154-
else if (auto *n = getCorrespondingNominalTypeDecl().getPtrOrNull())
155-
out << "'" << n->getFullName() << "'";
156-
else
157-
out << "<no extended nominal?!>";
154+
// Sadly, the following can trip assertions
155+
// else if (auto *n = getCorrespondingNominalTypeDecl().getPtrOrNull())
156+
// out << "'" << n->getFullName() << "'";
157+
// else
158+
// out << "<no extended nominal?!>";
158159
}
159160

160161
void GenericParamScope::printSpecifics(llvm::raw_ostream &out) const {

0 commit comments

Comments
 (0)