@@ -897,68 +897,60 @@ bool TypeBase::isSendableType() {
897897// / Copyable and Escapable checking utilities
898898// /
899899
900- // / Preprocesses a type before querying whether it conforms to an invertible.
901- static CanType preprocessTypeForInvertibleQuery (Type orig) {
902- Type type = orig;
903-
904- // Strip off any StorageType wrapper.
905- type = type->getReferenceStorageReferent ();
906-
907- // Pack expansions such as `repeat T` themselves do not have conformances,
908- // so check its pattern type for conformance.
909- if (auto *pet = type->getAs <PackExpansionType>()) {
910- type = pet->getPatternType ()->getCanonicalType ();
911- }
912-
913- // Strip @lvalue and canonicalize.
914- auto canType = type->getRValueType ()->getCanonicalType ();
915- return canType;
916- }
917-
918900static bool conformsToInvertible (CanType type, InvertibleProtocolKind ip) {
919- auto &ctx = type->getASTContext ();
920-
921- auto *proto = ctx.getProtocol (getKnownProtocolKind (ip));
922- assert (proto && " missing Copyable/Escapable from stdlib!" );
901+ // FIXME: Remove these.
902+ if (isa<SILPackType>(type))
903+ return true ;
923904
924- // Must not have a type parameter!
925- assert (!type-> hasTypeParameter () && " caller forgot to mapTypeIntoContext! " ) ;
905+ if (isa<SILTokenType>( type))
906+ return true ;
926907
927- assert (!type->hasUnboundGenericType () && " a UGT has no conformances!" );
908+ auto *proto = type->getASTContext ().getProtocol (getKnownProtocolKind (ip));
909+ ASSERT (proto);
928910
929- assert (!type->is <PackExpansionType>());
911+ return (bool ) checkConformance (type, proto, /* allowMissing=*/ false );
912+ }
930913
931- // FIXME: lldb misbehaves by getting here with a SILPackType.
932- // just pretend it it conforms.
933- if (type->is <SILPackType>())
934- return true ;
914+ void TypeBase::computeInvertibleConformances () {
915+ Bits.TypeBase .ComputedInvertibleConformances = true ;
935916
936- if (type->is <SILTokenType>()) {
937- return true ;
938- }
939-
940- // The SIL types in the AST do not have real conformances, and should have
941- // been handled in SILType instead.
942- assert (!(type->is <SILBoxType,
943- SILMoveOnlyWrappedType,
944- SILPackType,
945- SILTokenType>()));
917+ Type type (this );
946918
947- const bool conforms =
948- ( bool ) checkConformance (type, proto, /* allowMissing= */ false );
919+ // FIXME: Remove all of the below. Callers should be changed to perform any
920+ // necessary unwrapping themselves.
949921
950- return conforms;
922+ // Pack expansions such as `repeat T` themselves do not have conformances,
923+ // so check its pattern type for conformance.
924+ if (auto *pet = type->getAs <PackExpansionType>())
925+ type = pet->getPatternType ();
926+
927+ auto canType = type->getReferenceStorageReferent ()
928+ ->getWithoutSpecifierType ()
929+ ->getCanonicalType ();
930+
931+ assert (!canType->hasTypeParameter ());
932+ assert (!canType->hasUnboundGenericType ());
933+ assert (!isa<SILBoxType>(canType));
934+ assert (!isa<SILMoveOnlyWrappedType>(canType));
935+
936+ Bits.TypeBase .IsCopyable = conformsToInvertible (
937+ canType, InvertibleProtocolKind::Copyable);
938+ Bits.TypeBase .IsEscapable = conformsToInvertible (
939+ canType, InvertibleProtocolKind::Escapable);
951940}
952941
953942// / \returns true iff this type lacks conformance to Copyable.
954943bool TypeBase::isNoncopyable () {
955- auto canType = preprocessTypeForInvertibleQuery (this );
956- return !conformsToInvertible (canType, InvertibleProtocolKind::Copyable);
944+ if (!Bits.TypeBase .ComputedInvertibleConformances )
945+ computeInvertibleConformances ();
946+ return !Bits.TypeBase .IsCopyable ;
957947}
958948
949+ // / \returns true iff this type conforms to Escaping.
959950bool TypeBase::isEscapable () {
960- auto canType = preprocessTypeForInvertibleQuery (this );
961- return conformsToInvertible (canType, InvertibleProtocolKind::Escapable);
951+ if (!Bits.TypeBase .ComputedInvertibleConformances )
952+ computeInvertibleConformances ();
953+ return Bits.TypeBase .IsEscapable ;
962954}
963955
964956bool TypeBase::isEscapable (GenericSignature sig) {
0 commit comments