@@ -1205,6 +1205,11 @@ static bool hasLessAccessibleSetter(const AbstractStorageDecl *ASD) {
12051205 return ASD->getSetterFormalAccess () < ASD->getFormalAccess ();
12061206}
12071207
1208+ static bool isImplicitRethrowsProtocol (const ProtocolDecl *proto) {
1209+ return proto->isSpecificProtocol (KnownProtocolKind::AsyncSequence) ||
1210+ proto->isSpecificProtocol (KnownProtocolKind::AsyncIteratorProtocol);
1211+ }
1212+
12081213void PrintAST::printAttributes (const Decl *D) {
12091214 if (Options.SkipAttributes )
12101215 return ;
@@ -1215,6 +1220,17 @@ void PrintAST::printAttributes(const Decl *D) {
12151220
12161221 auto attrs = D->getAttrs ();
12171222
1223+ // When printing a Swift interface, make sure that older compilers see
1224+ // @rethrows on the AsyncSequence and AsyncIteratorProtocol.
1225+ if (Options.AsyncSequenceRethrows && Options.IsForSwiftInterface ) {
1226+ if (auto proto = dyn_cast<ProtocolDecl>(D)) {
1227+ if (isImplicitRethrowsProtocol (proto)) {
1228+ Printer << " @rethrows" ;
1229+ Printer.printNewline ();
1230+ }
1231+ }
1232+ }
1233+
12181234 // Save the current number of exclude attrs to restore once we're done.
12191235 unsigned originalExcludeAttrCount = Options.ExcludeAttrList .size ();
12201236
@@ -3305,6 +3321,35 @@ static bool usesFeatureNoAsyncAvailability(Decl *decl) {
33053321 return decl->getAttrs ().getNoAsync (decl->getASTContext ()) != nullptr ;
33063322}
33073323
3324+ static bool usesFeatureAssociatedTypeAvailability (Decl *decl) {
3325+ return isa<AssociatedTypeDecl>(decl) &&
3326+ decl->getAttrs ().hasAttribute <AvailableAttr>();
3327+ }
3328+
3329+ static void
3330+ suppressingFeatureAssociatedTypeAvailability (
3331+ PrintOptions &options, llvm::function_ref<void ()> action) {
3332+ unsigned originalExcludeAttrCount = options.ExcludeAttrList .size ();
3333+ options.ExcludeAttrList .push_back (DeclAttrKind::Available);
3334+ action ();
3335+ options.ExcludeAttrList .resize (originalExcludeAttrCount);
3336+ }
3337+
3338+ static bool usesFeatureAsyncSequenceFailure (Decl *decl) {
3339+ if (auto proto = dyn_cast<ProtocolDecl>(decl)) {
3340+ return isImplicitRethrowsProtocol (proto);
3341+ }
3342+
3343+ return false ;
3344+ }
3345+
3346+ static void
3347+ suppressingFeatureAsyncSequenceFailure (
3348+ PrintOptions &options, llvm::function_ref<void ()> action) {
3349+ llvm::SaveAndRestore<bool > saved (options.AsyncSequenceRethrows , true );
3350+ action ();
3351+ }
3352+
33083353static bool usesFeatureBuiltinIntLiteralAccessors (Decl *decl) {
33093354 return false ;
33103355}
0 commit comments