@@ -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.
@@ -5695,16 +5694,15 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
56955694 return opaque->getDecl ()->hasExplicitGenericParams ();
56965695 case PrintOptions::OpaqueReturnTypePrintingMode::WithoutOpaqueKeyword:
56975696 return opaque->getDecl ()->hasExplicitGenericParams () ||
5698- isSimpleUnderPrintOptions (opaque->getExistentialType ());
5697+ isSimpleUnderPrintOptions (opaque->getExistentialType ()
5698+ ->castTo <ExistentialType>()
5699+ ->getConstraintType ());
56995700 }
57005701 llvm_unreachable (" bad opaque-return-type printing mode" );
57015702 }
57025703 } else if (auto existential = dyn_cast<ExistentialType>(T.getPointer ())) {
5703- if (!Options. PrintExplicitAny || ! existential->shouldPrintWithAny ())
5704+ if (!existential->shouldPrintWithAny ())
57045705 return isSimpleUnderPrintOptions (existential->getConstraintType ());
5705- } else if (auto existential = dyn_cast<ExistentialMetatypeType>(T.getPointer ())) {
5706- if (!Options.PrintExplicitAny )
5707- return isSimpleUnderPrintOptions (existential->getInstanceType ());
57085706 } else if (auto param = dyn_cast<GenericTypeParamType>(T.getPointer ())) {
57095707 if (param->isParameterPack ())
57105708 return false ;
@@ -6176,7 +6174,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
61766174 }
61776175
61786176 Type instanceType = T->getInstanceType ();
6179- if (Options. PrintExplicitAny && T->is <ExistentialMetatypeType>()) {
6177+ if (T->is <ExistentialMetatypeType>()) {
61806178 Printer << " any " ;
61816179
61826180 // FIXME: We need to replace nested existential metatypes so that
@@ -6188,27 +6186,23 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
61886186
61896187 return type;
61906188 }));
6191- } else if (T->is <MetatypeType>() && instanceType->is <ExistentialType>()) {
6192- // The 'any' keyword is needed to distinguish between existential
6193- // metatypes and singleton metatypes. However, 'any' usually isn't
6194- // printed for Any and AnyObject, because it's unnecessary to write
6195- // 'any' with these specific constraints. Force printing with 'any'
6196- // for the existential instance type in this case.
6197- instanceType->getAs <ExistentialType>()->forcePrintWithAny ([&](Type ty) {
6198- printWithParensIfNotSimple (ty);
6199- });
62006189 } else {
6201- printWithParensIfNotSimple (instanceType);
6190+ assert (T->is <MetatypeType>());
6191+ if (instanceType->is <ExistentialType>()) {
6192+ // The 'any' keyword is needed to distinguish between existential
6193+ // metatypes and singleton metatypes. However, 'any' usually isn't
6194+ // printed for Any and AnyObject, because it's unnecessary to write
6195+ // 'any' with these specific constraints. Force printing with 'any'
6196+ // for the existential instance type in this case.
6197+ instanceType->getAs <ExistentialType>()->forcePrintWithAny ([&](Type ty) {
6198+ printWithParensIfNotSimple (ty);
6199+ });
6200+ } else {
6201+ printWithParensIfNotSimple (instanceType);
6202+ }
62026203 }
62036204
6204- // We spell normal metatypes of existential types as .Protocol.
6205- if (isa<MetatypeType>(T) &&
6206- T->getInstanceType ()->isAnyExistentialType () &&
6207- !Options.PrintExplicitAny ) {
6208- Printer << " .Protocol" ;
6209- } else {
6210- Printer << " .Type" ;
6211- }
6205+ Printer << " .Type" ;
62126206 }
62136207
62146208 void visitModuleType (ModuleType *T) {
@@ -6835,7 +6829,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
68356829 }
68366830
68376831 void visitExistentialType (ExistentialType *T) {
6838- if (Options. PrintExplicitAny && T->shouldPrintWithAny ())
6832+ if (T->shouldPrintWithAny ())
68396833 Printer << " any " ;
68406834
68416835 // FIXME: The desugared type is used here only to support
0 commit comments