@@ -887,6 +887,22 @@ class TranslateIndirect : public Cleanup {
887
887
}
888
888
};
889
889
890
+ template <class Expander >
891
+ class OuterPackArgGenerator {
892
+ Expander &TheExpander;
893
+ public:
894
+ using reference = ManagedValue;
895
+
896
+ OuterPackArgGenerator (Expander &expander) : TheExpander(expander) {}
897
+
898
+ bool isFinished () const { llvm_unreachable (" don't call this" ); }
899
+ void finish () { llvm_unreachable (" don't call this" ); }
900
+ void advance () { llvm_unreachable (" don't call this" ); }
901
+ reference claimNext () const {
902
+ return TheExpander.claimNextOuterPackArg ();
903
+ }
904
+ };
905
+
890
906
// / A CRTP helper class for classes that supervise a translation between
891
907
// / inner and outer signatures.
892
908
template <class Impl >
@@ -897,11 +913,12 @@ class ExpanderBase {
897
913
SILGenFunction &SGF;
898
914
SILLocation Loc;
899
915
ArrayRefGenerator<ArrayRef<ManagedValue>> OuterArgs;
916
+ OuterPackArgGenerator<Impl> OuterPackArgs;
900
917
901
918
public:
902
919
ExpanderBase (SILGenFunction &SGF, SILLocation loc,
903
920
ArrayRef<ManagedValue> outerArgs)
904
- : SGF(SGF), Loc(loc), OuterArgs(outerArgs) {}
921
+ : SGF(SGF), Loc(loc), OuterArgs(outerArgs), OuterPackArgs(asImpl()) {}
905
922
906
923
void expand (AbstractionPattern innerOrigType,
907
924
CanType innerSubstType,
@@ -1913,6 +1930,10 @@ class TranslateArguments : public ExpanderBase<TranslateArguments> {
1913
1930
return OuterArgs.claimNext ();
1914
1931
}
1915
1932
1933
+ ManagedValue claimNextOuterPackArg () {
1934
+ return claimNextOuterArg ();
1935
+ }
1936
+
1916
1937
// / Claim the next lowered parameter in the inner. The conventions in
1917
1938
// / this class are set up such that the place that claims an inner type
1918
1939
// / is also responsible for adding the inner to inners. This allows
@@ -2660,9 +2681,9 @@ class ResultPlanner : public ExpanderBase<ResultPlanner> {
2660
2681
2661
2682
public:
2662
2683
ResultPlanner (SILGenFunction &SGF, SILLocation loc,
2663
- ArrayRef<ManagedValue> outerArgs ,
2684
+ ArrayRef<ManagedValue> outerIndirectArgs ,
2664
2685
SmallVectorImpl<SILValue> &innerArgs)
2665
- : ExpanderBase(SGF, loc, outerArgs ),
2686
+ : ExpanderBase(SGF, loc, outerIndirectArgs ),
2666
2687
InnerArgs (innerArgs), InnerPacks(*this ) {}
2667
2688
2668
2689
void plan (AbstractionPattern innerOrigType, CanType innerSubstType,
@@ -2842,6 +2863,14 @@ class ResultPlanner : public ExpanderBase<ResultPlanner> {
2842
2863
return { result, resultAddr };
2843
2864
}
2844
2865
2866
+ friend OuterPackArgGenerator<ResultPlanner>;
2867
+ ManagedValue claimNextOuterPackArg () {
2868
+ SILResultInfo result = claimNext (AllOuterResults);
2869
+ assert (result.isPack ()); (void ) result;
2870
+
2871
+ return OuterArgs.claimNext ();
2872
+ }
2873
+
2845
2874
// / Create a temporary address suitable for passing to the given inner
2846
2875
// / indirect result and add it as an inner indirect result.
2847
2876
SILValue addInnerIndirectResultTemporary (SILResultInfo innerResult) {
@@ -3125,7 +3154,7 @@ void ExpanderBase<Impl>::expandVanishingTuple(AbstractionPattern origType,
3125
3154
if (forInner) {
3126
3155
return asImpl ().getInnerPackGenerator ();
3127
3156
} else {
3128
- return OuterArgs ;
3157
+ return OuterPackArgs ;
3129
3158
}
3130
3159
}();
3131
3160
@@ -3169,7 +3198,7 @@ void ExpanderBase<Impl>::expandParallelTuples(
3169
3198
auto innerPacks = asImpl ().getInnerPackGenerator ();
3170
3199
ExpandedTupleInputGenerator innerElt (ctx, innerPacks,
3171
3200
innerOrigType, innerSubstType);
3172
- ExpandedTupleInputGenerator outerElt (ctx, OuterArgs ,
3201
+ ExpandedTupleInputGenerator outerElt (ctx, OuterPackArgs ,
3173
3202
outerOrigType, outerSubstType);
3174
3203
3175
3204
for (; !innerElt.isFinished (); innerElt.advance (), outerElt.advance ()) {
@@ -4036,7 +4065,7 @@ void ExpanderBase<Impl>::expandParallelTuplesInnerIndirect(
4036
4065
4037
4066
auto &ctx = SGF.getASTContext ();
4038
4067
ExpandedTupleInputGenerator
4039
- outerElt (ctx, OuterArgs , outerOrigType, outerSubstType);
4068
+ outerElt (ctx, OuterPackArgs , outerOrigType, outerSubstType);
4040
4069
TupleElementAddressGenerator
4041
4070
innerElt (ctx, innerAddr, innerOrigType, innerSubstType);
4042
4071
for (; !innerElt.isFinished (); innerElt.advance (), outerElt.advance ()) {
@@ -4118,7 +4147,7 @@ void ResultPlanner::planExpandedFromDirect(AbstractionPattern innerOrigType,
4118
4147
4119
4148
// Expand the outer tuple and recurse.
4120
4149
ExpandedTupleInputGenerator
4121
- outerElt (SGF.getASTContext (), OuterArgs , outerOrigType, outerSubstType);
4150
+ outerElt (SGF.getASTContext (), OuterPackArgs , outerOrigType, outerSubstType);
4122
4151
innerOrigType.forEachExpandedTupleElement (innerSubstType,
4123
4152
[&](AbstractionPattern innerOrigEltType,
4124
4153
CanType innerSubstEltType,
0 commit comments