@@ -534,6 +534,7 @@ static bool willUseTypeReprPrinting(TypeLoc tyLoc,
534534 (tyLoc.getType ().isNull () && tyLoc.getTypeRepr ()));
535535}
536536
537+ static std::vector<Feature> getUniqueFeaturesUsed (Decl *decl);
537538namespace {
538539// / AST pretty-printer.
539540class PrintAST : public ASTVisitor <PrintAST> {
@@ -1003,7 +1004,22 @@ class PrintAST : public ASTVisitor<PrintAST> {
10031004 ASTVisitor::visit (D);
10041005
10051006 if (haveFeatureChecks) {
1006- printCompatibilityFeatureChecksPost (Printer);
1007+
1008+ printCompatibilityFeatureChecksPost (Printer, [&]() -> void {
1009+ auto features = getUniqueFeaturesUsed (D);
1010+ assert (!features.empty ());
1011+ if (std::find_if (features.begin (), features.end (),
1012+ [](Feature feature) -> bool {
1013+ return getFeatureName (feature).equals (
1014+ " SpecializeAttributeWithAvailability" );
1015+ }) != features.end ()) {
1016+ Printer << " #else\n " ;
1017+ Options.PrintSpecializeAttributeWithAvailability = false ;
1018+ ASTVisitor::visit (D);
1019+ Options.PrintSpecializeAttributeWithAvailability = true ;
1020+ Printer.printNewline ();
1021+ }
1022+ });
10071023 }
10081024
10091025 if (Synthesize) {
@@ -2818,6 +2834,16 @@ static bool usesFeatureBuiltinMove(Decl *decl) {
28182834
28192835static bool usesFeatureBuiltinCopy (Decl *decl) { return false ; }
28202836
2837+ static bool usesFeatureSpecializeAttributeWithAvailability (Decl *decl) {
2838+ if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {
2839+ for (auto specialize : func->getAttrs ().getAttributes <SpecializeAttr>()) {
2840+ if (!specialize->getAvailableAttrs ().empty ())
2841+ return true ;
2842+ }
2843+ }
2844+ return false ;
2845+ }
2846+
28212847static bool usesFeatureInheritActorContext (Decl *decl) {
28222848 if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {
28232849 for (auto param : *func->getParameters ()) {
@@ -2926,12 +2952,13 @@ bool swift::printCompatibilityFeatureChecksPre(
29262952 return true ;
29272953}
29282954
2929- void swift::printCompatibilityFeatureChecksPost (ASTPrinter &printer) {
2955+ void swift::printCompatibilityFeatureChecksPost (
2956+ ASTPrinter &printer, llvm::function_ref<void ()> printElse) {
29302957 printer.printNewline ();
2958+ printElse ();
29312959 printer << " #endif\n " ;
29322960}
29332961
2934-
29352962void PrintAST::visitExtensionDecl (ExtensionDecl *decl) {
29362963 if (Options.TransformContext &&
29372964 Options.TransformContext ->isPrintingSynthesizedExtension ()) {
0 commit comments