mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[ConstraintSystem] NFC: Generalize DefaultClosureType constraint
This constraint is useful in more places than closures because it gives a way to provide a "fallback type" without it having effect on inference.
This commit is contained in:
@@ -2284,7 +2284,7 @@ ConstraintSystem::matchTupleTypes(TupleType *tuple1, TupleType *tuple2,
|
||||
case ConstraintKind::BridgingConversion:
|
||||
case ConstraintKind::OneWayEqual:
|
||||
case ConstraintKind::OneWayBindParam:
|
||||
case ConstraintKind::DefaultClosureType:
|
||||
case ConstraintKind::FallbackType:
|
||||
case ConstraintKind::UnresolvedMemberChainBase:
|
||||
case ConstraintKind::PropertyWrapper:
|
||||
case ConstraintKind::SyntacticElement:
|
||||
@@ -2643,7 +2643,7 @@ static bool matchFunctionRepresentations(FunctionType::ExtInfo einfo1,
|
||||
case ConstraintKind::ValueWitness:
|
||||
case ConstraintKind::OneWayEqual:
|
||||
case ConstraintKind::OneWayBindParam:
|
||||
case ConstraintKind::DefaultClosureType:
|
||||
case ConstraintKind::FallbackType:
|
||||
case ConstraintKind::UnresolvedMemberChainBase:
|
||||
case ConstraintKind::PropertyWrapper:
|
||||
case ConstraintKind::SyntacticElement:
|
||||
@@ -3161,7 +3161,7 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
|
||||
case ConstraintKind::BridgingConversion:
|
||||
case ConstraintKind::OneWayEqual:
|
||||
case ConstraintKind::OneWayBindParam:
|
||||
case ConstraintKind::DefaultClosureType:
|
||||
case ConstraintKind::FallbackType:
|
||||
case ConstraintKind::UnresolvedMemberChainBase:
|
||||
case ConstraintKind::PropertyWrapper:
|
||||
case ConstraintKind::SyntacticElement:
|
||||
@@ -6811,7 +6811,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
|
||||
case ConstraintKind::ValueWitness:
|
||||
case ConstraintKind::OneWayEqual:
|
||||
case ConstraintKind::OneWayBindParam:
|
||||
case ConstraintKind::DefaultClosureType:
|
||||
case ConstraintKind::FallbackType:
|
||||
case ConstraintKind::UnresolvedMemberChainBase:
|
||||
case ConstraintKind::PropertyWrapper:
|
||||
case ConstraintKind::SyntacticElement:
|
||||
@@ -10989,18 +10989,18 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyDefaultableConstraint(
|
||||
return SolutionKind::Solved;
|
||||
}
|
||||
|
||||
ConstraintSystem::SolutionKind
|
||||
ConstraintSystem::simplifyDefaultClosureTypeConstraint(
|
||||
Type closureType, Type inferredType,
|
||||
ArrayRef<TypeVariableType *> referencedOuterParameters,
|
||||
TypeMatchOptions flags, ConstraintLocatorBuilder locator) {
|
||||
closureType = getFixedTypeRecursive(closureType, flags, /*wantRValue=*/true);
|
||||
ConstraintSystem::SolutionKind ConstraintSystem::simplifyFallbackTypeConstraint(
|
||||
Type defaultableType, Type fallbackType,
|
||||
ArrayRef<TypeVariableType *> referencedVars, TypeMatchOptions flags,
|
||||
ConstraintLocatorBuilder locator) {
|
||||
defaultableType =
|
||||
getFixedTypeRecursive(defaultableType, flags, /*wantRValue=*/true);
|
||||
|
||||
if (closureType->isTypeVariableOrMember()) {
|
||||
if (defaultableType->isTypeVariableOrMember()) {
|
||||
if (flags.contains(TMF_GenerateConstraints)) {
|
||||
addUnsolvedConstraint(Constraint::create(
|
||||
*this, ConstraintKind::DefaultClosureType, closureType, inferredType,
|
||||
getConstraintLocator(locator), referencedOuterParameters));
|
||||
*this, ConstraintKind::FallbackType, defaultableType, fallbackType,
|
||||
getConstraintLocator(locator), referencedVars));
|
||||
return SolutionKind::Solved;
|
||||
}
|
||||
|
||||
@@ -15064,7 +15064,7 @@ ConstraintSystem::addConstraintImpl(ConstraintKind kind, Type first,
|
||||
case ConstraintKind::Conjunction:
|
||||
case ConstraintKind::KeyPath:
|
||||
case ConstraintKind::KeyPathApplication:
|
||||
case ConstraintKind::DefaultClosureType:
|
||||
case ConstraintKind::FallbackType:
|
||||
case ConstraintKind::SyntacticElement:
|
||||
llvm_unreachable("Use the correct addConstraint()");
|
||||
}
|
||||
@@ -15596,12 +15596,12 @@ ConstraintSystem::simplifyConstraint(const Constraint &constraint) {
|
||||
/*flags*/ None,
|
||||
constraint.getLocator());
|
||||
|
||||
case ConstraintKind::DefaultClosureType:
|
||||
return simplifyDefaultClosureTypeConstraint(constraint.getFirstType(),
|
||||
constraint.getSecondType(),
|
||||
constraint.getTypeVariables(),
|
||||
/*flags*/ None,
|
||||
constraint.getLocator());
|
||||
case ConstraintKind::FallbackType:
|
||||
return simplifyFallbackTypeConstraint(constraint.getFirstType(),
|
||||
constraint.getSecondType(),
|
||||
constraint.getTypeVariables(),
|
||||
/*flags*/ None,
|
||||
constraint.getLocator());
|
||||
|
||||
case ConstraintKind::PropertyWrapper:
|
||||
return simplifyPropertyWrapperConstraint(constraint.getFirstType(),
|
||||
|
||||
Reference in New Issue
Block a user