Skip to content

Commit 4121d45

Browse files
committed
AST: An opaque generic parameter is not 'simple' for purposes of type printing
1 parent 1f88fa8 commit 4121d45

File tree

2 files changed

+40
-32
lines changed

2 files changed

+40
-32
lines changed

include/swift/AST/Types.h

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6781,38 +6781,6 @@ inline TypeBase *TypeBase::getDesugaredType() {
67816781
return cast<SugarType>(this)->getSinglyDesugaredType()->getDesugaredType();
67826782
}
67836783

6784-
inline bool TypeBase::hasSimpleTypeRepr() const {
6785-
// NOTE: Please keep this logic in sync with TypeRepr::isSimple().
6786-
switch (getKind()) {
6787-
case TypeKind::Function:
6788-
case TypeKind::GenericFunction:
6789-
return false;
6790-
6791-
case TypeKind::Metatype:
6792-
return !cast<const AnyMetatypeType>(this)->hasRepresentation();
6793-
6794-
case TypeKind::ExistentialMetatype:
6795-
case TypeKind::Existential:
6796-
return false;
6797-
6798-
case TypeKind::OpaqueTypeArchetype:
6799-
case TypeKind::OpenedArchetype:
6800-
return false;
6801-
6802-
case TypeKind::ProtocolComposition: {
6803-
// 'Any', 'AnyObject' and single protocol compositions are simple
6804-
auto composition = cast<const ProtocolCompositionType>(this);
6805-
auto memberCount = composition->getMembers().size();
6806-
if (composition->hasExplicitAnyObject())
6807-
return memberCount == 0;
6808-
return memberCount <= 1;
6809-
}
6810-
6811-
default:
6812-
return true;
6813-
}
6814-
}
6815-
68166784
} // end namespace swift
68176785

68186786
namespace llvm {

lib/AST/Type.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6224,6 +6224,46 @@ bool TypeBase::isForeignReferenceType() {
62246224
return false;
62256225
}
62266226

6227+
bool TypeBase::hasSimpleTypeRepr() const {
6228+
// NOTE: Please keep this logic in sync with TypeRepr::isSimple().
6229+
switch (getKind()) {
6230+
case TypeKind::Function:
6231+
case TypeKind::GenericFunction:
6232+
return false;
6233+
6234+
case TypeKind::Metatype:
6235+
return !cast<const AnyMetatypeType>(this)->hasRepresentation();
6236+
6237+
case TypeKind::ExistentialMetatype:
6238+
case TypeKind::Existential:
6239+
return false;
6240+
6241+
case TypeKind::OpaqueTypeArchetype:
6242+
case TypeKind::OpenedArchetype:
6243+
return false;
6244+
6245+
case TypeKind::ProtocolComposition: {
6246+
// 'Any', 'AnyObject' and single protocol compositions are simple
6247+
auto composition = cast<const ProtocolCompositionType>(this);
6248+
auto memberCount = composition->getMembers().size();
6249+
if (composition->hasExplicitAnyObject())
6250+
return memberCount == 0;
6251+
return memberCount <= 1;
6252+
}
6253+
6254+
case TypeKind::GenericTypeParam: {
6255+
if (auto *decl = cast<const GenericTypeParamType>(this)) {
6256+
return !decl->isOpaqueType();
6257+
}
6258+
6259+
return true;
6260+
}
6261+
6262+
default:
6263+
return true;
6264+
}
6265+
}
6266+
62276267
bool CanType::isForeignReferenceType() {
62286268
if (auto *classDecl = getPointer()->lookThroughAllOptionalTypes()->getClassOrBoundGenericClass())
62296269
return classDecl->isForeignReferenceType();

0 commit comments

Comments
 (0)