Skip to content

Commit 81d87f9

Browse files
authored
Merge pull request swiftlang#33412 from hborla/remove-default-literal-favoring
[CSGen] Remove favoring based on literals from computeFavoredTypeForExpr
2 parents cb537b4 + cb4782c commit 81d87f9

File tree

1 file changed

+5
-63
lines changed

1 file changed

+5
-63
lines changed

lib/Sema/CSGen.cpp

Lines changed: 5 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,10 @@ namespace {
7979
/// Internal struct for tracking information about types within a series
8080
/// of "linked" expressions. (Such as a chain of binary operator invocations.)
8181
struct LinkedTypeInfo {
82-
unsigned haveIntLiteral : 1;
83-
unsigned haveFloatLiteral : 1;
84-
unsigned haveStringLiteral : 1;
82+
bool hasLiteral = false;
8583

8684
llvm::SmallSet<TypeBase*, 16> collectedTypes;
8785
llvm::SmallVector<BinaryExpr *, 4> binaryExprs;
88-
89-
LinkedTypeInfo() {
90-
haveIntLiteral = false;
91-
haveFloatLiteral = false;
92-
haveStringLiteral = false;
93-
}
94-
95-
bool hasLiteral() {
96-
return haveIntLiteral || haveFloatLiteral || haveStringLiteral;
97-
}
9886
};
9987

10088
/// Walks an expression sub-tree, and collects information about expressions
@@ -180,19 +168,9 @@ namespace {
180168
!CS.getType(expr)->hasTypeVariable()) {
181169
return { false, expr };
182170
}
183-
184-
if (isa<IntegerLiteralExpr>(expr)) {
185-
LTI.haveIntLiteral = true;
186-
return { false, expr };
187-
}
188-
189-
if (isa<FloatLiteralExpr>(expr)) {
190-
LTI.haveFloatLiteral = true;
191-
return { false, expr };
192-
}
193-
194-
if (isa<StringLiteralExpr>(expr)) {
195-
LTI.haveStringLiteral = true;
171+
172+
if (isa<LiteralExpr>(expr)) {
173+
LTI.hasLiteral = true;
196174
return { false, expr };
197175
}
198176

@@ -331,7 +309,7 @@ namespace {
331309
auto simplifyBinOpExprTyVars = [&]() {
332310
// Don't attempt to do linking if there are
333311
// literals intermingled with other inferred types.
334-
if (lti.hasLiteral())
312+
if (lti.hasLiteral)
335313
return;
336314

337315
for (auto binExp1 : lti.binaryExprs) {
@@ -391,42 +369,6 @@ namespace {
391369
simplifyBinOpExprTyVars();
392370

393371
return true;
394-
}
395-
396-
if (lti.haveFloatLiteral) {
397-
if (auto floatProto = CS.getASTContext().getProtocol(
398-
KnownProtocolKind::ExpressibleByFloatLiteral)) {
399-
if (auto defaultType = TypeChecker::getDefaultType(floatProto, CS.DC)) {
400-
if (!CS.getFavoredType(expr)) {
401-
CS.setFavoredType(expr, defaultType.getPointer());
402-
}
403-
return true;
404-
}
405-
}
406-
}
407-
408-
if (lti.haveIntLiteral) {
409-
if (auto intProto = CS.getASTContext().getProtocol(
410-
KnownProtocolKind::ExpressibleByIntegerLiteral)) {
411-
if (auto defaultType = TypeChecker::getDefaultType(intProto, CS.DC)) {
412-
if (!CS.getFavoredType(expr)) {
413-
CS.setFavoredType(expr, defaultType.getPointer());
414-
}
415-
return true;
416-
}
417-
}
418-
}
419-
420-
if (lti.haveStringLiteral) {
421-
if (auto stringProto = CS.getASTContext().getProtocol(
422-
KnownProtocolKind::ExpressibleByStringLiteral)) {
423-
if (auto defTy = TypeChecker::getDefaultType(stringProto, CS.DC)) {
424-
if (!CS.getFavoredType(expr)) {
425-
CS.setFavoredType(expr, defTy.getPointer());
426-
}
427-
return true;
428-
}
429-
}
430372
}
431373

432374
return false;

0 commit comments

Comments
 (0)