Skip to content

Commit 611776e

Browse files
committed
[NFC] Extract the parts of TupleElementAddressGenerator that just deal
with walking the tuple so that they can be used without an address.
1 parent 444e770 commit 611776e

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

lib/SILGen/SILGenPoly.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,18 +2124,18 @@ TupleElementAddressGenerator::projectElementAddress(SILGenFunction &SGF,
21242124
SGF.B.createTupleElementAddr(loc, tupleAddr, eltIndex, eltTy));
21252125
} else if (isSubstPackExpansion()) {
21262126
eltValue = cloner.cloneForTuplePackExpansionComponent(tupleAddr,
2127-
inducedPackType,
2128-
eltIndex);
2127+
getInducedPackType(),
2128+
eltIndex);
21292129
} else {
21302130
auto packIndex =
2131-
SGF.B.createScalarPackIndex(loc, eltIndex, inducedPackType);
2131+
SGF.B.createScalarPackIndex(loc, eltIndex, getInducedPackType());
21322132
auto eltAddr =
21332133
SGF.B.createTuplePackElementAddr(loc, packIndex, tupleAddr, eltTy);
21342134
eltValue = cloner.clone(eltAddr);
21352135
}
21362136

21372137
tupleValue = cloner.cloneForRemainingTupleComponents(tupleAddr,
2138-
inducedPackType,
2138+
getInducedPackTypeIfPresent(),
21392139
eltIndex + 1);
21402140
this->tupleAddr = tupleValue;
21412141

lib/SILGen/TupleGenerators.h

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,9 @@ class ExpandedTupleInputGenerator {
279279
ManagedValue elt);
280280
};
281281

282-
/// A generator for visiting the addresses of the elements of
283-
/// a tuple. Unlike the other tuple generators, this does not
284-
/// require the original abstraction pattern to be a tuple pattern:
285-
/// like forEachExpandedTupleElement, it permits an opaque
286-
/// abstraction pattern.
287-
class TupleElementAddressGenerator {
282+
/// A generator for visiting the substituted elements of a tuple
283+
/// (unlike TupleElementGenerator, which visits the orig elements).
284+
class TupleSubstElementGenerator {
288285
struct OpaquePatternStorage {
289286
AbstractionPattern origType;
290287
CanTupleType substType;
@@ -297,9 +294,6 @@ class TupleElementAddressGenerator {
297294
}
298295
ExternalUnion<bool, Members, getIndexForKind> origElt;
299296

300-
/// The address of the tuple value.
301-
ManagedValue tupleAddr;
302-
303297
/// If the substituted tuple type contains pack expansions, this is
304298
/// the induced pack type for the element sequence.
305299
CanPackType inducedPackType;
@@ -341,12 +335,9 @@ class TupleElementAddressGenerator {
341335
}
342336

343337
public:
344-
TupleElementAddressGenerator(const ASTContext &ctx,
345-
ManagedValue tupleAddr,
346-
AbstractionPattern origType,
347-
CanTupleType substType)
348-
: tupleAddr(tupleAddr) {
349-
338+
TupleSubstElementGenerator(const ASTContext &ctx,
339+
AbstractionPattern origType,
340+
CanTupleType substType) {
350341
if (substType->containsPackExpansionType()) {
351342
inducedPackType = CanPackType::get(ctx, substType.getElementTypes());
352343
}
@@ -420,6 +411,13 @@ class TupleElementAddressGenerator {
420411
return inducedPackType;
421412
}
422413

414+
/// Return the induced pack type if the substituted tuple contains
415+
/// pack expansions or null if it does not. Suitable for use with
416+
/// e.g. enterDestroyRemainingTupleComponentsCleanup.
417+
CanPackType getInducedPackTypeIfPresent() const {
418+
return inducedPackType;
419+
}
420+
423421
/// Given that we just processed an input, advance to the next,
424422
/// if there is on.
425423
///
@@ -444,6 +442,26 @@ class TupleElementAddressGenerator {
444442
gen.finish();
445443
}
446444
}
445+
};
446+
447+
/// A generator for visiting the addresses of the elements of
448+
/// a tuple. Unlike the other tuple generators, this does not
449+
/// require the original abstraction pattern to be a tuple pattern:
450+
/// like forEachExpandedTupleElement, it permits an opaque
451+
/// abstraction pattern.
452+
class TupleElementAddressGenerator : public TupleSubstElementGenerator {
453+
/// The address of the tuple value.
454+
ManagedValue tupleAddr;
455+
456+
public:
457+
TupleElementAddressGenerator(const ASTContext &ctx,
458+
ManagedValue tupleAddr,
459+
AbstractionPattern origType,
460+
CanTupleType substType)
461+
: TupleSubstElementGenerator(ctx, origType, substType),
462+
tupleAddr(tupleAddr) {
463+
assert(tupleAddr.getType().isAddress());
464+
}
447465

448466
/// Project out the current tuple element. Call this exactly once
449467
/// per element.

0 commit comments

Comments
 (0)