Skip to content

Commit 7684e73

Browse files
Merge pull request #8706 from practicalswift/excess-logic
[gardening] Remove redundant logic
2 parents 868a51b + 5e255e0 commit 7684e73

23 files changed

+39
-118
lines changed

include/swift/SILOptimizer/Analysis/EpilogueARCAnalysis.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,7 @@ class EpilogueARCContext {
172172
bool mayBlockEpilogueRelease(SILInstruction *II, SILValue Ptr) {
173173
// Check whether this instruction read reference count, i.e. uniqueness
174174
// check. Moving release past that may result in additional COW.
175-
if (II->mayReleaseOrReadRefCount())
176-
return true;
177-
return false;
175+
return II->mayReleaseOrReadRefCount();
178176
}
179177

180178
/// Does this instruction block the interested ARC instruction ?

lib/AST/ASTWalker.cpp

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,7 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
191191
}
192192

193193
bool visitTypeAliasDecl(TypeAliasDecl *TAD) {
194-
if (doIt(TAD->getUnderlyingTypeLoc()))
195-
return true;
196-
return false;
194+
return doIt(TAD->getUnderlyingTypeLoc());
197195
}
198196

199197
bool visitAbstractTypeParamDecl(AbstractTypeParamDecl *TPD) {
@@ -1501,9 +1499,7 @@ bool Traversal::visitErrorTypeRepr(ErrorTypeRepr *T) {
15011499
}
15021500

15031501
bool Traversal::visitAttributedTypeRepr(AttributedTypeRepr *T) {
1504-
if (doIt(T->getTypeRepr()))
1505-
return true;
1506-
return false;
1502+
return doIt(T->getTypeRepr());
15071503
}
15081504

15091505
bool Traversal::visitSimpleIdentTypeRepr(SimpleIdentTypeRepr *T) {
@@ -1527,37 +1523,23 @@ bool Traversal::visitCompoundIdentTypeRepr(CompoundIdentTypeRepr *T) {
15271523
}
15281524

15291525
bool Traversal::visitFunctionTypeRepr(FunctionTypeRepr *T) {
1530-
if (doIt(T->getArgsTypeRepr()))
1531-
return true;
1532-
if (doIt(T->getResultTypeRepr()))
1533-
return true;
1534-
return false;
1526+
return doIt(T->getArgsTypeRepr()) || doIt(T->getResultTypeRepr());
15351527
}
15361528

15371529
bool Traversal::visitArrayTypeRepr(ArrayTypeRepr *T) {
1538-
if (doIt(T->getBase()))
1539-
return true;
1540-
return false;
1530+
return doIt(T->getBase());
15411531
}
15421532

15431533
bool Traversal::visitDictionaryTypeRepr(DictionaryTypeRepr *T) {
1544-
if (doIt(T->getKey()))
1545-
return true;
1546-
if (doIt(T->getValue()))
1547-
return true;
1548-
return false;
1534+
return doIt(T->getKey()) || doIt(T->getValue());
15491535
}
15501536

15511537
bool Traversal::visitOptionalTypeRepr(OptionalTypeRepr *T) {
1552-
if (doIt(T->getBase()))
1553-
return true;
1554-
return false;
1538+
return doIt(T->getBase());
15551539
}
15561540

15571541
bool Traversal::visitImplicitlyUnwrappedOptionalTypeRepr(ImplicitlyUnwrappedOptionalTypeRepr *T) {
1558-
if (doIt(T->getBase()))
1559-
return true;
1560-
return false;
1542+
return doIt(T->getBase());
15611543
}
15621544

15631545
bool Traversal::visitTupleTypeRepr(TupleTypeRepr *T) {
@@ -1577,21 +1559,15 @@ bool Traversal::visitCompositionTypeRepr(CompositionTypeRepr *T) {
15771559
}
15781560

15791561
bool Traversal::visitMetatypeTypeRepr(MetatypeTypeRepr *T) {
1580-
if (doIt(T->getBase()))
1581-
return true;
1582-
return false;
1562+
return doIt(T->getBase());
15831563
}
15841564

15851565
bool Traversal::visitProtocolTypeRepr(ProtocolTypeRepr *T) {
1586-
if (doIt(T->getBase()))
1587-
return true;
1588-
return false;
1566+
return doIt(T->getBase());
15891567
}
15901568

15911569
bool Traversal::visitInOutTypeRepr(InOutTypeRepr *T) {
1592-
if (doIt(T->getBase()))
1593-
return true;
1594-
return false;
1570+
return doIt(T->getBase());
15951571
}
15961572

15971573
bool Traversal::visitFixedTypeRepr(FixedTypeRepr *T) {

lib/AST/Decl.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,9 +1451,7 @@ bool ValueDecl::needsCapture() const {
14511451
if (!getDeclContext()->isLocalContext())
14521452
return false;
14531453
// We don't need to capture types.
1454-
if (isa<TypeDecl>(this))
1455-
return false;
1456-
return true;
1454+
return !isa<TypeDecl>(this);
14571455
}
14581456

14591457
ValueDecl *ValueDecl::getOverriddenDecl() const {
@@ -4912,9 +4910,7 @@ ConstructorDecl::getDelegatingOrChainedInitKind(DiagnosticEngine *diags,
49124910

49134911
bool walkToDeclPre(class Decl *D) override {
49144912
// Don't walk into further nominal decls.
4915-
if (isa<NominalTypeDecl>(D))
4916-
return false;
4917-
return true;
4913+
return !isa<NominalTypeDecl>(D);
49184914
}
49194915

49204916
std::pair<bool, Expr*> walkToExprPre(Expr *E) override {

lib/AST/ModuleNameLookup.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ static bool isOverloadable(const ValueDecl *VD) {
4949
static bool isValidOverload(CanTypeSet &overloads, const ValueDecl *VD) {
5050
if (!isOverloadable(VD))
5151
return overloads.empty();
52-
if (overloads.count(VD->getInterfaceType()->getCanonicalType()))
53-
return false;
54-
return true;
52+
return !overloads.count(VD->getInterfaceType()->getCanonicalType());
5553
}
5654

5755
static bool isValidOverload(NamedCanTypeSet &overloads, const ValueDecl *VD) {

lib/AST/SourceEntityWalker.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,7 @@ Expr *SemaAnnotator::walkToExprPost(Expr *E) {
346346
}
347347

348348
bool SemaAnnotator::walkToTypeReprPost(TypeRepr *T) {
349-
if (isDone())
350-
return false;
351-
return true;
349+
return !isDone();
352350
}
353351

354352
std::pair<bool, Pattern *> SemaAnnotator::walkToPatternPre(Pattern *P) {

lib/AST/TypeWalker.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,7 @@ class Traversal : public TypeVisitor<Traversal, bool>
158158
bool visitTypeVariableType(TypeVariableType *ty) { return false; }
159159

160160
bool visitSILBlockStorageType(SILBlockStorageType *ty) {
161-
if (doIt(ty->getCaptureType()))
162-
return true;
163-
return false;
161+
return doIt(ty->getCaptureType());
164162
}
165163

166164
bool visitSILBoxType(SILBoxType *ty) {

lib/ClangImporter/ClangImporter.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,13 +2015,8 @@ class DarwinBlacklistDeclConsumer : public swift::VisibleDeclConsumer {
20152015
: NextConsumer(consumer), ClangASTContext(clangASTContext) {}
20162016

20172017
static bool needsBlacklist(const clang::Module *topLevelModule) {
2018-
if (!topLevelModule)
2019-
return false;
2020-
if (topLevelModule->Name == "Darwin")
2021-
return true;
2022-
if (topLevelModule->Name == "CoreServices")
2023-
return true;
2024-
return false;
2018+
return topLevelModule && (topLevelModule->Name == "Darwin" ||
2019+
topLevelModule->Name == "CoreServices");
20252020
}
20262021

20272022
void foundDecl(ValueDecl *VD, DeclVisibilityKind Reason) override {

lib/ClangImporter/ImportDecl.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ getDefaultMakeStructRawValuedOptions() {
9393
}
9494

9595
static bool isInSystemModule(DeclContext *D) {
96-
if (cast<ClangModuleUnit>(D->getModuleScopeContext())->isSystemModule())
97-
return true;
98-
return false;
96+
return cast<ClangModuleUnit>(D->getModuleScopeContext())->isSystemModule();
9997
}
10098

10199
static Accessibility getOverridableAccessibility(DeclContext *dc) {

lib/ClangImporter/ImportMacro.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ parseNumericLiteral(ClangImporter::Implementation &impl,
6666

6767
// FIXME: Duplicated from ImportDecl.cpp.
6868
static bool isInSystemModule(DeclContext *D) {
69-
if (cast<ClangModuleUnit>(D->getModuleScopeContext())->isSystemModule())
70-
return true;
71-
return false;
69+
return cast<ClangModuleUnit>(D->getModuleScopeContext())->isSystemModule();
7270
}
7371

7472
static ValueDecl *

lib/ClangImporter/ImportName.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,9 +506,7 @@ static bool moduleIsInferImportAsMember(const clang::NamedDecl *decl,
506506
if (submodule->IsSwiftInferImportAsMember) {
507507
// HACK HACK HACK: This is a workaround for some module invalidation issue
508508
// and inconsistency. This will go away soon.
509-
if (submodule->Name != "CoreGraphics")
510-
return false;
511-
return true;
509+
return submodule->Name == "CoreGraphics";
512510
}
513511
submodule = submodule->Parent;
514512
}

lib/Demangling/NodePrinter.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,7 @@ class NodePrinter {
263263
return true;
264264

265265
case Node::Kind::ProtocolList:
266-
if (pointer->getChild(0)->getNumChildren() <= 1)
267-
return true;
268-
return false;
266+
return pointer->getChild(0)->getNumChildren() <= 1;
269267

270268
case Node::Kind::Allocator:
271269
case Node::Kind::ArgumentTuple:

lib/IDE/SwiftSourceDocInfo.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,8 @@ struct RangeResolver::Implementation {
350350

351351
// Explicitly allow the selection of multiple case statments.
352352
auto IsCase = [](ASTNode N) { return N.isStmt(StmtKind::Case); };
353-
if (llvm::any_of(StartMatches, IsCase) && llvm::any_of(EndMatches, IsCase))
354-
return true;
355-
return false;
353+
return llvm::any_of(StartMatches, IsCase) &&
354+
llvm::any_of(EndMatches, IsCase);
356355
}
357356
};
358357

@@ -603,14 +602,12 @@ struct RangeResolver::Implementation {
603602
for (auto N : Nodes) {
604603
if (Stmt *S = N.is<Stmt*>() ? N.get<Stmt*>() : nullptr) {
605604
if (S->getKind() == StmtKind::Case)
606-
CaseCount ++;
605+
CaseCount++;
607606
}
608607
}
609608
// If there are more than one case/default statements, there are more than
610609
// one entry point.
611-
if (CaseCount > 1)
612-
return false;
613-
return true;
610+
return CaseCount == 0;
614611
}
615612

616613
OrphanKind getOrphanKind(ArrayRef<ASTNode> Nodes) {

lib/IDE/SyntaxModel.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,9 +1055,7 @@ bool ModelASTWalker::annotateIfConfigConditionIdentifiers(Expr *Cond) {
10551055
};
10561056

10571057
IdRefWalker<decltype(passNode)> Walker(passNode);
1058-
if (!Cond->walk(Walker))
1059-
return false;
1060-
return true;
1058+
return Cond->walk(Walker);
10611059
}
10621060

10631061
bool ModelASTWalker::handleSpecialDeclAttribute(const DeclAttribute *D,
@@ -1248,9 +1246,7 @@ bool ModelASTWalker::passNode(const SyntaxNode &Node) {
12481246
}
12491247
}
12501248

1251-
if (!Walker.walkToNodePost(Node))
1252-
return false;
1253-
return true;
1249+
return Walker.walkToNodePost(Node);
12541250
}
12551251

12561252
bool ModelASTWalker::pushStructureNode(const SyntaxStructureNode &Node,

lib/IRGen/AllocStackHoisting.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ static bool isHoistable(AllocStackInst *Inst, irgen::IRGenModule &Mod) {
5959

6060
// Don't hoist generics with opened archetypes. We would have to hoist the
6161
// open archetype instruction which might not be possible.
62-
if (!Inst->getTypeDependentOperands().empty())
63-
return false;
64-
return true;
62+
return Inst->getTypeDependentOperands().empty();
6563
}
6664

6765
/// A partition of alloc_stack instructions.

lib/SIL/SILInstruction.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,7 @@ namespace {
375375

376376
bool visitRefTailAddrInst(RefTailAddrInst *RHS) {
377377
auto *X = cast<RefTailAddrInst>(LHS);
378-
if (X->getTailType() != RHS->getTailType())
379-
return false;
380-
return true;
378+
return X->getTailType() == RHS->getTailType();
381379
}
382380

383381
bool visitStructElementAddrInst(const StructElementAddrInst *RHS) {
@@ -453,9 +451,7 @@ namespace {
453451

454452
bool visitTailAddrInst(TailAddrInst *RHS) {
455453
auto *X = cast<TailAddrInst>(LHS);
456-
if (X->getTailType() != RHS->getTailType())
457-
return false;
458-
return true;
454+
return X->getTailType() == RHS->getTailType();
459455
}
460456

461457
bool visitCondFailInst(CondFailInst *RHS) {

lib/SILGen/SILGenApply.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -664,9 +664,7 @@ class ArchetypeCalleeBuilder {
664664

665665
assert(SGF.silConv.useLoweredAddresses() ==
666666
SGF.silConv.isSILIndirect(getSelfParameterInfo()));
667-
if (!SGF.silConv.useLoweredAddresses())
668-
return false;
669-
return true;
667+
return SGF.silConv.useLoweredAddresses();
670668
}
671669

672670
// If we're calling a member of a non-class-constrained protocol,

lib/SILOptimizer/IPO/CapturePropagation.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,7 @@ static bool onlyContainsReturnOrThrowOfArg(SILBasicBlock *BB) {
320320
for (SILInstruction &I : *BB) {
321321
if (isa<ReturnInst>(&I) || isa<ThrowInst>(&I)) {
322322
SILValue RetVal = I.getOperand(0);
323-
if (BB->getNumArguments() == 1 && RetVal == BB->getArgument(0))
324-
return true;
325-
return false;
323+
return BB->getNumArguments() == 1 && RetVal == BB->getArgument(0);
326324
}
327325
if (I.mayHaveSideEffects() || isa<TermInst>(&I))
328326
return false;

lib/SILOptimizer/IPO/GlobalPropertyOpt.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,7 @@ class GlobalPropertyOpt {
147147
linkage = SILLinkage::Public;
148148
break;
149149
}
150-
if (isPossiblyUsedExternally(linkage, M.isWholeModule()))
151-
return true;
152-
return false;
150+
return isPossiblyUsedExternally(linkage, M.isWholeModule());
153151
}
154152

155153
static bool canAddressEscape(SILValue V, bool acceptStore);

lib/SILOptimizer/LoopTransforms/ArrayBoundsCheckOpts.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -651,9 +651,7 @@ static bool isLessThanCheck(SILValue Start, SILValue End,
651651
// Special case: if it is a 0-to-count loop, we know that the count cannot
652652
// be negative. In this case the 'Start < End' check can also be done with
653653
// 'count != 0'.
654-
if (getZeroToCountArray(Start, End))
655-
return true;
656-
return false;
654+
return getZeroToCountArray(Start, End);
657655
default:
658656
return false;
659657
}

lib/SILOptimizer/LoopTransforms/LICM.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,7 @@ static bool hoistInstructions(SILLoop *Loop, DominanceInfo *DT,
269269
// that dominate all exits.
270270
if (!std::all_of(ExitingBBs.begin(), ExitingBBs.end(),
271271
[=](SILBasicBlock *ExitBB) {
272-
if (DT->dominates(CurBB, ExitBB))
273-
return true;
274-
return false;
272+
return DT->dominates(CurBB, ExitBB);
275273
})) {
276274
DEBUG(llvm::dbgs() << " skipping conditional block " << *CurBB << "\n");
277275
It.skipChildren();

lib/SILOptimizer/Transforms/CSE.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -822,10 +822,7 @@ bool CSE::canHandle(SILInstruction *Inst) {
822822
case ArrayCallKind::kGetCapacity:
823823
case ArrayCallKind::kCheckIndex:
824824
case ArrayCallKind::kCheckSubscript:
825-
if (SemCall.hasGuaranteedSelf()) {
826-
return true;
827-
}
828-
return false;
825+
return SemCall.hasGuaranteedSelf();
829826
default:
830827
return false;
831828
}

lib/SILOptimizer/Transforms/DeadCodeElimination.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ static bool seemsUseful(SILInstruction *I) {
4646
if (auto *BI = dyn_cast<BuiltinInst>(I)) {
4747
// Although the onFastPath builtin has no side-effects we don't want to
4848
// remove it.
49-
if (BI->getBuiltinInfo().ID == BuiltinValueKind::OnFastPath)
50-
return true;
51-
return false;
49+
return BI->getBuiltinInfo().ID == BuiltinValueKind::OnFastPath;
5250
}
5351

5452
if (isa<ReturnInst>(I) || isa<UnreachableInst>(I) || isa<ThrowInst>(I))

lib/Sema/CSDiag.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6998,9 +6998,7 @@ bool FailureDiagnosis::visitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
69986998
case CC_Unavailable:
69996999
case CC_Inaccessible:
70007000
// Diagnose some simple and common errors.
7001-
if (candidateInfo.diagnoseSimpleErrors(E))
7002-
return true;
7003-
return false;
7001+
return candidateInfo.diagnoseSimpleErrors(E);
70047002

70057003
case CC_ArgumentLabelMismatch: { // Argument labels are not correct.
70067004
auto argExpr = typeCheckArgumentChildIndependently(E->getArgument(),

0 commit comments

Comments
 (0)