@@ -973,6 +973,30 @@ static void printDifferentiableAttrArguments(
973
973
printer << ' (' << stream.str () << ' )' ;
974
974
}
975
975
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
+
976
1000
void DeclAttributes::print (ASTPrinter &Printer, const PrintOptions &Options,
977
1001
const Decl *D) const {
978
1002
if (!DeclAttrs)
@@ -995,6 +1019,8 @@ void DeclAttributes::print(ASTPrinter &Printer, const PrintOptions &Options,
995
1019
AttributeVector longAttributes;
996
1020
AttributeVector attributes;
997
1021
AttributeVector modifiers;
1022
+ bool libraryLevelAPI =
1023
+ D->getASTContext ().LangOpts .LibraryLevel == LibraryLevel::API;
998
1024
999
1025
for (auto DA : llvm::reverse (FlattenedAttrs)) {
1000
1026
// Don't skip implicit custom attributes. Custom attributes like global
@@ -1010,6 +1036,12 @@ void DeclAttributes::print(ASTPrinter &Printer, const PrintOptions &Options,
1010
1036
if (Options.excludeAttrKind (DA->getKind ()))
1011
1037
continue ;
1012
1038
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
+
1013
1045
// If we're supposed to suppress expanded macros, check whether this is
1014
1046
// a macro.
1015
1047
if (Options.SuppressExpandedMacros ) {
0 commit comments