Skip to content

Commit cf33a8a

Browse files
author
David Ungar
committed
---
yaml --- r: 326303 b: refs/heads/master-next c: 7f834cd h: refs/heads/master i: 326301: 328097c 326299: 97ddb6f 326295: 2fd8e11 326287: ee45234 326271: a721ae0
1 parent 43747de commit cf33a8a

File tree

3 files changed

+37
-25
lines changed

3 files changed

+37
-25
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: e052da7d8886fa0439677852e8f7830b20c2e1da
3-
refs/heads/master-next: 10583f89c6c014537baefb1f772df096a71a0c5c
3+
refs/heads/master-next: 7f834cdb54a7f9b1bb04eba3f9a6688a6b058d20
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea
66
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-b: 66d897bfcf64a82cb9a87f5e663d889189d06d07

branches/master-next/include/swift/AST/ASTScope.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,14 @@ class ASTScopeImpl {
193193

194194
public: // for addReusedBodyScopes
195195
void addChild(ASTScopeImpl *child, ASTContext &);
196-
std::vector<ASTScopeImpl *> rescueYoungestChildren(unsigned count);
196+
std::vector<ASTScopeImpl *>
197+
rescueASTAncestorScopesForReuseFromMe(unsigned count);
197198

198199
/// When reexpanding, do we always create a new body?
199-
virtual NullablePtr<ASTScopeImpl> getParentOfRescuedScopes();
200-
std::vector<ASTScopeImpl *> rescueScopesToReuse();
201-
void addReusedScopes(ArrayRef<ASTScopeImpl *>);
200+
virtual NullablePtr<ASTScopeImpl> getParentOfASTAncestorScopesToBeRescued();
201+
std::vector<ASTScopeImpl *>
202+
rescueASTAncestorScopesForReuseFromMeOrDescendants();
203+
void replaceASTAncestorScopes(ArrayRef<ASTScopeImpl *>);
202204

203205
private:
204206
void removeChildren();
@@ -1073,7 +1075,7 @@ class AbstractFunctionBodyScope : public ASTScopeImpl {
10731075
Decl *getDecl() const { return decl; }
10741076
static bool isAMethod(const AbstractFunctionDecl *);
10751077

1076-
NullablePtr<ASTScopeImpl> getParentOfRescuedScopes() override;
1078+
NullablePtr<ASTScopeImpl> getParentOfASTAncestorScopesToBeRescued() override;
10771079

10781080
protected:
10791081
bool lookupLocalsOrMembers(ArrayRef<const ASTScopeImpl *>,
@@ -1496,7 +1498,7 @@ class TopLevelCodeScope final : public ASTScopeImpl {
14961498
Decl *getDecl() const { return decl; }
14971499
NullablePtr<const void> getReferrent() const override;
14981500

1499-
NullablePtr<ASTScopeImpl> getParentOfRescuedScopes() override;
1501+
NullablePtr<ASTScopeImpl> getParentOfASTAncestorScopesToBeRescued() override;
15001502
};
15011503

15021504
/// The \c _@specialize attribute.

branches/master-next/lib/AST/ASTScopeCreation.cpp

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,10 +1739,10 @@ bool ASTScopeImpl::reexpandIfObsolete(ScopeCreator &scopeCreator) {
17391739
}
17401740

17411741
void ASTScopeImpl::reexpand(ScopeCreator &scopeCreator) {
1742-
auto scopesToReuse = rescueScopesToReuse();
1742+
auto astAncestorScopes = rescueASTAncestorScopesForReuseFromMeOrDescendants();
17431743
disownDescendants(scopeCreator);
17441744
expandAndBeCurrent(scopeCreator);
1745-
addReusedScopes(scopesToReuse);
1745+
replaceASTAncestorScopes(astAncestorScopes);
17461746
}
17471747

17481748
#pragma mark getScopeCreator
@@ -1911,34 +1911,43 @@ bool WholeClosureScope::isCurrentIfWasExpanded() const {
19111911
return bodyWhenLastExpanded == closureExpr->getBody();
19121912
}
19131913

1914-
#pragma mark getParentOfRescuedScopes
1915-
NullablePtr<ASTScopeImpl> ASTScopeImpl::getParentOfRescuedScopes() {
1914+
#pragma mark getParentOfASTAncestorScopesToBeRescued
1915+
NullablePtr<ASTScopeImpl>
1916+
ASTScopeImpl::getParentOfASTAncestorScopesToBeRescued() {
19161917
return this;
19171918
}
19181919
NullablePtr<ASTScopeImpl>
1919-
AbstractFunctionBodyScope::getParentOfRescuedScopes() {
1920+
AbstractFunctionBodyScope::getParentOfASTAncestorScopesToBeRescued() {
19201921
// Reexpansion always creates a new body as the first child
1922+
// That body contains the scopes to be rescued.
19211923
return getChildren().empty() ? nullptr : getChildren().front();
19221924
}
1923-
NullablePtr<ASTScopeImpl> TopLevelCodeScope::getParentOfRescuedScopes() {
1925+
NullablePtr<ASTScopeImpl>
1926+
TopLevelCodeScope::getParentOfASTAncestorScopesToBeRescued() {
19241927
// Reexpansion always creates a new body as the first child
1928+
// That body contains the scopes to be rescued.
19251929
return getChildren().empty() ? nullptr : getChildren().front();
19261930
}
19271931

19281932
#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())
19321937
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());
19361941
}
1942+
ASTScopeAssert(
1943+
scopesFromASTAncestors == 0,
1944+
"If receives ASTAncestor scopes, must know where to find parent");
19371945
return {};
19381946
}
19391947

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();
19421951
if (!p) {
19431952
ASTScopeAssert(scopesToAdd.empty(), "Non-empty body disappeared?!");
19441953
return;
@@ -1952,16 +1961,17 @@ void ASTScopeImpl::addReusedScopes(ArrayRef<ASTScopeImpl *> scopesToAdd) {
19521961
}
19531962

19541963
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;
19571966
for (unsigned i = getChildren().size() - count; i < getChildren().size(); ++i)
1958-
youngestChildren.push_back(getChildren()[i]);
1967+
astAncestorScopes.push_back(getChildren()[i]);
19591968
// So they don't get disowned and children cleared.
19601969
for (unsigned i = 0; i < count; ++i) {
19611970
storedChildren.back()->emancipate();
19621971
storedChildren.pop_back();
1972+
--scopesFromASTAncestors;
19631973
}
1964-
return youngestChildren;
1974+
return astAncestorScopes;
19651975
}
19661976

19671977
unsigned ASTScopeImpl::getChildrenCountWhenLastExpanded() const {

0 commit comments

Comments
 (0)