Skip to content

Commit 66ea1f1

Browse files
committed
[NFC] Fix an oversight in my previous NFC patches
This is starting to feel a little spaghetti-ish. This kind of existential stuff is hard to do in C++.
1 parent 127acfa commit 66ea1f1

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

lib/SILGen/SILGenPoly.cpp

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,22 @@ class TranslateIndirect : public Cleanup {
887887
}
888888
};
889889

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+
890906
/// A CRTP helper class for classes that supervise a translation between
891907
/// inner and outer signatures.
892908
template <class Impl>
@@ -897,11 +913,12 @@ class ExpanderBase {
897913
SILGenFunction &SGF;
898914
SILLocation Loc;
899915
ArrayRefGenerator<ArrayRef<ManagedValue>> OuterArgs;
916+
OuterPackArgGenerator<Impl> OuterPackArgs;
900917

901918
public:
902919
ExpanderBase(SILGenFunction &SGF, SILLocation loc,
903920
ArrayRef<ManagedValue> outerArgs)
904-
: SGF(SGF), Loc(loc), OuterArgs(outerArgs) {}
921+
: SGF(SGF), Loc(loc), OuterArgs(outerArgs), OuterPackArgs(asImpl()) {}
905922

906923
void expand(AbstractionPattern innerOrigType,
907924
CanType innerSubstType,
@@ -1913,6 +1930,10 @@ class TranslateArguments : public ExpanderBase<TranslateArguments> {
19131930
return OuterArgs.claimNext();
19141931
}
19151932

1933+
ManagedValue claimNextOuterPackArg() {
1934+
return claimNextOuterArg();
1935+
}
1936+
19161937
/// Claim the next lowered parameter in the inner. The conventions in
19171938
/// this class are set up such that the place that claims an inner type
19181939
/// is also responsible for adding the inner to inners. This allows
@@ -2660,9 +2681,9 @@ class ResultPlanner : public ExpanderBase<ResultPlanner> {
26602681

26612682
public:
26622683
ResultPlanner(SILGenFunction &SGF, SILLocation loc,
2663-
ArrayRef<ManagedValue> outerArgs,
2684+
ArrayRef<ManagedValue> outerIndirectArgs,
26642685
SmallVectorImpl<SILValue> &innerArgs)
2665-
: ExpanderBase(SGF, loc, outerArgs),
2686+
: ExpanderBase(SGF, loc, outerIndirectArgs),
26662687
InnerArgs(innerArgs), InnerPacks(*this) {}
26672688

26682689
void plan(AbstractionPattern innerOrigType, CanType innerSubstType,
@@ -2842,6 +2863,14 @@ class ResultPlanner : public ExpanderBase<ResultPlanner> {
28422863
return { result, resultAddr };
28432864
}
28442865

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+
28452874
/// Create a temporary address suitable for passing to the given inner
28462875
/// indirect result and add it as an inner indirect result.
28472876
SILValue addInnerIndirectResultTemporary(SILResultInfo innerResult) {
@@ -3125,7 +3154,7 @@ void ExpanderBase<Impl>::expandVanishingTuple(AbstractionPattern origType,
31253154
if (forInner) {
31263155
return asImpl().getInnerPackGenerator();
31273156
} else {
3128-
return OuterArgs;
3157+
return OuterPackArgs;
31293158
}
31303159
}();
31313160

@@ -3169,7 +3198,7 @@ void ExpanderBase<Impl>::expandParallelTuples(
31693198
auto innerPacks = asImpl().getInnerPackGenerator();
31703199
ExpandedTupleInputGenerator innerElt(ctx, innerPacks,
31713200
innerOrigType, innerSubstType);
3172-
ExpandedTupleInputGenerator outerElt(ctx, OuterArgs,
3201+
ExpandedTupleInputGenerator outerElt(ctx, OuterPackArgs,
31733202
outerOrigType, outerSubstType);
31743203

31753204
for (; !innerElt.isFinished(); innerElt.advance(), outerElt.advance()) {
@@ -4036,7 +4065,7 @@ void ExpanderBase<Impl>::expandParallelTuplesInnerIndirect(
40364065

40374066
auto &ctx = SGF.getASTContext();
40384067
ExpandedTupleInputGenerator
4039-
outerElt(ctx, OuterArgs, outerOrigType, outerSubstType);
4068+
outerElt(ctx, OuterPackArgs, outerOrigType, outerSubstType);
40404069
TupleElementAddressGenerator
40414070
innerElt(ctx, innerAddr, innerOrigType, innerSubstType);
40424071
for (; !innerElt.isFinished(); innerElt.advance(), outerElt.advance()) {
@@ -4118,7 +4147,7 @@ void ResultPlanner::planExpandedFromDirect(AbstractionPattern innerOrigType,
41184147

41194148
// Expand the outer tuple and recurse.
41204149
ExpandedTupleInputGenerator
4121-
outerElt(SGF.getASTContext(), OuterArgs, outerOrigType, outerSubstType);
4150+
outerElt(SGF.getASTContext(), OuterPackArgs, outerOrigType, outerSubstType);
41224151
innerOrigType.forEachExpandedTupleElement(innerSubstType,
41234152
[&](AbstractionPattern innerOrigEltType,
41244153
CanType innerSubstEltType,

0 commit comments

Comments
 (0)