Skip to content

Commit ce98971

Browse files
authored
Merge pull request swiftlang#31642 from slavapestov/sil-parser-astscope
SIL: Use ASTScope for SIL parsing
2 parents 692d5fa + 3ee2409 commit ce98971

File tree

6 files changed

+10
-22
lines changed

6 files changed

+10
-22
lines changed

include/swift/AST/SourceFile.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,6 @@ class SourceFile final : public FileUnit {
595595

596596
bool canBeParsedInFull() const;
597597

598-
bool isSuitableForASTScopes() const { return canBeParsedInFull(); }
599-
600598
/// Whether the bodies of types and functions within this file can be lazily
601599
/// parsed.
602600
bool hasDelayedBodyParsing() const;

lib/AST/ASTScopeCreation.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -768,8 +768,7 @@ bool ASTScope::areInactiveIfConfigClausesSupported() {
768768

769769
void ASTScope::expandFunctionBody(AbstractFunctionDecl *AFD) {
770770
auto *const SF = AFD->getParentSourceFile();
771-
if (SF->isSuitableForASTScopes())
772-
SF->getScope().expandFunctionBodyImpl(AFD);
771+
SF->getScope().expandFunctionBodyImpl(AFD);
773772
}
774773

775774
void ASTScope::expandFunctionBodyImpl(AbstractFunctionDecl *AFD) {

lib/AST/Module.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2566,7 +2566,6 @@ StringRef SourceFile::getFilename() const {
25662566
}
25672567

25682568
ASTScope &SourceFile::getScope() {
2569-
assert(isSuitableForASTScopes() && "Should not be creating scope tree");
25702569
if (!Scope)
25712570
Scope = std::unique_ptr<ASTScope>(new (getASTContext()) ASTScope(this));
25722571
return *Scope.get();

lib/AST/UnqualifiedLookup.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,7 @@ bool UnqualifiedLookupFactory::wouldUseASTScopesForLookupIfItWereEnabled()
571571
const {
572572
if (!Loc.isValid())
573573
return false;
574-
const auto *const SF = DC->getParentSourceFile();
575-
return SF && SF->isSuitableForASTScopes();
574+
return (bool) DC->getParentSourceFile();
576575
}
577576

578577
#pragma mark context-based lookup definitions

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@ namespace {
184184
std::function<void(Type)> ParsedTypeCallback;
185185

186186
bool performTypeLocChecking(TypeLoc &T, bool IsSILType,
187-
GenericEnvironment *GenericEnv = nullptr,
188-
DeclContext *DC = nullptr);
187+
GenericEnvironment *GenericEnv = nullptr);
189188

190189
void convertRequirements(SILFunction *F, ArrayRef<RequirementRepr> From,
191190
SmallVectorImpl<Requirement> &To);
@@ -1105,19 +1104,13 @@ static bool parseDeclSILOptional(bool *isTransparent,
11051104
}
11061105

11071106
bool SILParser::performTypeLocChecking(TypeLoc &T, bool IsSILType,
1108-
GenericEnvironment *GenericEnv,
1109-
DeclContext *DC) {
1107+
GenericEnvironment *GenericEnv) {
11101108
if (GenericEnv == nullptr)
11111109
GenericEnv = ContextGenericEnv;
11121110

1113-
if (!DC)
1114-
DC = &P.SF;
1115-
else if (!GenericEnv)
1116-
GenericEnv = DC->getGenericEnvironmentOfContext();
1117-
11181111
return swift::performTypeLocChecking(P.Context, T,
11191112
/*isSILMode=*/true, IsSILType,
1120-
GenericEnv, DC);
1113+
GenericEnv, &P.SF);
11211114
}
11221115

11231116
/// Find the top-level ValueDecl or Module given a name.
@@ -1712,8 +1705,7 @@ bool SILParser::parseSubstitutions(SmallVectorImpl<ParsedSubstitution> &parsed,
17121705
TypeLoc Ty = TyR.get();
17131706
if (defaultForProto)
17141707
bindProtocolSelfInTypeRepr(Ty, defaultForProto);
1715-
if (performTypeLocChecking(Ty, /*IsSILType=*/ false, GenericEnv,
1716-
defaultForProto))
1708+
if (performTypeLocChecking(Ty, /*IsSILType=*/ false, GenericEnv))
17171709
return true;
17181710
parsed.push_back({Loc, Ty.getType()});
17191711
} while (P.consumeIf(tok::comma));
@@ -6268,6 +6260,8 @@ ProtocolConformanceRef SILParser::parseProtocolConformance(
62686260
auto *genericParams = P.maybeParseGenericParams().getPtrOrNull();
62696261
if (genericParams) {
62706262
genericEnv = handleSILGenericParams(genericParams, &P.SF);
6263+
} else if (defaultForProto) {
6264+
genericEnv = defaultForProto->getGenericEnvironment();
62716265
}
62726266

62736267
auto retVal = parseProtocolConformanceHelper(proto, genericEnv, context,
@@ -6291,8 +6285,7 @@ ProtocolConformanceRef SILParser::parseProtocolConformanceHelper(
62916285
bindProtocolSelfInTypeRepr(Ty, defaultForProto);
62926286
}
62936287

6294-
if (performTypeLocChecking(Ty, /*IsSILType=*/ false, witnessEnv,
6295-
defaultForProto))
6288+
if (performTypeLocChecking(Ty, /*IsSILType=*/ false, witnessEnv))
62966289
return ProtocolConformanceRef();
62976290
auto ConformingTy = Ty.getType();
62986291

lib/Sema/TypeChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ TypeCheckSourceFileRequest::evaluate(Evaluator &eval, SourceFile *SF) const {
320320
// scope-based lookups. Only the top-level scopes because extensions have not
321321
// been bound yet.
322322
auto &Ctx = SF->getASTContext();
323-
if (Ctx.LangOpts.EnableASTScopeLookup && SF->isSuitableForASTScopes())
323+
if (Ctx.LangOpts.EnableASTScopeLookup)
324324
SF->getScope()
325325
.buildEnoughOfTreeForTopLevelExpressionsButDontRequestGenericsOrExtendedNominals();
326326

0 commit comments

Comments
 (0)