Skip to content

Commit 49547a5

Browse files
committed
[NFC][Basic] Import llvm::isa_and_nonnull to 'swift' namespace
Just for convenicence. * Replace `llvm::isa_and_nonnull` with imported `isa_and_nonnull` * Repalce some `EXPR && isa<T>(EXPR)` with `isa_and_nonnull<T>(EXPR)`
1 parent 9de5d6e commit 49547a5

26 files changed

+43
-50
lines changed

include/swift/Basic/LLVM.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ namespace llvm {
7373
namespace swift {
7474
// Casting operators.
7575
using llvm::isa;
76+
using llvm::isa_and_nonnull;
7677
using llvm::cast;
7778
using llvm::dyn_cast;
7879
using llvm::dyn_cast_or_null;

lib/AST/ASTWalker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
12531253
if (Walker.Parent.getAsDecl() && VD->getParentPatternBinding())
12541254
return true;
12551255
auto walkerParentAsStmt = Walker.Parent.getAsStmt();
1256-
if (walkerParentAsStmt && isa<BraceStmt>(walkerParentAsStmt))
1256+
if (isa_and_nonnull<BraceStmt>(walkerParentAsStmt))
12571257
return true;
12581258
}
12591259
return false;

lib/ClangImporter/ImportDecl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,8 +1343,7 @@ synthesizeValueConstructorBody(AbstractFunctionDecl *afd, void *context) {
13431343
for (unsigned i = 0, e = members.size(); i < e; ++i) {
13441344
auto var = members[i];
13451345

1346-
if (var->hasClangNode() &&
1347-
isa<clang::IndirectFieldDecl>(var->getClangDecl()))
1346+
if (isa_and_nonnull<clang::IndirectFieldDecl>(var->getClangDecl()))
13481347
continue;
13491348

13501349
if (var->hasStorage() == (pass != 0)) {

lib/IDE/CodeCompletion.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6366,7 +6366,7 @@ void CodeCompletionCallbacksImpl::addKeywords(CodeCompletionResultSink &Sink,
63666366
if (ParsedDecl && ParsedDecl == CurDeclContext->getAsDecl())
63676367
DC = ParsedDecl->getDeclContext();
63686368
if (!isa<ProtocolDecl>(DC))
6369-
if (DC->isTypeContext() || (ParsedDecl && isa<FuncDecl>(ParsedDecl)))
6369+
if (DC->isTypeContext() || isa_and_nonnull<FuncDecl>(ParsedDecl))
63706370
addOpaqueTypeKeyword(Sink);
63716371

63726372
LLVM_FALLTHROUGH;
@@ -7012,7 +7012,7 @@ void CodeCompletionCallbacksImpl::doneParsing() {
70127012
}
70137013
if (auto *DRE = dyn_cast_or_null<DeclRefExpr>(ParsedExpr)) {
70147014
Lookup.setIsSelfRefExpr(DRE->getDecl()->getName() == Context.Id_self);
7015-
} else if (ParsedExpr && isa<SuperRefExpr>(ParsedExpr)) {
7015+
} else if (isa_and_nonnull<SuperRefExpr>(ParsedExpr)) {
70167016
Lookup.setIsSuperRefExpr();
70177017
}
70187018

@@ -7205,7 +7205,7 @@ void CodeCompletionCallbacksImpl::doneParsing() {
72057205
Lookup.setHaveLParen(true);
72067206
for (auto &typeAndDecl : ContextInfo.getPossibleCallees()) {
72077207
auto apply = ContextInfo.getAnalyzedExpr();
7208-
if (apply && isa<SubscriptExpr>(apply)) {
7208+
if (isa_and_nonnull<SubscriptExpr>(apply)) {
72097209
Lookup.addSubscriptCallPattern(
72107210
typeAndDecl.Type,
72117211
dyn_cast_or_null<SubscriptDecl>(typeAndDecl.Decl),

lib/IDE/Refactoring.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4505,7 +4505,7 @@ struct AsyncHandlerParamDesc : public AsyncHandlerDesc {
45054505
}
45064506

45074507
bool alternativeIsAccessor() const {
4508-
return Alternative && isa<AccessorDecl>(Alternative);
4508+
return isa_and_nonnull<AccessorDecl>(Alternative);
45094509
}
45104510
};
45114511

@@ -6828,7 +6828,7 @@ class AsyncConverter : private SourceEntityWalker {
68286828
// for the completion handler call, e.g 'return completion(args...)'. In
68296829
// that case, be sure not to add another return.
68306830
auto *parent = getWalker().Parent.getAsStmt();
6831-
if (parent && isa<ReturnStmt>(parent) &&
6831+
if (isa_and_nonnull<ReturnStmt>(parent) &&
68326832
!cast<ReturnStmt>(parent)->isImplicit()) {
68336833
// The statement already has a return keyword. Don't add another one.
68346834
AddedReturnOrThrow = false;

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,8 +1690,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
16901690
static bool canMangle(TypeBase *Ty) {
16911691
// TODO: C++ types are not yet supported (SR-13223).
16921692
if (Ty->getStructOrBoundGenericStruct() &&
1693-
Ty->getStructOrBoundGenericStruct()->getClangDecl() &&
1694-
isa<clang::CXXRecordDecl>(
1693+
isa_and_nonnull<clang::CXXRecordDecl>(
16951694
Ty->getStructOrBoundGenericStruct()->getClangDecl()))
16961695
return false;
16971696

@@ -2445,7 +2444,7 @@ void IRGenDebugInfoImpl::emitVariableDeclaration(
24452444
while (isa<llvm::DILexicalBlock>(Scope))
24462445
Scope = cast<llvm::DILexicalBlock>(Scope)->getScope();
24472446
}
2448-
assert(Scope && isa<llvm::DIScope>(Scope) && "variable has no scope");
2447+
assert(isa_and_nonnull<llvm::DIScope>(Scope) && "variable has no scope");
24492448
llvm::DIFile *Unit = getFile(Scope);
24502449
llvm::DIType *DITy = getOrCreateType(DbgTy);
24512450
assert(DITy && "could not determine debug type of variable");
@@ -2636,8 +2635,7 @@ void IRGenDebugInfoImpl::emitGlobalVariableDeclaration(
26362635
if (MetatypeType *metaTy = dyn_cast<MetatypeType>(ty))
26372636
ty = metaTy->getInstanceType().getPointer();
26382637
if (ty->getStructOrBoundGenericStruct() &&
2639-
ty->getStructOrBoundGenericStruct()->getClangDecl() &&
2640-
isa<clang::CXXRecordDecl>(
2638+
isa_and_nonnull<clang::CXXRecordDecl>(
26412639
ty->getStructOrBoundGenericStruct()->getClangDecl()))
26422640
return;
26432641
}

lib/IRGen/IRGenSIL.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,8 +1065,7 @@ class IRGenSILFunction :
10651065
if (MetatypeType *metaTy = dyn_cast<MetatypeType>(ty))
10661066
ty = metaTy->getRootClass().getPointer();
10671067
if (ty->getStructOrBoundGenericStruct() &&
1068-
ty->getStructOrBoundGenericStruct()->getClangDecl() &&
1069-
isa<clang::CXXRecordDecl>(
1068+
isa_and_nonnull<clang::CXXRecordDecl>(
10701069
ty->getStructOrBoundGenericStruct()->getClangDecl()))
10711070
return;
10721071
}
@@ -1709,7 +1708,7 @@ IRGenSILFunction::IRGenSILFunction(IRGenModule &IGM, SILFunction *f)
17091708
CurFn->addFnAttr(llvm::Attribute::SanitizeAddress);
17101709
if (IGM.IRGen.Opts.Sanitizers & SanitizerKind::Thread) {
17111710
auto declContext = f->getDeclContext();
1712-
if (declContext && isa<DestructorDecl>(declContext)) {
1711+
if (isa_and_nonnull<DestructorDecl>(declContext)) {
17131712
// Do not report races in deinit and anything called from it
17141713
// because TSan does not observe synchronization between retain
17151714
// count dropping to '0' and the object deinitialization.

lib/Parse/ParseDecl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6906,7 +6906,7 @@ ParserResult<FuncDecl> Parser::parseDeclFunc(SourceLoc StaticLoc,
69066906
CurDeclContext);
69076907

69086908
// Let the source file track the opaque return type mapping, if any.
6909-
if (FuncRetTy && isa<OpaqueReturnTypeRepr>(FuncRetTy) &&
6909+
if (isa_and_nonnull<OpaqueReturnTypeRepr>(FuncRetTy) &&
69106910
!InInactiveClauseEnvironment) {
69116911
if (auto sf = CurDeclContext->getParentSourceFile()) {
69126912
sf->addUnvalidatedDeclWithOpaqueResultType(FD);
@@ -7773,7 +7773,7 @@ Parser::parseDeclSubscript(SourceLoc StaticLoc,
77737773
Subscript->getAttrs() = Attributes;
77747774

77757775
// Let the source file track the opaque return type mapping, if any.
7776-
if (ElementTy.get() && isa<OpaqueReturnTypeRepr>(ElementTy.get()) &&
7776+
if (isa_and_nonnull<OpaqueReturnTypeRepr>(ElementTy.get()) &&
77777777
!InInactiveClauseEnvironment) {
77787778
if (auto sf = CurDeclContext->getParentSourceFile()) {
77797779
sf->addUnvalidatedDeclWithOpaqueResultType(Subscript);

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4309,8 +4309,8 @@ TypeConverter::getLoweredFormalTypes(SILDeclRef constant,
43094309

43104310
// If this is a C++ constructor, don't add the metatype "self" parameter
43114311
// because we'll never use it and it will cause problems in IRGen.
4312-
if (constant.getDecl()->getClangDecl() &&
4313-
isa<clang::CXXConstructorDecl>(constant.getDecl()->getClangDecl())) {
4312+
if (isa_and_nonnull<clang::CXXConstructorDecl>(
4313+
constant.getDecl()->getClangDecl())) {
43144314
// But, make sure it is actually a metatype that we're not adding. If
43154315
// changes to the self parameter are made in the future, this logic may
43164316
// need to be updated.

lib/SILGen/SILGenApply.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,8 @@ class Callee {
555555
};
556556

557557
// Remove the metatype "self" parameter by making this a static member.
558-
if (constant->getDecl()->getClangDecl() &&
559-
isa<clang::CXXConstructorDecl>(constant->getDecl()->getClangDecl()))
558+
if (isa_and_nonnull<clang::CXXConstructorDecl>(
559+
constant->getDecl()->getClangDecl()))
560560
result.foreign.self.setStatic();
561561

562562
return result;

0 commit comments

Comments
 (0)