Skip to content

Commit a09382c

Browse files
committed
AST: Completely remove NominalTypeDecl::LookupDirectFlags::IgnoreNewExtensions
1 parent 3196b5e commit a09382c

File tree

5 files changed

+26
-50
lines changed

5 files changed

+26
-50
lines changed

include/swift/AST/Decl.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3275,7 +3275,7 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
32753275
llvm::PointerIntPair<MemberLookupTable *, 1, bool> LookupTable;
32763276

32773277
/// Prepare the lookup table to make it ready for lookups.
3278-
void prepareLookupTable(bool ignoreNewExtensions);
3278+
void prepareLookupTable();
32793279

32803280
/// True if the entries in \c LookupTable are complete--that is, if a
32813281
/// name is present, it contains all members with that name.
@@ -3383,12 +3383,9 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
33833383

33843384
/// Special-behaviour flags passed to lookupDirect()
33853385
enum class LookupDirectFlags {
3386-
/// Whether to avoid loading any new extension.
3387-
/// Used by the module loader to break recursion.
3388-
IgnoreNewExtensions = 1 << 0,
33893386
/// Whether to include @_implements members.
33903387
/// Used by conformance-checking to find special @_implements members.
3391-
IncludeAttrImplements = 1 << 1,
3388+
IncludeAttrImplements = 1 << 0,
33923389
};
33933390

33943391
/// Find all of the declarations with the given name within this nominal type

lib/AST/Decl.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3906,10 +3906,7 @@ bool ClassDecl::hasMissingDesignatedInitializers() const {
39063906
if (!Bits.ClassDecl.ComputedHasMissingDesignatedInitializers) {
39073907
auto *mutableThis = const_cast<ClassDecl *>(this);
39083908
mutableThis->Bits.ClassDecl.ComputedHasMissingDesignatedInitializers = 1;
3909-
auto flags = OptionSet<LookupDirectFlags>();
3910-
flags |= LookupDirectFlags::IgnoreNewExtensions;
3911-
(void)mutableThis->lookupDirect(DeclBaseName::createConstructor(),
3912-
flags);
3909+
(void)mutableThis->lookupDirect(DeclBaseName::createConstructor());
39133910
}
39143911

39153912
return Bits.ClassDecl.HasMissingDesignatedInitializers;

lib/AST/NameLookup.cpp

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,9 +1008,6 @@ void ExtensionDecl::addedMember(Decl *member) {
10081008
// If the IDC list is later populated and/or an extension is added _after_
10091009
// MemberLookupTable is constructed (and possibly has entries in it),
10101010
// MemberLookupTable is purged and reconstructed from IDC's list.
1011-
//
1012-
// In all lookup routines, the 'ignoreNewExtensions' flag means that
1013-
// lookup should only use the set of extensions already observed.
10141011

10151012
static bool
10161013
populateLookupTableEntryFromLazyIDCLoader(ASTContext &ctx,
@@ -1058,19 +1055,16 @@ static void
10581055
populateLookupTableEntryFromExtensions(ASTContext &ctx,
10591056
MemberLookupTable &table,
10601057
NominalTypeDecl *nominal,
1061-
DeclName name,
1062-
bool ignoreNewExtensions) {
1063-
if (!ignoreNewExtensions) {
1064-
for (auto e : nominal->getExtensions()) {
1065-
if (e->wasDeserialized() || e->hasClangNode()) {
1066-
assert(!e->hasUnparsedMembers());
1067-
if (populateLookupTableEntryFromLazyIDCLoader(ctx, table,
1068-
name, e)) {
1069-
populateLookupTableEntryFromCurrentMembers(ctx, table, name, e);
1070-
}
1071-
} else {
1058+
DeclName name) {
1059+
for (auto e : nominal->getExtensions()) {
1060+
if (e->wasDeserialized() || e->hasClangNode()) {
1061+
assert(!e->hasUnparsedMembers());
1062+
if (populateLookupTableEntryFromLazyIDCLoader(ctx, table,
1063+
name, e)) {
10721064
populateLookupTableEntryFromCurrentMembers(ctx, table, name, e);
10731065
}
1066+
} else {
1067+
populateLookupTableEntryFromCurrentMembers(ctx, table, name, e);
10741068
}
10751069
}
10761070
}
@@ -1083,7 +1077,7 @@ void NominalTypeDecl::setLookupTablePopulated(bool value) {
10831077
LookupTable.setInt(value);
10841078
}
10851079

1086-
void NominalTypeDecl::prepareLookupTable(bool ignoreNewExtensions) {
1080+
void NominalTypeDecl::prepareLookupTable() {
10871081
// If we haven't allocated the lookup table yet, do so now.
10881082
if (!LookupTable.getPointer()) {
10891083
auto &ctx = getASTContext();
@@ -1109,8 +1103,7 @@ void NominalTypeDecl::prepareLookupTable(bool ignoreNewExtensions) {
11091103
for (auto baseName : baseNamesPresent) {
11101104
populateLookupTableEntryFromExtensions(getASTContext(),
11111105
*LookupTable.getPointer(),
1112-
this, baseName,
1113-
ignoreNewExtensions);
1106+
this, baseName);
11141107
}
11151108
}
11161109

@@ -1121,9 +1114,7 @@ void NominalTypeDecl::prepareLookupTable(bool ignoreNewExtensions) {
11211114
setLookupTablePopulated(true);
11221115
LookupTable.getPointer()->addMembers(getMembers());
11231116
}
1124-
if (!ignoreNewExtensions) {
1125-
LookupTable.getPointer()->updateLookupTable(this);
1126-
}
1117+
LookupTable.getPointer()->updateLookupTable(this);
11271118
}
11281119
}
11291120

@@ -1161,9 +1152,6 @@ TinyPtrVector<ValueDecl *> NominalTypeDecl::lookupDirect(
11611152
bool useNamedLazyMemberLoading = (ctx.LangOpts.NamedLazyMemberLoading &&
11621153
hasLazyMembers());
11631154

1164-
bool ignoreNewExtensions =
1165-
flags.contains(LookupDirectFlags::IgnoreNewExtensions);
1166-
11671155
bool includeAttrImplements =
11681156
flags.contains(LookupDirectFlags::IncludeAttrImplements);
11691157

@@ -1175,7 +1163,7 @@ TinyPtrVector<ValueDecl *> NominalTypeDecl::lookupDirect(
11751163
useNamedLazyMemberLoading = false;
11761164

11771165
LLVM_DEBUG(llvm::dbgs() << getNameStr() << ".lookupDirect("
1178-
<< name << ", " << ignoreNewExtensions << ")"
1166+
<< name << ")"
11791167
<< ", isLookupTablePopulated()=" << isLookupTablePopulated()
11801168
<< ", hasLazyMembers()=" << hasLazyMembers()
11811169
<< ", useNamedLazyMemberLoading=" << useNamedLazyMemberLoading
@@ -1211,15 +1199,13 @@ TinyPtrVector<ValueDecl *> NominalTypeDecl::lookupDirect(
12111199

12121200
// Make sure we have the complete list of members (in this nominal and in
12131201
// all extensions).
1214-
if (!ignoreNewExtensions) {
1215-
for (auto E : getExtensions())
1216-
(void)E->getMembers();
1217-
}
1202+
for (auto E : getExtensions())
1203+
(void)E->getMembers();
12181204
}
12191205

12201206
// Next, in all cases, prepare the lookup table for use, possibly
12211207
// repopulating it from the IDC if the IDC member list has just grown.
1222-
prepareLookupTable(ignoreNewExtensions);
1208+
prepareLookupTable();
12231209

12241210
// Look for a declaration with this name.
12251211
auto known = LookupTable.getPointer()->find(name);
@@ -1243,8 +1229,7 @@ TinyPtrVector<ValueDecl *> NominalTypeDecl::lookupDirect(
12431229
name, this)) {
12441230
useNamedLazyMemberLoading = false;
12451231
} else {
1246-
populateLookupTableEntryFromExtensions(ctx, Table, this, name,
1247-
ignoreNewExtensions);
1232+
populateLookupTableEntryFromExtensions(ctx, Table, this, name);
12481233
}
12491234
}
12501235

lib/ClangImporter/ImportDecl.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -782,9 +782,8 @@ static VarDecl *findAnonymousInnerFieldDecl(VarDecl *importedFieldDecl,
782782
auto anonymousFieldTypeDecl
783783
= anonymousFieldType->getStructOrBoundGenericStruct();
784784

785-
auto lookupFlags = NominalTypeDecl::LookupDirectFlags::IgnoreNewExtensions;
786785
for (auto decl : anonymousFieldTypeDecl->lookupDirect(
787-
importedFieldDecl->getName(), lookupFlags)) {
786+
importedFieldDecl->getName())) {
788787
if (isa<VarDecl>(decl)) {
789788
return cast<VarDecl>(decl);
790789
}
@@ -8306,8 +8305,7 @@ synthesizeConstantGetterBody(AbstractFunctionDecl *afd, void *voidContext) {
83068305
DeclName initName = DeclName(ctx, DeclBaseName::createConstructor(),
83078306
{ ctx.Id_rawValue });
83088307
auto nominal = type->getAnyNominal();
8309-
auto lookupFlags = NominalTypeDecl::LookupDirectFlags::IgnoreNewExtensions;
8310-
for (auto found : nominal->lookupDirect(initName, lookupFlags)) {
8308+
for (auto found : nominal->lookupDirect(initName)) {
83118309
init = dyn_cast<ConstructorDecl>(found);
83128310
if (init && init->getDeclContext() == nominal)
83138311
break;

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4855,10 +4855,11 @@ void TypeChecker::checkConformancesInContext(DeclContext *dc,
48554855
continue;
48564856

48574857
bool valueIsType = isa<TypeDecl>(value);
4858-
auto flags = OptionSet<NominalTypeDecl::LookupDirectFlags>();
4859-
flags |= NominalTypeDecl::LookupDirectFlags::IgnoreNewExtensions;
48604858
for (auto requirement
4861-
: diag.Protocol->lookupDirect(value->getFullName(), flags)) {
4859+
: diag.Protocol->lookupDirect(value->getFullName())) {
4860+
if (requirement->getDeclContext() != diag.Protocol)
4861+
continue;
4862+
48624863
auto requirementIsType = isa<TypeDecl>(requirement);
48634864
if (valueIsType != requirementIsType)
48644865
continue;
@@ -5056,9 +5057,7 @@ swift::findWitnessedObjCRequirements(const ValueDecl *witness,
50565057
if (!proto->isObjC()) continue;
50575058

50585059
Optional<ProtocolConformance *> conformance;
5059-
auto flags = OptionSet<NominalTypeDecl::LookupDirectFlags>();
5060-
flags |= NominalTypeDecl::LookupDirectFlags::IgnoreNewExtensions;
5061-
for (auto req : proto->lookupDirect(name, flags)) {
5060+
for (auto req : proto->lookupDirect(name)) {
50625061
// Skip anything in a protocol extension.
50635062
if (req->getDeclContext() != proto) continue;
50645063

0 commit comments

Comments
 (0)