@@ -425,6 +425,7 @@ class AbstractionPattern {
425
425
const void *RawTypePtr;
426
426
};
427
427
CanGenericSignature GenericSig;
428
+ SubstitutionMap GenericSubs;
428
429
429
430
Kind getKind () const { return Kind (TheKind); }
430
431
@@ -507,45 +508,53 @@ class AbstractionPattern {
507
508
}
508
509
}
509
510
510
- void initSwiftType (CanGenericSignature signature, CanType origType,
511
+ void initSwiftType (SubstitutionMap subs,
512
+ CanGenericSignature signature,
513
+ CanType origType,
511
514
Kind kind = Kind::Type) {
512
515
assert (signature || !origType->hasTypeParameter ());
513
516
TheKind = unsigned (kind);
514
517
OrigType = origType;
515
518
GenericSig = CanGenericSignature ();
519
+ GenericSubs = subs;
516
520
if (OrigType->hasTypeParameter ()) {
517
521
assert (OrigType == signature.getReducedType (origType));
518
522
GenericSig = signature;
519
523
}
524
+ assert (!subs || !OrigType->hasTypeParameter () ||
525
+ subs.getGenericSignature ()->isEqual (
526
+ getGenericSignatureForFunctionComponent ()));
520
527
}
521
528
522
- void initClangType (CanGenericSignature signature,
529
+ void initClangType (SubstitutionMap subs, CanGenericSignature signature,
523
530
CanType origType, const clang::Type *clangType,
524
531
Kind kind = Kind::ClangType) {
525
- initSwiftType (signature, origType, kind);
532
+ initSwiftType (subs, signature, origType, kind);
526
533
ClangType = clangType;
527
534
}
528
535
529
- void initObjCMethod (CanGenericSignature signature,
536
+ void initObjCMethod (SubstitutionMap subs, CanGenericSignature signature,
530
537
CanType origType, const clang::ObjCMethodDecl *method,
531
538
Kind kind, EncodedForeignInfo errorInfo) {
532
- initSwiftType (signature, origType, kind);
539
+ initSwiftType (subs, signature, origType, kind);
533
540
ObjCMethod = method;
534
541
OtherData = errorInfo.getOpaqueValue ();
535
542
}
536
543
537
- void initCFunctionAsMethod (CanGenericSignature signature,
544
+ void initCFunctionAsMethod (SubstitutionMap subs,
545
+ CanGenericSignature signature,
538
546
CanType origType, const clang::Type *clangType,
539
547
Kind kind,
540
548
ImportAsMemberStatus memberStatus) {
541
- initClangType (signature, origType, clangType, kind);
549
+ initClangType (subs, signature, origType, clangType, kind);
542
550
OtherData = memberStatus.getRawValue ();
543
551
}
544
552
545
- void initCXXMethod (CanGenericSignature signature, CanType origType,
553
+ void initCXXMethod (SubstitutionMap subs,
554
+ CanGenericSignature signature, CanType origType,
546
555
const clang::CXXMethodDecl *method, Kind kind,
547
556
ImportAsMemberStatus memberStatus) {
548
- initSwiftType (signature, origType, kind);
557
+ initSwiftType (subs, signature, origType, kind);
549
558
CXXMethod = method;
550
559
OtherData = memberStatus.getRawValue ();
551
560
}
@@ -559,13 +568,27 @@ class AbstractionPattern {
559
568
explicit AbstractionPattern (CanType origType)
560
569
: AbstractionPattern(nullptr , origType) {}
561
570
explicit AbstractionPattern (CanGenericSignature signature, CanType origType) {
562
- initSwiftType (signature, origType);
571
+ initSwiftType (SubstitutionMap (), signature, origType);
572
+ }
573
+ explicit AbstractionPattern (SubstitutionMap subs, CanType origType) {
574
+ initSwiftType (subs, subs.getGenericSignature ().getCanonicalSignature (),
575
+ origType);
576
+ }
577
+ explicit AbstractionPattern (SubstitutionMap subs, CanGenericSignature sig,
578
+ CanType origType) {
579
+ initSwiftType (subs, sig, origType);
563
580
}
564
581
explicit AbstractionPattern (CanType origType, const clang::Type *clangType)
565
582
: AbstractionPattern(nullptr , origType, clangType) {}
566
583
explicit AbstractionPattern (CanGenericSignature signature, CanType origType,
567
584
const clang::Type *clangType) {
568
- initClangType (signature, origType, clangType);
585
+ initClangType (SubstitutionMap (), signature, origType, clangType);
586
+ }
587
+ explicit AbstractionPattern (SubstitutionMap subs,
588
+ CanGenericSignature signature,
589
+ CanType origType,
590
+ const clang::Type *clangType) {
591
+ initClangType (subs, signature, origType, clangType);
569
592
}
570
593
571
594
static AbstractionPattern getOpaque () {
@@ -610,6 +633,10 @@ class AbstractionPattern {
610
633
llvm_unreachable (" Unhandled AbstractionPatternKind in switch" );
611
634
}
612
635
636
+ SubstitutionMap getGenericSubstitutions () const {
637
+ return GenericSubs;
638
+ }
639
+
613
640
CanGenericSignature getGenericSignature () const {
614
641
assert (hasGenericSignature ());
615
642
return CanGenericSignature (GenericSig);
@@ -635,12 +662,13 @@ class AbstractionPattern {
635
662
// / corresponding to the parameters of a completion handler
636
663
// / block of an API that was imported as async.
637
664
static AbstractionPattern
638
- getObjCCompletionHandlerArgumentsType (CanGenericSignature sig,
665
+ getObjCCompletionHandlerArgumentsType (SubstitutionMap subs,
666
+ CanGenericSignature sig,
639
667
CanType origTupleType,
640
668
const clang::Type *clangBlockType,
641
669
EncodedForeignInfo foreignInfo) {
642
670
AbstractionPattern pattern (Kind::ObjCCompletionHandlerArgumentsType);
643
- pattern.initClangType (sig, origTupleType, clangBlockType,
671
+ pattern.initClangType (subs, sig, origTupleType, clangBlockType,
644
672
Kind::ObjCCompletionHandlerArgumentsType);
645
673
pattern.OtherData = foreignInfo.getOpaqueValue ();
646
674
@@ -670,7 +698,8 @@ class AbstractionPattern {
670
698
ImportAsMemberStatus memberStatus) {
671
699
assert (isa<AnyFunctionType>(origType));
672
700
AbstractionPattern pattern;
673
- pattern.initCFunctionAsMethod (nullptr , origType, clangType,
701
+ pattern.initCFunctionAsMethod (SubstitutionMap (), nullptr ,
702
+ origType, clangType,
674
703
Kind::CFunctionAsMethodType,
675
704
memberStatus);
676
705
return pattern;
@@ -705,7 +734,7 @@ class AbstractionPattern {
705
734
ImportAsMemberStatus memberStatus) {
706
735
assert (isa<AnyFunctionType>(origType));
707
736
AbstractionPattern pattern;
708
- pattern.initCXXMethod (nullptr , origType, method,
737
+ pattern.initCXXMethod (SubstitutionMap (), nullptr , origType, method,
709
738
Kind::CXXMethodType, memberStatus);
710
739
return pattern;
711
740
}
@@ -722,7 +751,7 @@ class AbstractionPattern {
722
751
ImportAsMemberStatus memberStatus) {
723
752
assert (isa<AnyFunctionType>(origType));
724
753
AbstractionPattern pattern;
725
- pattern.initCXXMethod (nullptr , origType, method,
754
+ pattern.initCXXMethod (SubstitutionMap (), nullptr , origType, method,
726
755
Kind::CurriedCXXMethodType, memberStatus);
727
756
return pattern;
728
757
}
@@ -738,10 +767,11 @@ class AbstractionPattern {
738
767
739
768
// / Return an abstraction pattern for a value that is discarded after being
740
769
// / evaluated.
741
- static AbstractionPattern
742
- getDiscard (CanGenericSignature signature, CanType origType) {
770
+ static AbstractionPattern getDiscard (SubstitutionMap subs,
771
+ CanGenericSignature signature,
772
+ CanType origType) {
743
773
AbstractionPattern pattern;
744
- pattern.initSwiftType (signature, origType, Kind::Discard);
774
+ pattern.initSwiftType (subs, signature, origType, Kind::Discard);
745
775
return pattern;
746
776
}
747
777
@@ -761,7 +791,7 @@ class AbstractionPattern {
761
791
EncodedForeignInfo errorInfo) {
762
792
assert (isa<AnyFunctionType>(origType));
763
793
AbstractionPattern pattern;
764
- pattern.initObjCMethod (nullptr , origType, method,
794
+ pattern.initObjCMethod (SubstitutionMap (), nullptr , origType, method,
765
795
Kind::CurriedObjCMethodType, errorInfo);
766
796
return pattern;
767
797
}
@@ -772,7 +802,8 @@ class AbstractionPattern {
772
802
ImportAsMemberStatus memberStatus) {
773
803
assert (isa<AnyFunctionType>(origType));
774
804
AbstractionPattern pattern;
775
- pattern.initCFunctionAsMethod (nullptr , origType, clangType,
805
+ pattern.initCFunctionAsMethod (SubstitutionMap (), nullptr ,
806
+ origType, clangType,
776
807
Kind::CurriedCFunctionAsMethodType,
777
808
memberStatus);
778
809
return pattern;
@@ -781,13 +812,14 @@ class AbstractionPattern {
781
812
// / Return an abstraction pattern for the partially-applied curried
782
813
// / type of an Objective-C method.
783
814
static AbstractionPattern
784
- getPartialCurriedObjCMethod (CanGenericSignature signature,
815
+ getPartialCurriedObjCMethod (SubstitutionMap subs,
816
+ CanGenericSignature signature,
785
817
CanType origType,
786
818
const clang::ObjCMethodDecl *method,
787
819
EncodedForeignInfo errorInfo) {
788
820
assert (isa<AnyFunctionType>(origType));
789
821
AbstractionPattern pattern;
790
- pattern.initObjCMethod (signature, origType, method,
822
+ pattern.initObjCMethod (subs, signature, origType, method,
791
823
Kind::PartialCurriedObjCMethodType, errorInfo);
792
824
return pattern;
793
825
}
@@ -802,13 +834,14 @@ class AbstractionPattern {
802
834
// / and the partially-applied curried type is:
803
835
// / (CCTemperature) -> ()
804
836
static AbstractionPattern
805
- getPartialCurriedCFunctionAsMethod (CanGenericSignature signature,
837
+ getPartialCurriedCFunctionAsMethod (SubstitutionMap subs,
838
+ CanGenericSignature signature,
806
839
CanType origType,
807
840
const clang::Type *clangType,
808
841
ImportAsMemberStatus memberStatus) {
809
842
assert (isa<AnyFunctionType>(origType));
810
843
AbstractionPattern pattern;
811
- pattern.initCFunctionAsMethod (signature, origType, clangType,
844
+ pattern.initCFunctionAsMethod (subs, signature, origType, clangType,
812
845
Kind::PartialCurriedCFunctionAsMethodType,
813
846
memberStatus);
814
847
return pattern;
@@ -823,12 +856,13 @@ class AbstractionPattern {
823
856
// / then the partially-applied curried type is:
824
857
// / (Compartment, Temperature) -> ()
825
858
static AbstractionPattern
826
- getPartialCurriedCXXMethod (CanGenericSignature signature, CanType origType,
859
+ getPartialCurriedCXXMethod (SubstitutionMap subs,
860
+ CanGenericSignature signature, CanType origType,
827
861
const clang::CXXMethodDecl *method,
828
862
ImportAsMemberStatus memberStatus) {
829
863
assert (isa<AnyFunctionType>(origType));
830
864
AbstractionPattern pattern;
831
- pattern.initCXXMethod (signature, origType, method,
865
+ pattern.initCXXMethod (subs, signature, origType, method,
832
866
Kind::PartialCurriedCXXMethodType, memberStatus);
833
867
return pattern;
834
868
}
@@ -848,7 +882,8 @@ class AbstractionPattern {
848
882
EncodedForeignInfo errorInfo) {
849
883
assert (isa<AnyFunctionType>(origType));
850
884
AbstractionPattern pattern;
851
- pattern.initObjCMethod (nullptr , origType, method, Kind::ObjCMethodType,
885
+ pattern.initObjCMethod (SubstitutionMap (), nullptr ,
886
+ origType, method, Kind::ObjCMethodType,
852
887
errorInfo);
853
888
return pattern;
854
889
}
@@ -947,7 +982,17 @@ class AbstractionPattern {
947
982
return false ;
948
983
}
949
984
}
950
-
985
+
986
+ bool isPackExpansion () const {
987
+ switch (getKind ()) {
988
+ case Kind::Type:
989
+ case Kind::Discard:
990
+ return isa<PackExpansionType>(getType ());
991
+ default :
992
+ return false ;
993
+ }
994
+ }
995
+
951
996
// / Is this an interface type that is subject to a concrete
952
997
// / same-type constraint?
953
998
bool isConcreteType () const ;
@@ -1032,6 +1077,24 @@ class AbstractionPattern {
1032
1077
llvm_unreachable (" bad kind" );
1033
1078
}
1034
1079
1080
+ // / Add substitutions to this pattern.
1081
+ AbstractionPattern withSubstitutions (SubstitutionMap subs) const {
1082
+ AbstractionPattern result = *this ;
1083
+ if (subs) {
1084
+ #ifndef NDEBUG
1085
+ // If we have a generic signature, it should match the substitutions.
1086
+ // But there are situations in which it's okay that we don't store
1087
+ // a signature.
1088
+ auto sig = getGenericSignatureForFunctionComponent ();
1089
+ assert ((sig && sig->isEqual (subs.getGenericSignature ())) ||
1090
+ !OrigType ||
1091
+ !OrigType->hasTypeParameter ());
1092
+ #endif
1093
+ result.GenericSubs = subs;
1094
+ }
1095
+ return result;
1096
+ }
1097
+
1035
1098
// / Return whether this abstraction pattern contains foreign type
1036
1099
// / information.
1037
1100
// /
@@ -1359,8 +1422,14 @@ class AbstractionPattern {
1359
1422
// / the abstraction pattern for one of its parameter types.
1360
1423
AbstractionPattern getFunctionParamType (unsigned index) const ;
1361
1424
1362
- // / Given that the value being abstracted is a function type, return
1363
- // / the number of parameters.
1425
+ // / Given that the value being abstracted is a function type, and that
1426
+ // / this is not an opaque abstraction pattern, return the parameter flags
1427
+ // / for one of its parameters.
1428
+ ParameterTypeFlags getFunctionParamFlags (unsigned index) const ;
1429
+
1430
+ // / Given that the value being abstracted is a function type, and that
1431
+ // / this is not an opaque abstraction pattern, return the number of
1432
+ // / parameters in the pattern.
1364
1433
unsigned getNumFunctionParams () const ;
1365
1434
1366
1435
// / Given that the value being abstracted is optional, return the
@@ -1394,13 +1463,22 @@ class AbstractionPattern {
1394
1463
AbstractionPattern getObjCMethodAsyncCompletionHandlerType (
1395
1464
CanType swiftCompletionHandlerType) const ;
1396
1465
1466
+ // / Given that this is a pack expansion, invoke the given callback for
1467
+ // / each component of the substituted expansion of this pattern. The
1468
+ // / pattern will be for a pack expansion type over a contextual type if
1469
+ // / the substituted component is still a pack expansion. If there aren't
1470
+ // / substitutions available, this will just invoke the callback with the
1471
+ // / component.
1472
+ void forEachPackExpandedComponent (
1473
+ llvm::function_ref<void (AbstractionPattern pattern)> fn) const ;
1474
+
1397
1475
// / If this pattern refers to a foreign ObjC method that was imported as
1398
1476
// / async, return the bridged-back-to-ObjC completion handler type.
1399
1477
CanType getObjCMethodAsyncCompletionHandlerForeignType (
1400
1478
ForeignAsyncConvention convention,
1401
1479
Lowering::TypeConverter &TC
1402
1480
) const ;
1403
-
1481
+
1404
1482
// / How values are passed or returned according to this abstraction pattern.
1405
1483
enum CallingConventionKind {
1406
1484
// Value is passed or returned directly as a unit.
0 commit comments