Skip to content

Commit ecd0358

Browse files
committed
Handle vanishing tuples correctly in type lowering.
Test to follow.
1 parent 30817b1 commit ecd0358

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,8 +1270,7 @@ class DestructureResults {
12701270
void destructure(AbstractionPattern origType, CanType substType) {
12711271
// Recur into tuples.
12721272
if (origType.isTuple()) {
1273-
auto substTupleType = cast<TupleType>(substType);
1274-
origType.forEachTupleElement(substTupleType,
1273+
origType.forEachTupleElement(substType,
12751274
[&](TupleElementGenerator &elt) {
12761275
// If the original element type is not a pack expansion, just
12771276
// pull off the next substituted element type.
@@ -1646,7 +1645,7 @@ class DestructureInputs {
16461645

16471646
// Tuples get expanded unless they're inout.
16481647
if (origType.isTuple() && ownership != ValueOwnership::InOut) {
1649-
expandTuple(ownership, forSelf, origType, cast<TupleType>(substType),
1648+
expandTuple(ownership, forSelf, origType, substType,
16501649
isNonDifferentiable);
16511650
return;
16521651
}
@@ -1683,7 +1682,7 @@ class DestructureInputs {
16831682

16841683
/// Recursively expand a tuple type into separate parameters.
16851684
void expandTuple(ValueOwnership ownership, bool forSelf,
1686-
AbstractionPattern origType, CanTupleType substType,
1685+
AbstractionPattern origType, CanType substType,
16871686
bool isNonDifferentiable) {
16881687
assert(ownership != ValueOwnership::InOut);
16891688
assert(origType.isTuple());

lib/SIL/IR/TypeLowering.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ namespace {
178178
class TypeClassifierBase
179179
: public CanTypeVisitor<Impl, RetTy, AbstractionPattern, IsTypeExpansionSensitive_t>
180180
{
181+
using super =
182+
CanTypeVisitor<Impl, RetTy, AbstractionPattern, IsTypeExpansionSensitive_t>;
181183
Impl &asImpl() { return *static_cast<Impl*>(this); }
182184
protected:
183185
TypeConverter &TC;
@@ -285,6 +287,15 @@ namespace {
285287
RecursiveProperties::forOpaque());
286288
}
287289

290+
RetTy visit(CanType substType, AbstractionPattern origType,
291+
IsTypeExpansionSensitive_t isSensitive) {
292+
if (auto origEltType = origType.getVanishingTupleElementPatternType()) {
293+
return visit(substType, *origEltType, isSensitive);
294+
}
295+
296+
return super::visit(substType, origType, isSensitive);
297+
}
298+
288299
#define IMPL(TYPE, LOWERING) \
289300
RetTy visit##TYPE##Type(Can##TYPE##Type type, AbstractionPattern orig, \
290301
IsTypeExpansionSensitive_t isSensitive) { \
@@ -2900,7 +2911,10 @@ TypeConverter::computeLoweredRValueType(TypeExpansionContext forExpansion,
29002911
LoweredRValueTypeVisitor(TypeConverter &TC,
29012912
TypeExpansionContext forExpansion,
29022913
AbstractionPattern origType)
2903-
: TC(TC), forExpansion(forExpansion), origType(origType) {}
2914+
: TC(TC), forExpansion(forExpansion), origType(origType) {
2915+
if (auto origEltType = origType.getVanishingTupleElementPatternType())
2916+
origType = *origEltType;
2917+
}
29042918

29052919
// AST function types are turned into SIL function types:
29062920
// - the type is uncurried as desired

0 commit comments

Comments
 (0)