Skip to content

Commit c8e2dc1

Browse files
authored
Merge pull request #38788 from hamishknight/literally
Remove some obsolete literal handling logic
2 parents 923c69d + e82edad commit c8e2dc1

File tree

3 files changed

+4
-71
lines changed

3 files changed

+4
-71
lines changed

lib/SILOptimizer/Utils/ConstantFolding.cpp

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -875,28 +875,7 @@ constantFoldAndCheckIntegerConversions(BuiltinInst *BI,
875875
template<unsigned N>
876876
static bool tryExtractLiteralText(FloatLiteralInst *flitInst,
877877
SmallString<N> &fpStr) {
878-
879-
Expr *expr = flitInst->getLoc().getAsASTNode<Expr>();
880-
if (!expr)
881-
return false;
882-
883-
// 'expr' may not be a FloatLiteralExpr since 'flitInst' could have been
884-
// created by the ConstantFolder by folding floating-point constructor calls.
885-
// So we iterate through the sequence of folded constructors if any, and
886-
// try to extract the FloatLiteralExpr.
887-
while (auto *callExpr = dyn_cast<CallExpr>(expr)) {
888-
if (callExpr->getNumArguments() != 1 ||
889-
!dyn_cast<ConstructorRefCallExpr>(callExpr->getFn()))
890-
break;
891-
892-
auto *tupleExpr = dyn_cast<TupleExpr>(callExpr->getArg());
893-
if (!tupleExpr)
894-
break;
895-
896-
expr = tupleExpr->getElement(0);
897-
}
898-
899-
auto *flitExpr = dyn_cast<FloatLiteralExpr>(expr);
878+
auto *flitExpr = flitInst->getLoc().getAsASTNode<FloatLiteralExpr>();
900879
if (!flitExpr)
901880
return false;
902881

@@ -1074,27 +1053,8 @@ bool isLossyUnderflow(APFloat srcVal, BuiltinFloatType *srcType,
10741053
/// This function determines whether the float literal in the given
10751054
/// SIL instruction is specified using hex-float notation in the Swift source.
10761055
bool isHexLiteralInSource(FloatLiteralInst *flitInst) {
1077-
Expr *expr = flitInst->getLoc().getAsASTNode<Expr>();
1078-
if (!expr)
1079-
return false;
1080-
1081-
// Iterate through a sequence of folded implicit constructors if any, and
1082-
// try to extract the FloatLiteralExpr.
1083-
while (auto *callExpr = dyn_cast<CallExpr>(expr)) {
1084-
if (!callExpr->isImplicit() || callExpr->getNumArguments() != 1 ||
1085-
!dyn_cast<ConstructorRefCallExpr>(callExpr->getFn()))
1086-
break;
1087-
1088-
auto *tupleExpr = dyn_cast<TupleExpr>(callExpr->getArg());
1089-
if (!tupleExpr)
1090-
break;
1091-
1092-
expr = tupleExpr->getElement(0);
1093-
}
1094-
auto *flitExpr = dyn_cast<FloatLiteralExpr>(expr);
1095-
if (!flitExpr)
1096-
return false;
1097-
return flitExpr->getDigitsText().startswith("0x");
1056+
auto *flitExpr = flitInst->getLoc().getAsASTNode<FloatLiteralExpr>();
1057+
return flitExpr && flitExpr->getDigitsText().startswith("0x");
10981058
}
10991059

11001060
bool maybeExplicitFPCons(BuiltinInst *BI, const BuiltinInfo &Builtin) {

lib/Sema/CSDiagnostics.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,19 +1988,6 @@ bool AssignmentFailure::diagnoseAsError() {
19881988
// If the expression is the result of a call, it is an rvalue, not a mutable
19891989
// lvalue.
19901990
if (auto *AE = dyn_cast<ApplyExpr>(immutableExpr)) {
1991-
// Handle literals, which are a call to the conversion function.
1992-
auto argsTuple =
1993-
dyn_cast<TupleExpr>(AE->getArg()->getSemanticsProvidingExpr());
1994-
if (isa<CallExpr>(AE) && AE->isImplicit() && argsTuple &&
1995-
argsTuple->getNumElements() == 1) {
1996-
if (auto LE = dyn_cast<LiteralExpr>(
1997-
argsTuple->getElement(0)->getSemanticsProvidingExpr())) {
1998-
emitDiagnosticAt(Loc, DeclDiagnostic, "literals are not mutable")
1999-
.highlight(LE->getSourceRange());
2000-
return true;
2001-
}
2002-
}
2003-
20041991
std::string name = "call";
20051992
if (isa<PrefixUnaryExpr>(AE) || isa<PostfixUnaryExpr>(AE))
20061993
name = "unary operator";

lib/Sema/TypeCheckStmt.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,21 +1421,7 @@ void TypeChecker::checkIgnoredExpr(Expr *E) {
14211421

14221422
// Otherwise, complain. Start with more specific diagnostics.
14231423

1424-
// Diagnose unused literals that were translated to implicit
1425-
// constructor calls during CSApply / ExprRewriter::convertLiteral.
1426-
if (call->isImplicit()) {
1427-
Expr *arg = call->getArg();
1428-
if (auto *TE = dyn_cast<TupleExpr>(arg))
1429-
if (TE->getNumElements() == 1)
1430-
arg = TE->getElement(0);
1431-
1432-
if (auto *LE = dyn_cast<LiteralExpr>(arg)) {
1433-
diagnoseIgnoredLiteral(Context, LE);
1434-
return;
1435-
}
1436-
}
1437-
1438-
// Other unused constructor calls.
1424+
// Diagnose unused constructor calls.
14391425
if (callee && isa<ConstructorDecl>(callee) && !call->isImplicit()) {
14401426
DE.diagnose(fn->getLoc(), diag::expression_unused_init_result,
14411427
callee->getDeclContext()->getDeclaredInterfaceType())

0 commit comments

Comments
 (0)