Skip to content

Commit 1dfba34

Browse files
Merge pull request #13204 from apple/revert-12843-force-on-named-lazy-member-loading
Revert "Finish and default-enable named lazy member loading"
2 parents 183a7c6 + eba12a7 commit 1dfba34

24 files changed

+88
-213
lines changed

include/swift/AST/DeclContext.h

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -610,15 +610,10 @@ class IterableDeclContext {
610610
mutable llvm::PointerIntPair<Decl *, 2, IterableDeclContextKind>
611611
LastDeclAndKind;
612612

613-
/// The DeclID this IDC was deserialized from, if any. Used for named lazy
614-
/// member loading, as a key when doing lookup in this IDC.
613+
// The DeclID this IDC was deserialized from, if any. Used for named lazy
614+
// member loading, as a key when doing lookup in this IDC.
615615
serialization::DeclID SerialID;
616616

617-
/// Lazy member loading has a variety of feedback loops that need to
618-
/// switch to pseudo-empty-member behaviour to avoid infinite recursion;
619-
/// we use this flag to control them.
620-
bool lazyMemberLoadingInProgress = false;
621-
622617
template<class A, class B, class C>
623618
friend struct ::llvm::cast_convert_val;
624619

@@ -648,14 +643,6 @@ class IterableDeclContext {
648643
return FirstDeclAndLazyMembers.getInt();
649644
}
650645

651-
bool isLoadingLazyMembers() {
652-
return lazyMemberLoadingInProgress;
653-
}
654-
655-
void setLoadingLazyMembers(bool inProgress) {
656-
lazyMemberLoadingInProgress = inProgress;
657-
}
658-
659646
/// Setup the loader for lazily-loaded members.
660647
void setMemberLoader(LazyMemberLoader *loader, uint64_t contextData);
661648

include/swift/Basic/LangOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ namespace swift {
159159
bool IterativeTypeChecker = false;
160160

161161
/// \brief Enable named lazy member loading.
162-
bool NamedLazyMemberLoading = true;
162+
bool NamedLazyMemberLoading = false;
163163

164164
/// Debug the generic signatures computed by the generic signature builder.
165165
bool DebugGenericSignatures = false;

include/swift/Option/FrontendOptions.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ def propagate_constraints : Flag<["-"], "propagate-constraints">,
155155
def iterative_type_checker : Flag<["-"], "iterative-type-checker">,
156156
HelpText<"Enable the iterative type checker">;
157157

158-
def disable_named_lazy_member_loading : Flag<["-"], "disable-named-lazy-member-loading">,
159-
HelpText<"Disable per-name lazy member loading">;
158+
def enable_named_lazy_member_loading : Flag<["-"], "enable-named-lazy-member-loading">,
159+
HelpText<"Enable per-name lazy member loading">;
160160

161161
def debug_generic_signatures : Flag<["-"], "debug-generic-signatures">,
162162
HelpText<"Debug generic signatures">;

lib/AST/NameLookup.cpp

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,15 @@ class swift::MemberLookupTable {
10241024
return Lookup.find(name);
10251025
}
10261026

1027+
/// \brief Add an empty entry to the lookup map for a given name if it does
1028+
/// not yet have one.
1029+
void addEmptyEntry(DeclName name) {
1030+
(void)Lookup[name];
1031+
if (!name.isSimpleName()) {
1032+
(void)Lookup[name.getBaseName()];
1033+
}
1034+
}
1035+
10271036
// \brief Mark all Decls in this table as not-resident in a table, drop
10281037
// references to them. Should only be called when this was not fully-populated
10291038
// from an IterableDeclContext.
@@ -1280,14 +1289,13 @@ populateLookupTableEntryFromLazyIDCLoader(ASTContext &ctx,
12801289
MemberLookupTable &LookupTable,
12811290
DeclName name,
12821291
IterableDeclContext *IDC) {
1283-
if (IDC->isLoadingLazyMembers()) {
1284-
return false;
1285-
}
1286-
IDC->setLoadingLazyMembers(true);
12871292
auto ci = ctx.getOrCreateLazyIterableContextData(IDC,
12881293
/*lazyLoader=*/nullptr);
1294+
// Populate LookupTable with an empty vector before we call into our loader,
1295+
// so that any reentry of this routine will find the set-so-far, and not
1296+
// fall into infinite recursion.
1297+
LookupTable.addEmptyEntry(name);
12891298
if (auto res = ci->loader->loadNamedMembers(IDC, name, ci->memberData)) {
1290-
IDC->setLoadingLazyMembers(false);
12911299
if (auto s = ctx.Stats) {
12921300
++s->getFrontendCounters().NamedLazyMemberLoadSuccessCount;
12931301
}
@@ -1296,7 +1304,6 @@ populateLookupTableEntryFromLazyIDCLoader(ASTContext &ctx,
12961304
}
12971305
return false;
12981306
} else {
1299-
IDC->setLoadingLazyMembers(false);
13001307
if (auto s = ctx.Stats) {
13011308
++s->getFrontendCounters().NamedLazyMemberLoadFailureCount;
13021309
}
@@ -1339,13 +1346,6 @@ TinyPtrVector<ValueDecl *> NominalTypeDecl::lookupDirect(
13391346
bool useNamedLazyMemberLoading = (ctx.LangOpts.NamedLazyMemberLoading &&
13401347
hasLazyMembers());
13411348

1342-
// FIXME: At present, lazy member loading conflicts with a bunch of other code
1343-
// that appears to special-case initializers (clang-imported initializer
1344-
// sorting, implicit initializer synthesis), so for the time being we have to
1345-
// turn it off for them entirely.
1346-
if (name.getBaseName() == ctx.Id_init)
1347-
useNamedLazyMemberLoading = false;
1348-
13491349
// We check the LookupTable at most twice, possibly treating a miss in the
13501350
// first try as a cache-miss that we then do a cache-fill on, and retry.
13511351
for (int i = 0; i < 2; ++i) {
@@ -1355,11 +1355,10 @@ TinyPtrVector<ValueDecl *> NominalTypeDecl::lookupDirect(
13551355
// will flip the hasLazyMembers() flag to false as well.
13561356
if (!useNamedLazyMemberLoading) {
13571357
// If we're about to load members here, purge the MemberLookupTable;
1358-
// it will be rebuilt in prepareLookup, below. Base this decision on
1359-
// the LookupTable's int value, not hasLazyMembers(), since the latter
1360-
// can sometimes change underfoot if some other party calls getMembers
1361-
// outside of lookup (eg. typo correction).
1362-
if (LookupTable.getPointer() && !LookupTable.getInt()) {
1358+
// it will be rebuilt in prepareLookup, below.
1359+
if (hasLazyMembers() && LookupTable.getPointer()) {
1360+
// We should not have scanned the IDC list yet. Double check.
1361+
assert(!LookupTable.getInt());
13631362
LookupTable.getPointer()->clear();
13641363
}
13651364

@@ -1401,7 +1400,7 @@ TinyPtrVector<ValueDecl *> NominalTypeDecl::lookupDirect(
14011400
} else {
14021401
if (!ignoreNewExtensions) {
14031402
for (auto E : getExtensions()) {
1404-
if (E->wasDeserialized() || E->hasClangNode()) {
1403+
if (E->wasDeserialized()) {
14051404
if (populateLookupTableEntryFromLazyIDCLoader(ctx, Table,
14061405
name, E)) {
14071406
useNamedLazyMemberLoading = false;

lib/ClangImporter/ClangImporter.cpp

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3278,23 +3278,8 @@ ClangImporter::Implementation::loadNamedMembers(
32783278
auto *D = IDC->getDecl();
32793279
auto *DC = cast<DeclContext>(D);
32803280
auto *CD = D->getClangDecl();
3281-
auto *CDC = cast<clang::DeclContext>(CD);
32823281
assert(CD && "loadNamedMembers on a Decl without a clangDecl");
32833282

3284-
3285-
// FIXME: The legacy of mirroring protocol members rears its ugly head,
3286-
// and as a result we have to bail on any @interface or @category that
3287-
// has a declared protocol conformance.
3288-
if (auto *ID = dyn_cast<clang::ObjCInterfaceDecl>(CD)) {
3289-
if (ID->protocol_begin() != ID->protocol_end())
3290-
return None;
3291-
}
3292-
if (auto *CCD = dyn_cast<clang::ObjCCategoryDecl>(CD)) {
3293-
if (CCD->protocol_begin() != CCD->protocol_end())
3294-
return None;
3295-
}
3296-
3297-
32983283
// There are 3 cases:
32993284
//
33003285
// - The decl is from a bridging header, CMO is Some(nullptr)
@@ -3318,32 +3303,29 @@ ClangImporter::Implementation::loadNamedMembers(
33183303

33193304
clang::ASTContext &clangCtx = getClangASTContext();
33203305

3321-
assert(isa<clang::ObjCContainerDecl>(CD));
3322-
33233306
TinyPtrVector<ValueDecl *> Members;
3324-
auto *Nominal = DC->getAsNominalTypeOrNominalTypeExtensionContext();
3325-
auto ClangContext = getEffectiveClangContext(Nominal);
3326-
for (auto entry : table->lookup(SerializedSwiftName(N.getBaseName()),
3327-
ClangContext)) {
3328-
if (!entry.is<clang::NamedDecl *>()) continue;
3329-
auto member = entry.get<clang::NamedDecl *>();
3330-
if (!isVisibleClangEntry(clangCtx, member)) continue;
3331-
3332-
// Skip Decls from different clang::DeclContexts
3333-
if (member->getDeclContext() != CDC) continue;
3334-
3335-
SmallVector<Decl*, 4> tmp;
3336-
insertMembersAndAlternates(member, tmp);
3337-
for (auto *TD : tmp) {
3338-
if (auto *V = dyn_cast<ValueDecl>(TD)) {
3339-
// Skip ValueDecls if they import under different names.
3340-
if (V->getFullName().matchesRef(N)) {
3341-
Members.push_back(V);
3307+
if (auto *CCD = dyn_cast<clang::ObjCContainerDecl>(CD)) {
3308+
for (auto entry : table->lookup(SerializedSwiftName(N.getBaseName()), CCD)) {
3309+
if (!entry.is<clang::NamedDecl *>()) continue;
3310+
auto member = entry.get<clang::NamedDecl *>();
3311+
if (!isVisibleClangEntry(clangCtx, member)) continue;
3312+
SmallVector<Decl*, 4> tmp;
3313+
insertMembersAndAlternates(member, tmp);
3314+
for (auto *TD : tmp) {
3315+
if (auto *V = dyn_cast<ValueDecl>(TD)) {
3316+
// Skip ValueDecls if they import into different DeclContexts
3317+
// or under different names than the one we asked about.
3318+
if (V->getDeclContext() == DC &&
3319+
V->getFullName().matchesRef(N)) {
3320+
Members.push_back(V);
3321+
}
33423322
}
33433323
}
33443324
}
3325+
return Members;
33453326
}
3346-
return Members;
3327+
3328+
return None;
33473329
}
33483330

33493331

lib/ClangImporter/ImportDecl.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4970,7 +4970,6 @@ SwiftDeclConverter::importCFClassType(const clang::TypedefNameDecl *decl,
49704970
}
49714971
}
49724972

4973-
theClass->addImplicitDestructor();
49744973
return theClass;
49754974
}
49764975

lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
989989
Opts.DebugConstraintSolver |= Args.hasArg(OPT_debug_constraints);
990990
Opts.EnableConstraintPropagation |= Args.hasArg(OPT_propagate_constraints);
991991
Opts.IterativeTypeChecker |= Args.hasArg(OPT_iterative_type_checker);
992-
Opts.NamedLazyMemberLoading &= !Args.hasArg(OPT_disable_named_lazy_member_loading);
992+
Opts.NamedLazyMemberLoading |= Args.hasArg(OPT_enable_named_lazy_member_loading);
993993
Opts.DebugGenericSignatures |= Args.hasArg(OPT_debug_generic_signatures);
994994

995995
Opts.DebuggerSupport |= Args.hasArg(OPT_debugger_support);

lib/Serialization/ModuleFile.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "swift/AST/GenericSignature.h"
2020
#include "swift/AST/ModuleLoader.h"
2121
#include "swift/AST/NameLookup.h"
22-
#include "swift/AST/PrettyStackTrace.h"
2322
#include "swift/AST/USRGeneration.h"
2423
#include "swift/Basic/Range.h"
2524
#include "swift/ClangImporter/ClangImporter.h"
@@ -1795,15 +1794,15 @@ void ModuleFile::loadObjCMethods(
17951794
Optional<TinyPtrVector<ValueDecl *>>
17961795
ModuleFile::loadNamedMembers(const IterableDeclContext *IDC, DeclName N,
17971796
uint64_t contextData) {
1798-
PrettyStackTraceDecl trace("loading members for", IDC->getDecl());
17991797

18001798
assert(IDC->wasDeserialized());
1801-
assert(DeclMemberNames);
18021799

1803-
TinyPtrVector<ValueDecl *> results;
1800+
if (!DeclMemberNames)
1801+
return None;
1802+
18041803
auto i = DeclMemberNames->find(N.getBaseName());
18051804
if (i == DeclMemberNames->end())
1806-
return results;
1805+
return None;
18071806

18081807
BitOffset subTableOffset = *i;
18091808
std::unique_ptr<SerializedDeclMembersTable> &subTable =
@@ -1826,6 +1825,7 @@ ModuleFile::loadNamedMembers(const IterableDeclContext *IDC, DeclName N,
18261825
}
18271826

18281827
assert(subTable);
1828+
TinyPtrVector<ValueDecl *> results;
18291829
auto j = subTable->find(IDC->getDeclID());
18301830
if (j != subTable->end()) {
18311831
for (DeclID d : *j) {
@@ -1838,9 +1838,8 @@ ModuleFile::loadNamedMembers(const IterableDeclContext *IDC, DeclName N,
18381838
} else {
18391839
if (!getContext().LangOpts.EnableDeserializationRecovery)
18401840
fatal(mem.takeError());
1841-
// Eat the error and treat this as a cache-miss to the caller; let
1842-
// them attempt to refill through the normal loadAllMembers() path.
1843-
llvm::consumeError(mem.takeError());
1841+
// Treat this as a cache-miss to the caller and let them attempt
1842+
// to refill through the normal loadAllMembers() path.
18441843
return None;
18451844
}
18461845
}

test/NameBinding/Inputs/NamedLazyMembers/NamedLazyMembers.h

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -50,50 +50,3 @@
5050

5151
@end
5252

53-
54-
// Don't conform to the protocol; that loads all protocol members.
55-
@interface SimpleDoer (Category)
56-
- (void)categoricallyDoSomeWork;
57-
- (void)categoricallyDoSomeWorkWithSpeed:(int)s;
58-
- (void)categoricallyDoSomeWorkWithSpeed:(int)s thoroughness:(int)t
59-
NS_SWIFT_NAME(categoricallyDoVeryImportantWork(speed:thoroughness:));
60-
- (void)categoricallyDoSomeWorkWithSpeed:(int)s alacrity:(int)a
61-
NS_SWIFT_NAME(categoricallyDoSomeWorkWithSpeed(speed:levelOfAlacrity:));
62-
63-
// These we are generally trying to not-import, via laziness.
64-
- (void)categoricallyGoForWalk;
65-
- (void)categoricallyTakeNap;
66-
- (void)categoricallyEatMeal;
67-
- (void)categoricallyTidyHome;
68-
- (void)categoricallyCallFamily;
69-
- (void)categoricallySingSong;
70-
- (void)categoricallyReadBook;
71-
- (void)categoricallyAttendLecture;
72-
- (void)categoricallyWriteLetter;
73-
@end
74-
75-
76-
@protocol MirroredBase
77-
+ (void)mirroredBaseClassMethod;
78-
- (void)mirroredBaseInstanceMethod;
79-
@end
80-
81-
@protocol MirroredDoer <MirroredBase>
82-
+ (void)mirroredDerivedClassMethod;
83-
- (void)mirroredDerivedInstanceMethod;
84-
@end
85-
86-
@interface MirroringDoer : NSObject<MirroredDoer>
87-
- (void)unobtrusivelyGoForWalk;
88-
- (void)unobtrusivelyTakeNap;
89-
- (void)unobtrusivelyEatMeal;
90-
- (void)unobtrusivelyTidyHome;
91-
- (void)unobtrusivelyCallFamily;
92-
- (void)unobtrusivelySingSong;
93-
- (void)unobtrusivelyReadBook;
94-
- (void)unobtrusivelyAttendLecture;
95-
- (void)unobtrusivelyWriteLetter;
96-
@end
97-
98-
@interface DerivedFromMirroringDoer : MirroringDoer
99-
@end

test/NameBinding/named_lazy_member_loading_objc_category.swift

Lines changed: 0 additions & 20 deletions
This file was deleted.

test/NameBinding/named_lazy_member_loading_objc_interface.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
// RUN: %target-swift-frontend -typecheck -I %S/Inputs/NamedLazyMembers -typecheck %s
77
//
88
// Check that named-lazy-member-loading reduces the number of Decls deserialized
9-
// RUN: %target-swift-frontend -typecheck -I %S/Inputs/NamedLazyMembers -disable-named-lazy-member-loading -stats-output-dir %t/stats-pre %s
10-
// RUN: %target-swift-frontend -typecheck -I %S/Inputs/NamedLazyMembers -stats-output-dir %t/stats-post %s
9+
// RUN: %target-swift-frontend -typecheck -I %S/Inputs/NamedLazyMembers -stats-output-dir %t/stats-pre %s
10+
// RUN: %target-swift-frontend -typecheck -I %S/Inputs/NamedLazyMembers -enable-named-lazy-member-loading -stats-output-dir %t/stats-post %s
1111
// RUN: %utils/process-stats-dir.py --evaluate-delta 'NumTotalClangImportedEntities < -10' %t/stats-pre %t/stats-post
1212

1313
import NamedLazyMembers

test/NameBinding/named_lazy_member_loading_objc_protocol.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
// RUN: %target-swift-frontend -typecheck -I %S/Inputs/NamedLazyMembers -typecheck %s
77
//
88
// Check that named-lazy-member-loading reduces the number of Decls deserialized
9-
// RUN: %target-swift-frontend -typecheck -I %S/Inputs/NamedLazyMembers -disable-named-lazy-member-loading -stats-output-dir %t/stats-pre %s
10-
// RUN: %target-swift-frontend -typecheck -I %S/Inputs/NamedLazyMembers -stats-output-dir %t/stats-post %s
11-
// RUN: %utils/process-stats-dir.py --evaluate-delta 'NumTotalClangImportedEntities < -9' %t/stats-pre %t/stats-post
9+
// RUN: %target-swift-frontend -typecheck -I %S/Inputs/NamedLazyMembers -stats-output-dir %t/stats-pre %s
10+
// RUN: %target-swift-frontend -typecheck -I %S/Inputs/NamedLazyMembers -enable-named-lazy-member-loading -stats-output-dir %t/stats-post %s
11+
// RUN: %utils/process-stats-dir.py --evaluate-delta 'NumTotalClangImportedEntities < -10' %t/stats-pre %t/stats-post
1212

1313
import NamedLazyMembers
1414

test/NameBinding/named_lazy_member_loading_protocol_mirroring.swift

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)