@@ -897,68 +897,50 @@ bool TypeBase::isSendableType() {
897
897
// / Copyable and Escapable checking utilities
898
898
// /
899
899
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
-
918
900
static 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
+ auto *proto = type->getASTContext ().getProtocol (getKnownProtocolKind (ip));
902
+ ASSERT (proto);
923
903
924
- // Must not have a type parameter!
925
- assert (!type->hasTypeParameter () && " caller forgot to mapTypeIntoContext!" );
926
-
927
- assert (!type->hasUnboundGenericType () && " a UGT has no conformances!" );
928
-
929
- assert (!type->is <PackExpansionType>());
930
-
931
- // FIXME: lldb misbehaves by getting here with a SILPackType.
932
- // just pretend it it conforms.
933
- if (type->is <SILPackType>())
934
- return true ;
935
-
936
- if (type->is <SILTokenType>()) {
937
- return true ;
938
- }
904
+ return (bool ) checkConformance (type, proto, /* allowMissing=*/ false );
905
+ }
939
906
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>()));
907
+ void TypeBase::computeInvertibleConformances () {
908
+ Bits.TypeBase .ComputedInvertibleConformances = true ;
946
909
947
- const bool conforms =
948
- (bool ) checkConformance (type, proto, /* allowMissing=*/ false );
910
+ Type type (this );
949
911
950
- return conforms;
912
+ // Pack expansions such as `repeat T` themselves do not have conformances,
913
+ // so check its pattern type for conformance.
914
+ if (auto *pet = type->getAs <PackExpansionType>())
915
+ type = pet->getPatternType ();
916
+
917
+ auto canType = type->getReferenceStorageReferent ()
918
+ ->getWithoutSpecifierType ()
919
+ ->getCanonicalType ();
920
+
921
+ assert (!canType->hasTypeParameter ());
922
+ assert (!canType->hasUnboundGenericType ());
923
+ assert (!isa<SILBoxType>(canType));
924
+ assert (!isa<SILMoveOnlyWrappedType>(canType));
925
+
926
+ Bits.TypeBase .IsCopyable = conformsToInvertible (
927
+ canType, InvertibleProtocolKind::Copyable);
928
+ Bits.TypeBase .IsEscapable = conformsToInvertible (
929
+ canType, InvertibleProtocolKind::Escapable);
951
930
}
952
931
953
932
// / \returns true iff this type lacks conformance to Copyable.
954
933
bool TypeBase::isNoncopyable () {
955
- auto canType = preprocessTypeForInvertibleQuery (this );
956
- return !conformsToInvertible (canType, InvertibleProtocolKind::Copyable);
934
+ if (!Bits.TypeBase .ComputedInvertibleConformances )
935
+ computeInvertibleConformances ();
936
+ return !Bits.TypeBase .IsCopyable ;
957
937
}
958
938
939
+ // / \returns true iff this type conforms to Escaping.
959
940
bool TypeBase::isEscapable () {
960
- auto canType = preprocessTypeForInvertibleQuery (this );
961
- return conformsToInvertible (canType, InvertibleProtocolKind::Escapable);
941
+ if (!Bits.TypeBase .ComputedInvertibleConformances )
942
+ computeInvertibleConformances ();
943
+ return Bits.TypeBase .IsEscapable ;
962
944
}
963
945
964
946
bool TypeBase::isEscapable (GenericSignature sig) {
0 commit comments