Skip to content

Commit c3c490e

Browse files
committed
Remove the ability to reference instances of TypeChecker
1 parent 52c8086 commit c3c490e

File tree

10 files changed

+15
-68
lines changed

10 files changed

+15
-68
lines changed

include/swift/AST/ASTContext.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -445,15 +445,7 @@ class ASTContext final {
445445
private:
446446
friend class TypeChecker;
447447

448-
void installGlobalTypeChecker(TypeChecker *TC);
449448
public:
450-
/// Returns if semantic AST queries are enabled. This generally means module
451-
/// loading and name lookup can take place.
452-
bool areSemanticQueriesEnabled() const;
453-
454-
/// Retrieve the global \c TypeChecker instance associated with this context.
455-
TypeChecker *getLegacyGlobalTypeChecker() const;
456-
457449
/// getIdentifier - Return the uniqued and AST-Context-owned version of the
458450
/// specified string.
459451
Identifier getIdentifier(StringRef Str) const;

include/swift/AST/LookupKinds.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,15 @@ enum NLOptions : unsigned {
6262
/// Include synonyms declared with @_implements()
6363
NL_IncludeAttributeImplements = 0x100,
6464

65+
/// Synthesize property wrappers and include them in the lookup results.
66+
NL_IncludePropertyWrappers = 0x200,
67+
6568
/// This lookup is known to not add any additional dependencies to the
6669
/// primary source file.
6770
///
6871
/// \see NL_KnownDependencyMask
6972
NL_KnownNoDependency =
70-
NL_KnownNonCascadingDependency|NL_KnownCascadingDependency,
73+
NL_KnownNonCascadingDependency | NL_KnownCascadingDependency,
7174

7275
/// A mask of all options controlling how a lookup should be recorded as a
7376
/// dependency.
@@ -83,10 +86,12 @@ enum NLOptions : unsigned {
8386
///
8487
/// FIXME: Eventually, add NL_ProtocolMembers to this, once all of the
8588
/// callers can handle it.
86-
NL_QualifiedDefault = NL_RemoveNonVisible | NL_RemoveOverridden,
89+
NL_QualifiedDefault =
90+
NL_RemoveNonVisible | NL_RemoveOverridden | NL_IncludePropertyWrappers,
8791

8892
/// The default set of options used for unqualified name lookup.
89-
NL_UnqualifiedDefault = NL_RemoveNonVisible | NL_RemoveOverridden
93+
NL_UnqualifiedDefault =
94+
NL_RemoveNonVisible | NL_RemoveOverridden | NL_IncludePropertyWrappers,
9095
};
9196

9297
static inline NLOptions operator|(NLOptions lhs, NLOptions rhs) {

include/swift/Subsystems.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ namespace swift {
145145
/// doesn't already have one.
146146
///
147147
/// \returns a reference to the type checker instance.
148-
TypeChecker &createTypeChecker(ASTContext &Ctx);
148+
void createTypeChecker(ASTContext &Ctx);
149149

150150
/// Bind all 'extension' visible from \p SF to the extended nominal.
151151
void bindExtensions(SourceFile &SF);

lib/AST/ASTContext.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,6 @@ struct ASTContext::Implementation {
155155
/// The set of cleanups to be called when the ASTContext is destroyed.
156156
std::vector<std::function<void(void)>> Cleanups;
157157

158-
/// A global type checker instance..
159-
TypeChecker *Checker = nullptr;
160-
161158
// FIXME: This is a StringMap rather than a StringSet because StringSet
162159
// doesn't allow passing in a pre-existing allocator.
163160
llvm::StringMap<Identifier::Aligner, llvm::BumpPtrAllocator&>
@@ -632,19 +629,6 @@ RC<syntax::SyntaxArena> ASTContext::getSyntaxArena() const {
632629
return getImpl().TheSyntaxArena;
633630
}
634631

635-
bool ASTContext::areSemanticQueriesEnabled() const {
636-
return getLegacyGlobalTypeChecker() != nullptr;
637-
}
638-
639-
TypeChecker *ASTContext::getLegacyGlobalTypeChecker() const {
640-
return getImpl().Checker;
641-
}
642-
643-
void ASTContext::installGlobalTypeChecker(TypeChecker *TC) {
644-
assert(!getImpl().Checker);
645-
getImpl().Checker = TC;
646-
}
647-
648632
/// getIdentifier - Return the uniqued and AST-Context-owned version of the
649633
/// specified string.
650634
Identifier ASTContext::getIdentifier(StringRef Str) const {

lib/AST/Decl.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2998,8 +2998,6 @@ bool ValueDecl::isRecursiveValidation() const {
29982998
Type ValueDecl::getInterfaceType() const {
29992999
auto &ctx = getASTContext();
30003000

3001-
assert(ctx.areSemanticQueriesEnabled());
3002-
30033001
if (auto type =
30043002
evaluateOrDefault(ctx.evaluator,
30053003
InterfaceTypeRequest{const_cast<ValueDecl *>(this)},
@@ -5813,10 +5811,6 @@ StaticSpellingKind AbstractStorageDecl::getCorrectStaticSpelling() const {
58135811

58145812
llvm::TinyPtrVector<CustomAttr *> VarDecl::getAttachedPropertyWrappers() const {
58155813
auto &ctx = getASTContext();
5816-
if (!ctx.areSemanticQueriesEnabled()) {
5817-
return { };
5818-
}
5819-
58205814
auto mutableThis = const_cast<VarDecl *>(this);
58215815
return evaluateOrDefault(ctx.evaluator,
58225816
AttachedPropertyWrappersRequest{mutableThis},
@@ -6786,7 +6780,7 @@ ObjCSelector
67866780
AbstractFunctionDecl::getObjCSelector(DeclName preferredName,
67876781
bool skipIsObjCResolution) const {
67886782
// FIXME: Forces computation of the Objective-C selector.
6789-
if (getASTContext().areSemanticQueriesEnabled() && !skipIsObjCResolution)
6783+
if (!skipIsObjCResolution)
67906784
(void)isObjC();
67916785

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

lib/AST/NameLookup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,8 +1612,8 @@ QualifiedLookupRequest::evaluate(Evaluator &eval, const DeclContext *DC,
16121612

16131613
// Visit all of the nominal types we know about, discovering any others
16141614
// we need along the way.
1615-
auto &ctx = DC->getASTContext();
16161615
bool wantProtocolMembers = (options & NL_ProtocolMembers);
1616+
const bool includesPropertyWrappers = (options & NL_IncludePropertyWrappers);
16171617
while (!stack.empty()) {
16181618
auto current = stack.back();
16191619
stack.pop_back();
@@ -1622,7 +1622,7 @@ QualifiedLookupRequest::evaluate(Evaluator &eval, const DeclContext *DC,
16221622
tracker->addUsedMember({current, member.getBaseName()},isLookupCascading);
16231623

16241624
// Make sure we've resolved property wrappers, if we need them.
1625-
if (ctx.areSemanticQueriesEnabled()) {
1625+
if (includesPropertyWrappers) {
16261626
installPropertyWrapperMembersIfNeeded(current, member);
16271627
}
16281628

lib/Sema/CSGen.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4405,7 +4405,6 @@ getMemberDecls(InterestedMemberKind Kind) {
44054405
ResolvedMemberResult
44064406
swift::resolveValueMember(DeclContext &DC, Type BaseTy, DeclName Name) {
44074407
ResolvedMemberResult Result;
4408-
assert(DC.getASTContext().areSemanticQueriesEnabled());
44094408
ConstraintSystem CS(&DC, None);
44104409

44114410
// Look up all members of BaseTy with the given Name.

lib/Sema/TypeCheckPropertyWrapper.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,6 @@ AttachedPropertyWrapperTypeRequest::evaluate(Evaluator &evaluator,
498498
return Type();
499499

500500
ASTContext &ctx = var->getASTContext();
501-
if (!ctx.areSemanticQueriesEnabled())
502-
return nullptr;
503-
504501
auto resolution =
505502
TypeResolution::forContextual(var->getDeclContext());
506503
TypeResolutionOptions options(TypeResolverContext::PatternBindingDecl);
@@ -533,10 +530,6 @@ PropertyWrapperBackingPropertyTypeRequest::evaluate(
533530
if (!binding)
534531
return Type();
535532

536-
ASTContext &ctx = var->getASTContext();
537-
if (!ctx.areSemanticQueriesEnabled())
538-
return Type();
539-
540533
// If there's an initializer of some sort, checking it will determine the
541534
// property wrapper type.
542535
unsigned index = binding->getPatternEntryIndexForVarDecl(var);
@@ -546,6 +539,7 @@ PropertyWrapperBackingPropertyTypeRequest::evaluate(
546539
if (!binding->isInitializerChecked(index))
547540
TypeChecker::typeCheckPatternBinding(binding, index);
548541

542+
auto &ctx = var->getASTContext();
549543
Type type = ctx.getSideCachedPropertyWrapperBackingPropertyType(var);
550544
assert(type || ctx.Diags.hadAnyError());
551545
return type;

lib/Sema/TypeChecker.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,6 @@
5353

5454
using namespace swift;
5555

56-
TypeChecker &TypeChecker::createForContext(ASTContext &ctx) {
57-
assert(!ctx.getLegacyGlobalTypeChecker() &&
58-
"Cannot install more than one instance of the global type checker!");
59-
auto *TC = new TypeChecker();
60-
ctx.installGlobalTypeChecker(TC);
61-
ctx.addCleanup([=](){ delete TC; });
62-
return *ctx.getLegacyGlobalTypeChecker();
63-
}
64-
6556
ProtocolDecl *TypeChecker::getProtocol(ASTContext &Context, SourceLoc loc,
6657
KnownProtocolKind kind) {
6758
auto protocol = Context.getProtocol(kind);
@@ -346,7 +337,7 @@ TypeCheckSourceFileRequest::evaluate(Evaluator &eval, SourceFile *SF) const {
346337
BufferIndirectlyCausingDiagnosticRAII cpr(*SF);
347338

348339
// Make sure we have a type checker.
349-
TypeChecker &TC = createTypeChecker(Ctx);
340+
createTypeChecker(Ctx);
350341

351342
// Make sure that name binding has been completed before doing any type
352343
// checking.
@@ -537,7 +528,6 @@ bool swift::performTypeLocChecking(ASTContext &Ctx, TypeLoc &T,
537528
Optional<DiagnosticSuppression> suppression;
538529
if (!ProduceDiagnostics)
539530
suppression.emplace(Ctx.Diags);
540-
assert(Ctx.areSemanticQueriesEnabled());
541531
return TypeChecker::validateType(Ctx, T, resolution, options);
542532
}
543533

@@ -675,11 +665,7 @@ bool swift::typeCheckTopLevelCodeDecl(TopLevelCodeDecl *TLCD) {
675665
return true;
676666
}
677667

678-
TypeChecker &swift::createTypeChecker(ASTContext &Ctx) {
679-
if (auto *TC = Ctx.getLegacyGlobalTypeChecker())
680-
return *TC;
681-
return TypeChecker::createForContext(Ctx);
682-
}
668+
void swift::createTypeChecker(ASTContext &Ctx) {}
683669

684670
void TypeChecker::checkForForbiddenPrefix(ASTContext &C, DeclBaseName Name) {
685671
if (C.TypeCheckerOpts.DebugForbidTypecheckPrefix.empty())

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -411,13 +411,6 @@ class TypeChecker final {
411411

412412
friend class ASTContext;
413413

414-
public:
415-
/// Create a new type checker instance for the given ASTContext, if it
416-
/// doesn't already have one.
417-
///
418-
/// \returns a reference to the type checker.
419-
static TypeChecker &createForContext(ASTContext &ctx);
420-
421414
public:
422415
TypeChecker(const TypeChecker&) = delete;
423416
TypeChecker& operator=(const TypeChecker&) = delete;

0 commit comments

Comments
 (0)