-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[CodeCompletion] Avoid type checking all top-level decls in the primary file #27981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9203080
2564a6e
32e68c7
f6a76f5
d51d844
044790d
97b16ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "TypeChecker.h" | ||
#include "swift/AST/ASTContext.h" | ||
#include "swift/AST/GenericSignature.h" | ||
#include "swift/AST/GenericSignatureBuilder.h" | ||
|
@@ -24,6 +25,7 @@ | |
#include "swift/AST/ModuleNameLookup.h" | ||
#include "swift/AST/NameLookup.h" | ||
#include "swift/AST/ProtocolConformance.h" | ||
#include "swift/AST/PropertyWrappers.h" | ||
#include "swift/AST/SourceFile.h" | ||
#include "swift/Basic/SourceManager.h" | ||
#include "swift/Basic/STLExtras.h" | ||
|
@@ -203,6 +205,9 @@ static void collectVisibleMemberDecls(const DeclContext *CurrDC, LookupState LS, | |
} | ||
} | ||
|
||
static void | ||
synthesizePropertyWrapperStorageWrapperProperties(IterableDeclContext *IDC); | ||
|
||
/// Lookup members in extensions of \p LookupType, using \p BaseType as the | ||
/// underlying type when checking any constraints on the extensions. | ||
static void doGlobalExtensionLookup(Type BaseType, | ||
|
@@ -220,6 +225,8 @@ static void doGlobalExtensionLookup(Type BaseType, | |
extension)), false)) | ||
continue; | ||
|
||
synthesizePropertyWrapperStorageWrapperProperties(extension); | ||
|
||
collectVisibleMemberDecls(CurrDC, LS, BaseType, extension, FoundDecls); | ||
} | ||
|
||
|
@@ -474,6 +481,49 @@ static void | |
lookupTypeMembers(BaseTy, PT, Consumer, CurrDC, LS, Reason); | ||
} | ||
|
||
// Generate '$' and '_' prefixed variables that have attached property | ||
// wrappers. | ||
static void | ||
synthesizePropertyWrapperStorageWrapperProperties(IterableDeclContext *IDC) { | ||
auto SF = IDC->getDecl()->getDeclContext()->getParentSourceFile(); | ||
if (!SF || SF->Kind == SourceFileKind::Interface) | ||
return; | ||
|
||
for (auto Member : IDC->getMembers()) | ||
if (auto var = dyn_cast<VarDecl>(Member)) | ||
if (var->hasAttachedPropertyWrapper()) | ||
(void)var->getPropertyWrapperBackingPropertyInfo(); | ||
} | ||
|
||
/// Trigger synthesizing implicit member declarations to make them "visible". | ||
static void synthesizeMemberDeclsForLookup(NominalTypeDecl *NTD, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is this triggered during normal type-checking? This seems kind of brittle to live in lookup-visible-decls, although admittedly this whole file is basically like that... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the type is declared in the primary files, they are synthesized in But if it's in the non-primary files, AFAIU, they are lazily synthesized on demand in I can move this |
||
const DeclContext *DC) { | ||
// Synthesize the memberwise initializer for structs or default initializer | ||
// for classes. | ||
if (!NTD->getASTContext().evaluator.hasActiveRequest( | ||
SynthesizeMemberwiseInitRequest{NTD})) | ||
TypeChecker::addImplicitConstructors(NTD); | ||
|
||
// Check all conformances to trigger the synthesized decl generation. | ||
// e.g. init(rawValue:) for RawRepresentable. | ||
for (auto Conformance : NTD->getAllConformances()) { | ||
auto Proto = Conformance->getProtocol(); | ||
if (!Proto->isAccessibleFrom(DC)) | ||
continue; | ||
auto NormalConformance = dyn_cast<NormalProtocolConformance>( | ||
Conformance->getRootConformance()); | ||
if (!NormalConformance) | ||
continue; | ||
NormalConformance->forEachTypeWitness( | ||
[](AssociatedTypeDecl *, Type, TypeDecl *) { return false; }, | ||
/*useResolver=*/true); | ||
NormalConformance->forEachValueWitness([](ValueDecl *, Witness) {}, | ||
/*useResolver=*/true); | ||
} | ||
|
||
synthesizePropertyWrapperStorageWrapperProperties(NTD); | ||
} | ||
|
||
static void lookupVisibleMemberDeclsImpl( | ||
Type BaseTy, VisibleDeclConsumer &Consumer, const DeclContext *CurrDC, | ||
LookupState LS, DeclVisibilityKind Reason, GenericSignatureBuilder *GSB, | ||
|
@@ -583,6 +633,8 @@ static void lookupVisibleMemberDeclsImpl( | |
if (!CurNominal) | ||
break; | ||
|
||
synthesizeMemberDeclsForLookup(CurNominal, CurrDC); | ||
|
||
// Look in for members of a nominal type. | ||
lookupTypeMembers(BaseTy, BaseTy, Consumer, CurrDC, LS, Reason); | ||
lookupDeclsFromProtocolsBeingConformedTo(BaseTy, Consumer, LS, CurrDC, | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved after
typeCheckContextUntil()
becauseaddKeywords()
may callDeclContext::getSelfProtocolDecl()
which can only be called afterbindExtensions()
.