Skip to content

Commit babe52f

Browse files
committed
Nuke IgnoreNewExtensions From High Orbit
This flag was always a hack to get clients that were not properly handling circular constructions (module loading, associated type inference) to stop crashing. Technically, it is unsound, but by sheer coinicidence of the structure of the name lookup requests and the cache faulting here we have never observed that unsoundness in the wild.
1 parent 35aa862 commit babe52f

File tree

5 files changed

+10
-32
lines changed

5 files changed

+10
-32
lines changed

include/swift/AST/Decl.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3196,12 +3196,6 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
31963196
/// Whether to include @_implements members.
31973197
/// Used by conformance-checking to find special @_implements members.
31983198
IncludeAttrImplements = 1 << 0,
3199-
/// Whether to avoid loading lazy members from any new extensions that would otherwise be found
3200-
/// by deserialization.
3201-
///
3202-
/// Used by the module loader to break recursion and as an optimization e.g. when it is known that a
3203-
/// particular member declaration will never appear in an extension.
3204-
IgnoreNewExtensions = 1 << 1,
32053199
};
32063200

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

lib/AST/Decl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4846,8 +4846,7 @@ ValueDecl *ProtocolDecl::getSingleRequirement(DeclName name) const {
48464846
}
48474847

48484848
AssociatedTypeDecl *ProtocolDecl::getAssociatedType(Identifier name) const {
4849-
const auto flags = NominalTypeDecl::LookupDirectFlags::IgnoreNewExtensions;
4850-
auto results = const_cast<ProtocolDecl *>(this)->lookupDirect(name, flags);
4849+
auto results = const_cast<ProtocolDecl *>(this)->lookupDirect(name);
48514850
for (auto candidate : results) {
48524851
if (candidate->getDeclContext() == this &&
48534852
isa<AssociatedTypeDecl>(candidate)) {

lib/AST/NameLookup.cpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,8 +1434,6 @@ DirectLookupRequest::evaluate(Evaluator &evaluator,
14341434
ASTContext &ctx = decl->getASTContext();
14351435
const bool useNamedLazyMemberLoading = (ctx.LangOpts.NamedLazyMemberLoading &&
14361436
decl->hasLazyMembers());
1437-
const bool disableAdditionalExtensionLoading =
1438-
flags.contains(NominalTypeDecl::LookupDirectFlags::IgnoreNewExtensions);
14391437
const bool includeAttrImplements =
14401438
flags.contains(NominalTypeDecl::LookupDirectFlags::IncludeAttrImplements);
14411439

@@ -1451,35 +1449,27 @@ DirectLookupRequest::evaluate(Evaluator &evaluator,
14511449
// If we're allowed to load extensions, call prepareExtensions to ensure we
14521450
// properly invalidate the lazily-complete cache for any extensions brought in
14531451
// by modules loaded after-the-fact. This can happen with the LLDB REPL.
1454-
if (!disableAdditionalExtensionLoading)
1455-
decl->prepareExtensions();
1452+
decl->prepareExtensions();
14561453

14571454
auto &Table = *decl->LookupTable;
14581455
if (!useNamedLazyMemberLoading) {
14591456
// Make sure we have the complete list of members (in this nominal and in
14601457
// all extensions).
14611458
(void)decl->getMembers();
14621459

1463-
if (!disableAdditionalExtensionLoading) {
1464-
for (auto E : decl->getExtensions())
1465-
(void)E->getMembers();
1460+
for (auto E : decl->getExtensions())
1461+
(void)E->getMembers();
14661462

1467-
Table.updateLookupTable(decl);
1468-
}
1463+
Table.updateLookupTable(decl);
14691464
} else if (!Table.isLazilyComplete(name.getBaseName())) {
14701465
// The lookup table believes it doesn't have a complete accounting of this
14711466
// name - either because we're never seen it before, or another extension
14721467
// was registered since the last time we searched. Ask the loaders to give
14731468
// us a hand.
14741469
DeclBaseName baseName(name.getBaseName());
14751470
populateLookupTableEntryFromLazyIDCLoader(ctx, Table, baseName, decl);
1471+
populateLookupTableEntryFromExtensions(ctx, Table, baseName, decl);
14761472

1477-
if (!disableAdditionalExtensionLoading) {
1478-
populateLookupTableEntryFromExtensions(ctx, Table, baseName, decl);
1479-
}
1480-
1481-
// FIXME: If disableAdditionalExtensionLoading is true, we should
1482-
// not mark the entry as complete.
14831473
Table.markLazilyComplete(baseName);
14841474
}
14851475

lib/ClangImporter/ImportDecl.cpp

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

774-
const auto flags = NominalTypeDecl::LookupDirectFlags::IgnoreNewExtensions;
775774
for (auto decl : anonymousFieldTypeDecl->lookupDirect(
776-
importedFieldDecl->getName(), flags)) {
775+
importedFieldDecl->getName())) {
777776
if (isa<VarDecl>(decl)) {
778777
return cast<VarDecl>(decl);
779778
}
@@ -9628,8 +9627,7 @@ synthesizeConstantGetterBody(AbstractFunctionDecl *afd, void *voidContext) {
96289627
DeclName initName = DeclName(ctx, DeclBaseName::createConstructor(),
96299628
{ ctx.Id_rawValue });
96309629
auto nominal = type->getAnyNominal();
9631-
const auto flags = NominalTypeDecl::LookupDirectFlags::IgnoreNewExtensions;
9632-
for (auto found : nominal->lookupDirect(initName, flags)) {
9630+
for (auto found : nominal->lookupDirect(initName)) {
96339631
init = dyn_cast<ConstructorDecl>(found);
96349632
if (init && init->getDeclContext() == nominal)
96359633
break;

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6005,10 +6005,8 @@ void TypeChecker::checkConformancesInContext(IterableDeclContext *idc) {
60056005
continue;
60066006

60076007
bool valueIsType = isa<TypeDecl>(value);
6008-
const auto flags =
6009-
NominalTypeDecl::LookupDirectFlags::IgnoreNewExtensions;
60106008
for (auto requirement
6011-
: diag.Protocol->lookupDirect(value->getName(), flags)) {
6009+
: diag.Protocol->lookupDirect(value->getName())) {
60126010
if (requirement->getDeclContext() != diag.Protocol)
60136011
continue;
60146012

@@ -6210,8 +6208,7 @@ swift::findWitnessedObjCRequirements(const ValueDecl *witness,
62106208
if (!proto->isObjC()) continue;
62116209

62126210
Optional<ProtocolConformance *> conformance;
6213-
const auto flags = NominalTypeDecl::LookupDirectFlags::IgnoreNewExtensions;
6214-
for (auto req : proto->lookupDirect(name, flags)) {
6211+
for (auto req : proto->lookupDirect(name)) {
62156212
// Skip anything in a protocol extension.
62166213
if (req->getDeclContext() != proto) continue;
62176214

0 commit comments

Comments
 (0)