@@ -22,7 +22,7 @@ using namespace swift;
22
22
using namespace constraints ;
23
23
24
24
void ConstraintSystem::PotentialBindings::inferTransitiveBindings (
25
- ConstraintSystem &cs,
25
+ ConstraintSystem &cs, llvm::SmallPtrSetImpl<CanType> &existingTypes,
26
26
const llvm::SmallDenseMap<TypeVariableType *,
27
27
ConstraintSystem::PotentialBindings>
28
28
&inferredBindings) {
@@ -43,12 +43,6 @@ void ConstraintSystem::PotentialBindings::inferTransitiveBindings(
43
43
if (subtypeOf.empty ())
44
44
return ;
45
45
46
- // We need to make sure that there are no duplicate bindings in the
47
- // set, otherwise solver would produce multiple identical solutions.
48
- llvm::SmallPtrSet<CanType, 4 > existingTypes;
49
- for (const auto &binding : Bindings)
50
- existingTypes.insert (binding.BindingType ->getCanonicalType ());
51
-
52
46
for (auto *constraint : subtypeOf) {
53
47
auto *tv =
54
48
cs.simplifyType (constraint->getFirstType ())->getAs <TypeVariableType>();
@@ -90,6 +84,20 @@ void ConstraintSystem::PotentialBindings::inferTransitiveBindings(
90
84
}
91
85
}
92
86
87
+ void ConstraintSystem::PotentialBindings::finalize (
88
+ ConstraintSystem &cs,
89
+ const llvm::SmallDenseMap<TypeVariableType *,
90
+ ConstraintSystem::PotentialBindings>
91
+ &inferredBindings) {
92
+ // We need to make sure that there are no duplicate bindings in the
93
+ // set, otherwise solver would produce multiple identical solutions.
94
+ llvm::SmallPtrSet<CanType, 4 > existingTypes;
95
+ for (const auto &binding : Bindings)
96
+ existingTypes.insert (binding.BindingType ->getCanonicalType ());
97
+
98
+ inferTransitiveBindings (cs, existingTypes, inferredBindings);
99
+ }
100
+
93
101
Optional<ConstraintSystem::PotentialBindings>
94
102
ConstraintSystem::determineBestBindings () {
95
103
// Look for potential type variable bindings.
@@ -114,7 +122,7 @@ ConstraintSystem::determineBestBindings() {
114
122
115
123
auto &bindings = cachedBindings->getSecond ();
116
124
117
- bindings.inferTransitiveBindings (*this , cache);
125
+ bindings.finalize (*this , cache);
118
126
119
127
if (isDebugMode ()) {
120
128
bindings.dump (typeVar, llvm::errs (), solverState->depth * 2 );
0 commit comments