@@ -935,13 +935,21 @@ class ExpanderBase {
935
935
AbstractionPattern outerOrigType,
936
936
CanType outerSubstType);
937
937
938
- void expandVanishingTuple (AbstractionPattern origType, CanType substType,
939
- bool forInner,
940
- llvm::function_ref<void (AbstractionPattern origType,
941
- CanType substType)> handleSingle,
942
- llvm::function_ref<void(AbstractionPattern origType,
943
- CanType substType,
944
- ManagedValue eltResult)> handlePackElement);
938
+ void expandInnerVanishingTuple (AbstractionPattern innerOrigType,
939
+ CanType innerSubstType,
940
+ llvm::function_ref<void (AbstractionPattern innerOrigEltType,
941
+ CanType innerSubstEltType)> handleSingle,
942
+ llvm::function_ref<void(AbstractionPattern innerOrigEltType,
943
+ CanType innerSubstEltType,
944
+ ManagedValue innerEltAddr)> handlePackElement);
945
+
946
+ void expandOuterVanishingTuple (AbstractionPattern outerOrigType,
947
+ CanType outerSubstType,
948
+ llvm::function_ref<void (AbstractionPattern outerOrigEltType,
949
+ CanType outerSubstEltType)> handleSingle,
950
+ llvm::function_ref<void(AbstractionPattern outerOrigEltType,
951
+ CanType outerSubstEltType,
952
+ ManagedValue outerEltAddr)> handlePackElement);
945
953
946
954
void expandParallelTuples (AbstractionPattern innerOrigType,
947
955
CanType innerSubstType,
@@ -3102,8 +3110,7 @@ void ExpanderBase<Impl>::expand(AbstractionPattern innerOrigType,
3102
3110
// through that and recurse.
3103
3111
bool outerIsExpanded = outerOrigType.isTuple ();
3104
3112
if (outerIsExpanded && outerOrigType.doesTupleVanish ()) {
3105
- asImpl ().expandVanishingTuple (outerOrigType, outerSubstType,
3106
- /* inner*/ false ,
3113
+ asImpl ().expandOuterVanishingTuple (outerOrigType, outerSubstType,
3107
3114
[&](AbstractionPattern outerOrigEltType, CanType outerSubstEltType) {
3108
3115
asImpl ().expand (innerOrigType, innerSubstType,
3109
3116
outerOrigEltType, outerSubstEltType);
@@ -3120,7 +3127,7 @@ void ExpanderBase<Impl>::expand(AbstractionPattern innerOrigType,
3120
3127
// through that and recurse.
3121
3128
bool innerIsExpanded = innerOrigType.isTuple ();
3122
3129
if (innerIsExpanded && innerOrigType.doesTupleVanish ()) {
3123
- expandVanishingTuple (innerOrigType, innerSubstType, /* inner */ true ,
3130
+ expandInnerVanishingTuple (innerOrigType, innerSubstType,
3124
3131
[&](AbstractionPattern innerOrigEltType, CanType innerSubstEltType) {
3125
3132
asImpl ().expand (innerOrigEltType, innerSubstEltType,
3126
3133
outerOrigType, outerSubstType);
@@ -3149,43 +3156,69 @@ void ExpanderBase<Impl>::expand(AbstractionPattern innerOrigType,
3149
3156
}
3150
3157
3151
3158
template <class Impl >
3152
- void ExpanderBase<Impl>::expandVanishingTuple(AbstractionPattern origType,
3153
- CanType substType,
3154
- bool forInner,
3155
- llvm::function_ref<void (AbstractionPattern origType,
3156
- CanType substType)> handleSingle,
3157
- llvm::function_ref<void (AbstractionPattern origType,
3158
- CanType substType,
3159
- ManagedValue eltValue)> handlePackElement) {
3159
+ void ExpanderBase<Impl>::expandOuterVanishingTuple(
3160
+ AbstractionPattern outerOrigType,
3161
+ CanType outerSubstType,
3162
+ llvm::function_ref<void (AbstractionPattern outerOrigEltType,
3163
+ CanType outerSubstEltType)> handleSingle,
3164
+ llvm::function_ref<void (AbstractionPattern outerOrigEltType,
3165
+ CanType outerOrigSubstType,
3166
+ ManagedValue outerEltAddr)> handlePackElement) {
3167
+ assert (outerOrigType.isTuple ());
3168
+ assert (outerOrigType.doesTupleVanish ());
3160
3169
3161
3170
bool foundSurvivor = false ;
3162
3171
3163
- auto packInputs = [&]() -> PackGeneratorRef {
3164
- if (forInner) {
3165
- return asImpl ().getInnerPackGenerator ();
3172
+ ExpandedTupleInputGenerator elt (SGF.getASTContext (), OuterPackArgs,
3173
+ outerOrigType, outerSubstType);
3174
+ for (; !elt.isFinished (); elt.advance ()) {
3175
+ assert (!foundSurvivor);
3176
+ foundSurvivor = true ;
3177
+
3178
+ if (!elt.isOrigPackExpansion ()) {
3179
+ handleSingle (elt.getOrigType (), outerSubstType);
3166
3180
} else {
3167
- return OuterPackArgs;
3181
+ assert (elt.getPackComponentIndex () == 0 );
3182
+ assert (!isa<PackExpansionType>(elt.getSubstType ()));
3183
+ ManagedValue eltAddr = elt.projectPackComponent (SGF, Loc);
3184
+ handlePackElement (elt.getOrigType ().getPackExpansionPatternType (),
3185
+ outerSubstType, eltAddr);
3168
3186
}
3169
- }();
3187
+ }
3188
+ elt.finish ();
3189
+
3190
+ assert (foundSurvivor && " vanishing tuple had no surviving element?" );
3191
+ }
3192
+
3193
+ template <class Impl >
3194
+ void ExpanderBase<Impl>::expandInnerVanishingTuple(
3195
+ AbstractionPattern innerOrigType,
3196
+ CanType innerSubstType,
3197
+ llvm::function_ref<void (AbstractionPattern innerOrigEltType,
3198
+ CanType innerSubstEltType)> handleSingle,
3199
+ llvm::function_ref<void (AbstractionPattern innerOrigEltType,
3200
+ CanType innerOrigSubstType,
3201
+ ManagedValue innerEltAddr)> handlePackElement) {
3202
+ assert (innerOrigType.isTuple ());
3203
+ assert (innerOrigType.doesTupleVanish ());
3204
+
3205
+ bool foundSurvivor = false ;
3170
3206
3171
- ExpandedTupleInputGenerator elt (SGF.getASTContext (), packInputs,
3172
- origType, substType);
3207
+ ExpandedTupleInputGenerator elt (SGF.getASTContext (),
3208
+ asImpl ().getInnerPackGenerator (),
3209
+ innerOrigType, innerSubstType);
3173
3210
for (; !elt.isFinished (); elt.advance ()) {
3174
3211
assert (!foundSurvivor);
3175
3212
foundSurvivor = true ;
3176
3213
3177
3214
if (!elt.isOrigPackExpansion ()) {
3178
- handleSingle (elt.getOrigType (), elt. getSubstType () );
3215
+ handleSingle (elt.getOrigType (), innerSubstType );
3179
3216
} else {
3180
3217
assert (elt.getPackComponentIndex () == 0 );
3181
3218
assert (!isa<PackExpansionType>(elt.getSubstType ()));
3182
- ManagedValue eltAddr = [&] {
3183
- if (forInner)
3184
- return elt.createPackComponentTemporary (SGF, Loc);
3185
- return elt.projectPackComponent (SGF, Loc);
3186
- }();
3219
+ ManagedValue eltAddr = elt.createPackComponentTemporary (SGF, Loc);
3187
3220
handlePackElement (elt.getOrigType ().getPackExpansionPatternType (),
3188
- substType , eltAddr);
3221
+ innerSubstType , eltAddr);
3189
3222
}
3190
3223
}
3191
3224
elt.finish ();
@@ -3604,7 +3637,7 @@ void ExpanderBase<Impl>::expandOuterIndirect(
3604
3637
3605
3638
// Otherwise, we have a vanishing tuple. Expand it, find the surviving
3606
3639
// element, and recurse.
3607
- asImpl ().expandVanishingTuple (innerOrigType, innerSubstType, /* inner */ true ,
3640
+ asImpl ().expandInnerVanishingTuple (innerOrigType, innerSubstType,
3608
3641
[&](AbstractionPattern innerOrigEltType, CanType innerSubstEltType) {
3609
3642
asImpl ().expandOuterIndirect (innerOrigEltType, innerSubstEltType,
3610
3643
outerOrigType, outerSubstType,
@@ -3783,7 +3816,7 @@ void ResultPlanner::planIntoDirect(AbstractionPattern innerOrigType,
3783
3816
3784
3817
// Otherwise, the inner tuple vanishes. Expand it, find the surviving
3785
3818
// element, and recurse.
3786
- expandVanishingTuple (innerOrigType, innerSubstType, /* inner */ true ,
3819
+ expandInnerVanishingTuple (innerOrigType, innerSubstType,
3787
3820
[&](AbstractionPattern innerOrigEltType, CanType innerSubstEltType) {
3788
3821
planIntoDirect (innerOrigEltType, innerSubstEltType,
3789
3822
outerOrigType, outerSubstType,
@@ -4025,7 +4058,7 @@ void ExpanderBase<Impl>::expandInnerIndirect(AbstractionPattern innerOrigType,
4025
4058
4026
4059
// Otherwise, the outer pattern is a vanishing tuple. Expand it,
4027
4060
// find the surviving element, and recurse.
4028
- asImpl ().expandVanishingTuple (outerOrigType, outerSubstType, /* inner */ false ,
4061
+ asImpl ().expandOuterVanishingTuple (outerOrigType, outerSubstType,
4029
4062
[&](AbstractionPattern outerOrigEltType, CanType outerSubstEltType) {
4030
4063
asImpl ().expandInnerIndirect (innerOrigType, innerSubstType,
4031
4064
outerOrigEltType, outerSubstEltType,
@@ -4208,7 +4241,7 @@ void ResultPlanner::planFromDirect(AbstractionPattern innerOrigType,
4208
4241
4209
4242
// Otherwise, expand the outer tuple and recurse for the surviving
4210
4243
// element.
4211
- expandVanishingTuple (outerOrigType, outerSubstType, /* inner */ false ,
4244
+ expandOuterVanishingTuple (outerOrigType, outerSubstType,
4212
4245
[&](AbstractionPattern outerOrigEltType, CanType outerSubstEltType) {
4213
4246
planFromDirect (innerOrigType, innerSubstType,
4214
4247
outerOrigEltType, outerSubstEltType,
0 commit comments