Skip to content

Commit 31ccd60

Browse files
committed
[ConstraintSystem] Maintain insertion order of all shrunk expressions and their overload sets
1 parent 0ee9e69 commit 31ccd60

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,7 +2278,7 @@ class ConstraintSystem {
22782278
/// domains have been successfully shrunk so far.
22792279
///
22802280
/// \returns true on solver failure, false otherwise.
2281-
bool solve(llvm::SmallDenseSet<OverloadSetRefExpr *> &shrunkExprs);
2281+
bool solve(llvm::SmallSetVector<OverloadSetRefExpr *, 4> &shrunkExprs);
22822282

22832283
/// Apply solutions found by solver as reduced OSR sets for
22842284
/// for current and all of it's sub-expressions.
@@ -2290,14 +2290,14 @@ class ConstraintSystem {
22902290
/// domains have been successfully shrunk so far.
22912291
void applySolutions(
22922292
llvm::SmallVectorImpl<Solution> &solutions,
2293-
llvm::SmallDenseSet<OverloadSetRefExpr *> &shrunkExprs) const;
2293+
llvm::SmallSetVector<OverloadSetRefExpr *, 4> &shrunkExprs) const;
22942294

22952295
/// Check if attempt at solving of the candidate makes sense given
22962296
/// the current conditions - number of shrunk domains which is related
22972297
/// to the given candidate over the total number of disjunctions present.
22982298
static bool
22992299
isTooComplexGiven(ConstraintSystem *const cs,
2300-
llvm::SmallDenseSet<OverloadSetRefExpr *> &shrunkExprs) {
2300+
llvm::SmallSetVector<OverloadSetRefExpr *, 4> &shrunkExprs) {
23012301
SmallVector<Constraint *, 8> disjunctions;
23022302
cs->collectDisjunctions(disjunctions);
23032303

lib/Sema/CSSolver.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ ConstraintSystem::solveSingle(FreeTypeVariableBinding allowFreeTypeVariables,
610610
}
611611

612612
bool ConstraintSystem::Candidate::solve(
613-
llvm::SmallDenseSet<OverloadSetRefExpr *> &shrunkExprs) {
613+
llvm::SmallSetVector<OverloadSetRefExpr *, 4> &shrunkExprs) {
614614
// Don't attempt to solve candidate if there is closure
615615
// expression involved, because it's handled specially
616616
// by parent constraint system (e.g. parameter lists).
@@ -722,11 +722,11 @@ bool ConstraintSystem::Candidate::solve(
722722

723723
void ConstraintSystem::Candidate::applySolutions(
724724
llvm::SmallVectorImpl<Solution> &solutions,
725-
llvm::SmallDenseSet<OverloadSetRefExpr *> &shrunkExprs) const {
725+
llvm::SmallSetVector<OverloadSetRefExpr *, 4> &shrunkExprs) const {
726726
// A collection of OSRs with their newly reduced domains,
727727
// it's domains are sets because multiple solutions can have the same
728728
// choice for one of the type variables, and we want no duplication.
729-
llvm::SmallDenseMap<OverloadSetRefExpr *, llvm::SmallSet<ValueDecl *, 2>>
729+
llvm::SmallDenseMap<OverloadSetRefExpr *, llvm::SmallSetVector<ValueDecl *, 2>>
730730
domains;
731731
for (auto &solution : solutions) {
732732
for (auto choice : solution.overloadChoices) {
@@ -743,7 +743,7 @@ void ConstraintSystem::Candidate::applySolutions(
743743
auto overload = choice.getSecond().choice;
744744
auto type = overload.getDecl()->getInterfaceType();
745745

746-
// One of the solutions has polymorphic type assigned with one of it's
746+
// One of the solutions has polymorphic type associated with one of its
747747
// type variables. Such functions can only be properly resolved
748748
// via complete expression, so we'll have to forget solutions
749749
// we have already recorded. They might not include all viable overload
@@ -1094,7 +1094,7 @@ void ConstraintSystem::shrink(Expr *expr) {
10941094
// so we can start solving them separately.
10951095
expr->walk(collector);
10961096

1097-
llvm::SmallDenseSet<OverloadSetRefExpr *> shrunkExprs;
1097+
llvm::SmallSetVector<OverloadSetRefExpr *, 4> shrunkExprs;
10981098
for (auto &candidate : collector.Candidates) {
10991099
// If there are no results, let's forget everything we know about the
11001100
// system so far. This actually is ok, because some of the expressions
@@ -1110,7 +1110,7 @@ void ConstraintSystem::shrink(Expr *expr) {
11101110
return childExpr;
11111111

11121112
OSR->setDecls(domain->getSecond());
1113-
shrunkExprs.erase(OSR);
1113+
shrunkExprs.remove(OSR);
11141114
}
11151115

11161116
return childExpr;

0 commit comments

Comments
 (0)