Skip to content

Commit 810c418

Browse files
committed
Serialization: Option to skip writing decls marked @_implementationOnly
1 parent 06db612 commit 810c418

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

include/swift/Serialization/SerializationOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ class SerializationOptions {
163163
bool HermeticSealAtLink = false;
164164
bool EmbeddedSwiftModule = false;
165165
bool SkipNonExportableDecls = false;
166+
bool SkipImplementationOnlyDecls = false;
166167
bool ExplicitModuleBuild = false;
167168
bool EnableSerializationRemarks = false;
168169
bool IsInterfaceSDKRelative = false;

lib/Frontend/Frontend.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ SerializationOptions CompilerInvocation::computeSerializationOptions(
284284
serializationOpts.SkipNonExportableDecls =
285285
getLangOptions().SkipNonExportableDecls;
286286

287+
serializationOpts.SkipImplementationOnlyDecls =
288+
getLangOptions().hasFeature(Feature::CheckImplementationOnly);
289+
287290
serializationOpts.ExplicitModuleBuild = FrontendOpts.DisableImplicitModules;
288291

289292
serializationOpts.EnableSerializationRemarks =

lib/Serialization/Serialization.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5390,6 +5390,20 @@ bool Serializer::shouldSkipDecl(const Decl *D) const {
53905390
void Serializer::writeASTBlockEntity(const Decl *D) {
53915391
using namespace decls_block;
53925392

5393+
if (Options.SkipImplementationOnlyDecls) {
5394+
// Skip @_implementationOnly types.
5395+
if (D->getAttrs().hasAttribute<ImplementationOnlyAttr>())
5396+
return;
5397+
5398+
// Skip non-public @export(interface) functions.
5399+
auto FD = dyn_cast<AbstractFunctionDecl>(D);
5400+
if (FD &&
5401+
FD->getAttrs().hasAttribute<NeverEmitIntoClientAttr>() &&
5402+
!FD->getFormalAccessScope(/*useDC*/nullptr,
5403+
/*treatUsableFromInlineAsPublic*/true).isPublicOrPackage())
5404+
return;
5405+
}
5406+
53935407
PrettyStackTraceDecl trace("serializing", D);
53945408
assert(DeclsToSerialize.hasRef(D));
53955409

0 commit comments

Comments
 (0)