Skip to content

Commit 592a7da

Browse files
committed
Sema: Move some code from canPossiblyConvertTo() to isLikelyExactMatch()
1 parent df75037 commit 592a7da

3 files changed

Lines changed: 20 additions & 23 deletions

File tree

include/swift/Sema/Subtyping.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,15 @@ bool hasConversions(Type type);
6161
enum ConflictFlag : unsigned {
6262
Category = 1 << 0,
6363
Exact = 1 << 1,
64-
Nominal = 1 << 2,
65-
Class = 1 << 3,
66-
Structural = 1 << 4,
67-
Array = 1 << 5,
68-
Dictionary = 1 << 6,
69-
Set = 1 << 7,
70-
Optional = 1 << 8,
71-
Double = 1 << 9,
72-
Conformance = 1 << 10,
73-
Mutability = 1 << 11
64+
Class = 1 << 2,
65+
Structural = 1 << 3,
66+
Array = 1 << 4,
67+
Dictionary = 1 << 5,
68+
Set = 1 << 6,
69+
Optional = 1 << 7,
70+
Double = 1 << 8,
71+
Conformance = 1 << 9,
72+
Mutability = 1 << 10
7473
};
7574
using ConflictReason = OptionSet<ConflictFlag>;
7675

lib/Sema/CSLookahead.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,6 @@ static void pruneDisjunctionImpl(
230230
llvm::errs() << " category";
231231
if (reason.contains(ConflictFlag::Exact))
232232
llvm::errs() << " exact";
233-
if (reason.contains(ConflictFlag::Nominal))
234-
llvm::errs() << " nominal";
235233
if (reason.contains(ConflictFlag::Class))
236234
llvm::errs() << " class";
237235
if (reason.contains(ConflictFlag::Structural))

lib/Sema/Subtyping.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,18 @@ using namespace swift;
3030
using namespace constraints;
3131

3232
std::optional<bool>
33-
swift::constraints::isLikelyExactMatch(Type first, Type second) {
34-
if (auto *firstDecl = first->getAnyNominal()) {
33+
swift::constraints::isLikelyExactMatch(Type lhs, Type rhs) {
34+
if (!lhs->hasTypeVariable() && !lhs->hasTypeParameter() &&
35+
!rhs->hasTypeVariable() && !rhs->hasTypeParameter()) {
36+
return lhs->isEqual(rhs);
37+
}
38+
39+
if (auto *lhsDecl = lhs->getAnyNominal()) {
3540
// FIXME: Make this more precise.
36-
auto *secondDecl = second->getAnyNominal();
37-
return firstDecl == secondDecl;
41+
auto *rhsDecl = rhs->getAnyNominal();
42+
return lhsDecl == rhsDecl;
3843
}
44+
3945
// FIXME: Handle other type kinds.
4046
return std::nullopt;
4147
}
@@ -139,15 +145,9 @@ ConflictReason swift::constraints::canPossiblyConvertTo(
139145
if (lhsKind == rhsKind) {
140146
switch (lhsKind) {
141147
case ConversionBehavior::None: {
142-
if (!lhs->hasTypeVariable() && !lhs->hasTypeParameter() &&
143-
!rhs->hasTypeVariable() && !rhs->hasTypeParameter()) {
144-
if (!lhs->isEqual(rhs))
145-
return ConflictFlag::Exact;
146-
}
147-
148148
auto result = isLikelyExactMatch(lhs, rhs);
149149
if (result.has_value() && !*result)
150-
return ConflictFlag::Nominal;
150+
return ConflictFlag::Exact;
151151

152152
break;
153153
}

0 commit comments

Comments
 (0)