Only treat lookup-slot-calls going through 'with' special

This replaces LOOKUP_SLOT_CALL with WITH_CALL, and relies on regular lookup-slot handling in variable load to support other lookup slots (variables resolved in the context of sloppy eval). This allows optimizations for such variable loads to kick in for calls as well. We only need special handling for function calls in the context of with, since it changes the receiver of the call from undefined/global to the with-object.

This currently doesn't yet make it work for the direct eval call itself, since the POSSIBLY_EVAL_CALL flag is also used to deal with direct eval later.

BUG=

Review-Url: https://codereview.chromium.org/2480253006
Cr-Commit-Position: refs/heads/master@{#40962}
This commit is contained in:
verwaest 2016-11-14 04:23:32 -08:00 committed by Commit bot
parent 1c9528c4c4
commit 733af7eb1a
6 changed files with 13 additions and 10 deletions

View File

@ -905,7 +905,9 @@ Call::CallType Call::GetCallType() const {
} else if (proxy->var()->IsUnallocated()) {
return GLOBAL_CALL;
} else if (proxy->var()->IsLookupSlot()) {
return LOOKUP_SLOT_CALL;
// Calls going through 'with' always use DYNAMIC rather than DYNAMIC_LOCAL
// or DYNAMIC_GLOBAL.
return proxy->var()->mode() == DYNAMIC ? WITH_CALL : OTHER_CALL;
}
}

View File

@ -1902,7 +1902,7 @@ class Call final : public Expression {
enum CallType {
POSSIBLY_EVAL_CALL,
GLOBAL_CALL,
LOOKUP_SLOT_CALL,
WITH_CALL,
NAMED_PROPERTY_CALL,
KEYED_PROPERTY_CALL,
NAMED_SUPER_PROPERTY_CALL,

View File

@ -2297,7 +2297,7 @@ void AstGraphBuilder::VisitCall(Call* expr) {
receiver_value = jsgraph()->UndefinedConstant();
break;
}
case Call::LOOKUP_SLOT_CALL: {
case Call::WITH_CALL: {
Variable* variable = callee->AsVariableProxy()->var();
DCHECK(variable->location() == VariableLocation::LOOKUP);
Node* name = jsgraph()->Constant(variable->name());

View File

@ -1673,8 +1673,8 @@ void FullCodeGenerator::VisitCall(Call* expr) {
case Call::GLOBAL_CALL:
EmitCallWithLoadIC(expr);
break;
case Call::LOOKUP_SLOT_CALL:
// Call to a lookup slot (dynamically introduced variable).
case Call::WITH_CALL:
// Call to a lookup slot looked up through a with scope.
PushCalleeAndWithBaseObject(expr);
EmitCall(expr);
break;

View File

@ -2391,7 +2391,7 @@ void BytecodeGenerator::VisitCall(Call* expr) {
builder()->StoreAccumulatorInRegister(callee);
break;
}
case Call::LOOKUP_SLOT_CALL:
case Call::WITH_CALL:
case Call::POSSIBLY_EVAL_CALL: {
if (callee_expr->AsVariableProxy()->var()->IsLookupSlot()) {
RegisterAllocationScope inner_register_scope(this);

View File

@ -11,7 +11,7 @@ snippet: "
"
frame size: 10
parameter count: 1
bytecode array length: 83
bytecode array length: 82
bytecodes: [
B(CreateFunctionContext), U8(3),
B(PushContext), R(0),
@ -41,9 +41,10 @@ bytecodes: [
B(CallRuntime), U16(Runtime::kResolvePossiblyDirectEval), R(4), U8(6),
B(Star), R(1),
/* 52 E> */ B(Call), R(1), R(2), U8(2), U8(2),
/* 62 S> */ B(LdaConstant), U8(1),
B(Star), R(3),
B(CallRuntimeForPair), U16(Runtime::kLoadLookupSlotForCall), R(3), U8(1), R(1),
/* 62 S> */ B(LdaUndefined),
B(Star), R(2),
/* 69 E> */ B(LdaLookupGlobalSlot), U8(1), U8(8), U8(1),
B(Star), R(1),
/* 69 E> */ B(Call), R(1), R(2), U8(1), U8(6),
/* 74 S> */ B(Return),
]