From d71837a31695817533a1418b6457894e8787e552 Mon Sep 17 00:00:00 2001 From: Tess Strickland Date: Fri, 9 Aug 2024 14:16:49 +0000 Subject: [PATCH] [vm/compiler] Remove dead code in LocalScope/bitfield in LocalVariable. There are no callers of CaptureLocalVariables(), and only CaptureLocalVariables() checks the IsForcedStackBit bitfield of LocalVariables, so remove that and its setter/getter as well. TEST=ci (dead code removal) Issue: https://github.com/dart-lang/sdk/issues/27590 Change-Id: I8032ff8f8cd7a43d3d30f1a4ec4e37cbfcee0a82 Cq-Include-Trybots: luci.dart.try:vm-aot-linux-release-x64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/379802 Commit-Queue: Tess Strickland Reviewed-by: Daco Harkes --- runtime/vm/compiler/frontend/scope_builder.cc | 6 ----- runtime/vm/scopes.cc | 22 ------------------- runtime/vm/scopes.h | 18 ++------------- 3 files changed, 2 insertions(+), 44 deletions(-) diff --git a/runtime/vm/compiler/frontend/scope_builder.cc b/runtime/vm/compiler/frontend/scope_builder.cc index 4fbf80ae878e..6bcf76390d3c 100644 --- a/runtime/vm/compiler/frontend/scope_builder.cc +++ b/runtime/vm/compiler/frontend/scope_builder.cc @@ -98,7 +98,6 @@ ScopeBuildingResult* ScopeBuilder::BuildScopes() { LocalVariable* suspend_state_var = MakeVariable(TokenPosition::kNoSource, TokenPosition::kNoSource, Symbols::SuspendStateVar(), AbstractType::dynamic_type()); - suspend_state_var->set_is_forced_stack(); suspend_state_var->set_invisible(true); scope_->AddVariable(suspend_state_var); parsed_function_->set_suspend_state_var(suspend_state_var); @@ -118,7 +117,6 @@ ScopeBuildingResult* ScopeBuilder::BuildScopes() { } LocalVariable* context_var = parsed_function_->current_context_var(); - context_var->set_is_forced_stack(); scope_->AddVariable(context_var); parsed_function_->set_scope(scope_); @@ -178,7 +176,6 @@ ScopeBuildingResult* ScopeBuilder::BuildScopes() { LocalVariable* closure_parameter = MakeVariable( TokenPosition::kNoSource, TokenPosition::kNoSource, Symbols::ClosureParameter(), AbstractType::dynamic_type()); - closure_parameter->set_is_forced_stack(); scope_->InsertParameterAt(pos++, closure_parameter); } else if (!function.is_static()) { // We use [is_static] instead of [IsStaticFunction] because the latter @@ -1798,7 +1795,6 @@ void ScopeBuilder::AddExceptionVariable( // If transformer did not lift the variable then there is no need // to lift it into the context when we encounter a YieldStatement. - v->set_is_forced_stack(); current_function_scope_->AddVariable(v); } @@ -1820,7 +1816,6 @@ void ScopeBuilder::FinalizeExceptionVariable( raw_variable = new LocalVariable(TokenPosition::kNoSource, TokenPosition::kNoSource, symbol, AbstractType::dynamic_type()); - raw_variable->set_is_forced_stack(); const bool ok = scope_->AddVariable(raw_variable); ASSERT(ok); } else { @@ -1857,7 +1852,6 @@ void ScopeBuilder::AddSwitchVariable() { LocalVariable* variable = MakeVariable(TokenPosition::kNoSource, TokenPosition::kNoSource, Symbols::SwitchExpr(), AbstractType::dynamic_type()); - variable->set_is_forced_stack(); current_function_scope_->AddVariable(variable); result_->switch_variable = variable; } diff --git a/runtime/vm/scopes.cc b/runtime/vm/scopes.cc index 9931a4683498..da03c6a6127f 100644 --- a/runtime/vm/scopes.cc +++ b/runtime/vm/scopes.cc @@ -555,28 +555,6 @@ LocalScope* LocalScope::RestoreOuterScope(const ContextScope& context_scope) { return outer_scope; } -void LocalScope::CaptureLocalVariables(LocalScope* top_scope) { - ASSERT(top_scope->function_level() == function_level()); - LocalScope* scope = this; - while (scope != top_scope->parent()) { - for (intptr_t i = 0; i < scope->num_variables(); i++) { - LocalVariable* variable = scope->VariableAt(i); - if (variable->is_forced_stack() || - (variable->name().ptr() == Symbols::ExceptionVar().ptr()) || - (variable->name().ptr() == Symbols::SavedTryContextVar().ptr()) || - (variable->name().ptr() == Symbols::ArgDescVar().ptr()) || - (variable->name().ptr() == - Symbols::FunctionTypeArgumentsVar().ptr())) { - // Don't capture those variables because the VM expects them to be on - // the stack. - continue; - } - scope->CaptureVariable(variable); - } - scope = scope->parent(); - } -} - ContextScopePtr LocalScope::CreateImplicitClosureScope(const Function& func) { const intptr_t kNumCapturedVars = 1; diff --git a/runtime/vm/scopes.h b/runtime/vm/scopes.h index 4440f23c2fb4..59b3e382990f 100644 --- a/runtime/vm/scopes.h +++ b/runtime/vm/scopes.h @@ -148,15 +148,6 @@ class LocalVariable : public ZoneAllocated { is_awaiter_link_ = value ? IsAwaiterLink::kLink : IsAwaiterLink::kNotLink; } - // Variables marked as forced to stack are skipped and not captured by - // CaptureLocalVariables - which iterates scope chain between two scopes - // and indiscriminately marks all variables as captured. - // TODO(27590) remove the hardcoded list of names from CaptureLocalVariables - bool is_forced_stack() const { return IsForcedStackBit::decode(bitfield_); } - void set_is_forced_stack() { - bitfield_ = IsForcedStackBit::update(true, bitfield_); - } - bool is_late() const { return IsLateBit::decode(bitfield_); } void set_is_late() { bitfield_ = IsLateBit::update(true, bitfield_); } @@ -235,9 +226,8 @@ class LocalVariable : public ZoneAllocated { using IsInvisibleBit = BitField; using IsCapturedParameterBit = BitField; - using IsForcedStackBit = - BitField; - using IsLateBit = BitField; + using IsLateBit = + BitField; enum CovarianceMode { kNotCovariant, @@ -431,10 +421,6 @@ class LocalScope : public ZoneAllocated { ContextScopePtr PreserveOuterScope(const Function& function, intptr_t current_context_level) const; - // Mark all local variables that are accessible from this scope up to - // top_scope (included) as captured unless they are marked as forced to stack. - void CaptureLocalVariables(LocalScope* top_scope); - // Creates a LocalScope representing the outer scope of a local function to be // compiled. This outer scope contains the variables captured by the function // as specified by the given ContextScope, which was created during the