@@ -82,8 +82,7 @@ class ScopeCreator final {
82
82
if (auto *ip = child->insertionPointForDeferredExpansion ().getPtrOrNull ())
83
83
return ip;
84
84
85
- ASTScopeImpl *insertionPoint =
86
- child->expandAndBeCurrentDetectingRecursion (*this );
85
+ ASTScopeImpl *insertionPoint = child->expandAndBeCurrent (*this );
87
86
return insertionPoint;
88
87
}
89
88
@@ -224,15 +223,18 @@ ASTSourceFileScope *ASTScope::createScopeTree(SourceFile *SF) {
224
223
}
225
224
226
225
void ASTSourceFileScope::buildFullyExpandedTree () {
227
- expandAndBeCurrentDetectingRecursion (*scopeCreator);
226
+ if (!getWasExpanded ())
227
+ expandAndBeCurrent (*scopeCreator);
228
228
preOrderChildrenDo ([&](ASTScopeImpl *s) {
229
- s->expandAndBeCurrentDetectingRecursion (*scopeCreator);
229
+ if (!s->getWasExpanded ())
230
+ s->expandAndBeCurrent (*scopeCreator);
230
231
});
231
232
}
232
233
233
234
void ASTSourceFileScope::
234
235
buildEnoughOfTreeForTopLevelExpressionsButDontRequestGenericsOrExtendedNominals () {
235
- expandAndBeCurrentDetectingRecursion (*scopeCreator);
236
+ if (!getWasExpanded ())
237
+ expandAndBeCurrent (*scopeCreator);
236
238
}
237
239
238
240
void ASTSourceFileScope::expandFunctionBody (AbstractFunctionDecl *AFD) {
@@ -242,7 +244,8 @@ void ASTSourceFileScope::expandFunctionBody(AbstractFunctionDecl *AFD) {
242
244
if (sr.isInvalid ())
243
245
return ;
244
246
ASTScopeImpl *bodyScope = findInnermostEnclosingScope (sr.Start , nullptr );
245
- bodyScope->expandAndBeCurrentDetectingRecursion (*scopeCreator);
247
+ if (!bodyScope->getWasExpanded ())
248
+ bodyScope->expandAndBeCurrent (*scopeCreator);
246
249
}
247
250
248
251
ASTSourceFileScope::ASTSourceFileScope (SourceFile *SF,
@@ -411,8 +414,6 @@ class NodeAdder
411
414
endLocForBraceStmt = *endLoc;
412
415
413
416
ASTContext &ctx = scopeCreator.getASTContext ();
414
- if (auto *s = ctx.Stats )
415
- ++s->getFrontendCounters ().NumBraceStmtASTScopes ;
416
417
417
418
return
418
419
scopeCreator.constructExpandAndInsert <BraceStmtScope>(
@@ -596,26 +597,17 @@ void ASTScopeImpl::addChild(ASTScopeImpl *child, ASTContext &ctx) {
596
597
597
598
#pragma mark implementations of expansion
598
599
599
- ASTScopeImpl *
600
- ASTScopeImpl::expandAndBeCurrentDetectingRecursion (ScopeCreator &scopeCreator) {
601
- return evaluateOrDefault (scopeCreator.getASTContext ().evaluator ,
602
- ExpandASTScopeRequest{this , &scopeCreator}, nullptr );
603
- }
604
-
605
- ASTScopeImpl *
606
- ExpandASTScopeRequest::evaluate (Evaluator &evaluator, ASTScopeImpl *parent,
607
- ScopeCreator *scopeCreator) const {
608
- auto *insertionPoint = parent->expandAndBeCurrent (*scopeCreator);
609
- ASTScopeAssert (insertionPoint,
610
- " Used to return a null pointer if the insertion point would "
611
- " not be used, but it breaks the request dependency hashing" );
612
- return insertionPoint;
613
- }
614
-
615
600
ASTScopeImpl *ASTScopeImpl::expandAndBeCurrent (ScopeCreator &scopeCreator) {
616
601
ASTScopeAssert (!getWasExpanded (),
617
602
" Cannot expand the same scope twice" );
618
603
604
+ // Set the flag before we actually expand, to detect re-entrant calls
605
+ // via the above assertion.
606
+ setWasExpanded ();
607
+
608
+ if (auto *s = scopeCreator.getASTContext ().Stats )
609
+ ++s->getFrontendCounters ().NumASTScopeExpansions ;
610
+
619
611
auto *insertionPoint = expandSpecifically (scopeCreator);
620
612
ASTScopeAssert (!insertionPointForDeferredExpansion () ||
621
613
insertionPointForDeferredExpansion ().get () ==
@@ -624,8 +616,6 @@ ASTScopeImpl *ASTScopeImpl::expandAndBeCurrent(ScopeCreator &scopeCreator) {
624
616
" accurate before expansion, the insertion point before "
625
617
" expansion must be the same as after expansion." );
626
618
627
- setWasExpanded ();
628
-
629
619
return insertionPoint;
630
620
}
631
621
@@ -826,9 +816,6 @@ BraceStmtScope::expandAScopeThatCreatesANewInsertionPoint(
826
816
nd, insertionPoint, endLoc);
827
817
}
828
818
829
- if (auto *s = scopeCreator.getASTContext ().Stats )
830
- ++s->getFrontendCounters ().NumBraceStmtASTScopeExpansions ;
831
-
832
819
return {
833
820
insertionPoint,
834
821
" For top-level code decls, need the scope under, say a guard statment." };
@@ -1085,24 +1072,17 @@ ASTScopeImpl *GenericTypeOrExtensionWherePortion::expandScope(
1085
1072
1086
1073
#pragma mark createBodyScope
1087
1074
1088
- void IterableTypeScope::countBodies (ScopeCreator &scopeCreator) const {
1089
- if (auto *s = scopeCreator.getASTContext ().Stats )
1090
- ++s->getFrontendCounters ().NumIterableTypeBodyASTScopes ;
1091
- }
1092
-
1093
1075
void ExtensionScope::createBodyScope (ASTScopeImpl *leaf,
1094
1076
ScopeCreator &scopeCreator) {
1095
1077
scopeCreator.constructWithPortionExpandAndInsert <ExtensionScope,
1096
1078
IterableTypeBodyPortion>(
1097
1079
leaf, decl);
1098
- countBodies (scopeCreator);
1099
1080
}
1100
1081
void NominalTypeScope::createBodyScope (ASTScopeImpl *leaf,
1101
1082
ScopeCreator &scopeCreator) {
1102
1083
scopeCreator.constructWithPortionExpandAndInsert <NominalTypeScope,
1103
1084
IterableTypeBodyPortion>(
1104
1085
leaf, decl);
1105
- countBodies (scopeCreator);
1106
1086
}
1107
1087
1108
1088
#pragma mark createTrailingWhereClauseScope
@@ -1192,9 +1172,6 @@ void GenericTypeOrExtensionScope::expandBody(ScopeCreator &) {}
1192
1172
void IterableTypeScope::expandBody (ScopeCreator &scopeCreator) {
1193
1173
for (auto *d : getIterableDeclContext ().get ()->getMembers ())
1194
1174
scopeCreator.addToScopeTree (ASTNode (d), this );
1195
-
1196
- if (auto *s = scopeCreator.getASTContext ().Stats )
1197
- ++s->getFrontendCounters ().NumIterableTypeBodyASTScopeExpansions ;
1198
1175
}
1199
1176
1200
1177
#pragma mark getScopeCreator
@@ -1241,16 +1218,3 @@ void ast_scope::simple_display(llvm::raw_ostream &out,
1241
1218
const ScopeCreator *scopeCreator) {
1242
1219
scopeCreator->print (out);
1243
1220
}
1244
-
1245
- // ----------------------------------------------------------------------------//
1246
- // ExpandASTScopeRequest computation.
1247
- // ----------------------------------------------------------------------------//
1248
-
1249
- bool ExpandASTScopeRequest::isCached () const {
1250
- ASTScopeImpl *scope = std::get<0 >(getStorage ());
1251
- return scope->getWasExpanded ();
1252
- }
1253
-
1254
- Optional<ASTScopeImpl *> ExpandASTScopeRequest::getCachedResult () const {
1255
- return std::get<0 >(getStorage ());
1256
- }
0 commit comments