Skip to content

Commit 6ea39d2

Browse files
committed
Sema: Sink PotentialBindings::Literals down into BindingSet
1 parent 466c770 commit 6ea39d2

File tree

2 files changed

+15
-32
lines changed

2 files changed

+15
-32
lines changed

include/swift/Sema/CSBindings.h

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

227-
/// The set of unique literal protocol requirements placed on this
228-
/// type variable or inferred transitively through subtype chains.
229-
///
230-
/// Note that ordering is important when it comes to bindings, we'd
231-
/// like to add any "direct" default types first to attempt them
232-
/// before transitive ones.
233-
llvm::SmallPtrSet<Constraint *, 2> Literals;
234-
235227
/// The set of constraints which would be used to infer default types.
236228
llvm::SmallPtrSet<Constraint *, 2> Defaults;
237229

@@ -259,8 +251,6 @@ struct PotentialBindings {
259251

260252
void addDefault(Constraint *constraint);
261253

262-
void addLiteral(Constraint *constraint);
263-
264254
/// Add a potential binding to the list of bindings,
265255
/// coalescing supertype bounds when we are able to compute the meet.
266256
void addPotentialBinding(TypeVariableType *typeVar, PotentialBinding binding);
@@ -386,7 +376,14 @@ class BindingSet {
386376
/// The set of protocol conformance requirements placed on this type variable.
387377
llvm::SmallVector<Constraint *, 4> Protocols;
388378

379+
/// The set of unique literal protocol requirements placed on this
380+
/// type variable or inferred transitively through subtype chains.
381+
///
382+
/// Note that ordering is important when it comes to bindings, we'd
383+
/// like to add any "direct" default types first to attempt them
384+
/// before transitive ones.
389385
llvm::SmallMapVector<ProtocolDecl *, LiteralRequirement, 2> Literals;
386+
390387
llvm::SmallDenseMap<CanType, Constraint *, 2> Defaults;
391388

392389
/// The set of transitive protocol requirements inferred through

lib/Sema/CSBindings.cpp

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,26 @@ static std::optional<Type> checkTypeOfBinding(TypeVariableType *typeVar,
5050
BindingSet::BindingSet(ConstraintSystem &CS, TypeVariableType *TypeVar,
5151
const PotentialBindings &info)
5252
: CS(CS), TypeVar(TypeVar), Info(info) {
53+
5354
for (const auto &binding : info.Bindings)
5455
addBinding(binding, /*isTransitive=*/false);
5556

5657
for (auto *constraint : info.Constraints) {
5758
switch (constraint->getKind()) {
58-
case ConstraintKind::ConformsTo: {
59+
case ConstraintKind::ConformsTo:
5960
if (constraint->getSecondType()->is<ProtocolType>())
6061
Protocols.push_back(constraint);
6162
break;
62-
}
63+
64+
case ConstraintKind::LiteralConformsTo:
65+
addLiteralRequirement(constraint);
66+
break;
67+
6368
default:
6469
break;
6570
}
6671
}
6772

68-
for (auto *literal : info.Literals)
69-
addLiteralRequirement(literal);
70-
7173
for (auto *constraint : info.Defaults)
7274
addDefault(constraint);
7375

@@ -1311,10 +1313,6 @@ void PotentialBindings::addPotentialBinding(TypeVariableType *TypeVar,
13111313
Bindings.push_back(std::move(binding));
13121314
}
13131315

1314-
void PotentialBindings::addLiteral(Constraint *constraint) {
1315-
Literals.insert(constraint);
1316-
}
1317-
13181316
bool BindingSet::isViable(PotentialBinding &binding, bool isTransitive) {
13191317
// Prevent against checking against the same opened nominal type
13201318
// over and over again. Doing so means redundant work in the best
@@ -1969,6 +1967,7 @@ void PotentialBindings::infer(ConstraintSystem &CS,
19691967
case ConstraintKind::SameShape:
19701968
case ConstraintKind::MaterializePackExpansion:
19711969
case ConstraintKind::ConformsTo:
1970+
case ConstraintKind::LiteralConformsTo:
19721971
// Constraints from which we can't do anything.
19731972
break;
19741973

@@ -2009,13 +2008,6 @@ void PotentialBindings::infer(ConstraintSystem &CS,
20092008
DelayedBy.push_back(constraint);
20102009
break;
20112010

2012-
case ConstraintKind::LiteralConformsTo: {
2013-
// Record constraint where protocol requirement originated
2014-
// this is useful to use for the binding later.
2015-
addLiteral(constraint);
2016-
break;
2017-
}
2018-
20192011
case ConstraintKind::ApplicableFunction:
20202012
case ConstraintKind::DynamicCallableApplicableFunction: {
20212013
auto overloadTy = constraint->getSecondType();
@@ -2090,7 +2082,6 @@ void PotentialBindings::retract(ConstraintSystem &CS,
20902082

20912083
LLVM_DEBUG(
20922084
llvm::dbgs() << Constraints.size() << " " << Bindings.size() << " "
2093-
<< Literals.size() << " "
20942085
<< AdjacentVars.size() << " " << DelayedBy.size() << " "
20952086
<< SubtypeOf.size() << " " << SupertypeOf.size() << " "
20962087
<< EquivalentTo.size() << "\n");
@@ -2103,10 +2094,6 @@ void PotentialBindings::retract(ConstraintSystem &CS,
21032094
Bindings.end());
21042095

21052096
switch (constraint->getKind()) {
2106-
case ConstraintKind::LiteralConformsTo:
2107-
Literals.erase(constraint);
2108-
break;
2109-
21102097
case ConstraintKind::Defaultable:
21112098
case ConstraintKind::FallbackType: {
21122099
Defaults.erase(constraint);
@@ -2150,7 +2137,6 @@ void PotentialBindings::reset() {
21502137
if (CONDITIONAL_ASSERT_enabled()) {
21512138
ASSERT(Constraints.empty());
21522139
ASSERT(Bindings.empty());
2153-
ASSERT(Literals.empty());
21542140
ASSERT(Defaults.empty());
21552141
ASSERT(DelayedBy.empty());
21562142
ASSERT(AdjacentVars.empty());

0 commit comments

Comments
 (0)