Reviewers: adamk,
Description:
Correct handling of temporaries as parameters.
They need to be properly recorded in the scope's temps set, otherwise
allocation
doesn't know about them and can break. (Not observable right now, but
necessary
for follow-up changes to parameter destructuring.)
Also, print temporary variables in a useful manner.
[email protected]
BUG=
Please review this at https://codereview.chromium.org/1263563002/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+17, -11 lines):
M src/parser.h
M src/scopes.cc
M src/variables.h
Index: src/parser.h
diff --git a/src/parser.h b/src/parser.h
index
87269ed619581862cb4038173286a1c4b0d42b28..c5bee739475532642c2f57a6ce58419052132afc
100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -1318,8 +1318,9 @@ void ParserTraits::DeclareFormalParameter(
const AstRawString* name = is_simple
? pattern->AsVariableProxy()->raw_name()
:
parser_->ast_value_factory()->empty_string();
+ VariableMode mode = is_simple ? VAR : TEMPORARY;
Variable* var =
- parameters->scope->DeclareParameter(name, VAR, is_rest,
&is_duplicate);
+ parameters->scope->DeclareParameter(name, mode, is_rest,
&is_duplicate);
parameters->AddParameter(var, is_simple ? nullptr : pattern);
if (is_duplicate) {
classifier->RecordDuplicateFormalParameterError(
Index: src/scopes.cc
diff --git a/src/scopes.cc b/src/scopes.cc
index
1473b2471f59ebbd87acf6cebdbd5f3c114cfc42..b8c81fc0897bcfcae474490ec2afde8efe9a1605
100644
--- a/src/scopes.cc
+++ b/src/scopes.cc
@@ -465,16 +465,14 @@ Variable* Scope::DeclareParameter(const AstRawString*
name, VariableMode mode,
bool is_rest, bool* is_duplicate) {
DCHECK(!already_resolved());
DCHECK(is_function_scope());
-
Variable* var;
- if (!name->IsEmpty()) {
+ if (mode == TEMPORARY) {
+ var = NewTemporary(name);
+ } else {
var = variables_.Declare(this, name, mode, Variable::NORMAL,
kCreatedInitialized);
// TODO(wingo): Avoid O(n^2) check.
*is_duplicate = IsDeclaredParameter(name);
- } else {
- var = new (zone())
- Variable(this, name, TEMPORARY, Variable::NORMAL,
kCreatedInitialized);
}
if (is_rest) {
DCHECK_NULL(rest_parameter_);
@@ -620,9 +618,10 @@ void Scope::CollectStackAndContextLocals(
if (var->IsContextSlot()) {
DCHECK(has_forced_context_allocation());
context_locals->Add(var, zone());
- } else {
- DCHECK(var->IsStackLocal());
+ } else if (var->IsStackLocal()) {
stack_locals->Add(var, zone());
+ } else {
+ DCHECK(var->IsParameter());
}
}
}
@@ -862,7 +861,10 @@ static void PrintVar(int indent, Variable* var) {
if (var->is_used() || !var->IsUnallocated()) {
Indent(indent, Variable::Mode2String(var->mode()));
PrintF(" ");
- PrintName(var->raw_name());
+ if (var->raw_name()->IsEmpty())
+ PrintF(".%p", var);
+ else
+ PrintName(var->raw_name());
PrintF("; // ");
PrintLocation(var);
bool comma = !var->IsUnallocated();
@@ -908,7 +910,11 @@ void Scope::Print(int n) {
PrintF(" (");
for (int i = 0; i < params_.length(); i++) {
if (i > 0) PrintF(", ");
- PrintName(params_[i]->raw_name());
+ const AstRawString* name = params_[i]->raw_name();
+ if (name->IsEmpty())
+ PrintF(".%p", params_[i]);
+ else
+ PrintName(name);
}
PrintF(")");
}
Index: src/variables.h
diff --git a/src/variables.h b/src/variables.h
index
deebc5f80c83b5a63afd37bc63d2b896e1890c8c..dcd2e6af6e02d5d90d9221580bcd38bd867e3736
100644
--- a/src/variables.h
+++ b/src/variables.h
@@ -44,7 +44,6 @@ class Variable: public ZoneObject {
return force_context_allocation_;
}
void ForceContextAllocation() {
- DCHECK(mode_ != TEMPORARY);
force_context_allocation_ = true;
}
bool is_used() { return is_used_; }
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.