Skip to content

Commit 3ee2409

Browse files
committed
SIL: Use ASTScope for SIL parsing
1 parent ad3ea02 commit 3ee2409

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
@@ -170,8 +170,7 @@ namespace {
170170
std::function<void(Type)> ParsedTypeCallback;
171171

172172
bool performTypeLocChecking(TypeLoc &T, bool IsSILType,
173-
GenericEnvironment *GenericEnv = nullptr,
174-
DeclContext *DC = nullptr);
173+
GenericEnvironment *GenericEnv = nullptr);
175174

176175
void convertRequirements(SILFunction *F, ArrayRef<RequirementRepr> From,
177176
SmallVectorImpl<Requirement> &To);
@@ -1091,19 +1090,13 @@ static bool parseDeclSILOptional(bool *isTransparent,
10911090
}
10921091

10931092
bool SILParser::performTypeLocChecking(TypeLoc &T, bool IsSILType,
1094-
GenericEnvironment *GenericEnv,
1095-
DeclContext *DC) {
1093+
GenericEnvironment *GenericEnv) {
10961094
if (GenericEnv == nullptr)
10971095
GenericEnv = ContextGenericEnv;
10981096

1099-
if (!DC)
1100-
DC = &P.SF;
1101-
else if (!GenericEnv)
1102-
GenericEnv = DC->getGenericEnvironmentOfContext();
1103-
11041097
return swift::performTypeLocChecking(P.Context, T,
11051098
/*isSILMode=*/true, IsSILType,
1106-
GenericEnv, DC);
1099+
GenericEnv, &P.SF);
11071100
}
11081101

11091102
/// Find the top-level ValueDecl or Module given a name.
@@ -1698,8 +1691,7 @@ bool SILParser::parseSubstitutions(SmallVectorImpl<ParsedSubstitution> &parsed,
16981691
TypeLoc Ty = TyR.get();
16991692
if (defaultForProto)
17001693
bindProtocolSelfInTypeRepr(Ty, defaultForProto);
1701-
if (performTypeLocChecking(Ty, /*IsSILType=*/ false, GenericEnv,
1702-
defaultForProto))
1694+
if (performTypeLocChecking(Ty, /*IsSILType=*/ false, GenericEnv))
17031695
return true;
17041696
parsed.push_back({Loc, Ty.getType()});
17051697
} while (P.consumeIf(tok::comma));
@@ -6254,6 +6246,8 @@ ProtocolConformanceRef SILParser::parseProtocolConformance(
62546246
auto *genericParams = P.maybeParseGenericParams().getPtrOrNull();
62556247
if (genericParams) {
62566248
genericEnv = handleSILGenericParams(genericParams, &P.SF);
6249+
} else if (defaultForProto) {
6250+
genericEnv = defaultForProto->getGenericEnvironment();
62576251
}
62586252

62596253
auto retVal = parseProtocolConformanceHelper(proto, genericEnv, context,
@@ -6277,8 +6271,7 @@ ProtocolConformanceRef SILParser::parseProtocolConformanceHelper(
62776271
bindProtocolSelfInTypeRepr(Ty, defaultForProto);
62786272
}
62796273

6280-
if (performTypeLocChecking(Ty, /*IsSILType=*/ false, witnessEnv,
6281-
defaultForProto))
6274+
if (performTypeLocChecking(Ty, /*IsSILType=*/ false, witnessEnv))
62826275
return ProtocolConformanceRef();
62836276
auto ConformingTy = Ty.getType();
62846277

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)