30
30
31
31
#include " swift/AST/ASTNode.h"
32
32
#include " swift/AST/NameLookup.h" // for DeclVisibilityKind
33
+ #include " swift/AST/SimpleRequest.h"
33
34
#include " swift/Basic/Compiler.h"
34
35
#include " swift/Basic/LLVM.h"
35
36
#include " swift/Basic/NullablePtr.h"
@@ -88,6 +89,14 @@ struct AnnotatedInsertionPoint {
88
89
ASTScopeImpl *insertionPoint;
89
90
const char *explanation;
90
91
};
92
+ } // namespace ast_scope
93
+
94
+ namespace ast_scope {
95
+
96
+ void simple_display (llvm::raw_ostream &out, const ASTScopeImpl *);
97
+ void simple_display (llvm::raw_ostream &out, const ScopeCreator *);
98
+
99
+ SourceLoc extractNearestSourceLoc (std::tuple<ASTScopeImpl *, ScopeCreator *>);
91
100
92
101
#pragma mark the root ASTScopeImpl class
93
102
@@ -333,6 +342,11 @@ class ASTScopeImpl {
333
342
public:
334
343
// / expandScope me, sending deferred nodes to my descendants.
335
344
// / Return the scope into which to place subsequent decls
345
+ ASTScopeImpl *expandAndBeCurrentDetectingRecursion (ScopeCreator &);
346
+
347
+ // / Expand or reexpand the scope if unexpanded or if not current.
348
+ // / There are several places in the compiler that mutate the AST after the
349
+ // / fact, above and beyond adding Decls to the SourceFile.
336
350
ASTScopeImpl *expandAndBeCurrent (ScopeCreator &);
337
351
338
352
unsigned getASTAncestorScopeCount () const { return astAncestorScopeCount; }
@@ -344,6 +358,12 @@ class ASTScopeImpl {
344
358
void setWasExpanded () { wasExpanded = true ; }
345
359
virtual ASTScopeImpl *expandSpecifically (ScopeCreator &) = 0;
346
360
virtual void beCurrent ();
361
+ virtual bool doesExpansionOnlyAddNewDeclsAtEnd () const ;
362
+
363
+ public:
364
+ bool isExpansionNeeded (const ScopeCreator &) const ;
365
+
366
+ protected:
347
367
bool isCurrent () const ;
348
368
virtual bool isCurrentIfWasExpanded () const ;
349
369
@@ -374,16 +394,7 @@ class ASTScopeImpl {
374
394
375
395
bool isATypeDeclScope () const ;
376
396
377
- // / There are several places in the compiler that mutate the AST after the
378
- // / fact, above and beyond adding Decls to the SourceFile. These are
379
- // / documented in: rdar://53018839, rdar://53027266, rdar://53027733,
380
- // / rdar://53028050
381
- // / Return true if did reexpand
382
- bool reexpandIfObsolete (ScopeCreator &);
383
-
384
397
private:
385
- void reexpand (ScopeCreator &);
386
-
387
398
virtual ScopeCreator &getScopeCreator ();
388
399
389
400
#pragma mark - - creation queries
@@ -533,8 +544,8 @@ class ASTSourceFileScope final : public ASTScopeImpl {
533
544
// / The number of \c Decls in the \c SourceFile that were already seen.
534
545
// / Since parsing can be interleaved with type-checking, on every
535
546
// / lookup, look at creating scopes for any \c Decls beyond this number.
536
- // / rdar://55562483 Unify with numberOfChildrenWhenLastExpanded
537
- int numberOfDeclsAlreadySeen = 0 ;
547
+ // / TODO: Unify with numberOfChildrenWhenLastExpanded
548
+ size_t numberOfDeclsAlreadySeen = 0 ;
538
549
539
550
ASTSourceFileScope (SourceFile *SF, ScopeCreator *scopeCreator);
540
551
@@ -548,7 +559,6 @@ class ASTSourceFileScope final : public ASTScopeImpl {
548
559
public:
549
560
NullablePtr<DeclContext> getDeclContext () const override ;
550
561
551
- void addNewDeclsToScopeTree ();
552
562
void buildFullyExpandedTree ();
553
563
void
554
564
buildEnoughOfTreeForTopLevelExpressionsButDontRequestGenericsOrExtendedNominals ();
@@ -559,11 +569,15 @@ class ASTSourceFileScope final : public ASTScopeImpl {
559
569
560
570
protected:
561
571
ASTScopeImpl *expandSpecifically (ScopeCreator &scopeCreator) override ;
572
+ bool isCurrentIfWasExpanded () const override ;
573
+ void beCurrent () override ;
574
+ bool doesExpansionOnlyAddNewDeclsAtEnd () const override ;
562
575
563
576
ScopeCreator &getScopeCreator () override ;
564
577
565
578
private:
566
- void expandAScopeThatDoesNotCreateANewInsertionPoint (ScopeCreator &);
579
+ AnnotatedInsertionPoint
580
+ expandAScopeThatCreatesANewInsertionPoint (ScopeCreator &);
567
581
};
568
582
569
583
class Portion {
@@ -1148,7 +1162,6 @@ class AttachedPropertyWrapperScope final : public ASTScopeImpl {
1148
1162
// / false positives, that that doesn't hurt anything. However, the result of
1149
1163
// / the conservative source range computation doesn't seem to be stable. So
1150
1164
// / keep the original here, and use it for source range queries.
1151
- // / rdar://55263708
1152
1165
1153
1166
const SourceRange sourceRangeWhenCreated;
1154
1167
@@ -1251,7 +1264,6 @@ class PatternEntryDeclScope final : public AbstractPatternEntryScope {
1251
1264
};
1252
1265
1253
1266
class PatternEntryInitializerScope final : public AbstractPatternEntryScope {
1254
- // Should be able to remove this when rdar://53921703 is accomplished.
1255
1267
Expr *initAsWrittenWhenCreated;
1256
1268
1257
1269
public:
0 commit comments