Commit 757221e5 authored by adamk's avatar adamk Committed by Commit bot

Remove more dead code now that legacy const is gone

Neither globals nor lookup slots can be hole-initialized anymore, thus
removing some dead code from the code generators and runtime-scopes.

Review-Url: https://codereview.chromium.org/2051073004
Cr-Commit-Position: refs/heads/master@{#36876}
parent af10c45e
......@@ -1132,13 +1132,9 @@ void AstGraphBuilder::VisitVariableDeclaration(VariableDeclaration* decl) {
}
break;
case VariableLocation::LOOKUP: {
DCHECK(!hole_init);
Node* name = jsgraph()->Constant(variable->name());
// For variables we must not push an initial value (such as 'undefined')
// because we may have a (legal) redeclaration and we must not destroy
// the current value.
Node* value =
hole_init ? jsgraph()->TheHoleConstant()
: jsgraph()->ZeroConstant(); // Indicates no initial value.
Node* value = jsgraph()->ZeroConstant(); // Indicates no initial value.
Node* attr =
jsgraph()->Constant(variable->DeclarationPropertyAttributes());
const Operator* op =
......
......@@ -803,15 +803,8 @@ void FullCodeGenerator::VisitVariableDeclaration(
__ mov(r2, Operand(variable->name()));
// Declaration nodes are always introduced in one of four modes.
DCHECK(IsDeclaredVariableMode(mode));
// Push initial value, if any.
// Note: For variables we must not push an initial value (such as
// 'undefined') because we may have a (legal) redeclaration and we
// must not destroy the current value.
if (hole_init) {
__ LoadRoot(r0, Heap::kTheHoleValueRootIndex);
} else {
DCHECK(!hole_init);
__ mov(r0, Operand(Smi::FromInt(0))); // Indicates no initial value.
}
__ Push(r2, r0);
__ Push(Smi::FromInt(variable->DeclarationPropertyAttributes()));
__ CallRuntime(Runtime::kDeclareLookupSlot);
......
......@@ -800,17 +800,9 @@ void FullCodeGenerator::VisitVariableDeclaration(
__ Mov(x2, Operand(variable->name()));
// Declaration nodes are always introduced in one of four modes.
DCHECK(IsDeclaredVariableMode(mode));
// Push initial value, if any.
// Note: For variables we must not push an initial value (such as
// 'undefined') because we may have a (legal) redeclaration and we
// must not destroy the current value.
if (hole_init) {
__ LoadRoot(x0, Heap::kTheHoleValueRootIndex);
__ Push(x2, x0);
} else {
DCHECK(!hole_init);
// Pushing 0 (xzr) indicates no initial value.
__ Push(x2, xzr);
}
__ Push(Smi::FromInt(variable->DeclarationPropertyAttributes()));
__ CallRuntime(Runtime::kDeclareLookupSlot);
PrepareForBailoutForId(proxy->id(), BailoutState::NO_REGISTERS);
......
......@@ -750,15 +750,8 @@ void FullCodeGenerator::VisitVariableDeclaration(
__ push(Immediate(variable->name()));
// VariableDeclaration nodes are always introduced in one of four modes.
DCHECK(IsDeclaredVariableMode(mode));
// Push initial value, if any.
// Note: For variables we must not push an initial value (such as
// 'undefined') because we may have a (legal) redeclaration and we
// must not destroy the current value.
if (hole_init) {
__ push(Immediate(isolate()->factory()->the_hole_value()));
} else {
DCHECK(!hole_init);
__ push(Immediate(Smi::FromInt(0))); // Indicates no initial value.
}
__ push(
Immediate(Smi::FromInt(variable->DeclarationPropertyAttributes())));
__ CallRuntime(Runtime::kDeclareLookupSlot);
......
......@@ -800,16 +800,9 @@ void FullCodeGenerator::VisitVariableDeclaration(
__ li(a2, Operand(variable->name()));
// Declaration nodes are always introduced in one of four modes.
DCHECK(IsDeclaredVariableMode(mode));
// Push initial value, if any.
// Note: For variables we must not push an initial value (such as
// 'undefined') because we may have a (legal) redeclaration and we
// must not destroy the current value.
if (hole_init) {
__ LoadRoot(a0, Heap::kTheHoleValueRootIndex);
} else {
DCHECK(!hole_init);
DCHECK(Smi::FromInt(0) == 0);
__ mov(a0, zero_reg); // Smi::FromInt(0) indicates no initial value.
}
__ Push(a2, a0);
__ Push(Smi::FromInt(variable->DeclarationPropertyAttributes()));
__ CallRuntime(Runtime::kDeclareLookupSlot);
......
......@@ -799,16 +799,9 @@ void FullCodeGenerator::VisitVariableDeclaration(
__ li(a2, Operand(variable->name()));
// Declaration nodes are always introduced in one of four modes.
DCHECK(IsDeclaredVariableMode(mode));
// Push initial value, if any.
// Note: For variables we must not push an initial value (such as
// 'undefined') because we may have a (legal) redeclaration and we
// must not destroy the current value.
if (hole_init) {
__ LoadRoot(a0, Heap::kTheHoleValueRootIndex);
} else {
DCHECK(!hole_init);
DCHECK(Smi::FromInt(0) == 0);
__ mov(a0, zero_reg); // Smi::FromInt(0) indicates no initial value.
}
__ Push(a2, a0);
__ Push(Smi::FromInt(variable->DeclarationPropertyAttributes()));
__ CallRuntime(Runtime::kDeclareLookupSlot);
......
......@@ -762,15 +762,8 @@ void FullCodeGenerator::VisitVariableDeclaration(
__ Push(variable->name());
// Declaration nodes are always introduced in one of four modes.
DCHECK(IsDeclaredVariableMode(mode));
// Push initial value, if any.
// Note: For variables we must not push an initial value (such as
// 'undefined') because we may have a (legal) redeclaration and we
// must not destroy the current value.
if (hole_init) {
__ PushRoot(Heap::kTheHoleValueRootIndex);
} else {
DCHECK(!hole_init);
__ Push(Smi::FromInt(0)); // Indicates no initial value.
}
__ Push(Smi::FromInt(variable->DeclarationPropertyAttributes()));
__ CallRuntime(Runtime::kDeclareLookupSlot);
PrepareForBailoutForId(proxy->id(), BailoutState::NO_REGISTERS);
......
......@@ -759,6 +759,7 @@ void BytecodeGenerator::VisitVariableDeclaration(VariableDeclaration* decl) {
break;
case VariableLocation::LOOKUP: {
DCHECK(IsDeclaredVariableMode(mode));
DCHECK(!hole_init);
register_allocator()->PrepareForConsecutiveAllocations(3);
Register name = register_allocator()->NextConsecutiveRegister();
......@@ -766,16 +767,9 @@ void BytecodeGenerator::VisitVariableDeclaration(VariableDeclaration* decl) {
Register attributes = register_allocator()->NextConsecutiveRegister();
builder()->LoadLiteral(variable->name()).StoreAccumulatorInRegister(name);
if (hole_init) {
builder()->LoadTheHole().StoreAccumulatorInRegister(init_value);
} else {
// For variables, we must not use an initial value (such as 'undefined')
// because we may have a (legal) redeclaration and we must not destroy
// the current value.
builder()
->LoadLiteral(Smi::FromInt(0))
.StoreAccumulatorInRegister(init_value);
}
builder()
->LoadLiteral(Smi::FromInt(variable->DeclarationPropertyAttributes()))
.StoreAccumulatorInRegister(attributes)
......
......@@ -34,7 +34,7 @@ RUNTIME_FUNCTION(Runtime_ThrowConstAssignError) {
static Object* DeclareGlobals(Isolate* isolate, Handle<JSGlobalObject> global,
Handle<String> name, Handle<Object> value,
PropertyAttributes attr, bool is_var,
bool is_const, bool is_function) {
bool is_function) {
Handle<ScriptContextTable> script_contexts(
global->native_context()->script_context_table());
ScriptContextTable::LookupResult lookup;
......@@ -51,7 +51,6 @@ static Object* DeclareGlobals(Isolate* isolate, Handle<JSGlobalObject> global,
if (it.IsFound()) {
PropertyAttributes old_attributes = maybe.FromJust();
// The name was declared before; check for conflicting re-declarations.
if (is_const) return ThrowRedeclarationError(isolate, name);
// Skip var re-declarations.
if (is_var) return isolate->heap()->undefined_value();
......@@ -106,14 +105,9 @@ RUNTIME_FUNCTION(Runtime_DeclareGlobals) {
Handle<String> name(String::cast(pairs->get(i)));
Handle<Object> initial_value(pairs->get(i + 1), isolate);
// We have to declare a global const property. To capture we only
// assign to it when evaluating the assignment for "const x =
// <expr>" the initial value is the hole.
bool is_var = initial_value->IsUndefined(isolate);
bool is_const = initial_value->IsTheHole(isolate);
bool is_function = initial_value->IsSharedFunctionInfo();
DCHECK_EQ(1,
BoolToInt(is_var) + BoolToInt(is_const) + BoolToInt(is_function));
DCHECK_EQ(1, BoolToInt(is_var) + BoolToInt(is_function));
Handle<Object> value;
if (is_function) {
......@@ -133,13 +127,12 @@ RUNTIME_FUNCTION(Runtime_DeclareGlobals) {
bool is_native = DeclareGlobalsNativeFlag::decode(flags);
bool is_eval = DeclareGlobalsEvalFlag::decode(flags);
int attr = NONE;
if (is_const) attr |= READ_ONLY;
if (is_function && is_native) attr |= READ_ONLY;
if (!is_const && !is_eval) attr |= DONT_DELETE;
if (!is_eval) attr |= DONT_DELETE;
Object* result = DeclareGlobals(isolate, global, name, value,
static_cast<PropertyAttributes>(attr),
is_var, is_const, is_function);
is_var, is_function);
if (isolate->has_pending_exception()) return result;
});
......@@ -210,10 +203,8 @@ Object* DeclareLookupSlot(Isolate* isolate, Handle<String> name,
// TODO(verwaest): Unify the encoding indicating "var" with DeclareGlobals.
bool is_var = *initial_value == NULL;
bool is_const = initial_value->IsTheHole(isolate);
bool is_function = initial_value->IsJSFunction();
DCHECK_EQ(1,
BoolToInt(is_var) + BoolToInt(is_const) + BoolToInt(is_function));
DCHECK_EQ(1, BoolToInt(is_var) + BoolToInt(is_function));
int index;
PropertyAttributes attributes;
......@@ -245,24 +236,24 @@ Object* DeclareLookupSlot(Isolate* isolate, Handle<String> name,
// but by DeclareGlobals instead.
if (attributes != ABSENT && holder->IsJSGlobalObject()) {
return DeclareGlobals(isolate, Handle<JSGlobalObject>::cast(holder), name,
value, attr, is_var, is_const, is_function);
value, attr, is_var, is_function);
}
if (context_arg->extension()->IsJSGlobalObject()) {
Handle<JSGlobalObject> global(
JSGlobalObject::cast(context_arg->extension()), isolate);
return DeclareGlobals(isolate, global, name, value, attr, is_var, is_const,
return DeclareGlobals(isolate, global, name, value, attr, is_var,
is_function);
} else if (context->IsScriptContext()) {
DCHECK(context->global_object()->IsJSGlobalObject());
Handle<JSGlobalObject> global(
JSGlobalObject::cast(context->global_object()), isolate);
return DeclareGlobals(isolate, global, name, value, attr, is_var, is_const,
return DeclareGlobals(isolate, global, name, value, attr, is_var,
is_function);
}
if (attributes != ABSENT) {
// The name was declared before; check for conflicting re-declarations.
if (is_const || (attributes & READ_ONLY) != 0) {
if ((attributes & READ_ONLY) != 0) {
return ThrowRedeclarationError(isolate, name);
}
......
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