@@ -3529,24 +3529,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
3529
3529
return ;
3530
3530
}
3531
3531
3532
- bool isSimple = T->hasSimpleTypeRepr ();
3533
- if (!isSimple && T->is <OpaqueTypeArchetypeType>()) {
3534
- auto opaqueTy = T->castTo <OpaqueTypeArchetypeType>();
3535
- switch (Options.OpaqueReturnTypePrinting ) {
3536
- case PrintOptions::OpaqueReturnTypePrintingMode::StableReference:
3537
- case PrintOptions::OpaqueReturnTypePrintingMode::Description:
3538
- isSimple = true ;
3539
- break ;
3540
- case PrintOptions::OpaqueReturnTypePrintingMode::WithOpaqueKeyword:
3541
- isSimple = false ;
3542
- break ;
3543
- case PrintOptions::OpaqueReturnTypePrintingMode::WithoutOpaqueKeyword: {
3544
- isSimple = opaqueTy->getExistentialType ()->hasSimpleTypeRepr ();
3545
- break ;
3546
- }
3547
- }
3548
- }
3549
-
3532
+ bool isSimple = isSimpleUnderPrintOptions (T);
3550
3533
if (isSimple) {
3551
3534
visit (T);
3552
3535
} else {
@@ -3556,6 +3539,28 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
3556
3539
}
3557
3540
}
3558
3541
3542
+ // / Determinee whether the given type has a simple representation
3543
+ // / under the current print options.
3544
+ bool isSimpleUnderPrintOptions (Type T) {
3545
+ if (auto typealias = dyn_cast<TypeAliasType>(T.getPointer ())) {
3546
+ if (shouldDesugarTypeAliasType (typealias))
3547
+ return isSimpleUnderPrintOptions (typealias->getSinglyDesugaredType ());
3548
+ } else if (auto opaque =
3549
+ dyn_cast<OpaqueTypeArchetypeType>(T.getPointer ())) {
3550
+ switch (Options.OpaqueReturnTypePrinting ) {
3551
+ case PrintOptions::OpaqueReturnTypePrintingMode::StableReference:
3552
+ case PrintOptions::OpaqueReturnTypePrintingMode::Description:
3553
+ return true ;
3554
+ case PrintOptions::OpaqueReturnTypePrintingMode::WithOpaqueKeyword:
3555
+ return false ;
3556
+ case PrintOptions::OpaqueReturnTypePrintingMode::WithoutOpaqueKeyword:
3557
+ return isSimpleUnderPrintOptions (opaque->getExistentialType ());
3558
+ }
3559
+ llvm_unreachable (" bad opaque-return-type printing mode" );
3560
+ }
3561
+ return T->hasSimpleTypeRepr ();
3562
+ }
3563
+
3559
3564
template <typename T>
3560
3565
void printModuleContext (T *Ty) {
3561
3566
FileUnit *File = cast<FileUnit>(Ty->getDecl ()->getModuleScopeContext ());
@@ -3693,8 +3698,12 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
3693
3698
Printer << BUILTIN_TYPE_NAME_SILTOKEN;
3694
3699
}
3695
3700
3701
+ bool shouldDesugarTypeAliasType (TypeAliasType *T) {
3702
+ return Options.PrintForSIL || Options.PrintTypeAliasUnderlyingType ;
3703
+ }
3704
+
3696
3705
void visitTypeAliasType (TypeAliasType *T) {
3697
- if (Options. PrintForSIL || Options. PrintTypeAliasUnderlyingType ) {
3706
+ if (shouldDesugarTypeAliasType (T) ) {
3698
3707
visit (T->getSinglyDesugaredType ());
3699
3708
return ;
3700
3709
}
0 commit comments