@@ -264,28 +264,25 @@ bool TypeBase::allowsOwnership(const GenericSignatureImpl *sig) {
264264 return getCanonicalType ().allowsOwnership (sig);
265265}
266266
267- ExistentialLayout::ExistentialLayout (ProtocolType *type) {
268- assert (type->isCanonical ());
269-
267+ ExistentialLayout::ExistentialLayout (CanProtocolType type) {
270268 auto *protoDecl = type->getDecl ();
271269
272270 hasExplicitAnyObject = false ;
273271 containsNonObjCProtocol = !protoDecl->isObjC ();
274272 containsParameterized = false ;
275273
276- singleProtocol = type ;
274+ protocols. push_back (protoDecl) ;
277275}
278276
279- ExistentialLayout::ExistentialLayout (ProtocolCompositionType *type) {
280- assert (type->isCanonical ());
281-
277+ ExistentialLayout::ExistentialLayout (CanProtocolCompositionType type) {
282278 hasExplicitAnyObject = type->hasExplicitAnyObject ();
283279 containsNonObjCProtocol = false ;
284280 containsParameterized = false ;
285281
286282 auto members = type.getMembers ();
287283 if (!members.empty () &&
288- isa<ClassDecl>(members[0 ].getAnyNominal ())) {
284+ (members[0 ].getClassOrBoundGenericClass () ||
285+ isa<UnboundGenericType>(members[0 ]))) {
289286 explicitSuperclass = members[0 ];
290287 members = members.slice (1 );
291288 }
@@ -300,16 +297,12 @@ ExistentialLayout::ExistentialLayout(ProtocolCompositionType *type) {
300297 containsParameterized = true ;
301298 }
302299 containsNonObjCProtocol |= !protoDecl->isObjC ();
300+ protocols.push_back (protoDecl);
303301 }
304-
305- singleProtocol = nullptr ;
306- protocols = { members.data (), members.size () };
307302}
308303
309- ExistentialLayout::ExistentialLayout (ParameterizedProtocolType *type) {
310- assert (type->isCanonical ());
311-
312- *this = ExistentialLayout (type->getBaseType ());
304+ ExistentialLayout::ExistentialLayout (CanParameterizedProtocolType type)
305+ : ExistentialLayout(type.getBaseType()) {
313306 sameTypeRequirements = type->getArgs ();
314307 containsParameterized = true ;
315308}
@@ -320,10 +313,10 @@ ExistentialLayout TypeBase::getExistentialLayout() {
320313
321314ExistentialLayout CanType::getExistentialLayout () {
322315 if (auto existential = dyn_cast<ExistentialType>(*this ))
323- return existential-> getConstraintType ()-> getExistentialLayout ();
316+ return existential. getConstraintType (). getExistentialLayout ();
324317
325318 if (auto metatype = dyn_cast<ExistentialMetatypeType>(*this ))
326- return metatype-> getInstanceType ()-> getExistentialLayout ();
319+ return metatype. getInstanceType (). getExistentialLayout ();
327320
328321 if (auto proto = dyn_cast<ProtocolType>(*this ))
329322 return ExistentialLayout (proto);
@@ -351,11 +344,10 @@ Type ExistentialLayout::getSuperclass() const {
351344 if (explicitSuperclass)
352345 return explicitSuperclass;
353346
354- for (auto proto : getProtocols ()) {
347+ for (auto protoDecl : getProtocols ()) {
355348 // If we have a generic signature, check there, because it
356349 // will pick up superclass constraints from protocols that we
357350 // refine as well.
358- auto *protoDecl = proto->getDecl ();
359351 if (auto genericSig = protoDecl->getGenericSignature ()) {
360352 if (auto superclass = genericSig->getSuperclassBound (
361353 protoDecl->getSelfInterfaceType ()))
@@ -429,7 +421,7 @@ bool TypeBase::isActorType() {
429421 }
430422
431423 for (auto proto : layout.getProtocols ()) {
432- if (proto->isActorType ())
424+ if (proto->isActor ())
433425 return true ;
434426 }
435427
@@ -464,9 +456,9 @@ bool TypeBase::isDistributedActor() {
464456
465457 auto layout = getExistentialLayout ();
466458 return llvm::any_of (layout.getProtocols (),
467- [&actorProto](ProtocolType *protocol) {
468- return protocol-> getDecl () == actorProto ||
469- protocol->isDistributedActor ( );
459+ [&actorProto](ProtocolDecl *protocol) {
460+ return protocol == actorProto ||
461+ protocol->inheritsFrom (actorProto );
470462 });
471463 }
472464
@@ -991,15 +983,14 @@ bool ExistentialLayout::isErrorExistential() const {
991983 return (!hasExplicitAnyObject &&
992984 !explicitSuperclass &&
993985 protocols.size () == 1 &&
994- protocols[0 ]->getDecl ()-> isSpecificProtocol (KnownProtocolKind::Error));
986+ protocols[0 ]->isSpecificProtocol (KnownProtocolKind::Error));
995987}
996988
997989bool ExistentialLayout::isExistentialWithError (ASTContext &ctx) const {
998990 auto errorProto = ctx.getProtocol (KnownProtocolKind::Error);
999991 if (!errorProto) return false ;
1000992
1001- for (auto proto : getProtocols ()) {
1002- auto *protoDecl = proto->getDecl ();
993+ for (auto protoDecl : getProtocols ()) {
1003994 if (protoDecl == errorProto || protoDecl->inheritsFrom (errorProto))
1004995 return true ;
1005996 }
@@ -3971,7 +3962,7 @@ void ParameterizedProtocolType::Profile(llvm::FoldingSetNodeID &ID,
39713962
39723963void ParameterizedProtocolType::getRequirements (
39733964 Type baseType, SmallVectorImpl<Requirement> &reqs) const {
3974- auto *protoDecl = getBaseType ()-> getDecl ();
3965+ auto *protoDecl = getProtocol ();
39753966
39763967 auto assocTypes = protoDecl->getPrimaryAssociatedTypes ();
39773968 auto argTypes = getArgs ();
0 commit comments