[ConstraintSystem] TypeSimplifier: If pattern and shape are packs - produce pattern type

The `transformWithPosition` would handle its flattening.
This commit is contained in:
Pavel Yaskevich
2023-04-12 16:12:59 -07:00
committed by Pavel Yaskevich
parent 8a39f3f38d
commit f4a082d8f1

View File

@@ -3793,13 +3793,14 @@ struct TypeSimplifier {
}
if (auto expansion = dyn_cast<PackExpansionType>(type.getPointer())) {
auto patternType = expansion->getPatternType();
// First, let's check whether pattern type has all of the type variables
// that represent packs resolved, otherwise we don't have enough information
// to flatten this pack expansion type.
//
// Note that we don't actually need to do deep transformation here
// because pack variables can only appear in structural positions.
if (expansion->getPatternType().findIf([&](Type type) {
if (patternType.findIf([&](Type type) {
if (auto *typeVar = type->getAs<TypeVariableType>()) {
if (typeVar->getImpl().canBindToPack())
return GetFixedTypeFn(typeVar)->is<TypeVariableType>();
@@ -3813,6 +3814,12 @@ struct TypeSimplifier {
auto countType = expansion->getCountType().transform(
TypeSimplifier(CS, GetFixedTypeFn));
// If both pattern and count are resolves, let's just return
// the pattern type for `transformWithPosition` to take care
// of the rest.
if (patternType->is<PackType>() && countType->is<PackType>())
return patternType;
if (auto countPack = countType->getAs<PackType>()) {
SmallVector<Type, 4> elts;
ActivePackExpansions.push_back({false, 0});