Skip to content

Commit 70b6bbc

Browse files
committed
Remove swift::createTypeChecker
Replace it with the "legacy semantic queries" bit. The remaining client of this bit is SourceKit, which appears to require this bit be set conditionally so certain semantic property wrapper requests return a sentinel value. We should migrate these requests to a syntactic interface as soon as possible. rdar://60516325
1 parent e79ac7e commit 70b6bbc

File tree

14 files changed

+58
-36
lines changed

14 files changed

+58
-36
lines changed

include/swift/AST/ASTContext.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,32 @@ class ASTContext final {
332332
llvm::BumpPtrAllocator &
333333
getAllocator(AllocationArena arena = AllocationArena::Permanent) const;
334334

335+
private:
336+
bool SemanticQueriesEnabled = false;
337+
338+
public:
339+
/// Returns \c true if legacy semantic AST queries are enabled.
340+
///
341+
/// The request evaluator generally subsumes the use of this bit. However,
342+
/// there are clients - mostly SourceKit - that rely on the fact that this bit
343+
/// being \c false causes some property wrapper requests to return null
344+
/// sentinel values. These clients should be migrated off of this interface
345+
/// to syntactic requests as soon as possible.
346+
///
347+
/// rdar://60516325
348+
bool areLegacySemanticQueriesEnabled() const {
349+
return SemanticQueriesEnabled;
350+
}
351+
352+
/// Enable "semantic queries".
353+
///
354+
/// Setting this bit tells property wrapper requests to return a semantic
355+
/// value. It does not otherwise affect compiler behavior and should be
356+
/// removed as soon as possible.
357+
void setLegacySemanticQueriesEnabled() {
358+
SemanticQueriesEnabled = true;
359+
}
360+
335361
public:
336362
/// Allocate - Allocate memory from the ASTContext bump pointer.
337363
void *Allocate(unsigned long bytes, unsigned alignment,

include/swift/AST/LookupKinds.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,12 @@ 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-
6865
/// This lookup is known to not add any additional dependencies to the
6966
/// primary source file.
7067
///
7168
/// \see NL_KnownDependencyMask
7269
NL_KnownNoDependency =
73-
NL_KnownNonCascadingDependency | NL_KnownCascadingDependency,
70+
NL_KnownNonCascadingDependency|NL_KnownCascadingDependency,
7471

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

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

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

include/swift/Subsystems.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,6 @@ namespace swift {
140140
/// lib/Sema/PCMacro.cpp for a description of the calls inserted.
141141
void performPCMacro(SourceFile &SF);
142142

143-
/// Creates a type checker instance on the given AST context, if it
144-
/// doesn't already have one.
145-
///
146-
/// \returns a reference to the type checker instance.
147-
void createTypeChecker(ASTContext &Ctx);
148-
149143
/// Bind all 'extension' visible from \p SF to the extended nominal.
150144
void bindExtensions(SourceFile &SF);
151145

lib/AST/Decl.cpp

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

3001+
assert(ctx.areLegacySemanticQueriesEnabled());
3002+
30013003
if (auto type =
30023004
evaluateOrDefault(ctx.evaluator,
30033005
InterfaceTypeRequest{const_cast<ValueDecl *>(this)},

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();
16151616
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 (includesPropertyWrappers) {
1625+
if (ctx.areLegacySemanticQueriesEnabled()) {
16261626
installPropertyWrapperMembersIfNeeded(current, member);
16271627
}
16281628

lib/Frontend/Frontend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ bool CompilerInstance::setUpASTContextIfNeeded() {
239239
if (setUpModuleLoaders())
240240
return true;
241241

242-
createTypeChecker(*Context);
242+
Context->setLegacySemanticQueriesEnabled();
243243
return false;
244244
}
245245

lib/IDE/CodeCompletion.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,7 +1638,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
16381638
Importer(static_cast<ClangImporter *>(CurrDeclContext->getASTContext().
16391639
getClangModuleLoader())),
16401640
CompletionContext(CompletionContext) {
1641-
(void)swift::createTypeChecker(Ctx);
1641+
Ctx.setLegacySemanticQueriesEnabled();
16421642

16431643
// Determine if we are doing code completion inside a static method.
16441644
if (CurrDeclContext) {
@@ -4186,7 +4186,7 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
41864186
SourceLoc introducerLoc)
41874187
: Sink(Sink), Ctx(Ctx), CurrDeclContext(CurrDeclContext),
41884188
ParsedKeywords(ParsedKeywords), introducerLoc(introducerLoc) {
4189-
(void)createTypeChecker(Ctx);
4189+
Ctx.setLegacySemanticQueriesEnabled();
41904190

41914191
hasFuncIntroducer = isKeywordSpecified("func");
41924192
hasVarIntroducer = isKeywordSpecified("var") ||

lib/Sema/CSGen.cpp

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

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

lib/Sema/DebuggerTestingTransform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ class DebuggerTestingTransform : public ASTWalker {
243243
// TODO: typeCheckExpression() seems to assign types to everything here,
244244
// but may not be sufficient in some cases.
245245
Expr *FinalExpr = ClosureCall;
246-
(void)swift::createTypeChecker(Ctx);
246+
Ctx.setLegacySemanticQueriesEnabled();
247247
if (!TypeChecker::typeCheckExpression(FinalExpr, getCurrentDeclContext()))
248248
llvm::report_fatal_error("Could not type-check instrumentation");
249249

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)swift::createTypeChecker(DC->getASTContext());
59+
DC->getASTContext().setLegacySemanticQueriesEnabled();
6060
GenericSignature genericSig = ED->getGenericSignature();
6161
SubstitutionMap substMap = BaseTy->getContextSubstitutionMap(
6262
DC->getParentModule(), ED->getExtendedNominal());

0 commit comments

Comments
 (0)