Skip to content

Commit da8ecdc

Browse files
committed
[NFC] Add a method to just ask if a tuple AP vanishes under substitution
1 parent fab7628 commit da8ecdc

File tree

6 files changed

+19
-8
lines changed

6 files changed

+19
-8
lines changed

include/swift/SIL/AbstractionPattern.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,10 @@ class AbstractionPattern {
13441344
/// returned element is the pattern type of the expansion.
13451345
Optional<AbstractionPattern> getVanishingTupleElementPatternType() const;
13461346

1347+
/// Does this tuple type vanish, i.e. is it flattened to a singleton
1348+
/// non-expansion element under substitution?
1349+
bool doesTupleVanish() const;
1350+
13471351
static AbstractionPattern
13481352
projectTupleElementType(const AbstractionPattern *base, size_t index) {
13491353
return base->getTupleElementType(index);

include/swift/SIL/AbstractionPatternGenerators.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ class TupleElementGenerator {
224224
return origEltIndex == numOrigElts;
225225
}
226226

227+
/// Does the entire original tuple vanish?
228+
bool doesOrigTupleVanish() const {
229+
return origTupleVanishes;
230+
}
231+
227232
/// Advance to the next orig element.
228233
void advance() {
229234
assert(!isFinished());

lib/SIL/IR/AbstractionPattern.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ bool AbstractionPattern::matchesTuple(CanType substType) const {
314314
return false;
315315
LLVM_FALLTHROUGH;
316316
case Kind::Tuple: {
317-
if (getVanishingTupleElementPatternType()) {
317+
if (doesTupleVanish()) {
318318
// TODO: recurse into elements.
319319
return true;
320320
}
@@ -480,6 +480,11 @@ bool AbstractionPattern::doesTupleContainPackExpansionType() const {
480480
llvm_unreachable("bad kind");
481481
}
482482

483+
bool AbstractionPattern::doesTupleVanish() const {
484+
assert(isTuple());
485+
return getVanishingTupleElementPatternType().hasValue();
486+
}
487+
483488
Optional<AbstractionPattern>
484489
AbstractionPattern::getVanishingTupleElementPatternType() const {
485490
if (!isTuple()) return None;
@@ -552,8 +557,7 @@ TupleElementGenerator::TupleElementGenerator(
552557
assert(origTupleType.isTuple());
553558
assert(origTupleType.matchesTuple(substType));
554559

555-
origTupleVanishes =
556-
origTupleType.getVanishingTupleElementPatternType().hasValue();
560+
origTupleVanishes = origTupleType.doesTupleVanish();
557561
origTupleTypeIsOpaque = origTupleType.isOpaqueTuple();
558562
numOrigElts = origTupleType.getNumTupleElements();
559563

lib/SILGen/ResultPlan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,7 @@ ResultPlanPtr ResultPlanBuilder::buildForTuple(Initialization *init,
13261326
// emit directly into the initialization. If the orig tuple vanishes,
13271327
// that counts as the initialization being splittable.
13281328
if (init) {
1329-
bool vanishes = origType.getVanishingTupleElementPatternType().hasValue();
1329+
bool vanishes = origType.doesTupleVanish();
13301330
if (vanishes || init->canSplitIntoTupleElements()) {
13311331
return ResultPlanPtr(
13321332
new TupleInitializationResultPlan(*this, init, origType, substType,

lib/SILGen/SILGenApply.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3416,8 +3416,7 @@ class ArgEmitter {
34163416
// If the original parameter type is a vanishing tuple, we want to emit
34173417
// this as if the argument source was wrapped in an extra level of
34183418
// tuple literal.
3419-
bool origTupleVanishes =
3420-
origParamType.getVanishingTupleElementPatternType().hasValue();
3419+
bool origTupleVanishes = origParamType.doesTupleVanish();
34213420

34223421
auto substType = arg.getSubstRValueType();
34233422

lib/SILGen/SILGenStmt.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,7 @@ prepareIndirectResultInit(SILGenFunction &SGF, SILLocation loc,
588588
TupleInitialization *tupleInit = nullptr;
589589
SmallVector<InitializationPtr, 1> singletonEltInit;
590590

591-
bool vanishes =
592-
origResultType.getVanishingTupleElementPatternType().hasValue();
591+
bool vanishes = origResultType.doesTupleVanish();
593592
if (!vanishes) {
594593
auto resultTupleType = cast<TupleType>(resultType);
595594
tupleInit = new TupleInitialization(resultTupleType);

0 commit comments

Comments
 (0)