Skip to content

Named lazy member loading write by default #12741

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
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
1 change: 0 additions & 1 deletion include/swift/Serialization/SerializationOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ namespace swift {

bool AutolinkForceLoad = false;
bool EnableNestedTypeLookupTable = false;
bool EnableDeclMemberNamesTable = false;
bool SerializeAllSIL = false;
bool SerializeOptionsForDebugging = false;
bool IsSIB = false;
Expand Down
27 changes: 23 additions & 4 deletions lib/AST/NameLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,20 @@ populateLookupTableEntryFromLazyIDCLoader(ASTContext &ctx,
}
}

static void
populateLookupTableEntryFromMembers(ASTContext &ctx,
MemberLookupTable &LookupTable,
DeclName name,
IterableDeclContext *IDC) {
for (auto m : IDC->getMembers()) {
if (auto v = dyn_cast<ValueDecl>(m)) {
if (v->getFullName().matchesRef(name)) {
LookupTable.addMember(m);
}
}
}
}

TinyPtrVector<ValueDecl *> NominalTypeDecl::lookupDirect(
DeclName name,
bool ignoreNewExtensions) {
Expand Down Expand Up @@ -1385,10 +1399,15 @@ TinyPtrVector<ValueDecl *> NominalTypeDecl::lookupDirect(
} else {
if (!ignoreNewExtensions) {
for (auto E : getExtensions()) {
if (populateLookupTableEntryFromLazyIDCLoader(ctx, Table,
name, E)) {
useNamedLazyMemberLoading = false;
break;
if (E->wasDeserialized()) {
if (populateLookupTableEntryFromLazyIDCLoader(ctx, Table,
name, E)) {
useNamedLazyMemberLoading = false;
break;
}
} else {
populateLookupTableEntryFromMembers(ctx, Table,
name, E);
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions lib/FrontendTool/FrontendTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,8 +835,6 @@ static bool performCompile(CompilerInstance &Instance,
serializationOpts.OutputPath = opts.ModuleOutputPath.c_str();
serializationOpts.SerializeAllSIL = true;
serializationOpts.IsSIB = true;
serializationOpts.EnableDeclMemberNamesTable =
Invocation.getLangOptions().NamedLazyMemberLoading;

serialize(DC, serializationOpts, SM.get());
}
Expand Down Expand Up @@ -901,8 +899,6 @@ static bool performCompile(CompilerInstance &Instance,
Invocation.getClangImporterOptions().ExtraArgs;
serializationOpts.EnableNestedTypeLookupTable =
opts.EnableSerializationNestedTypeLookupTable;
serializationOpts.EnableDeclMemberNamesTable =
Invocation.getLangOptions().NamedLazyMemberLoading;
if (!IRGenOpts.ForceLoadSymbolName.empty())
serializationOpts.AutolinkForceLoad = true;

Expand Down Expand Up @@ -981,8 +977,6 @@ static bool performCompile(CompilerInstance &Instance,
serializationOpts.OutputPath = opts.ModuleOutputPath.c_str();
serializationOpts.SerializeAllSIL = true;
serializationOpts.IsSIB = true;
serializationOpts.EnableDeclMemberNamesTable =
Invocation.getLangOptions().NamedLazyMemberLoading;

serialize(DC, serializationOpts, SM.get());
}
Expand Down
36 changes: 16 additions & 20 deletions lib/Serialization/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4668,8 +4668,7 @@ static void collectInterestingNestedDeclarations(
}

void Serializer::writeAST(ModuleOrSourceFile DC,
bool enableNestedTypeLookupTable,
bool enableDeclMemberNamesTable) {
bool enableNestedTypeLookupTable) {
DeclTable topLevelDecls, operatorDecls, operatorMethodDecls;
DeclTable precedenceGroupDecls;
ObjCMethodTable objcMethods;
Expand Down Expand Up @@ -4804,24 +4803,22 @@ void Serializer::writeAST(ModuleOrSourceFile DC,
EntryPoint.emit(ScratchRecord, entryPointClassID.getValue());
}

if (enableDeclMemberNamesTable) {
{
// Write sub-tables to a skippable sub-block.
BCBlockRAII restoreBlock(Out, DECL_MEMBER_TABLES_BLOCK_ID, 4);
decl_member_tables_block::DeclMembersLayout DeclMembersTable(Out);
for (auto &entry : DeclMemberNames) {
// Save BitOffset we're writing sub-table to.
static_assert(bitOffsetFitsIn32Bits(), "BitOffset too large");
assert(Out.GetCurrentBitNo() < (1ull << 32));
entry.second.first = Out.GetCurrentBitNo();
// Write sub-table.
writeDeclMembersTable(DeclMembersTable, *entry.second.second);
}
{
// Write sub-tables to a skippable sub-block.
BCBlockRAII restoreBlock(Out, DECL_MEMBER_TABLES_BLOCK_ID, 4);
decl_member_tables_block::DeclMembersLayout DeclMembersTable(Out);
for (auto &entry : DeclMemberNames) {
// Save BitOffset we're writing sub-table to.
static_assert(bitOffsetFitsIn32Bits(), "BitOffset too large");
assert(Out.GetCurrentBitNo() < (1ull << 32));
entry.second.first = Out.GetCurrentBitNo();
// Write sub-table.
writeDeclMembersTable(DeclMembersTable, *entry.second.second);
}
// Write top-level table mapping names to sub-tables.
index_block::DeclMemberNamesLayout DeclMemberNamesTable(Out);
writeDeclMemberNamesTable(DeclMemberNamesTable, DeclMemberNames);
}
// Write top-level table mapping names to sub-tables.
index_block::DeclMemberNamesLayout DeclMemberNamesTable(Out);
writeDeclMemberNamesTable(DeclMemberNamesTable, DeclMemberNames);
}
}

Expand Down Expand Up @@ -4854,8 +4851,7 @@ void Serializer::writeToStream(raw_ostream &os, ModuleOrSourceFile DC,
S.writeHeader(options);
S.writeInputBlock(options);
S.writeSIL(SILMod, options.SerializeAllSIL);
S.writeAST(DC, options.EnableNestedTypeLookupTable,
options.EnableDeclMemberNamesTable);
S.writeAST(DC, options.EnableNestedTypeLookupTable);
}

S.writeToStream(os);
Expand Down
3 changes: 1 addition & 2 deletions lib/Serialization/Serialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,7 @@ class Serializer {

/// Top-level entry point for serializing a module.
void writeAST(ModuleOrSourceFile DC,
bool enableNestedTypeLookupTable,
bool enableDeclMemberNamesTable);
bool enableNestedTypeLookupTable);

void writeToStream(raw_ostream &os);

Expand Down