Commit 3a9c7b55 authored by verwaest's avatar verwaest Committed by Commit bot

Store NonLocals in variables_

Now that ordered_variables_ is used to find non-dynamic variables, and NonLocals are always stored in the scope that introduces them, we can rely on variables_ to also cache non-locals. This has 2 advantages:
1) we don't need DynamicScopePart anymore, reducing all scopes by a pointer
2) upon second lookup of a non-local we don't need to walk the entire chain anymore. The cached value will immediately be found.

BUG=v8:5209

Review-Url: https://codereview.chromium.org/2276483003
Cr-Commit-Position: refs/heads/master@{#38855}
parent a5c29021
...@@ -217,7 +217,6 @@ void Scope::SetDefaults() { ...@@ -217,7 +217,6 @@ void Scope::SetDefaults() {
inner_scope_ = nullptr; inner_scope_ = nullptr;
sibling_ = nullptr; sibling_ = nullptr;
unresolved_ = nullptr; unresolved_ = nullptr;
dynamics_ = nullptr;
start_position_ = kNoSourcePosition; start_position_ = kNoSourcePosition;
end_position_ = kNoSourcePosition; end_position_ = kNoSourcePosition;
...@@ -1077,14 +1076,16 @@ static void PrintVar(int indent, Variable* var) { ...@@ -1077,14 +1076,16 @@ static void PrintVar(int indent, Variable* var) {
} }
} }
static void PrintMap(int indent, VariableMap* map, bool locals) {
static void PrintMap(int indent, VariableMap* map) { for (VariableMap::Entry* p = map->Start(); p != nullptr; p = map->Next(p)) {
for (VariableMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) {
Variable* var = reinterpret_cast<Variable*>(p->value); Variable* var = reinterpret_cast<Variable*>(p->value);
if (var == NULL) { bool local = !IsDynamicVariableMode(var->mode());
Indent(indent, "<?>\n"); if (locals ? local : !local) {
} else { if (var == nullptr) {
PrintVar(indent, var); Indent(indent, "<?>\n");
} else {
PrintVar(indent, var);
}
} }
} }
} }
...@@ -1173,14 +1174,10 @@ void Scope::Print(int n) { ...@@ -1173,14 +1174,10 @@ void Scope::Print(int n) {
if (variables_.Start() != NULL) { if (variables_.Start() != NULL) {
Indent(n1, "// local vars:\n"); Indent(n1, "// local vars:\n");
PrintMap(n1, &variables_); PrintMap(n1, &variables_, true);
}
if (dynamics_ != NULL) {
Indent(n1, "// dynamic vars:\n"); Indent(n1, "// dynamic vars:\n");
PrintMap(n1, dynamics_->GetMap(DYNAMIC)); PrintMap(n1, &variables_, false);
PrintMap(n1, dynamics_->GetMap(DYNAMIC_LOCAL));
PrintMap(n1, dynamics_->GetMap(DYNAMIC_GLOBAL));
} }
// Print inner scopes (disable by providing negative n). // Print inner scopes (disable by providing negative n).
...@@ -1215,17 +1212,12 @@ void Scope::CheckZones() { ...@@ -1215,17 +1212,12 @@ void Scope::CheckZones() {
#endif // DEBUG #endif // DEBUG
Variable* Scope::NonLocal(const AstRawString* name, VariableMode mode) { Variable* Scope::NonLocal(const AstRawString* name, VariableMode mode) {
if (dynamics_ == NULL) dynamics_ = new (zone()) DynamicScopePart(zone()); // Declare a new non-local.
VariableMap* map = dynamics_->GetMap(mode); DCHECK(IsDynamicVariableMode(mode));
Variable* var = map->Lookup(name); Variable* var = variables_.Declare(zone(), NULL, name, mode, Variable::NORMAL,
if (var == NULL) { kCreatedInitialized);
// Declare a new non-local. // Allocate it by giving it a dynamic lookup.
DCHECK(!IsLexicalVariableMode(mode)); var->AllocateTo(VariableLocation::LOOKUP, -1);
var = map->Declare(zone(), NULL, name, mode, Variable::NORMAL,
kCreatedInitialized);
// Allocate it by giving it a dynamic lookup.
var->AllocateTo(VariableLocation::LOOKUP, -1);
}
return var; return var;
} }
......
...@@ -30,28 +30,6 @@ class VariableMap: public ZoneHashMap { ...@@ -30,28 +30,6 @@ class VariableMap: public ZoneHashMap {
}; };
// The dynamic scope part holds hash maps for the variables that will
// be looked up dynamically from within eval and with scopes. The objects
// are allocated on-demand from Scope::NonLocal to avoid wasting memory
// and setup time for scopes that don't need them.
class DynamicScopePart : public ZoneObject {
public:
explicit DynamicScopePart(Zone* zone) {
for (int i = 0; i < 3; i++)
maps_[i] = new(zone->New(sizeof(VariableMap))) VariableMap(zone);
}
VariableMap* GetMap(VariableMode mode) {
int index = mode - DYNAMIC;
DCHECK(index >= 0 && index < 3);
return maps_[index];
}
private:
VariableMap *maps_[3];
};
// Sloppy block-scoped function declarations to var-bind // Sloppy block-scoped function declarations to var-bind
class SloppyBlockFunctionMap : public ZoneHashMap { class SloppyBlockFunctionMap : public ZoneHashMap {
public: public:
...@@ -474,8 +452,6 @@ class Scope: public ZoneObject { ...@@ -474,8 +452,6 @@ class Scope: public ZoneObject {
// map above in order of addition. // map above in order of addition.
// TODO(verwaest): Thread through Variable. // TODO(verwaest): Thread through Variable.
ZoneList<Variable*> ordered_variables_; ZoneList<Variable*> ordered_variables_;
// Variables that must be looked up dynamically.
DynamicScopePart* dynamics_;
// Unresolved variables referred to from this scope. The proxies themselves // Unresolved variables referred to from this scope. The proxies themselves
// form a linked list of all unresolved proxies. // form a linked list of all unresolved proxies.
VariableProxy* unresolved_; VariableProxy* unresolved_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment