@@ -1141,6 +1141,7 @@ Type TypeBase::stripConcurrency(bool recurse, bool dropGlobalActor) {
11411141 if (!newMembers.empty ()) {
11421142 return ProtocolCompositionType::get (
11431143 getASTContext (), newMembers,
1144+ protocolCompositionType->getInverses (),
11441145 protocolCompositionType->hasExplicitAnyObject ());
11451146 }
11461147
@@ -1606,18 +1607,20 @@ static void addProtocols(Type T,
16061607 SmallVectorImpl<ProtocolDecl *> &Protocols,
16071608 ParameterizedProtocolMap &Parameterized,
16081609 Type &Superclass,
1610+ InvertibleProtocolSet &Inverses,
16091611 bool &HasExplicitAnyObject) {
16101612 if (auto Proto = T->getAs <ProtocolType>()) {
16111613 Protocols.push_back (Proto->getDecl ());
16121614 return ;
16131615 }
16141616
16151617 if (auto PC = T->getAs <ProtocolCompositionType>()) {
1616- if (PC->hasExplicitAnyObject ())
1617- HasExplicitAnyObject = true ;
1618- for (auto P : PC->getMembers ())
1619- addProtocols (P, Protocols, Parameterized, Superclass,
1618+ Inverses. insertAll (PC->getInverses ());
1619+ HasExplicitAnyObject |= PC-> hasExplicitAnyObject () ;
1620+ for (auto P : PC->getMembers ()) {
1621+ addProtocols (P, Protocols, Parameterized, Superclass, Inverses,
16201622 HasExplicitAnyObject);
1623+ }
16211624 return ;
16221625 }
16231626
@@ -1918,6 +1921,7 @@ CanType TypeBase::computeCanonicalType() {
19181921 assert (!CanProtos.empty () && " Non-canonical empty composition?" );
19191922 const ASTContext &C = CanProtos[0 ]->getASTContext ();
19201923 Type Composition = ProtocolCompositionType::get (C, CanProtos,
1924+ PCT->getInverses (),
19211925 PCT->hasExplicitAnyObject ());
19221926 Result = Composition.getPointer ();
19231927 break ;
@@ -3727,9 +3731,8 @@ Type ArchetypeType::getExistentialType() const {
37273731 auto interfaceType = getInterfaceType ();
37283732 auto genericSig = genericEnv->getGenericSignature ();
37293733
3730- auto upperBound = genericSig->getUpperBound (interfaceType);
3731-
3732- return genericEnv->mapTypeIntoContext (upperBound);
3734+ auto existentialType = genericSig->getExistentialType (interfaceType);
3735+ return genericEnv->mapTypeIntoContext (existentialType);
37333736}
37343737
37353738bool ArchetypeType::requiresClass () const {
@@ -4010,27 +4013,22 @@ bool ProtocolCompositionType::requiresClass() {
40104013
40114014// / Constructs a protocol composition corresponding to the `Any` type.
40124015Type ProtocolCompositionType::theAnyType (const ASTContext &C) {
4013- return ProtocolCompositionType::get (C, {}, /* HasExplicitAnyObject=*/ false );
4016+ return ProtocolCompositionType::get (C, {}, /* Inverses=*/ {},
4017+ /* HasExplicitAnyObject=*/ false );
40144018}
40154019
40164020// / Constructs a protocol composition containing the `AnyObject` constraint.
40174021Type ProtocolCompositionType::theAnyObjectType (const ASTContext &C) {
4018- return ProtocolCompositionType::get (C, {}, /* HasExplicitAnyObject=*/ true );
4022+ return ProtocolCompositionType::get (C, {}, /* Inverses=*/ {},
4023+ /* HasExplicitAnyObject=*/ true );
40194024}
40204025
40214026Type ProtocolCompositionType::getInverseOf (const ASTContext &C,
40224027 InvertibleProtocolKind IP) {
4023- return ProtocolCompositionType::get (C, {}, {IP},
4028+ return ProtocolCompositionType::get (C, {}, /* Inverses= */ {IP},
40244029 /* HasExplicitAnyObject=*/ false );
40254030}
40264031
4027- Type ProtocolCompositionType::get (const ASTContext &C, ArrayRef<Type> Members,
4028- bool HasExplicitAnyObject) {
4029- return ProtocolCompositionType::get (C, Members,
4030- /* Inverses=*/ {},
4031- HasExplicitAnyObject);
4032- }
4033-
40344032Type ProtocolCompositionType::get (const ASTContext &C,
40354033 ArrayRef<Type> Members,
40364034 InvertibleProtocolSet Inverses,
@@ -4056,29 +4054,29 @@ Type ProtocolCompositionType::get(const ASTContext &C,
40564054 if (!t->isCanonical ())
40574055 return build (C, Members, Inverses, HasExplicitAnyObject);
40584056 }
4059-
4057+
40604058 Type Superclass;
40614059 SmallVector<ProtocolDecl *, 4 > Protocols;
40624060 ParameterizedProtocolMap Parameterized;
40634061 for (Type t : Members) {
4064- addProtocols (t, Protocols, Parameterized, Superclass, HasExplicitAnyObject);
4062+ addProtocols (t, Protocols, Parameterized, Superclass,
4063+ Inverses, HasExplicitAnyObject);
40654064 }
40664065
4066+ // Form the set of canonical component types.
4067+ SmallVector<Type, 4 > CanTypes;
4068+
40674069 // The presence of a superclass constraint makes AnyObject redundant.
4068- if (Superclass)
4070+ if (Superclass) {
40694071 HasExplicitAnyObject = false ;
4072+ CanTypes.push_back (Superclass->getCanonicalType ());
4073+ }
40704074
40714075 // If there are any parameterized protocols, the canonicalization
40724076 // algorithm gets more complex.
4073-
4074- // Form the set of canonical component types.
4075- SmallVector<Type, 4 > CanTypes;
4076- if (Superclass)
4077- CanTypes.push_back (Superclass->getCanonicalType ());
4078-
40794077 canonicalizeProtocols (Protocols, &Parameterized);
40804078
4081- for (auto proto: Protocols) {
4079+ for (auto proto : Protocols) {
40824080 // If we have a parameterized type for this protocol, use the
40834081 // canonical type of that. Sema should prevent us from building
40844082 // compositions with the same protocol and conflicting constraints.
@@ -5347,6 +5345,7 @@ case TypeKind::Id:
53475345
53485346 return ProtocolCompositionType::get (Ptr->getASTContext (),
53495347 substMembers,
5348+ pc->getInverses (),
53505349 pc->hasExplicitAnyObject ());
53515350 }
53525351
0 commit comments