Skip to content

Commit d28622d

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-rebranch
2 parents ee7ccfd + e77b040 commit d28622d

30 files changed

+192
-207
lines changed

include/swift/AST/DeclContext.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,15 +487,11 @@ class alignas(1 << DeclContextAlignInBits) DeclContext {
487487
/// \param options Options that control name lookup, based on the
488488
/// \c NL_* constants in \c NameLookupOptions.
489489
///
490-
/// \param typeResolver Used to resolve types, usually for overload purposes.
491-
/// May be null.
492-
///
493490
/// \param[out] decls Will be populated with the declarations found by name
494491
/// lookup.
495492
///
496493
/// \returns true if anything was found.
497494
bool lookupQualified(Type type, DeclName member, NLOptions options,
498-
LazyResolver *typeResolver,
499495
SmallVectorImpl<ValueDecl *> &decls) const;
500496

501497
/// Look for the set of declarations with the given name within the

include/swift/AST/NameLookup.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ namespace swift {
3232
class DeclName;
3333
class Expr;
3434
class GenericSignatureBuilder;
35-
class LazyResolver;
3635
class TupleType;
3736
class Type;
3837
class TypeDecl;
@@ -147,7 +146,7 @@ class UnqualifiedLookup {
147146
///
148147
/// If the current DeclContext is nested in a function body, the SourceLoc
149148
/// is used to determine which declarations in that body are visible.
150-
UnqualifiedLookup(DeclName Name, DeclContext *DC, LazyResolver *TypeResolver,
149+
UnqualifiedLookup(DeclName Name, DeclContext *DC,
151150
SourceLoc Loc = SourceLoc(), Options options = Options());
152151

153152
using ResultsVector = SmallVector<LookupResultEntry, 4>;
@@ -394,7 +393,6 @@ bool removeShadowedDecls(SmallVectorImpl<ValueDecl*> &decls,
394393
/// are visible.
395394
void lookupVisibleDecls(VisibleDeclConsumer &Consumer,
396395
const DeclContext *DC,
397-
LazyResolver *typeResolver,
398396
bool IncludeTopLevel,
399397
SourceLoc Loc = SourceLoc());
400398

@@ -405,7 +403,6 @@ void lookupVisibleDecls(VisibleDeclConsumer &Consumer,
405403
void lookupVisibleMemberDecls(VisibleDeclConsumer &Consumer,
406404
Type BaseTy,
407405
const DeclContext *CurrDC,
408-
LazyResolver *typeResolver,
409406
bool includeInstanceMembers,
410407
GenericSignatureBuilder *GSB = nullptr);
411408

@@ -433,16 +430,13 @@ enum class ResolutionKind {
433430
/// \param[out] decls Any found decls will be added to this vector.
434431
/// \param lookupKind Whether this lookup is qualified or unqualified.
435432
/// \param resolutionKind What sort of decl is expected.
436-
/// \param typeResolver The type resolver for decls that need to be
437-
/// type-checked. This is needed for shadowing resolution.
438433
/// \param moduleScopeContext The top-level context from which the lookup is
439434
/// being performed, for checking access. This must be either a
440435
/// FileUnit or a Module.
441436
/// \param extraImports Private imports to include in this search.
442437
void lookupInModule(ModuleDecl *module, ModuleDecl::AccessPathTy accessPath,
443438
DeclName name, SmallVectorImpl<ValueDecl *> &decls,
444439
NLKind lookupKind, ResolutionKind resolutionKind,
445-
LazyResolver *typeResolver,
446440
const DeclContext *moduleScopeContext,
447441
ArrayRef<ModuleDecl::ImportedModule> extraImports = {});
448442

@@ -508,7 +502,6 @@ lookupVisibleDeclsInModule(ModuleDecl *M, ModuleDecl::AccessPathTy accessPath,
508502
SmallVectorImpl<ValueDecl *> &decls,
509503
NLKind lookupKind,
510504
ResolutionKind resolutionKind,
511-
LazyResolver *typeResolver,
512505
const DeclContext *moduleScopeContext,
513506
ArrayRef<ModuleDecl::ImportedModule> extraImports = {});
514507

include/swift/Basic/Statistics.def

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,28 @@ FRONTEND_STATISTIC(AST, NumPrefixOperators)
138138
/// Number of precedence groups in the AST context.
139139
FRONTEND_STATISTIC(AST, NumPrecedenceGroups)
140140

141+
/// Number of qualified lookups into a nominal type.
142+
FRONTEND_STATISTIC(AST, NumLookupQualifiedInNominal)
143+
144+
/// Number of qualified lookups into a module.
145+
FRONTEND_STATISTIC(AST, NumLookupQualifiedInModule)
146+
147+
/// Number of qualified lookups into AnyObject.
148+
FRONTEND_STATISTIC(AST, NumLookupQualifiedInAnyObject)
149+
150+
/// Number of lookups into a module and its imports.
151+
FRONTEND_STATISTIC(AST, NumLookupInModule)
152+
153+
/// Number of local lookups into a module.
154+
FRONTEND_STATISTIC(AST, NumModuleLookupValue)
155+
156+
/// Number of unqualified lookups.
157+
FRONTEND_STATISTIC(AST, NumUnqualifiedLookup)
158+
159+
/// Number of local lookups into a module's class members, for
160+
/// AnyObject lookup.
161+
FRONTEND_STATISTIC(AST, NumModuleLookupClassMember)
162+
141163
/// Number of full function bodies parsed.
142164
FRONTEND_STATISTIC(Parse, NumFunctionsParsed)
143165

@@ -227,6 +249,8 @@ FRONTEND_STATISTIC(Sema, NumTypesValidated)
227249
/// Number of lazy iterable declaration contexts left unloaded.
228250
FRONTEND_STATISTIC(Sema, NumUnloadedLazyIterableDeclContexts)
229251

252+
/// Number of lookups into a module and its imports.
253+
230254
/// All type check requests go into the Sema area.
231255
#define SWIFT_TYPEID(NAME) FRONTEND_STATISTIC(Sema, NAME)
232256
#include "swift/AST/AccessTypeIDZone.def"

include/swift/ClangImporter/ClangModule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ClangModuleUnit final : public LoadedFile {
3535
ClangImporter::Implementation &owner;
3636
const clang::Module *clangModule;
3737
llvm::PointerIntPair<ModuleDecl *, 1, bool> overlayModule;
38-
mutable ArrayRef<ModuleDecl::ImportedModule> importedModulesForLookup;
38+
mutable Optional<ArrayRef<ModuleDecl::ImportedModule>> importedModulesForLookup;
3939
/// The metadata of the underlying Clang module.
4040
clang::ExternalASTSource::ASTSourceDescriptor ASTSourceDescriptor;
4141

lib/AST/ASTContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ ClassDecl *ASTContext::get##NAME##Decl() const { \
871871
/* Note: use unqualified lookup so we find NSError regardless of */ \
872872
/* whether it's defined in the Foundation module or the Clang */ \
873873
/* Foundation module it imports. */ \
874-
UnqualifiedLookup lookup(getIdentifier(#NAME), M, nullptr); \
874+
UnqualifiedLookup lookup(getIdentifier(#NAME), M); \
875875
if (auto type = lookup.getSingleTypeResult()) { \
876876
if (auto classDecl = dyn_cast<ClassDecl>(type)) { \
877877
if (classDecl->getGenericParams() == nullptr) { \

lib/AST/DeclContext.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -476,20 +476,15 @@ unsigned DeclContext::getSemanticDepth() const {
476476
}
477477

478478
bool DeclContext::mayContainMembersAccessedByDynamicLookup() const {
479-
// Dynamic lookup can only find class and protocol members, or extensions of
480-
// classes.
481-
if (auto *NTD = dyn_cast<NominalTypeDecl>(this)) {
482-
if (isa<ClassDecl>(NTD))
483-
if (!isGenericContext())
484-
return true;
485-
if (auto *PD = dyn_cast<ProtocolDecl>(NTD))
486-
if (PD->getAttrs().hasAttribute<ObjCAttr>())
487-
return true;
488-
} else if (auto *ED = dyn_cast<ExtensionDecl>(this)) {
489-
if (auto *CD = dyn_cast<ClassDecl>(ED->getExtendedNominal()))
490-
if (!CD->isGenericContext())
491-
return true;
492-
}
479+
// Members of non-generic classes and class extensions can be found by
480+
/// dynamic lookup.
481+
if (auto *CD = getSelfClassDecl())
482+
return !CD->isGenericContext();
483+
484+
// Members of @objc protocols (but not protocol extensions) can be
485+
// found by dynamic lookup.
486+
if (auto *PD = dyn_cast<ProtocolDecl>(this))
487+
return PD->getAttrs().hasAttribute<ObjCAttr>();
493488

494489
return false;
495490
}

lib/AST/Module.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,11 @@ static bool isParsedModule(const ModuleDecl *mod) {
454454
void ModuleDecl::lookupValue(AccessPathTy AccessPath, DeclName Name,
455455
NLKind LookupKind,
456456
SmallVectorImpl<ValueDecl*> &Result) const {
457+
auto *stats = getASTContext().Stats;
458+
if (stats)
459+
stats->getFrontendCounters().NumModuleLookupValue++;
460+
457461
if (isParsedModule(this)) {
458-
FrontendStatsTracer tracer(getASTContext().Stats, "source-file-lookup-value");
459462
getSourceLookupCache().lookupValue(AccessPath, Name, LookupKind, Result);
460463
return;
461464
}
@@ -604,6 +607,10 @@ void SourceFile::lookupClassMembers(ModuleDecl::AccessPathTy accessPath,
604607
void ModuleDecl::lookupClassMember(AccessPathTy accessPath,
605608
DeclName name,
606609
SmallVectorImpl<ValueDecl*> &results) const {
610+
auto *stats = getASTContext().Stats;
611+
if (stats)
612+
stats->getFrontendCounters().NumModuleLookupClassMember++;
613+
607614
if (isParsedModule(this)) {
608615
FrontendStatsTracer tracer(getASTContext().Stats, "source-file-lookup-class-member");
609616
auto &cache = getSourceLookupCache();

lib/AST/ModuleNameLookup.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ class ModuleNameLookup {
5454
TinyPtrVector<ValueDecl *>, 32>;
5555

5656
ModuleLookupCache cache;
57-
LazyResolver * const typeResolver;
5857
const ResolutionKind resolutionKind;
5958
const bool respectAccessControl;
6059

@@ -106,10 +105,9 @@ class ModuleNameLookup {
106105
ArrayRef<ModuleDecl::ImportedModule> extraImports);
107106

108107
public:
109-
ModuleNameLookup(LazyResolver *typeResolver, ModuleDecl *M,
110-
ResolutionKind resolutionKind)
111-
: typeResolver(typeResolver), resolutionKind(resolutionKind),
112-
respectAccessControl(!M->getASTContext().isAccessControlDisabled()) {}
108+
ModuleNameLookup(ASTContext &ctx, ResolutionKind resolutionKind)
109+
: resolutionKind(resolutionKind),
110+
respectAccessControl(!ctx.isAccessControlDisabled()) {}
113111

114112
/// Performs a qualified lookup into the given module and, if necessary, its
115113
/// reexports, observing proper shadowing rules.
@@ -133,9 +131,9 @@ class LookupByName : public ModuleNameLookup<LookupByName> {
133131
const NLKind lookupKind;
134132

135133
public:
136-
LookupByName(LazyResolver *typeResolver, ModuleDecl *M,
137-
ResolutionKind resolutionKind, DeclName name, NLKind lookupKind)
138-
: Super(typeResolver, M, resolutionKind), name(name),
134+
LookupByName(ASTContext &ctx, ResolutionKind resolutionKind,
135+
DeclName name, NLKind lookupKind)
136+
: Super(ctx, resolutionKind), name(name),
139137
lookupKind(lookupKind) {}
140138

141139
private:
@@ -194,9 +192,9 @@ class LookupVisibleDecls : public ModuleNameLookup<LookupVisibleDecls> {
194192
const NLKind lookupKind;
195193

196194
public:
197-
LookupVisibleDecls(LazyResolver *typeResolver, ModuleDecl *M,
198-
ResolutionKind resolutionKind, NLKind lookupKind)
199-
: ModuleNameLookup(typeResolver, M, resolutionKind),
195+
LookupVisibleDecls(ASTContext &ctx, ResolutionKind resolutionKind,
196+
NLKind lookupKind)
197+
: ModuleNameLookup(ctx, resolutionKind),
200198
lookupKind(lookupKind) {}
201199

202200
private:
@@ -276,7 +274,7 @@ bool ModuleNameLookup<LookupStrategy>::recordImportDecls(
276274
llvm::copy_if(newDecls, std::back_inserter(results),
277275
[&](ValueDecl *result) -> bool {
278276
if (!result->hasInterfaceType()) {
279-
if (typeResolver) {
277+
if (auto *typeResolver = result->getASTContext().getLazyResolver()) {
280278
typeResolver->resolveDeclSignature(result);
281279
if (result->isInvalid())
282280
return true;
@@ -451,12 +449,17 @@ void namelookup::lookupInModule(ModuleDecl *startModule,
451449
SmallVectorImpl<ValueDecl *> &decls,
452450
NLKind lookupKind,
453451
ResolutionKind resolutionKind,
454-
LazyResolver *typeResolver,
455452
const DeclContext *moduleScopeContext,
456453
ArrayRef<ModuleDecl::ImportedModule> extraImports) {
454+
auto &ctx = startModule->getASTContext();
455+
auto *stats = ctx.Stats;
456+
if (stats)
457+
stats->getFrontendCounters().NumLookupInModule++;
458+
459+
FrontendStatsTracer tracer(stats, "lookup-in-module");
460+
457461
assert(moduleScopeContext && moduleScopeContext->isModuleScopeContext());
458-
LookupByName lookup(typeResolver, startModule, resolutionKind, name,
459-
lookupKind);
462+
LookupByName lookup(ctx, resolutionKind, name, lookupKind);
460463
lookup.lookupInModule(decls, startModule, topAccessPath, moduleScopeContext,
461464
extraImports);
462465
}
@@ -467,11 +470,11 @@ void namelookup::lookupVisibleDeclsInModule(
467470
SmallVectorImpl<ValueDecl *> &decls,
468471
NLKind lookupKind,
469472
ResolutionKind resolutionKind,
470-
LazyResolver *typeResolver,
471473
const DeclContext *moduleScopeContext,
472474
ArrayRef<ModuleDecl::ImportedModule> extraImports) {
475+
auto &ctx = M->getASTContext();
473476
assert(moduleScopeContext && moduleScopeContext->isModuleScopeContext());
474-
LookupVisibleDecls lookup(typeResolver, M, resolutionKind, lookupKind);
477+
LookupVisibleDecls lookup(ctx, resolutionKind, lookupKind);
475478
lookup.lookupInModule(decls, M, accessPath, moduleScopeContext, extraImports);
476479
}
477480

lib/AST/NameLookup.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,6 @@ static void extractDirectlyReferencedNominalTypes(
14371437
bool DeclContext::lookupQualified(Type type,
14381438
DeclName member,
14391439
NLOptions options,
1440-
LazyResolver *typeResolver,
14411440
SmallVectorImpl<ValueDecl *> &decls) const {
14421441
using namespace namelookup;
14431442
assert(decls.empty() && "additive lookup not supported");
@@ -1464,6 +1463,10 @@ bool DeclContext::lookupQualified(ArrayRef<NominalTypeDecl *> typeDecls,
14641463
using namespace namelookup;
14651464
assert(decls.empty() && "additive lookup not supported");
14661465

1466+
auto *stats = getASTContext().Stats;
1467+
if (stats)
1468+
stats->getFrontendCounters().NumLookupQualifiedInNominal++;
1469+
14671470
// Configure lookup and dig out the tracker.
14681471
ReferencedNameTracker *tracker = nullptr;
14691472
bool isLookupCascading;
@@ -1600,20 +1603,23 @@ bool DeclContext::lookupQualified(ModuleDecl *module, DeclName member,
16001603
SmallVectorImpl<ValueDecl *> &decls) const {
16011604
using namespace namelookup;
16021605

1606+
auto *stats = getASTContext().Stats;
1607+
if (stats)
1608+
stats->getFrontendCounters().NumLookupQualifiedInModule++;
1609+
16031610
// Configure lookup and dig out the tracker.
16041611
ReferencedNameTracker *tracker = nullptr;
16051612
bool isLookupCascading;
16061613
configureLookup(this, options, tracker, isLookupCascading);
16071614

1608-
ASTContext &ctx = getASTContext();
16091615
auto topLevelScope = getModuleScopeContext();
16101616
if (module == topLevelScope->getParentModule()) {
16111617
if (tracker) {
16121618
recordLookupOfTopLevelName(topLevelScope, member, isLookupCascading);
16131619
}
16141620
lookupInModule(module, /*accessPath=*/{}, member, decls,
16151621
NLKind::QualifiedLookup, ResolutionKind::Overloadable,
1616-
ctx.getLazyResolver(), topLevelScope);
1622+
topLevelScope);
16171623
} else {
16181624
// Note: This is a lookup into another module. Unless we're compiling
16191625
// multiple modules at once, or if the other module re-exports this one,
@@ -1627,7 +1633,7 @@ bool DeclContext::lookupQualified(ModuleDecl *module, DeclName member,
16271633
return true;
16281634
lookupInModule(import.second, import.first, member, decls,
16291635
NLKind::QualifiedLookup, ResolutionKind::Overloadable,
1630-
ctx.getLazyResolver(), topLevelScope);
1636+
topLevelScope);
16311637
// If we're able to do an unscoped lookup, we see everything. No need
16321638
// to keep going.
16331639
return !import.first.empty();
@@ -1671,6 +1677,10 @@ bool DeclContext::lookupAnyObject(DeclName member, NLOptions options,
16711677
if (options & NL_OnlyTypes)
16721678
return false;
16731679

1680+
auto *stats = getASTContext().Stats;
1681+
if (stats)
1682+
stats->getFrontendCounters().NumLookupQualifiedInAnyObject++;
1683+
16741684
// Collect all of the visible declarations.
16751685
SmallVector<ValueDecl *, 4> allDecls;
16761686
forAllVisibleModules(this, [&](ModuleDecl::ImportedModule import) {
@@ -1821,11 +1831,11 @@ resolveTypeDeclsToNominal(Evaluator &evaluator,
18211831

18221832
/// Perform unqualified name lookup for types at the given location.
18231833
static DirectlyReferencedTypeDecls
1824-
directReferencesForUnqualifiedTypeLookup(ASTContext &ctx, DeclName name,
1834+
directReferencesForUnqualifiedTypeLookup(DeclName name,
18251835
SourceLoc loc, DeclContext *dc) {
18261836
DirectlyReferencedTypeDecls results;
18271837
UnqualifiedLookup::Options options = UnqualifiedLookup::Flags::TypeLookup;
1828-
UnqualifiedLookup lookup(name, dc, ctx.getLazyResolver(), loc, options);
1838+
UnqualifiedLookup lookup(name, dc, loc, options);
18291839
for (const auto &result : lookup.Results) {
18301840
if (auto typeDecl = dyn_cast<TypeDecl>(result.getValueDecl()))
18311841
results.push_back(typeDecl);
@@ -1897,8 +1907,7 @@ directReferencesForIdentTypeRepr(Evaluator &evaluator,
18971907
// For the first component, perform unqualified name lookup.
18981908
if (current.empty()) {
18991909
current =
1900-
directReferencesForUnqualifiedTypeLookup(ctx,
1901-
component->getIdentifier(),
1910+
directReferencesForUnqualifiedTypeLookup(component->getIdentifier(),
19021911
component->getIdLoc(),
19031912
dc);
19041913

0 commit comments

Comments
 (0)