- Revision
- 180723
- Author
- [email protected]
- Date
- 2015-02-26 21:12:46 -0800 (Thu, 26 Feb 2015)
Log Message
BytecodeGenerator::constLocal() behaves identically to BytecodeGenerator::local() for the purposes of its one caller
https://bugs.webkit.org/show_bug.cgi?id=142071
Rubber stamped by Benjamin Poulain.
The only behavioral differences between constLocal() and local() are:
- constLocal() doesn't have a special case for "this" that overrides other checks like the
shouldOptimizeLocals() check. But the one user of constLocal() is for the "const x"
_expression_, and "const this" doesn't parse.
- constLocal() won't createArgumentsIfNecessary() for "arguments". But it's harmless if
it does, since its one user assigns to the local.
So, we can remove constLocal() and make its one caller use local() instead.
* bytecompiler/BytecodeGenerator.cpp:
(JSC::BytecodeGenerator::constLocal): Deleted.
* bytecompiler/BytecodeGenerator.h:
* bytecompiler/NodesCodegen.cpp:
(JSC::ConstDeclNode::emitCodeSingle):
* tests/stress/const-arguments.js: Added.
(foo):
(check):
Modified Paths
Added Paths
Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (180722 => 180723)
--- trunk/Source/_javascript_Core/ChangeLog 2015-02-27 04:11:03 UTC (rev 180722)
+++ trunk/Source/_javascript_Core/ChangeLog 2015-02-27 05:12:46 UTC (rev 180723)
@@ -1,3 +1,30 @@
+2015-02-26 Filip Pizlo <[email protected]>
+
+ BytecodeGenerator::constLocal() behaves identically to BytecodeGenerator::local() for the purposes of its one caller
+ https://bugs.webkit.org/show_bug.cgi?id=142071
+
+ Rubber stamped by Benjamin Poulain.
+
+ The only behavioral differences between constLocal() and local() are:
+
+ - constLocal() doesn't have a special case for "this" that overrides other checks like the
+ shouldOptimizeLocals() check. But the one user of constLocal() is for the "const x"
+ _expression_, and "const this" doesn't parse.
+
+ - constLocal() won't createArgumentsIfNecessary() for "arguments". But it's harmless if
+ it does, since its one user assigns to the local.
+
+ So, we can remove constLocal() and make its one caller use local() instead.
+
+ * bytecompiler/BytecodeGenerator.cpp:
+ (JSC::BytecodeGenerator::constLocal): Deleted.
+ * bytecompiler/BytecodeGenerator.h:
+ * bytecompiler/NodesCodegen.cpp:
+ (JSC::ConstDeclNode::emitCodeSingle):
+ * tests/stress/const-arguments.js: Added.
+ (foo):
+ (check):
+
2015-02-26 Mark Lam <[email protected]>
Assertion fix for r180711: The bool returning form of BytecodeGenerator::addVar() can be removed.
Modified: trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.cpp (180722 => 180723)
--- trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.cpp 2015-02-27 04:11:03 UTC (rev 180722)
+++ trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.cpp 2015-02-27 05:12:46 UTC (rev 180723)
@@ -1214,24 +1214,6 @@
return Local(local, entry.getAttributes(), isArguments ? Local::SpecialLocal : Local::NormalLocal);
}
-Local BytecodeGenerator::constLocal(const Identifier& property)
-{
- if (m_codeType != FunctionCode)
- return Local();
-
- SymbolTableEntry entry = symbolTable().get(property.impl());
- if (entry.isNull())
- return Local();
-
- RegisterID* local = createLazyRegisterIfNecessary(®isterFor(entry.getIndex()));
-
- bool isArguments = property == propertyNames().arguments;
- if (isCaptured(local->index()) && m_lexicalEnvironmentRegister)
- return Local();
-
- return Local(local, entry.getAttributes(), isArguments ? Local::SpecialLocal : Local::NormalLocal);
-}
-
void BytecodeGenerator::emitCheckHasInstance(RegisterID* dst, RegisterID* value, RegisterID* base, Label* target)
{
size_t begin = instructions().size();
Modified: trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.h (180722 => 180723)
--- trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.h 2015-02-27 04:11:03 UTC (rev 180722)
+++ trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.h 2015-02-27 05:12:46 UTC (rev 180723)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008, 2009, 2012, 2013, 2014 Apple Inc. All rights reserved.
+ * Copyright (C) 2008, 2009, 2012-2015 Apple Inc. All rights reserved.
* Copyright (C) 2008 Cameron Zwarich <[email protected]>
* Copyright (C) 2012 Igalia, S.L.
*
@@ -286,7 +286,6 @@
CaptureMode captureMode(int operand) { return isCaptured(operand) ? IsCaptured : NotCaptured; }
Local local(const Identifier&);
- Local constLocal(const Identifier&);
// Returns the register storing "this"
RegisterID* thisRegister() { return &m_thisRegister; }
Modified: trunk/Source/_javascript_Core/bytecompiler/NodesCodegen.cpp (180722 => 180723)
--- trunk/Source/_javascript_Core/bytecompiler/NodesCodegen.cpp 2015-02-27 04:11:03 UTC (rev 180722)
+++ trunk/Source/_javascript_Core/bytecompiler/NodesCodegen.cpp 2015-02-27 05:12:46 UTC (rev 180723)
@@ -1,7 +1,7 @@
/*
* Copyright (C) 1999-2002 Harri Porten ([email protected])
* Copyright (C) 2001 Peter Kelly ([email protected])
-* Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2012, 2013 Apple Inc. All rights reserved.
+* Copyright (C) 2003-2009, 2012-2013, 2015 Apple Inc. All rights reserved.
* Copyright (C) 2007 Cameron Zwarich ([email protected])
* Copyright (C) 2007 Maks Orlovich
* Copyright (C) 2007 Eric Seidel <[email protected]>
@@ -1695,7 +1695,7 @@
RegisterID* ConstDeclNode::emitCodeSingle(BytecodeGenerator& generator)
{
// FIXME: This code does not match the behavior of const in Firefox.
- if (Local local = generator.constLocal(m_ident)) {
+ if (Local local = generator.local(m_ident)) {
if (!m_init)
return local.get();
Added: trunk/Source/_javascript_Core/tests/stress/const-arguments.js (0 => 180723)
--- trunk/Source/_javascript_Core/tests/stress/const-arguments.js (rev 0)
+++ trunk/Source/_javascript_Core/tests/stress/const-arguments.js 2015-02-27 05:12:46 UTC (rev 180723)
@@ -0,0 +1,16 @@
+function foo() {
+ const arguments = 52;
+ return arguments;
+}
+
+noInline(foo);
+
+function check(result, expected)
+{
+ if (result !== expected)
+ throw new Error("Bad result at i = " + i + ": " + result + " (expected " + expected + ")");
+}
+
+for (var i = 0; i < 10000; ++i)
+ check(foo(), 52);
+