@@ -1978,6 +1978,11 @@ void PrintAST::printSingleDepthOfGenericSignature(
19781978 if (dependsOnOpaque (inverse.subject ))
19791979 continue ;
19801980
1981+ if (inverse.getKind () == InvertibleProtocolKind::Escapable &&
1982+ Options.SuppressNonEscapableTypes ) {
1983+ continue ;
1984+ }
1985+
19811986 if (isFirstReq) {
19821987 if (printRequirements)
19831988 Printer << " " << tok::kw_where << " " ;
@@ -3099,6 +3104,16 @@ suppressingFeatureAllowUnsafeAttribute(PrintOptions &options,
30993104 options.ExcludeAttrList .resize (originalExcludeAttrCount);
31003105}
31013106
3107+ static void
3108+ suppressingFeatureNonescapableTypes (PrintOptions &options,
3109+ llvm::function_ref<void ()> action) {
3110+ unsigned originalExcludeAttrCount = options.ExcludeAttrList .size ();
3111+ options.ExcludeAttrList .push_back (DeclAttrKind::Lifetime);
3112+ llvm::SaveAndRestore<bool > scope (options.SuppressNonEscapableTypes , true );
3113+ action ();
3114+ options.ExcludeAttrList .resize (originalExcludeAttrCount);
3115+ }
3116+
31023117// / Suppress the printing of a particular feature.
31033118static void suppressingFeature (PrintOptions &options, Feature feature,
31043119 llvm::function_ref<void ()> action) {
@@ -4107,10 +4122,12 @@ void PrintAST::visitFuncDecl(FuncDecl *decl) {
41074122 Printer.printDeclResultTypePre (decl, ResultTyLoc);
41084123 Printer.callPrintStructurePre (PrintStructureKind::FunctionReturnType);
41094124 {
4110- if (auto *typeRepr = dyn_cast_or_null<LifetimeDependentTypeRepr>(
4111- decl->getResultTypeRepr ())) {
4112- for (auto &dep : typeRepr->getLifetimeDependencies ()) {
4113- Printer << " " << dep.getDependsOnString () << " " ;
4125+ if (!Options.SuppressNonEscapableTypes ) {
4126+ if (auto *typeRepr = dyn_cast_or_null<LifetimeDependentTypeRepr>(
4127+ decl->getResultTypeRepr ())) {
4128+ for (auto &dep : typeRepr->getLifetimeDependencies ()) {
4129+ Printer << " " << dep.getDependsOnString () << " " ;
4130+ }
41144131 }
41154132 }
41164133 }
@@ -4330,15 +4347,17 @@ void PrintAST::visitConstructorDecl(ConstructorDecl *decl) {
43304347
43314348 printGenericDeclGenericParams (decl);
43324349 printFunctionParameters (decl);
4333- if (decl->hasLifetimeDependentReturn ()) {
4334- Printer << " -> " ;
4335- auto *typeRepr =
4336- cast<LifetimeDependentTypeRepr>(decl->getResultTypeRepr ());
4337- for (auto &dep : typeRepr->getLifetimeDependencies ()) {
4338- Printer << dep.getDependsOnString () << " " ;
4350+ if (!Options.SuppressNonEscapableTypes ) {
4351+ if (decl->hasLifetimeDependentReturn ()) {
4352+ Printer << " -> " ;
4353+ auto *typeRepr =
4354+ cast<LifetimeDependentTypeRepr>(decl->getResultTypeRepr ());
4355+ for (auto &dep : typeRepr->getLifetimeDependencies ()) {
4356+ Printer << dep.getDependsOnString () << " " ;
4357+ }
4358+ // TODO: Handle failable initializers with lifetime dependent returns
4359+ Printer << " Self" ;
43394360 }
4340- // TODO: Handle failable initializers with lifetime dependent returns
4341- Printer << " Self" ;
43424361 }
43434362 });
43444363
@@ -7796,7 +7815,28 @@ swift::getInheritedForPrinting(
77967815 }
77977816 continue ;
77987817 }
7818+
7819+ // Suppress Escapable and ~Escapable.
7820+ if (options.SuppressNonEscapableTypes ) {
7821+ if (auto pct = ty->getAs <ProtocolCompositionType>()) {
7822+ auto inverses = pct->getInverses ();
7823+ if (inverses.contains (InvertibleProtocolKind::Escapable)) {
7824+ inverses.remove (InvertibleProtocolKind::Escapable);
7825+ ty = ProtocolCompositionType::get (decl->getASTContext (),
7826+ pct->getMembers (), inverses,
7827+ pct->hasExplicitAnyObject ());
7828+ if (ty->isAny ())
7829+ continue ;
7830+ }
7831+ }
7832+
7833+ if (auto protoTy = ty->getAs <ProtocolType>())
7834+ if (protoTy->getDecl ()->isSpecificProtocol (
7835+ KnownProtocolKind::Escapable))
7836+ continue ;
7837+ }
77997838 }
7839+
78007840 if (options.SuppressConformanceSuppression &&
78017841 inherited.getEntry (i).isSuppressed ()) {
78027842 continue ;
0 commit comments