Skip to content

Commit

Permalink
ASTScope: Allocate list of local bindings for BraceStmt in the ASTCon…
Browse files Browse the repository at this point in the history
…text

Scopes need to register cleanups for non-trivial ivars in the ASTContext.
Instead of doing that here, let's just change the SmallVectors into
ArrayRefs.

Fixes <rdar://problem/69908937>.
  • Loading branch information
slavapestov committed Oct 8, 2020
1 parent cb70220 commit ef26ecf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 4 additions & 4 deletions include/swift/AST/ASTScope.h
Expand Up @@ -1534,11 +1534,11 @@ class BraceStmtScope final : public AbstractStmtScope {
BraceStmt *const stmt;

/// Declarations which are in scope from the beginning of the statement.
SmallVector<ValueDecl *, 2> localFuncsAndTypes;
ArrayRef<ValueDecl *> localFuncsAndTypes;

/// Declarations that are normally in scope only after their
/// definition.
SmallVector<VarDecl *, 2> localVars;
ArrayRef<VarDecl *> localVars;

/// The end location for bindings introduced in this scope. This can
/// extend past the actual end of the BraceStmt in top-level code,
Expand All @@ -1548,8 +1548,8 @@ class BraceStmtScope final : public AbstractStmtScope {

public:
BraceStmtScope(BraceStmt *e,
SmallVector<ValueDecl *, 2> localFuncsAndTypes,
SmallVector<VarDecl *, 2> localVars,
ArrayRef<ValueDecl *> localFuncsAndTypes,
ArrayRef<VarDecl *> localVars,
SourceLoc endLoc)
: stmt(e),
localFuncsAndTypes(localFuncsAndTypes),
Expand Down
7 changes: 5 additions & 2 deletions lib/AST/ASTScopeCreation.cpp
Expand Up @@ -588,12 +588,15 @@ class NodeAdder
if (endLoc.hasValue())
endLocForBraceStmt = *endLoc;

if (auto *s = scopeCreator.getASTContext().Stats)
ASTContext &ctx = scopeCreator.getASTContext();
if (auto *s = ctx.Stats)
++s->getFrontendCounters().NumBraceStmtASTScopes;

return
scopeCreator.constructExpandAndInsert<BraceStmtScope>(
p, bs, std::move(localFuncsAndTypes), std::move(localVars),
p, bs,
ctx.AllocateCopy(localFuncsAndTypes),
ctx.AllocateCopy(localVars),
endLocForBraceStmt);
}

Expand Down

0 comments on commit ef26ecf

Please sign in to comment.