mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[CS] Remove function component constraints
FunctionInput relies on being able to represent parameter lists as tuples, which won't be possible once parameter flags are stripped from tuple types. FunctionResult is reasonable, but is currently unused.
This commit is contained in:
@@ -171,12 +171,6 @@ enum class ConstraintKind : char {
|
|||||||
/// The key path type is chosen based on the selection of overloads for the
|
/// The key path type is chosen based on the selection of overloads for the
|
||||||
/// member references along the path.
|
/// member references along the path.
|
||||||
KeyPath,
|
KeyPath,
|
||||||
/// The first type is a function type, the second is the function's
|
|
||||||
/// input type.
|
|
||||||
FunctionInput,
|
|
||||||
/// The first type is a function type, the second is the function's
|
|
||||||
/// result type.
|
|
||||||
FunctionResult,
|
|
||||||
/// The first type will be equal to the second type, but only when the
|
/// The first type will be equal to the second type, but only when the
|
||||||
/// second type has been fully determined (and mapped down to a concrete
|
/// second type has been fully determined (and mapped down to a concrete
|
||||||
/// type). At that point, this constraint will be treated like an `Equal`
|
/// type). At that point, this constraint will be treated like an `Equal`
|
||||||
@@ -691,8 +685,6 @@ public:
|
|||||||
case ConstraintKind::KeyPath:
|
case ConstraintKind::KeyPath:
|
||||||
case ConstraintKind::KeyPathApplication:
|
case ConstraintKind::KeyPathApplication:
|
||||||
case ConstraintKind::Defaultable:
|
case ConstraintKind::Defaultable:
|
||||||
case ConstraintKind::FunctionInput:
|
|
||||||
case ConstraintKind::FunctionResult:
|
|
||||||
return ConstraintClassification::TypeProperty;
|
return ConstraintClassification::TypeProperty;
|
||||||
|
|
||||||
case ConstraintKind::Disjunction:
|
case ConstraintKind::Disjunction:
|
||||||
|
|||||||
@@ -4751,13 +4751,6 @@ private:
|
|||||||
TypeMatchOptions flags,
|
TypeMatchOptions flags,
|
||||||
ConstraintLocatorBuilder locator);
|
ConstraintLocatorBuilder locator);
|
||||||
|
|
||||||
/// Attempt to simplify a function input or result constraint.
|
|
||||||
SolutionKind simplifyFunctionComponentConstraint(
|
|
||||||
ConstraintKind kind,
|
|
||||||
Type first, Type second,
|
|
||||||
TypeMatchOptions flags,
|
|
||||||
ConstraintLocatorBuilder locator);
|
|
||||||
|
|
||||||
/// Attempt to simplify the BridgingConversion constraint.
|
/// Attempt to simplify the BridgingConversion constraint.
|
||||||
SolutionKind simplifyBridgingConstraint(Type type1,
|
SolutionKind simplifyBridgingConstraint(Type type1,
|
||||||
Type type2,
|
Type type2,
|
||||||
|
|||||||
@@ -1336,8 +1336,6 @@ void PotentialBindings::infer(Constraint *constraint) {
|
|||||||
case ConstraintKind::EscapableFunctionOf:
|
case ConstraintKind::EscapableFunctionOf:
|
||||||
case ConstraintKind::OpenedExistentialOf:
|
case ConstraintKind::OpenedExistentialOf:
|
||||||
case ConstraintKind::KeyPath:
|
case ConstraintKind::KeyPath:
|
||||||
case ConstraintKind::FunctionInput:
|
|
||||||
case ConstraintKind::FunctionResult:
|
|
||||||
case ConstraintKind::ClosureBodyElement:
|
case ConstraintKind::ClosureBodyElement:
|
||||||
case ConstraintKind::Conjunction:
|
case ConstraintKind::Conjunction:
|
||||||
// Constraints from which we can't do anything.
|
// Constraints from which we can't do anything.
|
||||||
|
|||||||
@@ -1632,8 +1632,6 @@ ConstraintSystem::matchTupleTypes(TupleType *tuple1, TupleType *tuple2,
|
|||||||
case ConstraintKind::ValueMember:
|
case ConstraintKind::ValueMember:
|
||||||
case ConstraintKind::ValueWitness:
|
case ConstraintKind::ValueWitness:
|
||||||
case ConstraintKind::BridgingConversion:
|
case ConstraintKind::BridgingConversion:
|
||||||
case ConstraintKind::FunctionInput:
|
|
||||||
case ConstraintKind::FunctionResult:
|
|
||||||
case ConstraintKind::OneWayEqual:
|
case ConstraintKind::OneWayEqual:
|
||||||
case ConstraintKind::OneWayBindParam:
|
case ConstraintKind::OneWayBindParam:
|
||||||
case ConstraintKind::DefaultClosureType:
|
case ConstraintKind::DefaultClosureType:
|
||||||
@@ -1773,8 +1771,6 @@ static bool matchFunctionRepresentations(FunctionType::ExtInfo einfo1,
|
|||||||
case ConstraintKind::UnresolvedValueMember:
|
case ConstraintKind::UnresolvedValueMember:
|
||||||
case ConstraintKind::ValueMember:
|
case ConstraintKind::ValueMember:
|
||||||
case ConstraintKind::ValueWitness:
|
case ConstraintKind::ValueWitness:
|
||||||
case ConstraintKind::FunctionInput:
|
|
||||||
case ConstraintKind::FunctionResult:
|
|
||||||
case ConstraintKind::OneWayEqual:
|
case ConstraintKind::OneWayEqual:
|
||||||
case ConstraintKind::OneWayBindParam:
|
case ConstraintKind::OneWayBindParam:
|
||||||
case ConstraintKind::DefaultClosureType:
|
case ConstraintKind::DefaultClosureType:
|
||||||
@@ -2178,8 +2174,6 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
|
|||||||
case ConstraintKind::ValueMember:
|
case ConstraintKind::ValueMember:
|
||||||
case ConstraintKind::ValueWitness:
|
case ConstraintKind::ValueWitness:
|
||||||
case ConstraintKind::BridgingConversion:
|
case ConstraintKind::BridgingConversion:
|
||||||
case ConstraintKind::FunctionInput:
|
|
||||||
case ConstraintKind::FunctionResult:
|
|
||||||
case ConstraintKind::OneWayEqual:
|
case ConstraintKind::OneWayEqual:
|
||||||
case ConstraintKind::OneWayBindParam:
|
case ConstraintKind::OneWayBindParam:
|
||||||
case ConstraintKind::DefaultClosureType:
|
case ConstraintKind::DefaultClosureType:
|
||||||
@@ -5266,8 +5260,6 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
|
|||||||
case ConstraintKind::UnresolvedValueMember:
|
case ConstraintKind::UnresolvedValueMember:
|
||||||
case ConstraintKind::ValueMember:
|
case ConstraintKind::ValueMember:
|
||||||
case ConstraintKind::ValueWitness:
|
case ConstraintKind::ValueWitness:
|
||||||
case ConstraintKind::FunctionInput:
|
|
||||||
case ConstraintKind::FunctionResult:
|
|
||||||
case ConstraintKind::OneWayEqual:
|
case ConstraintKind::OneWayEqual:
|
||||||
case ConstraintKind::OneWayBindParam:
|
case ConstraintKind::OneWayBindParam:
|
||||||
case ConstraintKind::DefaultClosureType:
|
case ConstraintKind::DefaultClosureType:
|
||||||
@@ -7058,71 +7050,6 @@ ConstraintSystem::simplifyOptionalObjectConstraint(
|
|||||||
return SolutionKind::Solved;
|
return SolutionKind::Solved;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attempt to simplify a function input or result constraint.
|
|
||||||
ConstraintSystem::SolutionKind
|
|
||||||
ConstraintSystem::simplifyFunctionComponentConstraint(
|
|
||||||
ConstraintKind kind,
|
|
||||||
Type first, Type second,
|
|
||||||
TypeMatchOptions flags,
|
|
||||||
ConstraintLocatorBuilder locator) {
|
|
||||||
auto simplified = simplifyType(first);
|
|
||||||
auto simplifiedCopy = simplified;
|
|
||||||
|
|
||||||
unsigned unwrapCount = 0;
|
|
||||||
if (shouldAttemptFixes()) {
|
|
||||||
while (auto objectTy = simplified->getOptionalObjectType()) {
|
|
||||||
simplified = objectTy;
|
|
||||||
|
|
||||||
// Track how many times we do this so that we can record a fix for each.
|
|
||||||
++unwrapCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (simplified->isPlaceholder()) {
|
|
||||||
if (auto *typeVar = second->getAs<TypeVariableType>())
|
|
||||||
recordPotentialHole(typeVar);
|
|
||||||
return SolutionKind::Solved;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (simplified->isTypeVariableOrMember()) {
|
|
||||||
if (!flags.contains(TMF_GenerateConstraints))
|
|
||||||
return SolutionKind::Unsolved;
|
|
||||||
|
|
||||||
addUnsolvedConstraint(
|
|
||||||
Constraint::create(*this, kind, simplified, second,
|
|
||||||
getConstraintLocator(locator)));
|
|
||||||
} else if (auto *funcTy = simplified->getAs<FunctionType>()) {
|
|
||||||
// Equate it to the other type in the constraint.
|
|
||||||
Type type;
|
|
||||||
ConstraintLocator::PathElementKind locKind;
|
|
||||||
|
|
||||||
if (kind == ConstraintKind::FunctionInput) {
|
|
||||||
type = AnyFunctionType::composeTuple(getASTContext(),
|
|
||||||
funcTy->getParams());
|
|
||||||
locKind = ConstraintLocator::FunctionArgument;
|
|
||||||
} else if (kind == ConstraintKind::FunctionResult) {
|
|
||||||
type = funcTy->getResult();
|
|
||||||
locKind = ConstraintLocator::FunctionResult;
|
|
||||||
} else {
|
|
||||||
llvm_unreachable("Bad function component constraint kind");
|
|
||||||
}
|
|
||||||
|
|
||||||
addConstraint(ConstraintKind::Bind, type, second,
|
|
||||||
locator.withPathElement(locKind));
|
|
||||||
} else {
|
|
||||||
return SolutionKind::Error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unwrapCount > 0) {
|
|
||||||
auto *fix = ForceOptional::create(*this, simplifiedCopy, second,
|
|
||||||
getConstraintLocator(locator));
|
|
||||||
if (recordFix(fix, /*impact=*/unwrapCount))
|
|
||||||
return SolutionKind::Error;
|
|
||||||
}
|
|
||||||
|
|
||||||
return SolutionKind::Solved;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool isForKeyPathSubscript(ConstraintSystem &cs,
|
static bool isForKeyPathSubscript(ConstraintSystem &cs,
|
||||||
ConstraintLocator *locator) {
|
ConstraintLocator *locator) {
|
||||||
if (!locator || !locator->getAnchor())
|
if (!locator || !locator->getAnchor())
|
||||||
@@ -12048,11 +11975,6 @@ ConstraintSystem::addConstraintImpl(ConstraintKind kind, Type first,
|
|||||||
case ConstraintKind::PropertyWrapper:
|
case ConstraintKind::PropertyWrapper:
|
||||||
return simplifyPropertyWrapperConstraint(first, second, subflags, locator);
|
return simplifyPropertyWrapperConstraint(first, second, subflags, locator);
|
||||||
|
|
||||||
case ConstraintKind::FunctionInput:
|
|
||||||
case ConstraintKind::FunctionResult:
|
|
||||||
return simplifyFunctionComponentConstraint(kind, first, second,
|
|
||||||
subflags, locator);
|
|
||||||
|
|
||||||
case ConstraintKind::OneWayEqual:
|
case ConstraintKind::OneWayEqual:
|
||||||
case ConstraintKind::OneWayBindParam:
|
case ConstraintKind::OneWayBindParam:
|
||||||
return simplifyOneWayConstraint(kind, first, second, subflags, locator);
|
return simplifyOneWayConstraint(kind, first, second, subflags, locator);
|
||||||
@@ -12582,14 +12504,6 @@ ConstraintSystem::simplifyConstraint(const Constraint &constraint) {
|
|||||||
/*flags*/ None,
|
/*flags*/ None,
|
||||||
constraint.getLocator());
|
constraint.getLocator());
|
||||||
|
|
||||||
case ConstraintKind::FunctionInput:
|
|
||||||
case ConstraintKind::FunctionResult:
|
|
||||||
return simplifyFunctionComponentConstraint(constraint.getKind(),
|
|
||||||
constraint.getFirstType(),
|
|
||||||
constraint.getSecondType(),
|
|
||||||
/*flags*/ None,
|
|
||||||
constraint.getLocator());
|
|
||||||
|
|
||||||
case ConstraintKind::Disjunction:
|
case ConstraintKind::Disjunction:
|
||||||
case ConstraintKind::Conjunction:
|
case ConstraintKind::Conjunction:
|
||||||
// {Dis, Con}junction constraints are never solved here.
|
// {Dis, Con}junction constraints are never solved here.
|
||||||
|
|||||||
@@ -73,8 +73,6 @@ Constraint::Constraint(ConstraintKind Kind, Type First, Type Second,
|
|||||||
case ConstraintKind::EscapableFunctionOf:
|
case ConstraintKind::EscapableFunctionOf:
|
||||||
case ConstraintKind::OpenedExistentialOf:
|
case ConstraintKind::OpenedExistentialOf:
|
||||||
case ConstraintKind::OptionalObject:
|
case ConstraintKind::OptionalObject:
|
||||||
case ConstraintKind::FunctionInput:
|
|
||||||
case ConstraintKind::FunctionResult:
|
|
||||||
case ConstraintKind::OneWayEqual:
|
case ConstraintKind::OneWayEqual:
|
||||||
case ConstraintKind::OneWayBindParam:
|
case ConstraintKind::OneWayBindParam:
|
||||||
case ConstraintKind::UnresolvedMemberChainBase:
|
case ConstraintKind::UnresolvedMemberChainBase:
|
||||||
@@ -157,8 +155,6 @@ Constraint::Constraint(ConstraintKind Kind, Type First, Type Second, Type Third,
|
|||||||
case ConstraintKind::BindOverload:
|
case ConstraintKind::BindOverload:
|
||||||
case ConstraintKind::Disjunction:
|
case ConstraintKind::Disjunction:
|
||||||
case ConstraintKind::Conjunction:
|
case ConstraintKind::Conjunction:
|
||||||
case ConstraintKind::FunctionInput:
|
|
||||||
case ConstraintKind::FunctionResult:
|
|
||||||
case ConstraintKind::OneWayEqual:
|
case ConstraintKind::OneWayEqual:
|
||||||
case ConstraintKind::OneWayBindParam:
|
case ConstraintKind::OneWayBindParam:
|
||||||
case ConstraintKind::DefaultClosureType:
|
case ConstraintKind::DefaultClosureType:
|
||||||
@@ -302,8 +298,6 @@ Constraint *Constraint::clone(ConstraintSystem &cs) const {
|
|||||||
case ConstraintKind::DynamicCallableApplicableFunction:
|
case ConstraintKind::DynamicCallableApplicableFunction:
|
||||||
case ConstraintKind::OptionalObject:
|
case ConstraintKind::OptionalObject:
|
||||||
case ConstraintKind::Defaultable:
|
case ConstraintKind::Defaultable:
|
||||||
case ConstraintKind::FunctionInput:
|
|
||||||
case ConstraintKind::FunctionResult:
|
|
||||||
case ConstraintKind::OneWayEqual:
|
case ConstraintKind::OneWayEqual:
|
||||||
case ConstraintKind::OneWayBindParam:
|
case ConstraintKind::OneWayBindParam:
|
||||||
case ConstraintKind::DefaultClosureType:
|
case ConstraintKind::DefaultClosureType:
|
||||||
@@ -448,10 +442,6 @@ void Constraint::print(llvm::raw_ostream &Out, SourceManager *sm) const {
|
|||||||
break;
|
break;
|
||||||
case ConstraintKind::OptionalObject:
|
case ConstraintKind::OptionalObject:
|
||||||
Out << " optional with object type "; break;
|
Out << " optional with object type "; break;
|
||||||
case ConstraintKind::FunctionInput:
|
|
||||||
Out << " bind function input of "; break;
|
|
||||||
case ConstraintKind::FunctionResult:
|
|
||||||
Out << " bind function result of "; break;
|
|
||||||
case ConstraintKind::BindOverload: {
|
case ConstraintKind::BindOverload: {
|
||||||
Out << " bound to ";
|
Out << " bound to ";
|
||||||
auto overload = getOverloadChoice();
|
auto overload = getOverloadChoice();
|
||||||
@@ -668,8 +658,6 @@ gatherReferencedTypeVars(Constraint *constraint,
|
|||||||
case ConstraintKind::LiteralConformsTo:
|
case ConstraintKind::LiteralConformsTo:
|
||||||
case ConstraintKind::TransitivelyConformsTo:
|
case ConstraintKind::TransitivelyConformsTo:
|
||||||
case ConstraintKind::SelfObjectOfProtocol:
|
case ConstraintKind::SelfObjectOfProtocol:
|
||||||
case ConstraintKind::FunctionInput:
|
|
||||||
case ConstraintKind::FunctionResult:
|
|
||||||
case ConstraintKind::OneWayEqual:
|
case ConstraintKind::OneWayEqual:
|
||||||
case ConstraintKind::OneWayBindParam:
|
case ConstraintKind::OneWayBindParam:
|
||||||
case ConstraintKind::DefaultClosureType:
|
case ConstraintKind::DefaultClosureType:
|
||||||
|
|||||||
Reference in New Issue
Block a user