Skip to content

Commit c9d96bc

Browse files
committed
[Profiler] Assert that we always have function bodies
It seems like this defensive logic was written back when we could create SILProfilers for declarations in addition to definitions. Now we should only ever create SILProfilers for definitions, so we can assert that we always have a function body available.
1 parent 0eba486 commit c9d96bc

File tree

1 file changed

+6
-36
lines changed

1 file changed

+6
-36
lines changed

lib/SIL/IR/SILProfiler.cpp

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,6 @@
3232

3333
using namespace swift;
3434

35-
/// Check if a closure has a body.
36-
static bool doesClosureHaveBody(AbstractClosureExpr *ACE) {
37-
if (auto *CE = dyn_cast<ClosureExpr>(ACE))
38-
return CE->getBody();
39-
if (auto *autoCE = dyn_cast<AutoClosureExpr>(ACE))
40-
return autoCE->getBody();
41-
return false;
42-
}
43-
4435
/// Check whether a root AST node should be profiled.
4536
static bool shouldProfile(ASTNode N, SILDeclRef Constant) {
4637
// Do not profile AST nodes with invalid source locations.
@@ -73,28 +64,6 @@ static bool shouldProfile(ASTNode N, SILDeclRef Constant) {
7364
return false;
7465
}
7566

76-
if (auto *E = N.dyn_cast<Expr *>()) {
77-
if (auto *CE = dyn_cast<AbstractClosureExpr>(E)) {
78-
// Only profile closure expressions with bodies.
79-
if (!doesClosureHaveBody(CE)) {
80-
LLVM_DEBUG(llvm::dbgs() << "Skipping ASTNode: closure without body\n");
81-
return false;
82-
}
83-
}
84-
85-
// Profile all other kinds of expressions.
86-
return true;
87-
}
88-
89-
auto *D = N.get<Decl *>();
90-
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(D)) {
91-
// Don't profile functions without bodies.
92-
if (!AFD->hasBody()) {
93-
LLVM_DEBUG(llvm::dbgs() << "Skipping ASTNode: function without body\n");
94-
return false;
95-
}
96-
}
97-
9867
return true;
9968
}
10069

@@ -127,21 +96,22 @@ static bool hasASTBeenTypeChecked(ASTNode N, SILDeclRef forDecl) {
12796
return !SF || SF->ASTStage >= SourceFile::TypeChecked;
12897
}
12998

130-
/// Check whether a mapped AST node requires a new profiler.
99+
/// Check whether a mapped AST node is valid for profiling.
131100
static bool canCreateProfilerForAST(ASTNode N, SILDeclRef forDecl) {
132101
assert(hasASTBeenTypeChecked(N, forDecl) &&
133102
"Cannot use this AST for profiling");
134103

135104
if (auto *D = N.dyn_cast<Decl *>()) {
136-
if (isa<AbstractFunctionDecl>(D))
137-
return true;
105+
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(D))
106+
return AFD->hasBody();
138107

139108
if (isa<TopLevelCodeDecl>(D))
140109
return true;
141110
} else if (N.get<Expr *>()) {
111+
if (auto *closure = forDecl.getAbstractClosureExpr())
112+
return closure->hasBody();
142113
if (forDecl.isStoredPropertyInitializer() ||
143-
forDecl.isPropertyWrapperBackingInitializer() ||
144-
forDecl.getAbstractClosureExpr())
114+
forDecl.isPropertyWrapperBackingInitializer())
145115
return true;
146116
}
147117
return false;

0 commit comments

Comments
 (0)