@@ -2712,74 +2712,81 @@ TypeConverter::getTypeLowering(AbstractionPattern origType,
2712
2712
2713
2713
#ifndef NDEBUG
2714
2714
bool TypeConverter::visitAggregateLeaves (
2715
- Lowering::AbstractionPattern origType, Type substType,
2715
+ Lowering::AbstractionPattern origType, CanType substType,
2716
2716
TypeExpansionContext context,
2717
- std::function<bool (Type , Lowering::AbstractionPattern, ValueDecl *,
2717
+ std::function<bool (CanType , Lowering::AbstractionPattern, ValueDecl *,
2718
2718
Optional<unsigned >)>
2719
2719
isLeafAggregate,
2720
- std::function<bool(Type , Lowering::AbstractionPattern, ValueDecl *,
2720
+ std::function<bool(CanType , Lowering::AbstractionPattern, ValueDecl *,
2721
2721
Optional<unsigned >)>
2722
2722
visit) {
2723
- llvm::SmallSet<std::tuple<TypeBase * , ValueDecl *, unsigned >, 16 > visited;
2723
+ llvm::SmallSet<std::tuple<CanType , ValueDecl *, unsigned >, 16 > visited;
2724
2724
llvm::SmallVector<
2725
- std::tuple<TypeBase * , AbstractionPattern, ValueDecl *, unsigned >, 16 >
2725
+ std::tuple<CanType , AbstractionPattern, ValueDecl *, unsigned >, 16 >
2726
2726
worklist;
2727
2727
auto insertIntoWorklist = [&visited,
2728
- &worklist](Type substTy, AbstractionPattern origTy,
2728
+ &worklist](CanType substTy,
2729
+ AbstractionPattern origTy,
2729
2730
ValueDecl *field,
2730
2731
Optional<unsigned > maybeIndex) -> bool {
2731
2732
unsigned index = maybeIndex.value_or (UINT_MAX);
2732
- if (!visited.insert ({substTy. getPointer () , field, index }).second )
2733
+ if (!visited.insert ({substTy, field, index }).second )
2733
2734
return false ;
2734
- worklist.push_back ({substTy. getPointer () , origTy, field, index });
2735
+ worklist.push_back ({substTy, origTy, field, index });
2735
2736
return true ;
2736
2737
};
2737
2738
auto popFromWorklist = [&worklist]()
2738
- -> std::tuple<Type , AbstractionPattern, ValueDecl *, Optional<unsigned >> {
2739
- TypeBase * ty;
2739
+ -> std::tuple<CanType , AbstractionPattern, ValueDecl *, Optional<unsigned >> {
2740
+ CanType ty;
2740
2741
AbstractionPattern origTy = AbstractionPattern::getOpaque ();
2741
2742
ValueDecl *field;
2742
2743
unsigned index ;
2743
2744
std::tie (ty, origTy, field, index ) = worklist.pop_back_val ();
2744
2745
Optional<unsigned > maybeIndex;
2745
2746
if (index != UINT_MAX)
2746
2747
maybeIndex = {index };
2747
- return {ty-> getCanonicalType () , origTy, field, index };
2748
+ return {ty, origTy, field, index };
2748
2749
};
2749
- auto isAggregate = [](Type ty) {
2750
- return ty->is <SILPackType>() || ty->is <TupleType>() || ty->getEnumOrBoundGenericEnum () ||
2751
- ty->getStructOrBoundGenericStruct ();
2750
+ auto isAggregate = [](CanType ty) {
2751
+ return isa<SILPackType>(ty) ||
2752
+ isa<TupleType>(ty) ||
2753
+ isa<PackExpansionType>(ty) ||
2754
+ ty.getEnumOrBoundGenericEnum () ||
2755
+ ty.getStructOrBoundGenericStruct ();
2752
2756
};
2753
2757
insertIntoWorklist (substType, origType, nullptr , llvm::None);
2754
2758
while (!worklist.empty ()) {
2755
- Type ty;
2759
+ CanType ty;
2756
2760
AbstractionPattern origTy = AbstractionPattern::getOpaque ();
2757
2761
ValueDecl *field;
2758
2762
Optional<unsigned > index ;
2759
2763
std::tie (ty, origTy, field, index ) = popFromWorklist ();
2760
2764
if (isAggregate (ty) && !isLeafAggregate (ty, origTy, field, index )) {
2761
- if (auto packTy = ty-> getAs <SILPackType>()) {
2765
+ if (auto packTy = dyn_cast <SILPackType>(ty )) {
2762
2766
for (auto packIndex : indices (packTy->getElementTypes ())) {
2763
2767
auto origElementTy = origTy.getPackElementType (packIndex);
2764
- auto substElementTy =
2765
- packTy->getElementType (packIndex)->getCanonicalType ();
2768
+ auto substElementTy = packTy.getElementType (packIndex);
2766
2769
substElementTy =
2767
2770
computeLoweredRValueType (context, origElementTy, substElementTy);
2768
2771
insertIntoWorklist (substElementTy, origElementTy, nullptr ,
2769
2772
packIndex);
2770
2773
}
2771
- } else if (auto tupleTy = ty-> getAs <TupleType>()) {
2774
+ } else if (auto tupleTy = dyn_cast <TupleType>(ty )) {
2772
2775
unsigned tupleIndex = 0 ;
2773
2776
origTy.forEachExpandedTupleElement (
2774
- CanTupleType ( tupleTy) ,
2777
+ tupleTy,
2775
2778
[&](auto origElementTy, auto substElementTy, auto element) {
2776
2779
substElementTy =
2777
2780
substOpaqueTypesWithUnderlyingTypes (substElementTy, context);
2778
2781
insertIntoWorklist (substElementTy, origElementTy, nullptr ,
2779
2782
tupleIndex);
2780
2783
++tupleIndex;
2781
2784
});
2782
- } else if (auto *decl = ty->getStructOrBoundGenericStruct ()) {
2785
+ } else if (auto expansion = dyn_cast<PackExpansionType>(ty)) {
2786
+ insertIntoWorklist (expansion.getPatternType (),
2787
+ origTy.getPackExpansionPatternType (),
2788
+ field, index );
2789
+ } else if (auto *decl = ty.getStructOrBoundGenericStruct ()) {
2783
2790
for (auto *structField : decl->getStoredProperties ()) {
2784
2791
auto subMap = ty->getContextSubstitutionMap (&M, decl);
2785
2792
auto substFieldTy =
@@ -2794,7 +2801,7 @@ bool TypeConverter::visitAggregateLeaves(
2794
2801
insertIntoWorklist (substFieldTy, origFieldType, structField,
2795
2802
llvm::None);
2796
2803
}
2797
- } else if (auto *decl = ty-> getEnumOrBoundGenericEnum ()) {
2804
+ } else if (auto *decl = ty. getEnumOrBoundGenericEnum ()) {
2798
2805
auto subMap = ty->getContextSubstitutionMap (&M, decl);
2799
2806
for (auto *element : decl->getAllElements ()) {
2800
2807
if (!element->hasAssociatedValues ())
@@ -2827,16 +2834,17 @@ bool TypeConverter::visitAggregateLeaves(
2827
2834
}
2828
2835
2829
2836
void TypeConverter::verifyLowering (const TypeLowering &lowering,
2830
- AbstractionPattern origType, Type substType,
2837
+ AbstractionPattern origType,
2838
+ CanType substType,
2831
2839
TypeExpansionContext forExpansion) {
2832
2840
// Non-trivial lowerings should always be lexical unless all non-trivial
2833
2841
// fields are eager move.
2834
2842
if (!lowering.isTrivial () && !lowering.isLexical ()) {
2835
2843
if (lowering.getRecursiveProperties ().isInfinite ())
2836
2844
return ;
2837
- auto getLifetimeAnnotation = [](Type ty) -> LifetimeAnnotation {
2845
+ auto getLifetimeAnnotation = [](CanType ty) -> LifetimeAnnotation {
2838
2846
NominalTypeDecl *nominal;
2839
- if (!(nominal = ty-> getAnyNominal ()))
2847
+ if (!(nominal = ty. getAnyNominal ()))
2840
2848
return LifetimeAnnotation::None;
2841
2849
return nominal->getLifetimeAnnotation ();
2842
2850
};
@@ -2865,7 +2873,7 @@ void TypeConverter::verifyLowering(const TypeLowering &lowering,
2865
2873
2866
2874
// If the leaf is the whole type, verify that it is annotated
2867
2875
// @_eagerMove.
2868
- if (ty-> getCanonicalType () == substType-> getCanonicalType () )
2876
+ if (ty == substType)
2869
2877
return getLifetimeAnnotation (ty) == LifetimeAnnotation::EagerMove;
2870
2878
2871
2879
auto &tyLowering = getTypeLowering (origTy, ty, forExpansion);
0 commit comments