Skip to content

Commit

Permalink
[vm/compiler] Remove dead code in LocalScope/bitfield in LocalVariable.
Browse files Browse the repository at this point in the history
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: #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 <sstrickl@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
  • Loading branch information
sstrickl authored and Commit Queue committed Aug 9, 2024
1 parent 0d67901 commit d71837a
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 44 deletions.
6 changes: 0 additions & 6 deletions runtime/vm/compiler/frontend/scope_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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_);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down
22 changes: 0 additions & 22 deletions runtime/vm/scopes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
18 changes: 2 additions & 16 deletions runtime/vm/scopes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_); }

Expand Down Expand Up @@ -235,9 +226,8 @@ class LocalVariable : public ZoneAllocated {
using IsInvisibleBit = BitField<uint32_t, bool, IsCapturedBit::kNextBit, 1>;
using IsCapturedParameterBit =
BitField<uint32_t, bool, IsInvisibleBit::kNextBit, 1>;
using IsForcedStackBit =
BitField<uint32_t, bool, IsCapturedParameterBit::kNextBit, 1>;
using IsLateBit = BitField<uint32_t, bool, IsForcedStackBit ::kNextBit, 1>;
using IsLateBit =
BitField<uint32_t, bool, IsCapturedParameterBit ::kNextBit, 1>;

enum CovarianceMode {
kNotCovariant,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d71837a

Please sign in to comment.