Skip to content

[ConstraintSystem] Improve type parameter requirement locators #13047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/Sema/ConstraintLocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void ConstraintLocator::Profile(llvm::FoldingSetNodeID &id, Expr *anchor,
case OpenedGeneric:
case KeyPathComponent:
case ConditionalRequirement:
case TypeParameterRequirement:
if (unsigned numValues = numNumericValuesInPathElement(elt.getKind())) {
id.AddInteger(elt.getValue());
if (numValues > 1)
Expand Down Expand Up @@ -243,6 +244,10 @@ void ConstraintLocator::dump(SourceManager *sm, raw_ostream &out) {
case ConditionalRequirement:
out << "conditional requirement #" << llvm::utostr(elt.getValue());
break;

case TypeParameterRequirement:
out << "type parameter requirement #" << llvm::utostr(elt.getValue());
break;
}
}

Expand Down
8 changes: 8 additions & 0 deletions lib/Sema/ConstraintLocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ class ConstraintLocator : public llvm::FoldingSetNode {
KeyPathComponent,
/// The Nth conditional requirement in the parent locator's conformance.
ConditionalRequirement,
/// A single requirement placed on the type parameters.
TypeParameterRequirement,
};

/// \brief Determine the number of numeric values used for the given path
Expand Down Expand Up @@ -164,6 +166,7 @@ class ConstraintLocator : public llvm::FoldingSetNode {
case TupleElement:
case KeyPathComponent:
case ConditionalRequirement:
case TypeParameterRequirement:
return 1;

case ApplyArgToParam:
Expand Down Expand Up @@ -217,6 +220,7 @@ class ConstraintLocator : public llvm::FoldingSetNode {
case Witness:
case KeyPathComponent:
case ConditionalRequirement:
case TypeParameterRequirement:
return 0;

case FunctionArgument:
Expand Down Expand Up @@ -353,6 +357,10 @@ class ConstraintLocator : public llvm::FoldingSetNode {
return PathElement(ConditionalRequirement, index);
}

static PathElement getTypeRequirementComponent(unsigned index) {
return PathElement(TypeParameterRequirement, index);
}

/// \brief Retrieve the kind of path element.
PathElementKind getKind() const {
switch (static_cast<StoredKind>(storedKind)) {
Expand Down
11 changes: 9 additions & 2 deletions lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,10 @@ void ConstraintSystem::openGeneric(
bindArchetypesFromContext(*this, outerDC, locatorPtr, replacements);

// Add the requirements as constraints.
for (auto req : sig->getRequirements()) {
auto requirements = sig->getRequirements();
for (unsigned pos = 0, n = requirements.size(); pos != n; ++pos) {
const auto &req = requirements[pos];

Optional<Requirement> openedReq;
auto openedFirst = openType(req.getFirstType(), replacements);

Expand All @@ -1078,7 +1081,11 @@ void ConstraintSystem::openGeneric(
openedReq = Requirement(kind, openedFirst, req.getLayoutConstraint());
break;
}
addConstraint(*openedReq, locatorPtr);

addConstraint(
*openedReq,
locator.withPathElement(ConstraintLocator::OpenedGeneric)
.withPathElement(LocatorPathElt::getTypeRequirementComponent(pos)));
}
}

Expand Down