[ConstraintSystem] Add a new transitive conformance constraint

Conformance constraints could be transferred through conversions,
but that would also require checking implicit conversions
such as optional and pointer promotions for conformance is the
type itself doesn't conform, for that let's add a special constraint
`TransitivelyConformsTo`.
This commit is contained in:
Pavel Yaskevich
2021-04-01 15:08:06 -07:00
parent 4de232ec57
commit 985843a21f
6 changed files with 48 additions and 1 deletions

View File

@@ -1542,6 +1542,7 @@ ConstraintSystem::matchTupleTypes(TupleType *tuple1, TupleType *tuple2,
case ConstraintKind::BindOverload:
case ConstraintKind::CheckedCast:
case ConstraintKind::ConformsTo:
case ConstraintKind::TransitivelyConformsTo:
case ConstraintKind::Defaultable:
case ConstraintKind::Disjunction:
case ConstraintKind::DynamicTypeOf:
@@ -1682,6 +1683,7 @@ static bool matchFunctionRepresentations(FunctionType::ExtInfo einfo1,
case ConstraintKind::BindOverload:
case ConstraintKind::CheckedCast:
case ConstraintKind::ConformsTo:
case ConstraintKind::TransitivelyConformsTo:
case ConstraintKind::Defaultable:
case ConstraintKind::Disjunction:
case ConstraintKind::DynamicTypeOf:
@@ -2072,6 +2074,7 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
case ConstraintKind::BindOverload:
case ConstraintKind::CheckedCast:
case ConstraintKind::ConformsTo:
case ConstraintKind::TransitivelyConformsTo:
case ConstraintKind::Defaultable:
case ConstraintKind::Disjunction:
case ConstraintKind::DynamicTypeOf:
@@ -4983,6 +4986,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
case ConstraintKind::BridgingConversion:
case ConstraintKind::CheckedCast:
case ConstraintKind::ConformsTo:
case ConstraintKind::TransitivelyConformsTo:
case ConstraintKind::Defaultable:
case ConstraintKind::Disjunction:
case ConstraintKind::DynamicTypeOf:
@@ -6186,6 +6190,12 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
return SolutionKind::Error;
}
ConstraintSystem::SolutionKind ConstraintSystem::simplifyTransitivelyConformsTo(
Type type, Type protocolTy, ConstraintLocatorBuilder locator,
TypeMatchOptions flags) {
return SolutionKind::Error;
}
/// Determine the kind of checked cast to perform from the given type to
/// the given type.
///
@@ -11259,6 +11269,10 @@ ConstraintSystem::addConstraintImpl(ConstraintKind kind, Type first,
return simplifyConformsToConstraint(first, second, kind, locator,
subflags);
case ConstraintKind::TransitivelyConformsTo:
return simplifyTransitivelyConformsTo(first, second, locator,
subflags);
case ConstraintKind::CheckedCast:
return simplifyCheckedCastConstraint(first, second, subflags, locator);
@@ -11727,6 +11741,13 @@ ConstraintSystem::simplifyConstraint(const Constraint &constraint) {
constraint.getLocator(),
None);
case ConstraintKind::TransitivelyConformsTo:
return simplifyTransitivelyConformsTo(
constraint.getFirstType(),
constraint.getSecondType(),
constraint.getLocator(),
None);
case ConstraintKind::CheckedCast: {
auto result = simplifyCheckedCastConstraint(constraint.getFirstType(),
constraint.getSecondType(),