@@ -756,6 +756,16 @@ IdentifierID Serializer::addContainingModuleRef(const DeclContext *DC,
756756 if (M->isClangHeaderImportModule ())
757757 return OBJC_HEADER_MODULE_ID;
758758
759+ // Reject references to hidden dependencies.
760+ if (getASTContext ().LangOpts .hasFeature (
761+ Feature::CheckImplementationOnlyStrict) &&
762+ !allowCompilerErrors () &&
763+ this ->M ->isImportedImplementationOnly (M, /* assumeImported=*/ false )) {
764+ getASTContext ().Diags .diagnose (SourceLoc (),
765+ diag::serialization_xref_to_hidden_dependency,
766+ M, crossReferencedDecl);
767+ }
768+
759769 auto exportedModuleName = file->getExportedModuleName ();
760770 assert (!exportedModuleName.empty ());
761771 auto moduleID = M->getASTContext ().getIdentifier (exportedModuleName);
@@ -2452,6 +2462,8 @@ void Serializer::writeCrossReference(const Decl *D) {
24522462
24532463 unsigned abbrCode;
24542464
2465+ llvm::SaveAndRestore<const Decl *> SaveDecl (crossReferencedDecl, D);
2466+
24552467 if (auto op = dyn_cast<OperatorDecl>(D)) {
24562468 writeCrossReference (op->getDeclContext (), 1 );
24572469
@@ -5389,6 +5401,19 @@ bool Serializer::shouldSkipDecl(const Decl *D) const {
53895401void Serializer::writeASTBlockEntity (const Decl *D) {
53905402 using namespace decls_block ;
53915403
5404+ if (Options.SkipImplementationOnlyDecls ) {
5405+ // Skip @_implementationOnly types.
5406+ if (D->getAttrs ().hasAttribute <ImplementationOnlyAttr>())
5407+ return ;
5408+
5409+ // Skip non-public @export(interface) functions.
5410+ auto FD = dyn_cast<AbstractFunctionDecl>(D);
5411+ if (FD && FD->isNeverEmittedIntoClient () &&
5412+ !FD->getFormalAccessScope (/* useDC*/ nullptr ,
5413+ /* treatUsableFromInlineAsPublic*/ true ).isPublicOrPackage ())
5414+ return ;
5415+ }
5416+
53925417 PrettyStackTraceDecl trace (" serializing" , D);
53935418 assert (DeclsToSerialize.hasRef (D));
53945419
@@ -7301,7 +7326,7 @@ void Serializer::writeToStream(
73017326 BCBlockRAII moduleBlock (S.Out , MODULE_BLOCK_ID, 2 );
73027327 S.writeHeader ();
73037328 S.writeInputBlock ();
7304- S.writeSIL (SILMod, options. SerializeAllSIL , options. SerializeDebugInfoSIL );
7329+ S.writeSIL (SILMod);
73057330 S.writeAST (DC);
73067331
73077332 if (S.hadError )
0 commit comments