@@ -1739,10 +1739,10 @@ bool ASTScopeImpl::reexpandIfObsolete(ScopeCreator &scopeCreator) {
1739
1739
}
1740
1740
1741
1741
void ASTScopeImpl::reexpand (ScopeCreator &scopeCreator) {
1742
- auto scopesToReuse = rescueScopesToReuse ();
1742
+ auto astAncestorScopes = rescueASTAncestorScopesForReuseFromMeOrDescendants ();
1743
1743
disownDescendants (scopeCreator);
1744
1744
expandAndBeCurrent (scopeCreator);
1745
- addReusedScopes (scopesToReuse );
1745
+ replaceASTAncestorScopes (astAncestorScopes );
1746
1746
}
1747
1747
1748
1748
#pragma mark getScopeCreator
@@ -1911,34 +1911,43 @@ bool WholeClosureScope::isCurrentIfWasExpanded() const {
1911
1911
return bodyWhenLastExpanded == closureExpr->getBody ();
1912
1912
}
1913
1913
1914
- #pragma mark getParentOfRescuedScopes
1915
- NullablePtr<ASTScopeImpl> ASTScopeImpl::getParentOfRescuedScopes () {
1914
+ #pragma mark getParentOfASTAncestorScopesToBeRescued
1915
+ NullablePtr<ASTScopeImpl>
1916
+ ASTScopeImpl::getParentOfASTAncestorScopesToBeRescued () {
1916
1917
return this ;
1917
1918
}
1918
1919
NullablePtr<ASTScopeImpl>
1919
- AbstractFunctionBodyScope::getParentOfRescuedScopes () {
1920
+ AbstractFunctionBodyScope::getParentOfASTAncestorScopesToBeRescued () {
1920
1921
// Reexpansion always creates a new body as the first child
1922
+ // That body contains the scopes to be rescued.
1921
1923
return getChildren ().empty () ? nullptr : getChildren ().front ();
1922
1924
}
1923
- NullablePtr<ASTScopeImpl> TopLevelCodeScope::getParentOfRescuedScopes () {
1925
+ NullablePtr<ASTScopeImpl>
1926
+ TopLevelCodeScope::getParentOfASTAncestorScopesToBeRescued () {
1924
1927
// Reexpansion always creates a new body as the first child
1928
+ // That body contains the scopes to be rescued.
1925
1929
return getChildren ().empty () ? nullptr : getChildren ().front ();
1926
1930
}
1927
1931
1928
1932
#pragma mark rescuing & reusing
1929
- std::vector<ASTScopeImpl *> ASTScopeImpl::rescueScopesToReuse () {
1930
- // If I was never expanded, then there won't be any rescuable scopes.
1931
- if (!wasEverExpanded ())
1933
+ std::vector<ASTScopeImpl *>
1934
+ ASTScopeImpl::rescueASTAncestorScopesForReuseFromMeOrDescendants () {
1935
+ // If I was never expanded, then there won't be any rescuable scopes.
1936
+ if (!getWasExpanded ())
1932
1937
return {};
1933
- if (auto *p = getParentOfRescuedScopes ().getPtrOrNull ()) {
1934
- return p->rescueYoungestChildren (p-> getChildren (). size () -
1935
- p->getChildrenCountWhenLastExpanded ());
1938
+ if (auto *p = getParentOfASTAncestorScopesToBeRescued ().getPtrOrNull ()) {
1939
+ return p->rescueASTAncestorScopesForReuseFromMe (
1940
+ p-> getChildren (). size () - p->getChildrenCountWhenLastExpanded ());
1936
1941
}
1942
+ ASTScopeAssert (
1943
+ scopesFromASTAncestors == 0 ,
1944
+ " If receives ASTAncestor scopes, must know where to find parent" );
1937
1945
return {};
1938
1946
}
1939
1947
1940
- void ASTScopeImpl::addReusedScopes (ArrayRef<ASTScopeImpl *> scopesToAdd) {
1941
- auto *p = getParentOfRescuedScopes ().getPtrOrNull ();
1948
+ void ASTScopeImpl::replaceASTAncestorScopes (
1949
+ ArrayRef<ASTScopeImpl *> scopesToAdd) {
1950
+ auto *p = getParentOfASTAncestorScopesToBeRescued ().getPtrOrNull ();
1942
1951
if (!p) {
1943
1952
ASTScopeAssert (scopesToAdd.empty (), " Non-empty body disappeared?!" );
1944
1953
return ;
@@ -1952,16 +1961,17 @@ void ASTScopeImpl::addReusedScopes(ArrayRef<ASTScopeImpl *> scopesToAdd) {
1952
1961
}
1953
1962
1954
1963
std::vector<ASTScopeImpl *>
1955
- ASTScopeImpl::rescueYoungestChildren (const unsigned int count) {
1956
- std::vector<ASTScopeImpl *> youngestChildren ;
1964
+ ASTScopeImpl::rescueASTAncestorScopesForReuseFromMe (const unsigned int count) {
1965
+ std::vector<ASTScopeImpl *> astAncestorScopes ;
1957
1966
for (unsigned i = getChildren ().size () - count; i < getChildren ().size (); ++i)
1958
- youngestChildren .push_back (getChildren ()[i]);
1967
+ astAncestorScopes .push_back (getChildren ()[i]);
1959
1968
// So they don't get disowned and children cleared.
1960
1969
for (unsigned i = 0 ; i < count; ++i) {
1961
1970
storedChildren.back ()->emancipate ();
1962
1971
storedChildren.pop_back ();
1972
+ --scopesFromASTAncestors;
1963
1973
}
1964
- return youngestChildren ;
1974
+ return astAncestorScopes ;
1965
1975
}
1966
1976
1967
1977
unsigned ASTScopeImpl::getChildrenCountWhenLastExpanded () const {
0 commit comments