Serialization: Option to skip writing decls marked @_implementationOnly

This commit is contained in:
Alexis Laferrière
2025-10-22 16:44:41 -07:00
parent 06db612d79
commit 810c418829
3 changed files with 18 additions and 0 deletions

View File

@@ -163,6 +163,7 @@ public:
bool HermeticSealAtLink = false;
bool EmbeddedSwiftModule = false;
bool SkipNonExportableDecls = false;
bool SkipImplementationOnlyDecls = false;
bool ExplicitModuleBuild = false;
bool EnableSerializationRemarks = false;
bool IsInterfaceSDKRelative = false;

View File

@@ -284,6 +284,9 @@ SerializationOptions CompilerInvocation::computeSerializationOptions(
serializationOpts.SkipNonExportableDecls =
getLangOptions().SkipNonExportableDecls;
serializationOpts.SkipImplementationOnlyDecls =
getLangOptions().hasFeature(Feature::CheckImplementationOnly);
serializationOpts.ExplicitModuleBuild = FrontendOpts.DisableImplicitModules;
serializationOpts.EnableSerializationRemarks =

View File

@@ -5390,6 +5390,20 @@ bool Serializer::shouldSkipDecl(const Decl *D) const {
void Serializer::writeASTBlockEntity(const Decl *D) {
using namespace decls_block;
if (Options.SkipImplementationOnlyDecls) {
// Skip @_implementationOnly types.
if (D->getAttrs().hasAttribute<ImplementationOnlyAttr>())
return;
// Skip non-public @export(interface) functions.
auto FD = dyn_cast<AbstractFunctionDecl>(D);
if (FD &&
FD->getAttrs().hasAttribute<NeverEmitIntoClientAttr>() &&
!FD->getFormalAccessScope(/*useDC*/nullptr,
/*treatUsableFromInlineAsPublic*/true).isPublicOrPackage())
return;
}
PrettyStackTraceDecl trace("serializing", D);
assert(DeclsToSerialize.hasRef(D));