@@ -178,7 +178,6 @@ PrintOptions PrintOptions::printSwiftInterfaceFile(ModuleDecl *ModuleToPrint,
178178 PrintOptions::FunctionRepresentationMode::Full;
179179 result.AlwaysTryPrintParameterLabels = true ;
180180 result.PrintSPIs = printSPIs;
181- result.PrintExplicitAny = true ;
182181 result.DesugarExistentialConstraint = true ;
183182
184183 // We should print __consuming, __owned, etc for the module interface file.
@@ -5712,16 +5711,15 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
57125711 return opaque->getDecl ()->hasExplicitGenericParams ();
57135712 case PrintOptions::OpaqueReturnTypePrintingMode::WithoutOpaqueKeyword:
57145713 return opaque->getDecl ()->hasExplicitGenericParams () ||
5715- isSimpleUnderPrintOptions (opaque->getExistentialType ());
5714+ isSimpleUnderPrintOptions (opaque->getExistentialType ()
5715+ ->castTo <ExistentialType>()
5716+ ->getConstraintType ());
57165717 }
57175718 llvm_unreachable (" bad opaque-return-type printing mode" );
57185719 }
57195720 } else if (auto existential = dyn_cast<ExistentialType>(T.getPointer ())) {
5720- if (!Options. PrintExplicitAny || ! existential->shouldPrintWithAny ())
5721+ if (!existential->shouldPrintWithAny ())
57215722 return isSimpleUnderPrintOptions (existential->getConstraintType ());
5722- } else if (auto existential = dyn_cast<ExistentialMetatypeType>(T.getPointer ())) {
5723- if (!Options.PrintExplicitAny )
5724- return isSimpleUnderPrintOptions (existential->getInstanceType ());
57255723 } else if (auto param = dyn_cast<GenericTypeParamType>(T.getPointer ())) {
57265724 if (param->isParameterPack ())
57275725 return false ;
@@ -6193,7 +6191,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
61936191 }
61946192
61956193 Type instanceType = T->getInstanceType ();
6196- if (Options. PrintExplicitAny && T->is <ExistentialMetatypeType>()) {
6194+ if (T->is <ExistentialMetatypeType>()) {
61976195 Printer << " any " ;
61986196
61996197 // FIXME: We need to replace nested existential metatypes so that
@@ -6205,27 +6203,23 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
62056203
62066204 return type;
62076205 }));
6208- } else if (T->is <MetatypeType>() && instanceType->is <ExistentialType>()) {
6209- // The 'any' keyword is needed to distinguish between existential
6210- // metatypes and singleton metatypes. However, 'any' usually isn't
6211- // printed for Any and AnyObject, because it's unnecessary to write
6212- // 'any' with these specific constraints. Force printing with 'any'
6213- // for the existential instance type in this case.
6214- instanceType->getAs <ExistentialType>()->forcePrintWithAny ([&](Type ty) {
6215- printWithParensIfNotSimple (ty);
6216- });
62176206 } else {
6218- printWithParensIfNotSimple (instanceType);
6207+ assert (T->is <MetatypeType>());
6208+ if (instanceType->is <ExistentialType>()) {
6209+ // The 'any' keyword is needed to distinguish between existential
6210+ // metatypes and singleton metatypes. However, 'any' usually isn't
6211+ // printed for Any and AnyObject, because it's unnecessary to write
6212+ // 'any' with these specific constraints. Force printing with 'any'
6213+ // for the existential instance type in this case.
6214+ instanceType->getAs <ExistentialType>()->forcePrintWithAny ([&](Type ty) {
6215+ printWithParensIfNotSimple (ty);
6216+ });
6217+ } else {
6218+ printWithParensIfNotSimple (instanceType);
6219+ }
62196220 }
62206221
6221- // We spell normal metatypes of existential types as .Protocol.
6222- if (isa<MetatypeType>(T) &&
6223- T->getInstanceType ()->isAnyExistentialType () &&
6224- !Options.PrintExplicitAny ) {
6225- Printer << " .Protocol" ;
6226- } else {
6227- Printer << " .Type" ;
6228- }
6222+ Printer << " .Type" ;
62296223 }
62306224
62316225 void visitModuleType (ModuleType *T) {
@@ -6852,7 +6846,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
68526846 }
68536847
68546848 void visitExistentialType (ExistentialType *T) {
6855- if (Options. PrintExplicitAny && T->shouldPrintWithAny ())
6849+ if (T->shouldPrintWithAny ())
68566850 Printer << " any " ;
68576851
68586852 // FIXME: The desugared type is used here only to support
0 commit comments