Skip to content

Commit d524c7d

Browse files
committed
Use correct parallel destructuring when lowering tuple types.
1 parent 9ab4dc4 commit d524c7d

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

lib/SIL/IR/TypeLowering.cpp

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2534,24 +2534,21 @@ static CanTupleType computeLoweredTupleType(TypeConverter &tc,
25342534
TypeExpansionContext context,
25352535
AbstractionPattern origType,
25362536
CanTupleType substType) {
2537-
assert(origType.matchesTuple(substType));
2537+
if (substType->getNumElements() == 0) return substType;
25382538

2539-
// Does the lowered tuple type differ from the substituted type in
2540-
// any interesting way?
25412539
bool changed = false;
25422540
SmallVector<TupleTypeElt, 4> loweredElts;
25432541
loweredElts.reserve(substType->getNumElements());
25442542

2545-
for (auto i : indices(substType->getElementTypes())) {
2546-
auto origEltType = origType.getTupleElementType(i);
2547-
auto substEltType = substType.getElementType(i);
2548-
2549-
CanType loweredTy =
2550-
tc.getLoweredRValueType(context, origEltType, substEltType);
2551-
changed = (changed || substEltType != loweredTy);
2552-
2553-
loweredElts.push_back(substType->getElement(i).getWithType(loweredTy));
2554-
}
2543+
origType.forEachExpandedTupleElement(substType,
2544+
[&](AbstractionPattern origEltType,
2545+
CanType substEltType,
2546+
const TupleTypeElt &elt) {
2547+
auto loweredTy =
2548+
tc.getLoweredRValueType(context, origEltType, substEltType);
2549+
if (loweredTy != substEltType) changed = true;
2550+
loweredElts.push_back(elt.getWithType(loweredTy));
2551+
});
25552552

25562553
if (!changed) return substType;
25572554

@@ -3014,12 +3011,8 @@ TypeConverter::computeLoweredRValueType(TypeExpansionContext forExpansion,
30143011
substPatternType);
30153012
changed |= (loweredSubstPatternType != substPatternType);
30163013

3017-
CanType substCountType = substPackExpansionType.getCountType();
3018-
CanType loweredSubstCountType = TC.getLoweredRValueType(
3019-
forExpansion,
3020-
origType.getPackExpansionCountType(),
3021-
substCountType);
3022-
changed |= (loweredSubstCountType != substCountType);
3014+
// Count types are AST types and are not lowered.
3015+
CanType loweredSubstCountType = substPackExpansionType.getCountType();
30233016

30243017
if (!changed)
30253018
return substPackExpansionType;

0 commit comments

Comments
 (0)