Skip to content

Commit b7b654e

Browse files
committed
Handle vanishing tuples correctly in result planning.
1 parent 7d7607a commit b7b654e

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

lib/SILGen/ResultPlan.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -584,16 +584,15 @@ class PackTransformResultPlan final : public ResultPlan {
584584
/// A result plan which produces a larger RValue from a bunch of
585585
/// components.
586586
class TupleRValueResultPlan final : public ResultPlan {
587-
CanTupleType substType;
588-
587+
CanType substType;
589588
SmallVector<ResultPlanPtr, 4> origEltPlans;
590589

591590
public:
592591
TupleRValueResultPlan(ResultPlanBuilder &builder, AbstractionPattern origType,
593-
CanTupleType substType)
592+
CanType substType)
594593
: substType(substType) {
595594
// Create plans for all the elements.
596-
origEltPlans.reserve(substType->getNumElements());
595+
origEltPlans.reserve(origType.getNumTupleElements());
597596
origType.forEachTupleElement(substType,
598597
[&](TupleElementGenerator &origElt) {
599598
AbstractionPattern origEltType = origElt.getOrigType();
@@ -643,7 +642,7 @@ class TupleInitializationResultPlan final : public ResultPlan {
643642
TupleInitializationResultPlan(ResultPlanBuilder &builder,
644643
Initialization *tupleInit,
645644
AbstractionPattern origType,
646-
CanTupleType substType)
645+
CanType substType)
647646
: tupleInit(tupleInit) {
648647
// Get the sub-initializations.
649648
eltInits = tupleInit->splitIntoTupleElements(builder.SGF, builder.loc,
@@ -1115,7 +1114,7 @@ ResultPlanPtr ResultPlanBuilder::build(Initialization *init,
11151114
CanType substType) {
11161115
// Destructure original tuples.
11171116
if (origType.isTuple()) {
1118-
return buildForTuple(init, origType, cast<TupleType>(substType));
1117+
return buildForTuple(init, origType, substType);
11191118
}
11201119

11211120
assert(!origType.isPackExpansion() &&
@@ -1299,13 +1298,17 @@ ResultPlanBuilder::buildScalarIntoPack(SILValue packAddr,
12991298

13001299
ResultPlanPtr ResultPlanBuilder::buildForTuple(Initialization *init,
13011300
AbstractionPattern origType,
1302-
CanTupleType substType) {
1301+
CanType substType) {
13031302
// If we have an initialization, and we can split it, do so.
13041303
if (init && init->canSplitIntoTupleElements()) {
13051304
return ResultPlanPtr(
13061305
new TupleInitializationResultPlan(*this, init, origType, substType));
13071306
}
13081307

1308+
auto substTupleType = dyn_cast<TupleType>(substType);
1309+
bool substHasPackExpansion =
1310+
(substTupleType && substTupleType.containsPackExpansionType());
1311+
13091312
// Otherwise, if the tuple contains a pack expansion, we'll need to
13101313
// initialize a single buffer one way or another: either we're giving
13111314
// this to RValue (which wants a single value for tuples with pack
@@ -1319,9 +1322,9 @@ ResultPlanPtr ResultPlanBuilder::buildForTuple(Initialization *init,
13191322
// do that if we're not using lowered addresses because we prefer to
13201323
// build tuples with scalar operations.
13211324
auto &substTL = SGF.getTypeLowering(substType);
1322-
assert(substTL.isAddressOnly() || !substType.containsPackExpansionType());
1325+
assert(substTL.isAddressOnly() || !substHasPackExpansion);
13231326
if (substTL.isAddressOnly() &&
1324-
(substType.containsPackExpansionType() ||
1327+
(substHasPackExpansion ||
13251328
(init != nullptr && SGF.F.getConventions().useLoweredAddresses()))) {
13261329
// Create a temporary.
13271330
auto temporary = SGF.emitTemporary(loc, substTL);

lib/SILGen/ResultPlan.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ struct ResultPlanBuilder {
9797
SILResultInfo result);
9898
ResultPlanPtr buildForTuple(Initialization *emitInto,
9999
AbstractionPattern origType,
100-
CanTupleType substType);
100+
CanType substType);
101101
ResultPlanPtr buildForPackExpansion(Optional<MutableArrayRef<InitializationPtr>> inits,
102102
AbstractionPattern origExpansionType,
103103
CanTupleEltTypeArrayRef substTypes);

0 commit comments

Comments
 (0)