Skip to content

Nuke IgnoreNewExtensions From High Orbit #38613

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

Merged
merged 1 commit into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3196,12 +3196,6 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
/// Whether to include @_implements members.
/// Used by conformance-checking to find special @_implements members.
IncludeAttrImplements = 1 << 0,
/// Whether to avoid loading lazy members from any new extensions that would otherwise be found
/// by deserialization.
///
/// Used by the module loader to break recursion and as an optimization e.g. when it is known that a
/// particular member declaration will never appear in an extension.
IgnoreNewExtensions = 1 << 1,
};

/// Find all of the declarations with the given name within this nominal type
Expand Down
3 changes: 1 addition & 2 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4846,8 +4846,7 @@ ValueDecl *ProtocolDecl::getSingleRequirement(DeclName name) const {
}

AssociatedTypeDecl *ProtocolDecl::getAssociatedType(Identifier name) const {
const auto flags = NominalTypeDecl::LookupDirectFlags::IgnoreNewExtensions;
auto results = const_cast<ProtocolDecl *>(this)->lookupDirect(name, flags);
auto results = const_cast<ProtocolDecl *>(this)->lookupDirect(name);
for (auto candidate : results) {
if (candidate->getDeclContext() == this &&
isa<AssociatedTypeDecl>(candidate)) {
Expand Down
20 changes: 5 additions & 15 deletions lib/AST/NameLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1434,8 +1434,6 @@ DirectLookupRequest::evaluate(Evaluator &evaluator,
ASTContext &ctx = decl->getASTContext();
const bool useNamedLazyMemberLoading = (ctx.LangOpts.NamedLazyMemberLoading &&
decl->hasLazyMembers());
const bool disableAdditionalExtensionLoading =
flags.contains(NominalTypeDecl::LookupDirectFlags::IgnoreNewExtensions);
const bool includeAttrImplements =
flags.contains(NominalTypeDecl::LookupDirectFlags::IncludeAttrImplements);

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

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

if (!disableAdditionalExtensionLoading) {
for (auto E : decl->getExtensions())
(void)E->getMembers();
for (auto E : decl->getExtensions())
(void)E->getMembers();

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

if (!disableAdditionalExtensionLoading) {
populateLookupTableEntryFromExtensions(ctx, Table, baseName, decl);
}

// FIXME: If disableAdditionalExtensionLoading is true, we should
// not mark the entry as complete.
Table.markLazilyComplete(baseName);
}

Expand Down
6 changes: 2 additions & 4 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,9 +771,8 @@ static VarDecl *findAnonymousInnerFieldDecl(VarDecl *importedFieldDecl,
auto anonymousFieldTypeDecl
= anonymousFieldType->getStructOrBoundGenericStruct();

const auto flags = NominalTypeDecl::LookupDirectFlags::IgnoreNewExtensions;
for (auto decl : anonymousFieldTypeDecl->lookupDirect(
importedFieldDecl->getName(), flags)) {
importedFieldDecl->getName())) {
if (isa<VarDecl>(decl)) {
return cast<VarDecl>(decl);
}
Expand Down Expand Up @@ -9628,8 +9627,7 @@ synthesizeConstantGetterBody(AbstractFunctionDecl *afd, void *voidContext) {
DeclName initName = DeclName(ctx, DeclBaseName::createConstructor(),
{ ctx.Id_rawValue });
auto nominal = type->getAnyNominal();
const auto flags = NominalTypeDecl::LookupDirectFlags::IgnoreNewExtensions;
for (auto found : nominal->lookupDirect(initName, flags)) {
for (auto found : nominal->lookupDirect(initName)) {
init = dyn_cast<ConstructorDecl>(found);
if (init && init->getDeclContext() == nominal)
break;
Expand Down
7 changes: 2 additions & 5 deletions lib/Sema/TypeCheckProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6005,10 +6005,8 @@ void TypeChecker::checkConformancesInContext(IterableDeclContext *idc) {
continue;

bool valueIsType = isa<TypeDecl>(value);
const auto flags =
NominalTypeDecl::LookupDirectFlags::IgnoreNewExtensions;
for (auto requirement
: diag.Protocol->lookupDirect(value->getName(), flags)) {
: diag.Protocol->lookupDirect(value->getName())) {
if (requirement->getDeclContext() != diag.Protocol)
continue;

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

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

Expand Down