Skip to content

Commit 03b6b41

Browse files
committed
[CSBindings] NFC: Don't pass constraint system as an argument to infer* methods
`PotentialBindings` already reference the constraint system they belong to, so there is no need to pass it as an argument to inference methods.
1 parent aa887fd commit 03b6b41

File tree

4 files changed

+16
-25
lines changed

4 files changed

+16
-25
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5040,12 +5040,9 @@ class ConstraintSystem {
50405040
///
50415041
/// Which gives us a new (superclass A) binding for T2 as well as T1.
50425042
///
5043-
/// \param cs The constraint system this type variable is associated with.
5044-
///
50455043
/// \param inferredBindings The set of all bindings inferred for type
50465044
/// variables in the workset.
50475045
void inferTransitiveBindings(
5048-
ConstraintSystem &cs,
50495046
const llvm::SmallDenseMap<TypeVariableType *,
50505047
ConstraintSystem::PotentialBindings>
50515048
&inferredBindings);
@@ -5054,18 +5051,16 @@ class ConstraintSystem {
50545051
/// between two type variables and attempt to propagate protocol
50555052
/// requirements down the subtype or equivalence chain.
50565053
void inferTransitiveProtocolRequirements(
5057-
const ConstraintSystem &cs,
50585054
llvm::SmallDenseMap<TypeVariableType *,
50595055
ConstraintSystem::PotentialBindings>
50605056
&inferredBindings);
50615057

50625058
public:
5063-
bool infer(ConstraintSystem &cs, Constraint *constraint);
5059+
bool infer(Constraint *constraint);
50645060

50655061
/// Finalize binding computation for this type variable by
50665062
/// inferring bindings from context e.g. transitive bindings.
5067-
void finalize(ConstraintSystem &cs,
5068-
llvm::SmallDenseMap<TypeVariableType *,
5063+
void finalize(llvm::SmallDenseMap<TypeVariableType *,
50695064
ConstraintSystem::PotentialBindings>
50705065
&inferredBindings);
50715066

lib/Sema/CSBindings.cpp

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ bool ConstraintSystem::PotentialBindings::isPotentiallyIncomplete() const {
152152
}
153153

154154
void ConstraintSystem::PotentialBindings::inferTransitiveProtocolRequirements(
155-
const ConstraintSystem &cs,
156155
llvm::SmallDenseMap<TypeVariableType *, ConstraintSystem::PotentialBindings>
157156
&inferredBindings) {
158157
if (TransitiveProtocols)
@@ -283,7 +282,6 @@ void ConstraintSystem::PotentialBindings::inferTransitiveProtocolRequirements(
283282
}
284283

285284
void ConstraintSystem::PotentialBindings::inferTransitiveBindings(
286-
ConstraintSystem &cs,
287285
const llvm::SmallDenseMap<TypeVariableType *,
288286
ConstraintSystem::PotentialBindings>
289287
&inferredBindings) {
@@ -353,11 +351,10 @@ void ConstraintSystem::PotentialBindings::inferTransitiveBindings(
353351
}
354352

355353
void ConstraintSystem::PotentialBindings::finalize(
356-
ConstraintSystem &cs,
357354
llvm::SmallDenseMap<TypeVariableType *, ConstraintSystem::PotentialBindings>
358355
&inferredBindings) {
359-
inferTransitiveProtocolRequirements(cs, inferredBindings);
360-
inferTransitiveBindings(cs, inferredBindings);
356+
inferTransitiveProtocolRequirements(inferredBindings);
357+
inferTransitiveBindings(inferredBindings);
361358
}
362359

363360
Optional<ConstraintSystem::PotentialBindings>
@@ -411,7 +408,7 @@ ConstraintSystem::determineBestBindings() {
411408
// produce a default type.
412409
bool isViable = isViableForRanking(bindings);
413410

414-
bindings.finalize(*this, cache);
411+
bindings.finalize(cache);
415412

416413
if (!bindings || !isViable)
417414
continue;
@@ -775,7 +772,7 @@ ConstraintSystem::inferBindingsFor(TypeVariableType *typeVar, bool finalize) {
775772
typeVar, ConstraintGraph::GatheringKind::EquivalenceClass);
776773

777774
for (auto *constraint : constraints) {
778-
bool failed = bindings.infer(*this, constraint);
775+
bool failed = bindings.infer(constraint);
779776

780777
// Upon inference failure let's produce an empty set of bindings.
781778
if (failed)
@@ -786,7 +783,7 @@ ConstraintSystem::inferBindingsFor(TypeVariableType *typeVar, bool finalize) {
786783
llvm::SmallDenseMap<TypeVariableType *, ConstraintSystem::PotentialBindings>
787784
inferred;
788785

789-
bindings.finalize(*this, inferred);
786+
bindings.finalize(inferred);
790787
}
791788

792789
return bindings;
@@ -995,8 +992,7 @@ ConstraintSystem::getPotentialBindingForRelationalConstraint(
995992
/// Retrieve the set of potential type bindings for the given
996993
/// representative type variable, along with flags indicating whether
997994
/// those types should be opened.
998-
bool ConstraintSystem::PotentialBindings::infer(ConstraintSystem &cs,
999-
Constraint *constraint) {
995+
bool ConstraintSystem::PotentialBindings::infer(Constraint *constraint) {
1000996
switch (constraint->getKind()) {
1001997
case ConstraintKind::Bind:
1002998
case ConstraintKind::Equal:
@@ -1008,7 +1004,7 @@ bool ConstraintSystem::PotentialBindings::infer(ConstraintSystem &cs,
10081004
case ConstraintKind::OperatorArgumentConversion:
10091005
case ConstraintKind::OptionalObject: {
10101006
auto binding =
1011-
cs.getPotentialBindingForRelationalConstraint(*this, constraint);
1007+
CS.getPotentialBindingForRelationalConstraint(*this, constraint);
10121008
if (!binding)
10131009
break;
10141010

@@ -1036,7 +1032,7 @@ bool ConstraintSystem::PotentialBindings::infer(ConstraintSystem &cs,
10361032
// let's have it try `Void` as well because there is an
10371033
// implicit conversion `() -> T` to `() -> Void` and this
10381034
// helps to avoid creating a thunk to support it.
1039-
auto voidType = cs.getASTContext().TheEmptyTupleType;
1035+
auto voidType = CS.getASTContext().TheEmptyTupleType;
10401036
if (locator->isLastElement<LocatorPathElt::ClosureResult>() &&
10411037
binding->Kind == AllowedBindingKind::Supertypes) {
10421038
(void)addPotentialBinding({voidType, binding->Kind, constraint},
@@ -1053,7 +1049,7 @@ bool ConstraintSystem::PotentialBindings::infer(ConstraintSystem &cs,
10531049
// we try to bind the key path type first, which can allow us to discover
10541050
// additional bindings for the result type.
10551051
SmallPtrSet<TypeVariableType *, 4> typeVars;
1056-
findInferableTypeVars(cs.simplifyType(constraint->getThirdType()),
1052+
findInferableTypeVars(CS.simplifyType(constraint->getThirdType()),
10571053
typeVars);
10581054
if (typeVars.count(TypeVar)) {
10591055
DelayedBy.push_back(constraint);
@@ -1092,7 +1088,7 @@ bool ConstraintSystem::PotentialBindings::infer(ConstraintSystem &cs,
10921088
case ConstraintKind::Defaultable:
10931089
case ConstraintKind::DefaultClosureType:
10941090
// Do these in a separate pass.
1095-
if (cs.getFixedTypeRecursive(constraint->getFirstType(), true)
1091+
if (CS.getFixedTypeRecursive(constraint->getFirstType(), true)
10961092
->getAs<TypeVariableType>() == TypeVar) {
10971093
addDefault(constraint);
10981094
}
@@ -1133,9 +1129,9 @@ bool ConstraintSystem::PotentialBindings::infer(ConstraintSystem &cs,
11331129
// and if so it would be beneficial to bind member to a hole
11341130
// early to propagate that information down to arguments,
11351131
// result type of a call that references such a member.
1136-
if (cs.shouldAttemptFixes() && TypeVar->getImpl().canBindToHole()) {
1132+
if (CS.shouldAttemptFixes() && TypeVar->getImpl().canBindToHole()) {
11371133
if (ConstraintSystem::typeVarOccursInType(
1138-
TypeVar, cs.simplifyType(constraint->getSecondType())))
1134+
TypeVar, CS.simplifyType(constraint->getSecondType())))
11391135
break;
11401136
}
11411137

unittests/Sema/BindingInferenceTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ TEST_F(SemaTest, TestIntLiteralBindingInference) {
128128
env;
129129
env.insert({floatLiteralTy, cs.inferBindingsFor(floatLiteralTy)});
130130

131-
bindings.finalize(cs, env);
131+
bindings.finalize(env);
132132

133133
// Inferred a single transitive binding through `$T_float`.
134134
ASSERT_EQ(bindings.Bindings.size(), (unsigned)1);

unittests/Sema/SemaFixture.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ SemaTest::inferBindings(ConstraintSystem &cs, TypeVariableType *typeVar) {
136136
continue;
137137

138138
auto &bindings = cachedBindings->getSecond();
139-
bindings.finalize(cs, cache);
139+
bindings.finalize(cache);
140140
}
141141

142142
auto result = cache.find(typeVar);

0 commit comments

Comments
 (0)