Skip to content

Commit 4b1cb12

Browse files
committed
Sema: Sink PotentialBindings::Defaults down into BindingSet
1 parent 6ea39d2 commit 4b1cb12

File tree

2 files changed

+11
-33
lines changed

2 files changed

+11
-33
lines changed

include/swift/Sema/CSBindings.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,6 @@ struct PotentialBindings {
224224
/// The set of potential bindings.
225225
llvm::SmallVector<PotentialBinding, 4> Bindings;
226226

227-
/// The set of constraints which would be used to infer default types.
228-
llvm::SmallPtrSet<Constraint *, 2> Defaults;
229-
230227
/// The set of constraints which delay attempting this type variable.
231228
llvm::TinyPtrVector<Constraint *> DelayedBy;
232229

@@ -249,8 +246,6 @@ struct PotentialBindings {
249246
llvm::SmallSetVector<std::pair<TypeVariableType *, Constraint *>, 4> SupertypeOf;
250247
llvm::SmallSetVector<std::pair<TypeVariableType *, Constraint *>, 4> EquivalentTo;
251248

252-
void addDefault(Constraint *constraint);
253-
254249
/// Add a potential binding to the list of bindings,
255250
/// coalescing supertype bounds when we are able to compute the meet.
256251
void addPotentialBinding(TypeVariableType *typeVar, PotentialBinding binding);

lib/Sema/CSBindings.cpp

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,20 @@ BindingSet::BindingSet(ConstraintSystem &CS, TypeVariableType *TypeVar,
6565
addLiteralRequirement(constraint);
6666
break;
6767

68+
case ConstraintKind::Defaultable:
69+
case ConstraintKind::FallbackType:
70+
// Do these in a separate pass.
71+
if (CS.getFixedTypeRecursive(constraint->getFirstType(), true)
72+
->getAs<TypeVariableType>() == TypeVar) {
73+
addDefault(constraint);
74+
}
75+
break;
76+
6877
default:
6978
break;
7079
}
7180
}
7281

73-
for (auto *constraint : info.Defaults)
74-
addDefault(constraint);
75-
7682
for (auto &entry : info.AdjacentVars)
7783
AdjacentVars.insert(entry.first);
7884
}
@@ -1215,10 +1221,6 @@ findInferableTypeVars(Type type,
12151221
type.walk(Walker(typeVars));
12161222
}
12171223

1218-
void PotentialBindings::addDefault(Constraint *constraint) {
1219-
Defaults.insert(constraint);
1220-
}
1221-
12221224
void BindingSet::addDefault(Constraint *constraint) {
12231225
auto defaultTy = constraint->getSecondType();
12241226
Defaults.insert({defaultTy->getCanonicalType(), constraint});
@@ -1968,6 +1970,8 @@ void PotentialBindings::infer(ConstraintSystem &CS,
19681970
case ConstraintKind::MaterializePackExpansion:
19691971
case ConstraintKind::ConformsTo:
19701972
case ConstraintKind::LiteralConformsTo:
1973+
case ConstraintKind::Defaultable:
1974+
case ConstraintKind::FallbackType:
19711975
// Constraints from which we can't do anything.
19721976
break;
19731977

@@ -1995,15 +1999,6 @@ void PotentialBindings::infer(ConstraintSystem &CS,
19951999
break;
19962000
}
19972001

1998-
case ConstraintKind::Defaultable:
1999-
case ConstraintKind::FallbackType:
2000-
// Do these in a separate pass.
2001-
if (CS.getFixedTypeRecursive(constraint->getFirstType(), true)
2002-
->getAs<TypeVariableType>() == TypeVar) {
2003-
addDefault(constraint);
2004-
}
2005-
break;
2006-
20072002
case ConstraintKind::Disjunction:
20082003
DelayedBy.push_back(constraint);
20092004
break;
@@ -2093,17 +2088,6 @@ void PotentialBindings::retract(ConstraintSystem &CS,
20932088
}),
20942089
Bindings.end());
20952090

2096-
switch (constraint->getKind()) {
2097-
case ConstraintKind::Defaultable:
2098-
case ConstraintKind::FallbackType: {
2099-
Defaults.erase(constraint);
2100-
break;
2101-
}
2102-
2103-
default:
2104-
break;
2105-
}
2106-
21072091
{
21082092
llvm::SmallPtrSet<TypeVariableType *, 2> unviable;
21092093
for (const auto &adjacent : AdjacentVars) {
@@ -2137,7 +2121,6 @@ void PotentialBindings::reset() {
21372121
if (CONDITIONAL_ASSERT_enabled()) {
21382122
ASSERT(Constraints.empty());
21392123
ASSERT(Bindings.empty());
2140-
ASSERT(Defaults.empty());
21412124
ASSERT(DelayedBy.empty());
21422125
ASSERT(AdjacentVars.empty());
21432126
ASSERT(SubtypeOf.empty());

0 commit comments

Comments
 (0)