@@ -62,34 +62,6 @@ static Stmt *getProfilerStmtForCase(CaseStmt *caseStmt) {
62
62
llvm_unreachable (" invalid parent kind" );
63
63
}
64
64
65
- // / Check that the input AST has at least been type-checked.
66
- LLVM_ATTRIBUTE_UNUSED
67
- static bool hasFileBeenTypeChecked (SILDeclRef forDecl) {
68
- auto *SF = forDecl.getInnermostDeclContext ()->getParentSourceFile ();
69
- return SF && SF->ASTStage >= SourceFile::TypeChecked;
70
- }
71
-
72
- // / Check whether a mapped AST node is valid for profiling.
73
- static bool canCreateProfilerForAST (ASTNode N, SILDeclRef forDecl) {
74
- assert (hasFileBeenTypeChecked (forDecl) &&
75
- " Cannot use this AST for profiling" );
76
-
77
- if (auto *D = N.dyn_cast <Decl *>()) {
78
- if (auto *AFD = dyn_cast<AbstractFunctionDecl>(D))
79
- return AFD->hasBody ();
80
-
81
- if (isa<TopLevelCodeDecl>(D))
82
- return true ;
83
- } else if (N.get <Expr *>()) {
84
- if (auto *closure = forDecl.getAbstractClosureExpr ())
85
- return closure->hasBody ();
86
- if (forDecl.isStoredPropertyInitializer () ||
87
- forDecl.isPropertyWrapperBackingInitializer ())
88
- return true ;
89
- }
90
- return false ;
91
- }
92
-
93
65
SILProfiler *SILProfiler::create (SILModule &M, ASTNode N, SILDeclRef Ref) {
94
66
// If profiling isn't enabled, don't profile anything.
95
67
const auto &Opts = M.getOptions ();
@@ -99,11 +71,6 @@ SILProfiler *SILProfiler::create(SILModule &M, ASTNode N, SILDeclRef Ref) {
99
71
if (!shouldProfile (N, Ref))
100
72
return nullptr ;
101
73
102
- if (!canCreateProfilerForAST (N, Ref)) {
103
- N.dump (llvm::errs ());
104
- llvm_unreachable (" Invalid AST node for profiling" );
105
- }
106
-
107
74
auto *Buf = M.allocate <SILProfiler>(1 );
108
75
auto *SP =
109
76
::new (Buf) SILProfiler (M, N, Ref, Opts.EmitProfileCoverageMapping );
@@ -163,6 +130,7 @@ namespace {
163
130
template <typename F>
164
131
ASTWalker::PreWalkAction
165
132
visitFunctionDecl (ASTWalker &Walker, AbstractFunctionDecl *AFD, F Func) {
133
+ assert (AFD->hasBody ());
166
134
if (Walker.Parent .isNull ()) {
167
135
Func ();
168
136
return ASTWalker::Action::Continue ();
@@ -177,7 +145,9 @@ shouldWalkIntoExpr(Expr *E, ASTWalker::ParentTy Parent, SILDeclRef Constant) {
177
145
178
146
// Profiling for closures should be handled separately. Do not visit
179
147
// closure expressions twice.
180
- if (isa<AbstractClosureExpr>(E)) {
148
+ if (auto *CE = dyn_cast<AbstractClosureExpr>(E)) {
149
+ assert (CE->hasBody ());
150
+
181
151
// A non-null parent means we have a closure child, which we will visit
182
152
// separately. Even if the parent is null, don't walk into a closure if the
183
153
// SILDeclRef is not for a closure, as it could be for a property
0 commit comments