Skip to content

Commit 2b08d1b

Browse files
committed
[NFC] ASTContext::getLazyResolver -> ASTContext::getLegacyGlobalTypeChecker
1 parent 56a713f commit 2b08d1b

19 files changed

+72
-66
lines changed

include/swift/AST/ASTContext.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ namespace swift {
101101
class SourceManager;
102102
class ValueDecl;
103103
class DiagnosticEngine;
104+
class TypeChecker;
104105
class TypeCheckerDebugConsumer;
105106
struct RawComment;
106107
class DocComment;
@@ -404,8 +405,13 @@ class ASTContext final {
404405
void setStatsReporter(UnifiedStatsReporter *stats);
405406

406407
private:
408+
friend class TypeChecker;
407409

410+
void installGlobalTypeChecker(TypeChecker *TC);
408411
public:
412+
/// Retrieve the global \c TypeChecker instance associated with this context.
413+
TypeChecker *getLegacyGlobalTypeChecker() const;
414+
409415
/// getIdentifier - Return the uniqued and AST-Context-owned version of the
410416
/// specified string.
411417
Identifier getIdentifier(StringRef Str) const;

lib/AST/ASTContext.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ struct ASTContext::Implementation {
159159
/// The set of cleanups to be called when the ASTContext is destroyed.
160160
std::vector<std::function<void(void)>> Cleanups;
161161

162-
/// The last resolver.
163-
LazyResolver *Resolver = nullptr;
162+
/// A global type checker instance..
163+
TypeChecker *Checker = nullptr;
164164

165165
// FIXME: This is a StringMap rather than a StringSet because StringSet
166166
// doesn't allow passing in a pre-existing allocator.
@@ -479,8 +479,6 @@ ASTContext::Implementation::Implementation()
479479
: IdentifierTable(Allocator),
480480
TheSyntaxArena(new syntax::SyntaxArena()) {}
481481
ASTContext::Implementation::~Implementation() {
482-
delete Resolver;
483-
484482
for (auto &cleanup : Cleanups)
485483
cleanup();
486484
}
@@ -630,8 +628,9 @@ TypeChecker *ASTContext::getLegacyGlobalTypeChecker() const {
630628
return getImpl().Checker;
631629
}
632630

633-
634-
getImpl().Resolver = resolver;
631+
void ASTContext::installGlobalTypeChecker(TypeChecker *TC) {
632+
assert(!getImpl().Checker);
633+
getImpl().Checker = TC;
635634
}
636635

637636
/// getIdentifier - Return the uniqued and AST-Context-owned version of the

lib/AST/Decl.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2889,8 +2889,8 @@ Type ValueDecl::getInterfaceType() const {
28892889

28902890
// N.B. This assertion exists to catch new broken callers. It can be removed
28912891
// with the LazyResolver when the time comes.
2892-
assert(ctx.getLazyResolver()
2893-
&& "The lazy resolver must be registered to make semantic queries!");
2892+
assert(ctx.getLegacyGlobalTypeChecker()
2893+
&& "The type checker must be installed to make semantic queries!");
28942894

28952895
if (auto type =
28962896
evaluateOrDefault(ctx.evaluator,
@@ -5686,8 +5686,9 @@ StaticSpellingKind AbstractStorageDecl::getCorrectStaticSpelling() const {
56865686

56875687
llvm::TinyPtrVector<CustomAttr *> VarDecl::getAttachedPropertyWrappers() const {
56885688
auto &ctx = getASTContext();
5689-
if (!ctx.getLazyResolver())
5689+
if (!ctx.getLegacyGlobalTypeChecker()) {
56905690
return { };
5691+
}
56915692

56925693
auto mutableThis = const_cast<VarDecl *>(this);
56935694
return evaluateOrDefault(ctx.evaluator,
@@ -6542,7 +6543,7 @@ ObjCSelector
65426543
AbstractFunctionDecl::getObjCSelector(DeclName preferredName,
65436544
bool skipIsObjCResolution) const {
65446545
// FIXME: Forces computation of the Objective-C selector.
6545-
if (getASTContext().getLazyResolver() && !skipIsObjCResolution)
6546+
if (getASTContext().getLegacyGlobalTypeChecker() && !skipIsObjCResolution)
65466547
(void)isObjC();
65476548

65486549
// If there is an @objc attribute with a name, use that name.

lib/AST/NameLookup.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,6 @@ bool DeclContext::lookupQualified(ArrayRef<NominalTypeDecl *> typeDecls,
15891589
// Visit all of the nominal types we know about, discovering any others
15901590
// we need along the way.
15911591
auto &ctx = getASTContext();
1592-
auto typeResolver = ctx.getLazyResolver();
15931592
bool wantProtocolMembers = (options & NL_ProtocolMembers);
15941593
while (!stack.empty()) {
15951594
auto current = stack.back();
@@ -1599,7 +1598,7 @@ bool DeclContext::lookupQualified(ArrayRef<NominalTypeDecl *> typeDecls,
15991598
tracker->addUsedMember({current, member.getBaseName()},isLookupCascading);
16001599

16011600
// Make sure we've resolved implicit members, if we need them.
1602-
if (typeResolver) {
1601+
if (ctx.getLegacyGlobalTypeChecker()) {
16031602
current->synthesizeSemanticMembersIfNeeded(member);
16041603
installPropertyWrapperMembersIfNeeded(current, member);
16051604
}

lib/AST/Type.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,8 +1150,6 @@ CanType TypeBase::computeCanonicalType() {
11501150
// If we haven't set a depth for this generic parameter, try to do so.
11511151
// FIXME: This is a dreadful hack.
11521152
if (gpDecl->getDepth() == GenericTypeParamDecl::InvalidDepth) {
1153-
auto resolver = gpDecl->getASTContext().getLazyResolver();
1154-
assert(resolver && "Need to resolve generic parameter depth");
11551153
if (auto decl =
11561154
gpDecl->getDeclContext()->getInnermostDeclarationDeclContext())
11571155
if (auto valueDecl = decl->getAsGenericContext())

lib/IDE/CodeCompletion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1643,7 +1643,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
16431643
Importer(static_cast<ClangImporter *>(CurrDeclContext->getASTContext().
16441644
getClangModuleLoader())),
16451645
CompletionContext(CompletionContext) {
1646-
(void)createTypeChecker(Ctx);
1646+
(void)swift::createTypeChecker(Ctx);
16471647

16481648
// Determine if we are doing code completion inside a static method.
16491649
if (CurrDeclContext) {

lib/Sema/CSGen.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3768,9 +3768,9 @@ bool swift::areGenericRequirementsSatisfied(
37683768
const DeclContext *DC, GenericSignature sig,
37693769
SubstitutionMap Substitutions, bool isExtension) {
37703770

3771-
TypeChecker &TC = createTypeChecker(DC->getASTContext());
3771+
auto *TC = DC->getASTContext().getLegacyGlobalTypeChecker();
37723772
ConstraintSystemOptions Options;
3773-
ConstraintSystem CS(TC, const_cast<DeclContext *>(DC), Options);
3773+
ConstraintSystem CS(*TC, const_cast<DeclContext *>(DC), Options);
37743774
auto Loc = CS.getConstraintLocator(nullptr);
37753775

37763776
// For every requirement, add a constraint.
@@ -3793,9 +3793,10 @@ bool swift::areGenericRequirementsSatisfied(
37933793
bool swift::canSatisfy(Type type1, Type type2, bool openArchetypes,
37943794
ConstraintKind kind, DeclContext *dc) {
37953795
std::unique_ptr<TypeChecker> CreatedTC;
3796-
auto &TC = TypeChecker::createForContext(dc->getASTContext());
3797-
return TC.typesSatisfyConstraint(type1, type2, openArchetypes, kind, dc,
3798-
/*unwrappedIUO=*/nullptr);
3796+
auto *TC = dc->getASTContext().getLegacyGlobalTypeChecker();
3797+
assert(TC && "Must have type checker to make semantic query!");
3798+
return TC->typesSatisfyConstraint(type1, type2, openArchetypes, kind, dc,
3799+
/*unwrappedIUO=*/nullptr);
37993800
}
38003801

38013802
void swift::eraseOpenedExistentials(ConstraintSystem &CS, Expr *&expr) {
@@ -3841,8 +3842,9 @@ swift::resolveValueMember(DeclContext &DC, Type BaseTy, DeclName Name) {
38413842
ResolvedMemberResult Result;
38423843
std::unique_ptr<TypeChecker> CreatedTC;
38433844
// If the current ast context has no type checker, create one for it.
3844-
auto &TC = TypeChecker::createForContext(DC.getASTContext());
3845-
ConstraintSystem CS(TC, &DC, None);
3845+
auto *TC = DC.getASTContext().getLegacyGlobalTypeChecker();
3846+
assert(TC && "Must have type checker to make global query!");
3847+
ConstraintSystem CS(*TC, &DC, None);
38463848

38473849
// Look up all members of BaseTy with the given Name.
38483850
MemberLookupResult LookupResult = CS.performMemberLookup(

lib/Sema/CSRanking.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,8 @@ llvm::Expected<bool> CompareDeclSpecializationRequest::evaluate(
390390
Evaluator &eval, DeclContext *dc, ValueDecl *decl1, ValueDecl *decl2,
391391
bool isDynamicOverloadComparison) const {
392392
auto &C = decl1->getASTContext();
393-
// FIXME: Remove dependency on the lazy resolver.
394-
auto *tc = static_cast<TypeChecker *>(C.getLazyResolver());
393+
// FIXME: Remove dependency on the global type checker.
394+
auto *tc = C.getLegacyGlobalTypeChecker();
395395

396396
if (C.LangOpts.DebugConstraintSolver) {
397397
auto &log = C.TypeCheckerDebug->getStream();

lib/Sema/DebuggerTestingTransform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ class DebuggerTestingTransform : public ASTWalker {
218218
CheckExpectExpr->setThrows(false);
219219

220220
// Create the closure.
221-
TypeChecker &TC = TypeChecker::createForContext(Ctx);
222221
auto *Params = ParameterList::createEmpty(Ctx);
223222
auto *Closure = new (Ctx)
224223
ClosureExpr(Params, SourceLoc(), SourceLoc(), SourceLoc(), TypeLoc(),
@@ -238,6 +237,7 @@ class DebuggerTestingTransform : public ASTWalker {
238237
// TODO: typeCheckExpression() seems to assign types to everything here,
239238
// but may not be sufficient in some cases.
240239
Expr *FinalExpr = ClosureCall;
240+
auto &TC = swift::createTypeChecker(Ctx);
241241
if (!TC.typeCheckExpression(FinalExpr, getCurrentDeclContext()))
242242
llvm::report_fatal_error("Could not type-check instrumentation");
243243

lib/Sema/IDETypeCheckingRequests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static bool isExtensionAppliedInternal(const DeclContext *DC, Type BaseTy,
5656
if (!ED->isConstrainedExtension())
5757
return true;
5858

59-
(void)TypeChecker::createForContext(DC->getASTContext());
59+
(void)swift::createTypeChecker(DC->getASTContext());
6060
GenericSignature genericSig = ED->getGenericSignature();
6161
SubstitutionMap substMap = BaseTy->getContextSubstitutionMap(
6262
DC->getParentModule(), ED->getExtendedNominal());

0 commit comments

Comments
 (0)