@@ -401,6 +401,159 @@ AbstractionPattern::getTupleElementType(unsigned index) const {
401401 llvm_unreachable (" bad kind" );
402402}
403403
404+ static CanType getCanPackElementType (CanType type, unsigned index) {
405+ return cast<PackType>(type).getElementType (index);
406+ }
407+
408+ AbstractionPattern
409+ AbstractionPattern::getPackElementType (unsigned index) const {
410+ switch (getKind ()) {
411+ case Kind::Invalid:
412+ llvm_unreachable (" querying invalid abstraction pattern!" );
413+ case Kind::PartialCurriedObjCMethodType:
414+ case Kind::CurriedObjCMethodType:
415+ case Kind::PartialCurriedCFunctionAsMethodType:
416+ case Kind::CurriedCFunctionAsMethodType:
417+ case Kind::CFunctionAsMethodType:
418+ case Kind::ObjCMethodType:
419+ case Kind::CXXMethodType:
420+ case Kind::CurriedCXXMethodType:
421+ case Kind::PartialCurriedCXXMethodType:
422+ case Kind::OpaqueFunction:
423+ case Kind::OpaqueDerivativeFunction:
424+ case Kind::ClangType:
425+ case Kind::Tuple:
426+ case Kind::ObjCCompletionHandlerArgumentsType:
427+ llvm_unreachable (" not a pack type" );
428+ case Kind::Opaque:
429+ return *this ;
430+ case Kind::Discard:
431+ llvm_unreachable (" operation not needed on discarded abstractions yet" );
432+ case Kind::Type:
433+ if (isTypeParameterOrOpaqueArchetype ())
434+ return AbstractionPattern::getOpaque ();
435+ return AbstractionPattern (getGenericSignature (),
436+ getCanPackElementType (getType (), index));
437+ }
438+ llvm_unreachable (" bad kind" );
439+ }
440+
441+ bool AbstractionPattern::matchesPack (CanPackType substType) {
442+ switch (getKind ()) {
443+ case Kind::Invalid:
444+ llvm_unreachable (" querying invalid abstraction pattern!" );
445+ case Kind::PartialCurriedObjCMethodType:
446+ case Kind::CurriedObjCMethodType:
447+ case Kind::PartialCurriedCFunctionAsMethodType:
448+ case Kind::CurriedCFunctionAsMethodType:
449+ case Kind::CFunctionAsMethodType:
450+ case Kind::ObjCMethodType:
451+ case Kind::CXXMethodType:
452+ case Kind::CurriedCXXMethodType:
453+ case Kind::PartialCurriedCXXMethodType:
454+ case Kind::OpaqueFunction:
455+ case Kind::OpaqueDerivativeFunction:
456+ case Kind::Tuple:
457+ case Kind::ObjCCompletionHandlerArgumentsType:
458+ case Kind::ClangType:
459+ return false ;
460+ case Kind::Opaque:
461+ return true ;
462+ case Kind::Type:
463+ case Kind::Discard: {
464+ if (isTypeParameterOrOpaqueArchetype ())
465+ return true ;
466+ auto type = getType ();
467+ if (auto pack = dyn_cast<PackType>(type))
468+ return (pack->getNumElements () == substType->getNumElements ());
469+ return false ;
470+ }
471+ }
472+ llvm_unreachable (" bad kind" );
473+ }
474+
475+ static CanType getPackExpansionPatternType (CanType type) {
476+ return cast<PackExpansionType>(type).getPatternType ();
477+ }
478+
479+ AbstractionPattern AbstractionPattern::getPackExpansionPatternType () const {
480+ switch (getKind ()) {
481+ case Kind::Invalid:
482+ llvm_unreachable (" querying invalid abstraction pattern!" );
483+ case Kind::ObjCMethodType:
484+ case Kind::CurriedObjCMethodType:
485+ case Kind::PartialCurriedObjCMethodType:
486+ case Kind::CFunctionAsMethodType:
487+ case Kind::CurriedCFunctionAsMethodType:
488+ case Kind::PartialCurriedCFunctionAsMethodType:
489+ case Kind::CXXMethodType:
490+ case Kind::CurriedCXXMethodType:
491+ case Kind::PartialCurriedCXXMethodType:
492+ case Kind::Tuple:
493+ case Kind::OpaqueFunction:
494+ case Kind::OpaqueDerivativeFunction:
495+ case Kind::ObjCCompletionHandlerArgumentsType:
496+ case Kind::ClangType:
497+ llvm_unreachable (" pattern for function or tuple cannot be for "
498+ " pack expansion type" );
499+
500+ case Kind::Opaque:
501+ return *this ;
502+
503+ case Kind::Type:
504+ if (isTypeParameterOrOpaqueArchetype ())
505+ return AbstractionPattern::getOpaque ();
506+ return AbstractionPattern (getGenericSignature (),
507+ ::getPackExpansionPatternType (getType()));
508+
509+ case Kind::Discard:
510+ return AbstractionPattern::getDiscard (
511+ getGenericSignature (), ::getPackExpansionPatternType (getType ()));
512+ }
513+ llvm_unreachable (" bad kind" );
514+ }
515+
516+ static CanType getPackExpansionCountType (CanType type) {
517+ return cast<PackExpansionType>(type).getCountType ();
518+ }
519+
520+ AbstractionPattern AbstractionPattern::getPackExpansionCountType () const {
521+ switch (getKind ()) {
522+ case Kind::Invalid:
523+ llvm_unreachable (" querying invalid abstraction pattern!" );
524+ case Kind::ObjCMethodType:
525+ case Kind::CurriedObjCMethodType:
526+ case Kind::PartialCurriedObjCMethodType:
527+ case Kind::CFunctionAsMethodType:
528+ case Kind::CurriedCFunctionAsMethodType:
529+ case Kind::PartialCurriedCFunctionAsMethodType:
530+ case Kind::CXXMethodType:
531+ case Kind::CurriedCXXMethodType:
532+ case Kind::PartialCurriedCXXMethodType:
533+ case Kind::Tuple:
534+ case Kind::OpaqueFunction:
535+ case Kind::OpaqueDerivativeFunction:
536+ case Kind::ObjCCompletionHandlerArgumentsType:
537+ case Kind::ClangType:
538+ llvm_unreachable (" pattern for function or tuple cannot be for "
539+ " pack expansion type" );
540+
541+ case Kind::Opaque:
542+ return *this ;
543+
544+ case Kind::Type:
545+ if (isTypeParameterOrOpaqueArchetype ())
546+ return AbstractionPattern::getOpaque ();
547+ return AbstractionPattern (getGenericSignature (),
548+ ::getPackExpansionCountType (getType()));
549+
550+ case Kind::Discard:
551+ return AbstractionPattern::getDiscard (
552+ getGenericSignature (), ::getPackExpansionCountType (getType ()));
553+ }
554+ llvm_unreachable (" bad kind" );
555+ }
556+
404557AbstractionPattern AbstractionPattern::removingMoveOnlyWrapper () const {
405558 switch (getKind ()) {
406559 case Kind::Invalid:
0 commit comments