@@ -973,6 +973,30 @@ static void printDifferentiableAttrArguments(
973973 printer << ' (' << stream.str () << ' )' ;
974974}
975975
976+ // / Returns the `PlatformKind` referenced by \p attr if applicable, or
977+ // / `std::nullopt` otherwise.
978+ static std::optional<PlatformKind>
979+ referencedPlatform (const DeclAttribute *attr) {
980+ switch (attr->getKind ()) {
981+ case DeclAttrKind::Available:
982+ return static_cast <const AvailableAttr *>(attr)->Platform ;
983+ case DeclAttrKind::BackDeployed:
984+ return static_cast <const BackDeployedAttr *>(attr)->Platform ;
985+ case DeclAttrKind::OriginallyDefinedIn:
986+ return static_cast <const OriginallyDefinedInAttr *>(attr)->Platform ;
987+ default :
988+ return std::nullopt ;
989+ }
990+ }
991+
992+ // / Returns true if \p attr contains a reference to a `PlatformKind` that should
993+ // / be considered SPI.
994+ static bool referencesSPIPlatform (const DeclAttribute *attr) {
995+ if (auto platform = referencedPlatform (attr))
996+ return isPlatformSPI (*platform);
997+ return false ;
998+ }
999+
9761000void DeclAttributes::print (ASTPrinter &Printer, const PrintOptions &Options,
9771001 const Decl *D) const {
9781002 if (!DeclAttrs)
@@ -995,6 +1019,8 @@ void DeclAttributes::print(ASTPrinter &Printer, const PrintOptions &Options,
9951019 AttributeVector longAttributes;
9961020 AttributeVector attributes;
9971021 AttributeVector modifiers;
1022+ bool libraryLevelAPI =
1023+ D->getASTContext ().LangOpts .LibraryLevel == LibraryLevel::API;
9981024
9991025 for (auto DA : llvm::reverse (FlattenedAttrs)) {
10001026 // Don't skip implicit custom attributes. Custom attributes like global
@@ -1010,6 +1036,12 @@ void DeclAttributes::print(ASTPrinter &Printer, const PrintOptions &Options,
10101036 if (Options.excludeAttrKind (DA->getKind ()))
10111037 continue ;
10121038
1039+ // In the public interfaces of -library-level=api modules, skip attributes
1040+ // that reference SPI platforms.
1041+ if (Options.printPublicInterface () && libraryLevelAPI &&
1042+ referencesSPIPlatform (DA))
1043+ continue ;
1044+
10131045 // If we're supposed to suppress expanded macros, check whether this is
10141046 // a macro.
10151047 if (Options.SuppressExpandedMacros ) {
0 commit comments