Skip to content

Commit dae1971

Browse files
committed
[ConstraintSystem] NFC: Remove duplicate code from LinkedExprAnalyzer
1 parent 379d88c commit dae1971

File tree

1 file changed

+11
-31
lines changed

1 file changed

+11
-31
lines changed

lib/Sema/CSGen.cpp

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ namespace {
360360
/// expression, attempt to derive a favored type for it.
361361
bool computeFavoredTypeForExpr(Expr *expr, ConstraintSystem &CS) {
362362
LinkedTypeInfo lti;
363-
363+
364364
expr->walk(LinkedExprAnalyzer(lti, CS));
365365

366366
// Link anonymous closure params of the same index.
@@ -381,41 +381,21 @@ namespace {
381381
}
382382
}
383383

384-
// Link integer literal tyvars.
385-
if (lti.intLiteralTyvars.size() > 1) {
386-
auto rep1 = CS.getRepresentative(lti.intLiteralTyvars[0]);
387-
388-
for (size_t i = 1; i < lti.intLiteralTyvars.size(); i++) {
389-
auto rep2 = CS.getRepresentative(lti.intLiteralTyvars[i]);
384+
auto mergeTypeVariables = [&](ArrayRef<TypeVariableType *> typeVars) {
385+
if (typeVars.size() < 2)
386+
return;
390387

388+
auto rep1 = CS.getRepresentative(typeVars.front());
389+
for (unsigned i = 1, n = typeVars.size(); i != n; ++i) {
390+
auto rep2 = CS.getRepresentative(typeVars[i]);
391391
if (rep1 != rep2)
392392
CS.mergeEquivalenceClasses(rep1, rep2, /*updateWorkList*/ false);
393393
}
394-
}
395-
396-
// Link float literal tyvars.
397-
if (lti.floatLiteralTyvars.size() > 1) {
398-
auto rep1 = CS.getRepresentative(lti.floatLiteralTyvars[0]);
399-
400-
for (size_t i = 1; i < lti.floatLiteralTyvars.size(); i++) {
401-
auto rep2 = CS.getRepresentative(lti.floatLiteralTyvars[i]);
402-
403-
if (rep1 != rep2)
404-
CS.mergeEquivalenceClasses(rep1, rep2, /*updateWorkList*/ false);
405-
}
406-
}
407-
408-
// Link string literal tyvars.
409-
if (lti.stringLiteralTyvars.size() > 1) {
410-
auto rep1 = CS.getRepresentative(lti.stringLiteralTyvars[0]);
411-
412-
for (size_t i = 1; i < lti.stringLiteralTyvars.size(); i++) {
413-
auto rep2 = CS.getRepresentative(lti.stringLiteralTyvars[i]);
394+
};
414395

415-
if (rep1 != rep2)
416-
CS.mergeEquivalenceClasses(rep1, rep2, /*updateWorkList*/ false);
417-
}
418-
}
396+
mergeTypeVariables(lti.intLiteralTyvars);
397+
mergeTypeVariables(lti.floatLiteralTyvars);
398+
mergeTypeVariables(lti.stringLiteralTyvars);
419399

420400
if (lti.collectedTypes.size() == 1) {
421401
// TODO: Compute the BCT.

0 commit comments

Comments
 (0)