Skip to content

Commit 163cfd5

Browse files
authored
Merge pull request #86093 from hamishknight/remove-mod
[ASTScopes] Remove ModuleDecl param from `findChildContaining`
2 parents 6691e26 + 0ad231f commit 163cfd5

File tree

4 files changed

+20
-33
lines changed

4 files changed

+20
-33
lines changed

include/swift/AST/ASTScope.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -327,18 +327,15 @@ class ASTScopeImpl : public ASTAllocated<ASTScopeImpl> {
327327

328328
protected:
329329
/// Not const because may reexpand some scopes.
330-
ASTScopeImpl *findInnermostEnclosingScope(ModuleDecl *,
331-
SourceLoc,
330+
ASTScopeImpl *findInnermostEnclosingScope(SourceLoc,
332331
NullablePtr<raw_ostream>);
333-
ASTScopeImpl *findInnermostEnclosingScopeImpl(ModuleDecl *,
334-
SourceLoc,
332+
ASTScopeImpl *findInnermostEnclosingScopeImpl(SourceLoc,
335333
NullablePtr<raw_ostream>,
336334
SourceManager &,
337335
ScopeCreator &);
338336

339337
private:
340-
NullablePtr<ASTScopeImpl> findChildContaining(ModuleDecl *,
341-
SourceLoc loc,
338+
NullablePtr<ASTScopeImpl> findChildContaining(SourceLoc loc,
342339
SourceManager &sourceMgr) const;
343340

344341
#pragma mark - - lookup- per scope

lib/AST/ASTScopeCreation.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,7 @@ void ASTSourceFileScope::expandFunctionBody(AbstractFunctionDecl *AFD) {
286286
auto sr = AFD->getOriginalBodySourceRange();
287287
if (sr.isInvalid())
288288
return;
289-
ASTScopeImpl *bodyScope =
290-
findInnermostEnclosingScope(AFD->getParentModule(), sr.Start, nullptr);
289+
ASTScopeImpl *bodyScope = findInnermostEnclosingScope(sr.Start, nullptr);
291290
if (!bodyScope->getWasExpanded())
292291
bodyScope->expandAndBeCurrent(*scopeCreator);
293292
}

lib/AST/ASTScopeLookup.cpp

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -68,32 +68,30 @@ const ASTScopeImpl *ASTScopeImpl::findStartingScopeForLookup(
6868
if (actualSF != sourceFile)
6969
fileScope = actualSF->getScope().impl;
7070

71-
const auto *innermost = fileScope->findInnermostEnclosingScope(
72-
sourceFile->getParentModule(), loc, nullptr);
71+
const auto *innermost = fileScope->findInnermostEnclosingScope(loc, nullptr);
7372
ASTScopeAssert(innermost->getWasExpanded(),
7473
"If looking in a scope, it must have been expanded.");
7574

7675
return innermost;
7776
}
7877

7978
ASTScopeImpl *
80-
ASTScopeImpl::findInnermostEnclosingScope(ModuleDecl *parentModule,
81-
SourceLoc loc,
79+
ASTScopeImpl::findInnermostEnclosingScope(SourceLoc loc,
8280
NullablePtr<raw_ostream> os) {
83-
return findInnermostEnclosingScopeImpl(parentModule, loc, os,
84-
getSourceManager(), getScopeCreator());
81+
return findInnermostEnclosingScopeImpl(loc, os, getSourceManager(),
82+
getScopeCreator());
8583
}
8684

8785
ASTScopeImpl *ASTScopeImpl::findInnermostEnclosingScopeImpl(
88-
ModuleDecl *parentModule, SourceLoc loc, NullablePtr<raw_ostream> os,
89-
SourceManager &sourceMgr, ScopeCreator &scopeCreator) {
86+
SourceLoc loc, NullablePtr<raw_ostream> os, SourceManager &sourceMgr,
87+
ScopeCreator &scopeCreator) {
9088
if (!getWasExpanded())
9189
expandAndBeCurrent(scopeCreator);
92-
auto child = findChildContaining(parentModule, loc, sourceMgr);
90+
auto child = findChildContaining(loc, sourceMgr);
9391
if (!child)
9492
return this;
95-
return child.get()->findInnermostEnclosingScopeImpl(parentModule, loc, os,
96-
sourceMgr, scopeCreator);
93+
return child.get()->findInnermostEnclosingScopeImpl(loc, os, sourceMgr,
94+
scopeCreator);
9795
}
9896

9997
/// If the \p loc is in a new buffer but \p range is not, consider the location
@@ -111,8 +109,7 @@ static SourceLoc translateLocForReplacedRange(SourceManager &sourceMgr,
111109
}
112110

113111
NullablePtr<ASTScopeImpl>
114-
ASTScopeImpl::findChildContaining(ModuleDecl *parentModule,
115-
SourceLoc loc,
112+
ASTScopeImpl::findChildContaining(SourceLoc loc,
116113
SourceManager &sourceMgr) const {
117114
if (loc.isInvalid())
118115
return nullptr;
@@ -596,8 +593,7 @@ llvm::SmallVector<LabeledStmt *, 4>
596593
ASTScopeImpl::lookupLabeledStmts(SourceFile *sourceFile, SourceLoc loc) {
597594
// Find the innermost scope from which to start our search.
598595
auto *const fileScope = sourceFile->getScope().impl;
599-
const auto *innermost = fileScope->findInnermostEnclosingScope(
600-
sourceFile->getParentModule(), loc, nullptr);
596+
const auto *innermost = fileScope->findInnermostEnclosingScope(loc, nullptr);
601597
ASTScopeAssert(innermost->getWasExpanded(),
602598
"If looking in a scope, it must have been expanded.");
603599

@@ -625,8 +621,7 @@ std::pair<CaseStmt *, CaseStmt *> ASTScopeImpl::lookupFallthroughSourceAndDest(
625621
SourceFile *sourceFile, SourceLoc loc) {
626622
// Find the innermost scope from which to start our search.
627623
auto *const fileScope = sourceFile->getScope().impl;
628-
const auto *innermost = fileScope->findInnermostEnclosingScope(
629-
sourceFile->getParentModule(), loc, nullptr);
624+
const auto *innermost = fileScope->findInnermostEnclosingScope(loc, nullptr);
630625
ASTScopeAssert(innermost->getWasExpanded(),
631626
"If looking in a scope, it must have been expanded.");
632627

@@ -660,8 +655,7 @@ void ASTScopeImpl::lookupEnclosingMacroScope(
660655
return;
661656

662657
auto *fileScope = sourceFile->getScope().impl;
663-
auto *scope = fileScope->findInnermostEnclosingScope(
664-
sourceFile->getParentModule(), loc, nullptr);
658+
auto *scope = fileScope->findInnermostEnclosingScope(loc, nullptr);
665659
do {
666660
if (auto expansionScope = dyn_cast<MacroExpansionDeclScope>(scope)) {
667661
auto *expansionDecl = expansionScope->decl;
@@ -692,8 +686,7 @@ lookupEnclosingABIAttributeScope(SourceFile *sourceFile, SourceLoc loc) {
692686
return nullptr;
693687

694688
auto *fileScope = sourceFile->getScope().impl;
695-
auto *scope = fileScope->findInnermostEnclosingScope(
696-
sourceFile->getParentModule(), loc, nullptr);
689+
auto *scope = fileScope->findInnermostEnclosingScope(loc, nullptr);
697690
do {
698691
if (auto abiAttrScope = dyn_cast<ABIAttributeScope>(scope)) {
699692
return abiAttrScope->attr;
@@ -744,8 +737,7 @@ CatchNode ASTScopeImpl::lookupCatchNode(ModuleDecl *module, SourceLoc loc) {
744737
return nullptr;
745738

746739
auto *fileScope = sourceFile->getScope().impl;
747-
const auto *innermost = fileScope->findInnermostEnclosingScope(
748-
module, loc, nullptr);
740+
const auto *innermost = fileScope->findInnermostEnclosingScope(loc, nullptr);
749741
ASTScopeAssert(innermost->getWasExpanded(),
750742
"If looking in a scope, it must have been expanded.");
751743

lib/AST/ASTScopePrinting.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ void ASTScopeImpl::dumpOneScopeMapLocation(
5353

5454
llvm::errs() << "***Scope at " << lineColumn.first << ":" << lineColumn.second
5555
<< "***\n";
56-
auto *parentModule = getSourceFile()->getParentModule();
57-
auto *locScope = findInnermostEnclosingScope(parentModule, loc, &llvm::errs());
56+
auto *locScope = findInnermostEnclosingScope(loc, &llvm::errs());
5857
locScope->print(llvm::errs(), 0, false, false);
5958

6059
namelookup::ASTScopeDeclGatherer gatherer;

0 commit comments

Comments
 (0)