Skip to content

Commit 5d55dc1

Browse files
committed
[Sema] A small OverloadChoice constructor cleanup
This patch basically just simplifies the constructors, where in 6 out of 8 cases `isSpecialized = false`
1 parent 8c7e75a commit 5d55dc1

File tree

4 files changed

+23
-30
lines changed

4 files changed

+23
-30
lines changed

lib/Sema/CSGen.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,8 +1024,8 @@ namespace {
10241024
auto memberLocator =
10251025
CS.getConstraintLocator(expr, ConstraintLocator::Member);
10261026
auto tv = CS.createTypeVariable(memberLocator, TVO_CanBindToLValue);
1027-
1028-
OverloadChoice choice(base->getType(), decl, /*isSpecialized=*/false, CS);
1027+
1028+
OverloadChoice choice(base->getType(), decl, CS);
10291029
auto locator = CS.getConstraintLocator(expr, ConstraintLocator::Member);
10301030
CS.addBindOverloadConstraint(tv, choice, locator);
10311031
return tv;
@@ -1114,8 +1114,7 @@ namespace {
11141114
// a known subscript here. This might be cleaner if we split off a new
11151115
// UnresolvedSubscriptExpr from SubscriptExpr.
11161116
if (decl) {
1117-
OverloadChoice choice(base->getType(), decl, /*isSpecialized=*/false,
1118-
CS);
1117+
OverloadChoice choice(base->getType(), decl, CS);
11191118
CS.addBindOverloadConstraint(fnTy, choice, subscriptMemberLocator);
11201119
} else {
11211120
CS.addValueMemberConstraint(baseTy, Context.Id_subscript,
@@ -1312,10 +1311,9 @@ namespace {
13121311
// Create an overload choice referencing this declaration and immediately
13131312
// resolve it. This records the overload for use later.
13141313
auto tv = CS.createTypeVariable(locator, TVO_CanBindToLValue);
1315-
CS.resolveOverload(locator, tv,
1316-
OverloadChoice(Type(), E->getDecl(),
1317-
E->isSpecialized(), CS));
1318-
1314+
CS.resolveOverload(locator, tv, OverloadChoice(Type(), E->getDecl(), CS,
1315+
E->isSpecialized()));
1316+
13191317
if (E->getDecl()->getType() &&
13201318
!E->getDecl()->getType()->getAs<TypeVariableType>()) {
13211319
CS.setFavoredType(E, E->getDecl()->getType().getPointer());
@@ -1377,9 +1375,8 @@ namespace {
13771375
if (decls[i]->isInvalid())
13781376
continue;
13791377

1380-
choices.push_back(OverloadChoice(Type(), decls[i],
1381-
expr->isSpecialized(),
1382-
CS));
1378+
choices.push_back(
1379+
OverloadChoice(Type(), decls[i], CS, expr->isSpecialized()));
13831380
}
13841381

13851382
// If there are no valid overloads, give up.

lib/Sema/CSSimplify.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2842,9 +2842,8 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
28422842
}
28432843
}
28442844
}
2845-
2846-
result.addViable(OverloadChoice(baseTy, ctor,
2847-
/*isSpecialized=*/false, *this));
2845+
2846+
result.addViable(OverloadChoice(baseTy, ctor, *this));
28482847
}
28492848

28502849

@@ -2885,9 +2884,8 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
28852884
TC.validateDecl(candidate.first, true);
28862885
if (candidate.first->isInvalid())
28872886
return result.markErrorAlreadyDiagnosed();
2888-
2889-
result.addViable(OverloadChoice(baseTy, candidate.first,
2890-
/*isSpecialized=*/false));
2887+
2888+
result.addViable(OverloadChoice(baseTy, candidate.first));
28912889
}
28922890

28932891
return result;
@@ -3020,8 +3018,7 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
30203018
result.addViable(OverloadChoice::getDeclViaUnwrappedOptional(ovlBaseTy,
30213019
cand));
30223020
} else {
3023-
result.addViable(OverloadChoice(ovlBaseTy, cand,
3024-
/*isSpecialized=*/false, *this));
3021+
result.addViable(OverloadChoice(ovlBaseTy, cand, *this));
30253022
}
30263023
};
30273024

lib/Sema/OverloadChoice.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@
2323
using namespace swift;
2424
using namespace constraints;
2525

26-
OverloadChoice::OverloadChoice(
27-
Type base, ValueDecl *value, bool isSpecialized, ConstraintSystem &CS)
26+
OverloadChoice::OverloadChoice(Type base, ValueDecl *value,
27+
ConstraintSystem &CS, bool isSpecialized)
2828
: BaseAndBits(base, isSpecialized ? IsSpecializedBit : 0) {
2929
assert((reinterpret_cast<uintptr_t>(value) & (uintptr_t)0x03) == 0 &&
3030
"Badly aligned decl");
31-
3231
DeclOrKind = reinterpret_cast<uintptr_t>(value);
3332
}

lib/Sema/OverloadChoice.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class OverloadChoice {
7575
/// optional context type, turning a "Decl" kind into
7676
/// "DeclViaUnwrappedOptional".
7777
IsUnwrappedOptionalBit = 0x04,
78-
78+
7979
// IsBridged and IsUnwrappedOptional are mutually exclusive, so there is
8080
// room for another mutually exclusive OverloadChoiceKind to be packed into
8181
// those two bits.
@@ -95,11 +95,11 @@ class OverloadChoice {
9595
OverloadChoice()
9696
: BaseAndBits(nullptr, 0), DeclOrKind() {}
9797

98-
OverloadChoice(
99-
Type base, ValueDecl *value, bool isSpecialized, ConstraintSystem &CS);
100-
101-
OverloadChoice(Type base, TypeDecl *type, bool isSpecialized)
102-
: BaseAndBits(base, isSpecialized ? IsSpecializedBit : 0) {
98+
OverloadChoice(Type base, ValueDecl *value, ConstraintSystem &CS,
99+
bool isSpecialized = false);
100+
101+
OverloadChoice(Type base, TypeDecl *type, bool isSpecialized = false)
102+
: BaseAndBits(base, isSpecialized ? IsSpecializedBit : 0) {
103103
assert((reinterpret_cast<uintptr_t>(type) & (uintptr_t)0x03) == 0
104104
&& "Badly aligned decl");
105105
DeclOrKind = reinterpret_cast<uintptr_t>(type) | 0x01;
@@ -170,14 +170,14 @@ class OverloadChoice {
170170
/// \brief Determines the kind of overload choice this is.
171171
OverloadChoiceKind getKind() const {
172172
switch (DeclOrKind & 0x03) {
173-
case 0x00:
173+
case 0x00:
174174
if (BaseAndBits.getInt() & IsBridgedBit)
175175
return OverloadChoiceKind::DeclViaBridge;
176176
if (BaseAndBits.getInt() & IsUnwrappedOptionalBit)
177177
return OverloadChoiceKind::DeclViaUnwrappedOptional;
178178

179179
return OverloadChoiceKind::Decl;
180-
180+
181181
case 0x01: return OverloadChoiceKind::TypeDecl;
182182
case 0x02: return OverloadChoiceKind::DeclViaDynamic;
183183
case 0x03: {

0 commit comments

Comments
 (0)