Skip to content

Commit 88a966d

Browse files
committed
Move some assertion logic into a helper, NFC
1 parent ee1e8e7 commit 88a966d

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/SIL/SILProfiler.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,21 @@ static void walkForProfiling(ASTNode N, ASTWalker &Walker) {
100100
}
101101
}
102102

103+
/// Check that the input AST has at least been type-checked.
104+
static bool hasASTBeenTypeChecked(ASTNode N) {
105+
DeclContext *DC = N.getAsDeclContext();
106+
assert(DC && "Invalid AST node for profiling");
107+
SourceFile *SF = DC->getParentSourceFile();
108+
return !SF || SF->ASTStage >= SourceFile::TypeChecked;
109+
}
110+
103111
SILProfiler *SILProfiler::create(SILModule &M, ForDefinition_t forDefinition,
104112
ASTNode N) {
105113
// Avoid generating profiling state for declarations.
106114
if (!forDefinition)
107115
return nullptr;
108116

109-
// Assert that the input AST has at least been type-checked.
110-
assert([&] {
111-
DeclContext *DC = N.getAsDeclContext();
112-
assert(DC && "Invalid AST node for profiling");
113-
SourceFile *SF = DC->getParentSourceFile();
114-
return !SF || SF->ASTStage >= SourceFile::TypeChecked;
115-
}() && "Cannot use this AST for code coverage");
117+
assert(hasASTBeenTypeChecked(N) && "Cannot use this AST for code coverage");
116118

117119
if (auto *D = N.dyn_cast<Decl *>()) {
118120
assert(isa<AbstractFunctionDecl>(D) ||

0 commit comments

Comments
 (0)