mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Sema/CS] Convenience function for adding a Requirement as a constraint.
This commit is contained in:
@@ -4859,6 +4859,43 @@ ConstraintSystem::addKeyPathConstraint(Type keypath,
|
||||
}
|
||||
}
|
||||
|
||||
void ConstraintSystem::addConstraint(Requirement req,
|
||||
ConstraintLocatorBuilder locator,
|
||||
bool isFavored) {
|
||||
bool conformsToAnyObject = false;
|
||||
Optional<ConstraintKind> kind;
|
||||
switch (req.getKind()) {
|
||||
case RequirementKind::Conformance:
|
||||
kind = ConstraintKind::ConformsTo;
|
||||
break;
|
||||
case RequirementKind::Superclass:
|
||||
conformsToAnyObject = true;
|
||||
kind = ConstraintKind::Subtype;
|
||||
break;
|
||||
case RequirementKind::SameType:
|
||||
kind = ConstraintKind::Equal;
|
||||
break;
|
||||
case RequirementKind::Layout:
|
||||
// Only a class constraint can be modeled as a constraint, and only that can
|
||||
// appear outside of a @_specialize at the moment anyway.
|
||||
if (req.getLayoutConstraint()->isClass()) {
|
||||
conformsToAnyObject = true;
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
auto firstType = req.getFirstType();
|
||||
if (kind) {
|
||||
addConstraint(*kind, req.getFirstType(), req.getSecondType(), locator,
|
||||
isFavored);
|
||||
}
|
||||
|
||||
if (conformsToAnyObject) {
|
||||
auto anyObject = getASTContext().getAnyObjectType();
|
||||
addConstraint(ConstraintKind::ConformsTo, firstType, anyObject, locator);
|
||||
}
|
||||
}
|
||||
|
||||
void ConstraintSystem::addConstraint(ConstraintKind kind, Type first,
|
||||
Type second,
|
||||
|
||||
Reference in New Issue
Block a user