Skip to content

Commit

Permalink
[interpreter] Don't number non-lexicals in TDZ elision
Browse files Browse the repository at this point in the history
Non-lexical bindings don't need to be numbered because they don't have a
TDZ. It is not incorrect to number them, but wasteful and may prevent
lexicals from being numbered and elidable.

Bug: v8:13723
Change-Id: Ife8de789622978b173951dd6d89231397af9dc53
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4552603
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#87810}
  • Loading branch information
syg authored and V8 LUCI CQ committed May 23, 2023
1 parent 290f58a commit 260b62d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/ast/scopes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,10 @@ void DeclarationScope::DeclareThis(AstValueFactory* ast_value_factory) {
THIS_VARIABLE,
derived_constructor ? kNeedsInitialization : kCreatedInitialized,
kNotAssigned);
// Derived constructors have hole checks when calling super. Mark the 'this'
// variable as having hole initialization forced so that TDZ elision analysis
// applies and numbers the variable.
if (derived_constructor) receiver_->ForceHoleInitialization();
locals_.Add(receiver_);
}

Expand Down
4 changes: 2 additions & 2 deletions src/interpreter/bytecode-generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4031,7 +4031,7 @@ void BytecodeGenerator::BuildVariableAssignment(
}

if (mode != VariableMode::kConst || op == Token::INIT) {
if (op == Token::INIT) {
if (op == Token::INIT && variable->IsHoleInitializationForced()) {
// After initializing a variable it won't be the hole anymore, so
// elide subsequent checks.
RememberHoleCheckInCurrentBlock(variable);
Expand Down Expand Up @@ -4072,7 +4072,7 @@ void BytecodeGenerator::BuildVariableAssignment(
}

if (mode != VariableMode::kConst || op == Token::INIT) {
if (op == Token::INIT) {
if (op == Token::INIT && variable->IsHoleInitializationForced()) {
// After initializing a variable it won't be the hole anymore, so
// elide subsequent checks.
RememberHoleCheckInCurrentBlock(variable);
Expand Down

0 comments on commit 260b62d

Please sign in to comment.