Skip to content

Commit a15a2e8

Browse files
committed
Add a helper function for checking if a tuple AP contains expansions
1 parent 2d72da3 commit a15a2e8

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

include/swift/SIL/AbstractionPattern.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,8 @@ class AbstractionPattern {
13331333
llvm_unreachable("bad kind");
13341334
}
13351335

1336+
bool doesTupleContainPackExpansionType() const;
1337+
13361338
static AbstractionPattern
13371339
projectTupleElementType(const AbstractionPattern *base, size_t index) {
13381340
return base->getTupleElementType(index);

lib/SIL/IR/AbstractionPattern.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,40 @@ AbstractionPattern::getTupleElementType(unsigned index) const {
430430
llvm_unreachable("bad kind");
431431
}
432432

433+
bool AbstractionPattern::doesTupleContainPackExpansionType() const {
434+
switch (getKind()) {
435+
case Kind::Invalid:
436+
llvm_unreachable("querying invalid abstraction pattern!");
437+
case Kind::Opaque:
438+
case Kind::PartialCurriedObjCMethodType:
439+
case Kind::CurriedObjCMethodType:
440+
case Kind::CFunctionAsMethodType:
441+
case Kind::CurriedCFunctionAsMethodType:
442+
case Kind::PartialCurriedCFunctionAsMethodType:
443+
case Kind::ObjCMethodType:
444+
case Kind::CXXMethodType:
445+
case Kind::CurriedCXXMethodType:
446+
case Kind::PartialCurriedCXXMethodType:
447+
case Kind::OpaqueFunction:
448+
case Kind::OpaqueDerivativeFunction:
449+
llvm_unreachable("pattern is not a tuple");
450+
case Kind::Tuple: {
451+
for (auto &elt : llvm::makeArrayRef(OrigTupleElements,
452+
getNumTupleElements_Stored())) {
453+
if (elt.isPackExpansion())
454+
return true;
455+
}
456+
return true;
457+
}
458+
case Kind::ObjCCompletionHandlerArgumentsType:
459+
case Kind::Type:
460+
case Kind::Discard:
461+
case Kind::ClangType:
462+
return cast<TupleType>(getType()).containsPackExpansionType();
463+
}
464+
llvm_unreachable("bad kind");
465+
}
466+
433467
static CanType getCanPackElementType(CanType type, unsigned index) {
434468
return cast<PackType>(type).getElementType(index);
435469
}

0 commit comments

Comments
 (0)