From c47ff06a7289ec2bde4730f34b50b87d0a82ba64 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 22 Jan 2025 13:28:35 -0500 Subject: [PATCH] Sema: Tiny cleanup for matchTypes() --- include/swift/Sema/ConstraintSystem.h | 13 +++++----- lib/Sema/CSSimplify.cpp | 34 +++++++++++++-------------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/include/swift/Sema/ConstraintSystem.h b/include/swift/Sema/ConstraintSystem.h index 1d435e6059f..189478c3184 100644 --- a/include/swift/Sema/ConstraintSystem.h +++ b/include/swift/Sema/ConstraintSystem.h @@ -4608,16 +4608,15 @@ public: inline bool isFailure() const { return Kind == SolutionKind::Error; } inline bool isAmbiguous() const { return Kind == SolutionKind::Unsolved; } - static TypeMatchResult success(ConstraintSystem &cs) { + static TypeMatchResult success() { return {SolutionKind::Solved}; } - static TypeMatchResult failure(ConstraintSystem &cs, - ConstraintLocatorBuilder location) { + static TypeMatchResult failure() { return {SolutionKind::Error}; } - static TypeMatchResult ambiguous(ConstraintSystem &cs) { + static TypeMatchResult ambiguous() { return {SolutionKind::Unsolved}; } @@ -4722,15 +4721,15 @@ public: // FIXME: public due to statics in CSSimplify.cpp ConstraintLocatorBuilder locator); TypeMatchResult getTypeMatchSuccess() { - return TypeMatchResult::success(*this); + return TypeMatchResult::success(); } TypeMatchResult getTypeMatchFailure(ConstraintLocatorBuilder locator) { - return TypeMatchResult::failure(*this, locator); + return TypeMatchResult::failure(); } TypeMatchResult getTypeMatchAmbiguous() { - return TypeMatchResult::ambiguous(*this); + return TypeMatchResult::ambiguous(); } public: diff --git a/lib/Sema/CSSimplify.cpp b/lib/Sema/CSSimplify.cpp index dbb0de6034d..3a57ef42662 100644 --- a/lib/Sema/CSSimplify.cpp +++ b/lib/Sema/CSSimplify.cpp @@ -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(desugar1)) { + if (auto *lvt = dyn_cast(desugar2)) { + return matchTypes(iot->getObjectType(), lvt->getObjectType(), + ConstraintKind::Bind, subflags, + locator.withPathElement( + ConstraintLocator::LValueConversion)); + } + } + } + if (kind >= ConstraintKind::Conversion) { // 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 @@ -7777,7 +7793,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind, } // Special implicit nominal conversions. - if (!type1->is() && kind >= ConstraintKind::Subtype) { + if (!type1->is()) { // Array -> Array. if (desugar1->isArray() && desugar2->isArray()) { 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) { // It is never legal to form an autoclosure that results in these // 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(desugar1)) { - if (auto *lvt = dyn_cast(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 // means a pack expansion was used where it isn't supported. if (type1->is() != type2->is()) {