Hole check elimination: compare closure scopes instead of declaration scopes

Varblock scopes can be treated as the "same scope" as their surrounding
function scope for the purposes of hole check elimination, as
source position comparison is sufficient to determine statically that
uses in the varblock scope are after initialization in the function scope.

This allows the elimination of hole checks of lexically-bound parameter
variables in functions with complex parameters, including rest parameters.

The pre-existing code compared DeclarationScopes for legacy reasons:
varblock scopes (and Scope::GetClosureScope()) did not exist at the
time this code was originally written.

R=neis@chromium.org

Bug: v8:6344, v8:6414
Change-Id: Ie787d58d1ea172e893788a9c716d3b6868980ab8
Reviewed-on: https://chromium-review.googlesource.com/508242
Commit-Queue: Adam Klein <adamk@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45405}
This commit is contained in:
Adam Klein 2017-05-18 12:52:02 -07:00 committed by Commit Bot
parent 9397c1b73a
commit afdf27fc78

View File

@ -1952,7 +1952,7 @@ void UpdateNeedsHoleCheck(Variable* var, VariableProxy* proxy, Scope* scope) {
// the source physically located after the initializer of the variable,
// and that the initializer cannot be skipped due to a nonlinear scope.
//
// The condition on the declaration scopes is a conservative check for
// The condition on the closure scopes is a conservative check for
// nested functions that access a binding and are called before the
// binding is initialized:
// function() { f(); let x = 1; function f() { x = 2; } }
@ -1962,12 +1962,12 @@ void UpdateNeedsHoleCheck(Variable* var, VariableProxy* proxy, Scope* scope) {
// switch (1) { case 0: let x = 2; case 1: f(x); }
// The scope of the variable needs to be checked, in case the use is
// in a sub-block which may be linear.
if (var->scope()->GetDeclarationScope() != scope->GetDeclarationScope()) {
if (var->scope()->GetClosureScope() != scope->GetClosureScope()) {
return SetNeedsHoleCheck(var, proxy);
}
if (var->is_this()) {
DCHECK(IsDerivedConstructor(scope->GetDeclarationScope()->function_kind()));
DCHECK(IsDerivedConstructor(scope->GetClosureScope()->function_kind()));
// TODO(littledan): implement 'this' hole check elimination.
return SetNeedsHoleCheck(var, proxy);
}