mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[ConstraintSystem] Add a locator path element for the pattern of a pack expansion.
This commit is contained in:
@@ -198,6 +198,9 @@ CUSTOM_LOCATOR_PATH_ELT(PackElement)
|
||||
/// The shape of a parameter pack.
|
||||
SIMPLE_LOCATOR_PATH_ELT(PackShape)
|
||||
|
||||
/// The pattern of a pack expansion.
|
||||
SIMPLE_LOCATOR_PATH_ELT(PackExpansionPattern)
|
||||
|
||||
/// An unresolved member.
|
||||
SIMPLE_LOCATOR_PATH_ELT(UnresolvedMember)
|
||||
|
||||
|
||||
@@ -2918,10 +2918,12 @@ namespace {
|
||||
CS.setType(binding, type);
|
||||
}
|
||||
|
||||
auto elementResultType = CS.getType(expr->getPatternExpr());
|
||||
auto patternTy = CS.createTypeVariable(CS.getConstraintLocator(expr),
|
||||
auto *patternLoc =
|
||||
CS.getConstraintLocator(expr, ConstraintLocator::PackExpansionPattern);
|
||||
auto patternTy = CS.createTypeVariable(patternLoc,
|
||||
TVO_CanBindToPack |
|
||||
TVO_CanBindToHole);
|
||||
auto elementResultType = CS.getType(expr->getPatternExpr());
|
||||
CS.addConstraint(ConstraintKind::PackElementOf, elementResultType,
|
||||
patternTy, CS.getConstraintLocator(expr));
|
||||
|
||||
|
||||
@@ -7559,9 +7559,10 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifySubclassOfConstraint(
|
||||
for (unsigned i = 0, e = packType->getNumElements(); i < e; ++i) {
|
||||
auto eltType = packType->getElementType(i);
|
||||
if (auto *packExpansionType = eltType->getAs<PackExpansionType>()) {
|
||||
// FIXME: Locator element for pack expansion pattern
|
||||
auto patternLoc =
|
||||
locator.withPathElement(ConstraintLocator::PackExpansionPattern);
|
||||
addConstraint(ConstraintKind::SubclassOf, packExpansionType->getPatternType(),
|
||||
classType, locator.withPathElement(LocatorPathElt::PackElement(i)));
|
||||
classType, patternLoc);
|
||||
} else {
|
||||
addConstraint(ConstraintKind::SubclassOf, eltType,
|
||||
classType, locator.withPathElement(LocatorPathElt::PackElement(i)));
|
||||
@@ -7677,11 +7678,12 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
|
||||
for (unsigned i = 0, e = packType->getNumElements(); i < e; ++i) {
|
||||
auto eltType = packType->getElementType(i);
|
||||
if (auto *packExpansionType = eltType->getAs<PackExpansionType>()) {
|
||||
// FIXME: Locator element for pack expansion pattern
|
||||
auto patternLoc =
|
||||
locator.withPathElement(ConstraintLocator::PackExpansionPattern);
|
||||
addConstraint(ConstraintKind::ConformsTo,
|
||||
packExpansionType->getPatternType(),
|
||||
protocol->getDeclaredInterfaceType(),
|
||||
locator.withPathElement(LocatorPathElt::PackElement(i)));
|
||||
patternLoc);
|
||||
} else {
|
||||
addConstraint(ConstraintKind::ConformsTo, eltType,
|
||||
protocol->getDeclaredInterfaceType(),
|
||||
|
||||
@@ -98,6 +98,7 @@ unsigned LocatorPathElt::getNewSummaryFlags() const {
|
||||
case ConstraintLocator::PackType:
|
||||
case ConstraintLocator::PackElement:
|
||||
case ConstraintLocator::PackShape:
|
||||
case ConstraintLocator::PackExpansionPattern:
|
||||
case ConstraintLocator::PatternBindingElement:
|
||||
case ConstraintLocator::NamedPatternDecl:
|
||||
case ConstraintLocator::AnyPatternDecl:
|
||||
@@ -450,6 +451,11 @@ void LocatorPathElt::dump(raw_ostream &out) const {
|
||||
break;
|
||||
}
|
||||
|
||||
case ConstraintLocator::PackExpansionPattern: {
|
||||
out << "pack expansion pattern";
|
||||
break;
|
||||
}
|
||||
|
||||
case ConstraintLocator::PatternBindingElement: {
|
||||
auto patternBindingElt =
|
||||
elt.castTo<LocatorPathElt::PatternBindingElement>();
|
||||
|
||||
@@ -5330,6 +5330,14 @@ void constraints::simplifyLocator(ASTNode &anchor,
|
||||
case ConstraintLocator::PackShape:
|
||||
break;
|
||||
|
||||
case ConstraintLocator::PackExpansionPattern: {
|
||||
if (auto *expansion = getAsExpr<PackExpansionExpr>(anchor))
|
||||
anchor = expansion->getPatternExpr();
|
||||
|
||||
path = path.slice(1);
|
||||
break;
|
||||
}
|
||||
|
||||
case ConstraintLocator::PatternBindingElement: {
|
||||
auto pattern = path[0].castTo<LocatorPathElt::PatternBindingElement>();
|
||||
auto *patternBinding = cast<PatternBindingDecl>(anchor.get<Decl *>());
|
||||
|
||||
Reference in New Issue
Block a user