Sema: Tiny cleanup for matchTypes()

This commit is contained in:
Slava Pestov
2025-01-22 13:28:35 -05:00
parent 5ee97c5275
commit c47ff06a72
2 changed files with 23 additions and 24 deletions

View File

@@ -4608,16 +4608,15 @@ public:
inline bool isFailure() const { return Kind == SolutionKind::Error; } inline bool isFailure() const { return Kind == SolutionKind::Error; }
inline bool isAmbiguous() const { return Kind == SolutionKind::Unsolved; } inline bool isAmbiguous() const { return Kind == SolutionKind::Unsolved; }
static TypeMatchResult success(ConstraintSystem &cs) { static TypeMatchResult success() {
return {SolutionKind::Solved}; return {SolutionKind::Solved};
} }
static TypeMatchResult failure(ConstraintSystem &cs, static TypeMatchResult failure() {
ConstraintLocatorBuilder location) {
return {SolutionKind::Error}; return {SolutionKind::Error};
} }
static TypeMatchResult ambiguous(ConstraintSystem &cs) { static TypeMatchResult ambiguous() {
return {SolutionKind::Unsolved}; return {SolutionKind::Unsolved};
} }
@@ -4722,15 +4721,15 @@ public: // FIXME: public due to statics in CSSimplify.cpp
ConstraintLocatorBuilder locator); ConstraintLocatorBuilder locator);
TypeMatchResult getTypeMatchSuccess() { TypeMatchResult getTypeMatchSuccess() {
return TypeMatchResult::success(*this); return TypeMatchResult::success();
} }
TypeMatchResult getTypeMatchFailure(ConstraintLocatorBuilder locator) { TypeMatchResult getTypeMatchFailure(ConstraintLocatorBuilder locator) {
return TypeMatchResult::failure(*this, locator); return TypeMatchResult::failure();
} }
TypeMatchResult getTypeMatchAmbiguous() { TypeMatchResult getTypeMatchAmbiguous() {
return TypeMatchResult::ambiguous(*this); return TypeMatchResult::ambiguous();
} }
public: public:

View File

@@ -7646,6 +7646,22 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
} }
} }
if (kind == ConstraintKind::BindToPointerType) {
if (desugar2->isEqual(getASTContext().TheEmptyTupleType))
return getTypeMatchSuccess();
}
if (kind == ConstraintKind::BindParam) {
if (auto *iot = dyn_cast<InOutType>(desugar1)) {
if (auto *lvt = dyn_cast<LValueType>(desugar2)) {
return matchTypes(iot->getObjectType(), lvt->getObjectType(),
ConstraintKind::Bind, subflags,
locator.withPathElement(
ConstraintLocator::LValueConversion));
}
}
}
if (kind >= ConstraintKind::Conversion) { if (kind >= ConstraintKind::Conversion) {
// An lvalue of type T1 can be converted to a value of type T2 so long as // An lvalue of type T1 can be converted to a value of type T2 so long as
// T1 is convertible to T2 (by loading the value). Note that we cannot get // T1 is convertible to T2 (by loading the value). Note that we cannot get
@@ -7777,7 +7793,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
} }
// Special implicit nominal conversions. // Special implicit nominal conversions.
if (!type1->is<LValueType>() && kind >= ConstraintKind::Subtype) { if (!type1->is<LValueType>()) {
// Array -> Array. // Array -> Array.
if (desugar1->isArray() && desugar2->isArray()) { if (desugar1->isArray() && desugar2->isArray()) {
conversionsOrFixes.push_back(ConversionRestrictionKind::ArrayUpcast); conversionsOrFixes.push_back(ConversionRestrictionKind::ArrayUpcast);
@@ -7793,11 +7809,6 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
} }
} }
if (kind == ConstraintKind::BindToPointerType) {
if (desugar2->isEqual(getASTContext().TheEmptyTupleType))
return getTypeMatchSuccess();
}
if (kind >= ConstraintKind::Conversion) { if (kind >= ConstraintKind::Conversion) {
// It is never legal to form an autoclosure that results in these // It is never legal to form an autoclosure that results in these
// implicit conversions to pointer types. // implicit conversions to pointer types.
@@ -8054,17 +8065,6 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
} }
} }
if (kind == ConstraintKind::BindParam) {
if (auto *iot = dyn_cast<InOutType>(desugar1)) {
if (auto *lvt = dyn_cast<LValueType>(desugar2)) {
return matchTypes(iot->getObjectType(), lvt->getObjectType(),
ConstraintKind::Bind, subflags,
locator.withPathElement(
ConstraintLocator::LValueConversion));
}
}
}
// Matching types where one side is a pack expansion and the other is not // Matching types where one side is a pack expansion and the other is not
// means a pack expansion was used where it isn't supported. // means a pack expansion was used where it isn't supported.
if (type1->is<PackExpansionType>() != type2->is<PackExpansionType>()) { if (type1->is<PackExpansionType>() != type2->is<PackExpansionType>()) {