Skip to content

Commit 87f4f71

Browse files
committed
SIL: Add forEachExpandedPackElement() and use it in type lowering
Probably there's no way to hit this right now, but there will be if concrete formal PackTypes start showing up in AST.
1 parent 8405745 commit 87f4f71

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

include/swift/SIL/AbstractionPattern.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,7 @@ class AbstractionPattern {
13951395

13961396
/// Is the given pack type a valid substitution of this abstraction
13971397
/// pattern?
1398-
bool matchesPack(CanPackType substType);
1398+
bool matchesPack(CanPackType substType) const;
13991399

14001400
bool isPack() const {
14011401
switch (getKind()) {
@@ -1460,6 +1460,17 @@ class AbstractionPattern {
14601460
void forEachPackElement(CanPackType substPackType,
14611461
llvm::function_ref<void(PackElementGenerator &element)> fn) const;
14621462

1463+
/// Perform a parallel visitation of the elements of a pack type,
1464+
/// expanding the elements of the type. This preserves the structure
1465+
/// of the *substituted* pack type: it will be called once per element
1466+
/// of the substituted type, in order.
1467+
///
1468+
/// This pattern must match the substituted type, but it may be an
1469+
/// opaque pattern.
1470+
void forEachExpandedPackElement(CanPackType substPackType,
1471+
llvm::function_ref<void(AbstractionPattern origEltType,
1472+
CanType substEltType)> handleElement) const;
1473+
14631474
/// Given that the value being abstracted is a move only type, return the
14641475
/// abstraction pattern with the move only bit removed.
14651476
AbstractionPattern removingMoveOnlyWrapper() const;

lib/SIL/IR/AbstractionPattern.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ AbstractionPattern::getPackElementType(unsigned index) const {
707707
llvm_unreachable("bad kind");
708708
}
709709

710-
bool AbstractionPattern::matchesPack(CanPackType substType) {
710+
bool AbstractionPattern::matchesPack(CanPackType substType) const {
711711
switch (getKind()) {
712712
case Kind::Invalid:
713713
llvm_unreachable("querying invalid abstraction pattern!");
@@ -750,11 +750,11 @@ void AbstractionPattern::forEachPackElement(CanPackType substType,
750750
elt.finish();
751751
}
752752

753-
void AbstractionPattern::forEachExpandedPackElement(CanPackType substType,
753+
void AbstractionPattern::forEachExpandedPackElement(CanPackType substPackType,
754754
llvm::function_ref<void(AbstractionPattern origEltType,
755755
CanType substEltType)>
756756
handleElement) const {
757-
assert(matchesPack(substType));
757+
assert(matchesPack(substPackType));
758758

759759
auto substEltTypes = substPackType.getElementTypes();
760760

lib/SIL/IR/TypeLowering.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2608,14 +2608,13 @@ static CanSILPackType computeLoweredPackType(TypeConverter &tc,
26082608
SmallVector<CanType, 4> loweredElts;
26092609
loweredElts.reserve(substType->getNumElements());
26102610

2611-
for (auto i : indices(substType->getElementTypes())) {
2612-
auto origEltType = origType.getPackElementType(i);
2613-
auto substEltType = substType.getElementType(i);
2614-
2615-
CanType loweredTy =
2611+
origType.forEachExpandedPackElement(substType,
2612+
[&](AbstractionPattern origEltType,
2613+
CanType substEltType) {
2614+
auto loweredTy =
26162615
tc.getLoweredRValueType(context, origEltType, substEltType);
26172616
loweredElts.push_back(loweredTy);
2618-
}
2617+
});
26192618

26202619
bool elementIsAddress = true; // TODO
26212620
SILPackType::ExtInfo extInfo(elementIsAddress);

0 commit comments

Comments
 (0)