Skip to content

Commit e14f2bc

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

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
@@ -1354,6 +1354,10 @@ class AbstractionPattern {
13541354
llvm::Optional<AbstractionPattern>
13551355
getVanishingTupleElementPatternType() const;
13561356

1357+
/// Does this tuple type vanish, i.e. is it flattened to a singleton
1358+
/// non-expansion element under substitution?
1359+
bool doesTupleVanish() const;
1360+
13571361
static AbstractionPattern
13581362
projectTupleElementType(const AbstractionPattern *base, size_t index) {
13591363
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
@@ -312,7 +312,7 @@ bool AbstractionPattern::matchesTuple(CanType substType) const {
312312
return false;
313313
LLVM_FALLTHROUGH;
314314
case Kind::Tuple: {
315-
if (getVanishingTupleElementPatternType()) {
315+
if (doesTupleVanish()) {
316316
// TODO: recurse into elements.
317317
return true;
318318
}
@@ -478,6 +478,11 @@ bool AbstractionPattern::doesTupleContainPackExpansionType() const {
478478
llvm_unreachable("bad kind");
479479
}
480480

481+
bool AbstractionPattern::doesTupleVanish() const {
482+
assert(isTuple());
483+
return getVanishingTupleElementPatternType().has_value();
484+
}
485+
481486
llvm::Optional<AbstractionPattern>
482487
AbstractionPattern::getVanishingTupleElementPatternType() const {
483488
if (!isTuple())
@@ -553,8 +558,7 @@ TupleElementGenerator::TupleElementGenerator(
553558
assert(origTupleType.isTuple());
554559
assert(origTupleType.matchesTuple(substType));
555560

556-
origTupleVanishes =
557-
origTupleType.getVanishingTupleElementPatternType().has_value();
561+
origTupleVanishes = origTupleType.doesTupleVanish();
558562
origTupleTypeIsOpaque = origTupleType.isOpaqueTuple();
559563
numOrigElts = origTupleType.getNumTupleElements();
560564

lib/SILGen/ResultPlan.cpp

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

lib/SILGen/SILGenApply.cpp

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

34233422
auto substType = arg.getSubstRValueType();
34243423

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().has_value();
591+
bool vanishes = origResultType.doesTupleVanish();
593592
if (!vanishes) {
594593
auto resultTupleType = cast<TupleType>(resultType);
595594
tupleInit = new TupleInitialization(resultTupleType);

0 commit comments

Comments
 (0)