Bug 1499574 - Part 3: Remove pn_arity. r=jwalden

Differential Revision: https://phabricator.services.mozilla.com/D8937

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jason Orendorff 2018-11-09 22:16:21 +00:00
parent 31f4a64309
commit 3d0645e205
3 changed files with 46 additions and 54 deletions

View File

@ -427,7 +427,6 @@ FoldType(JSContext* cx, ParseNode* pn, ParseNodeKind kind)
return false;
}
pn->setKind(ParseNodeKind::Number);
pn->setArity(PN_NUMBER);
pn->setOp(JSOP_DOUBLE);
pn->as<NumericLiteral>().setValue(d);
}
@ -440,7 +439,6 @@ FoldType(JSContext* cx, ParseNode* pn, ParseNodeKind kind)
return false;
}
pn->setKind(ParseNodeKind::String);
pn->setArity(PN_NAME);
pn->setOp(JSOP_STRING);
pn->as<NameNode>().setAtom(atom);
}
@ -547,7 +545,6 @@ FoldCondition(JSContext* cx, ParseNode** nodePtr, PerHandlerParser<FullParseHand
node->setKind(ParseNodeKind::False);
node->setOp(JSOP_FALSE);
}
node->setArity(PN_NULLARY);
}
return true;
@ -580,7 +577,6 @@ FoldTypeOfExpr(JSContext* cx, UnaryNode* node, PerHandlerParser<FullParseHandler
if (result) {
node->setKind(ParseNodeKind::String);
node->setArity(PN_NAME);
node->setOp(JSOP_NOP);
node->as<NameNode>().setAtom(result);
}
@ -603,7 +599,6 @@ FoldDeleteExpr(JSContext* cx, UnaryNode* node, PerHandlerParser<FullParseHandler
// For effectless expressions, eliminate the expression evaluation.
if (IsEffectless(expr)) {
node->setKind(ParseNodeKind::True);
node->setArity(PN_NULLARY);
node->setOp(JSOP_TRUE);
}
@ -677,12 +672,10 @@ FoldNot(JSContext* cx, UnaryNode* node, PerHandlerParser<FullParseHandler>& pars
node->setKind(ParseNodeKind::False);
node->setOp(JSOP_FALSE);
}
node->setArity(PN_NULLARY);
} else if (expr->isKind(ParseNodeKind::True) || expr->isKind(ParseNodeKind::False)) {
bool newval = !expr->isKind(ParseNodeKind::True);
node->setKind(newval ? ParseNodeKind::True : ParseNodeKind::False);
node->setArity(PN_NULLARY);
node->setOp(newval ? JSOP_TRUE : JSOP_FALSE);
}
@ -720,7 +713,6 @@ FoldUnaryArithmetic(JSContext* cx, UnaryNode* node, PerHandlerParser<FullParseHa
}
node->setKind(ParseNodeKind::Number);
node->setArity(PN_NUMBER);
node->setOp(JSOP_DOUBLE);
node->as<NumericLiteral>().setValue(d);
}
@ -965,7 +957,6 @@ FoldIf(JSContext* cx, ParseNode** nodePtr, PerHandlerParser<FullParseHandler>& p
// with no |else|. Replace the entire thing with an empty
// statement list.
node->setKind(ParseNodeKind::StatementList);
node->setArity(PN_LIST);
node->as<ListNode>().makeEmpty();
} else {
// Replacement invalidates |nextNode|, so reset it (if the
@ -1091,7 +1082,6 @@ FoldBinaryArithmetic(JSContext* cx, ListNode* node, PerHandlerParser<FullParseHa
elem->pn_next = next;
elem->setKind(ParseNodeKind::Number);
elem->setArity(PN_NUMBER);
elem->setOp(JSOP_DOUBLE);
elem->as<NumericLiteral>().setValue(d);
@ -1104,7 +1094,6 @@ FoldBinaryArithmetic(JSContext* cx, ListNode* node, PerHandlerParser<FullParseHa
double d = elem->as<NumericLiteral>().value();
node->setKind(ParseNodeKind::Number);
node->setArity(PN_NUMBER);
node->setOp(JSOP_DOUBLE);
node->as<NumericLiteral>().setValue(d);
}
@ -1152,7 +1141,6 @@ FoldExponentiation(JSContext* cx, ListNode* node, PerHandlerParser<FullParseHand
double d2 = exponent->as<NumericLiteral>().value();
node->setKind(ParseNodeKind::Number);
node->setArity(PN_NUMBER);
node->setOp(JSOP_DOUBLE);
node->as<NumericLiteral>().setValue(ecmaPow(d1, d2));
return true;
@ -1279,7 +1267,6 @@ FoldElement(JSContext* cx, ParseNode** nodePtr, PerHandlerParser<FullParseHandle
// Optimization 1: We have something like expr["100"]. This is
// equivalent to expr[100] which is faster.
key->setKind(ParseNodeKind::Number);
key->setArity(PN_NUMBER);
key->setOp(JSOP_DOUBLE);
key->as<NumericLiteral>().setValue(index);
} else {

View File

@ -102,14 +102,14 @@ ParseNode::appendOrCreateList(ParseNodeKind kind, ParseNode* left, ParseNode* ri
return list;
}
#ifdef DEBUG
const ParseNodeArity js::frontend::ParseNodeKindArity[] = {
#define ARITY(_name, arity) arity,
FOR_EACH_PARSE_NODE_KIND(ARITY)
#undef ARITY
};
#ifdef DEBUG
static const char * const parseNodeNames[] = {
#define STRINGIFY(name, _arity) #name,
FOR_EACH_PARSE_NODE_KIND(STRINGIFY)
@ -152,7 +152,7 @@ ParseNode::dump()
void
ParseNode::dump(GenericPrinter& out, int indent)
{
switch (ParseNodeArity(pn_arity)) {
switch (getArity()) {
case PN_NULLARY:
as<NullaryNode>().dump(out);
return;
@ -190,8 +190,8 @@ ParseNode::dump(GenericPrinter& out, int indent)
as<LexicalScopeNode>().dump(out, indent);
return;
}
out.printf("#<BAD NODE %p, kind=%u, arity=%u>",
(void*) this, unsigned(getKind()), unsigned(pn_arity));
out.printf("#<BAD NODE %p, kind=%u>",
(void*) this, unsigned(getKind()));
}
void

View File

@ -579,20 +579,17 @@ class typeName;
FOR_EACH_PARSENODE_SUBCLASS(DECLARE_CLASS)
#undef DECLARE_CLASS
#ifdef DEBUG
// ParseNodeKindArity[size_t(pnk)] is the arity of a ParseNode of kind pnk.
extern const ParseNodeArity ParseNodeKindArity[];
#endif
class ParseNode
{
ParseNodeKind pn_type; /* ParseNodeKind::PNK_* type */
// pn_op and pn_arity are not declared as the correct enum types
// due to difficulties with MS bitfield layout rules and a GCC
// bug. See https://bugzilla.mozilla.org/show_bug.cgi?id=1383157#c4 for
// details.
// pn_op is not declared as the correct enum type due to difficulties with
// MS bitfield layout rules and a GCC bug. See
// https://bugzilla.mozilla.org/show_bug.cgi?id=1383157#c4 for details.
uint8_t pn_op; /* see JSOp enum and jsopcode.tbl */
uint8_t pn_arity:4; /* see ParseNodeArity enum */
bool pn_parens:1; /* this expr was enclosed in parens */
bool pn_rhs_anon_fun:1; /* this expr is anonymous function or class that
* is a direct RHS of ParseNodeKind::Assign or ParseNodeKind::Colon of
@ -602,31 +599,27 @@ class ParseNode
void operator=(const ParseNode& other) = delete;
public:
ParseNode(ParseNodeKind kind, JSOp op, ParseNodeArity arity)
ParseNode(ParseNodeKind kind, JSOp op)
: pn_type(kind),
pn_op(op),
pn_arity(arity),
pn_parens(false),
pn_rhs_anon_fun(false),
pn_pos(0, 0),
pn_next(nullptr)
{
MOZ_ASSERT(kind < ParseNodeKind::Limit);
MOZ_ASSERT(hasExpectedArity());
memset(&pn_u, 0, sizeof pn_u);
}
ParseNode(ParseNodeKind kind, JSOp op, ParseNodeArity arity, const TokenPos& pos)
ParseNode(ParseNodeKind kind, JSOp op, const TokenPos& pos)
: pn_type(kind),
pn_op(op),
pn_arity(arity),
pn_parens(false),
pn_rhs_anon_fun(false),
pn_pos(pos),
pn_next(nullptr)
{
MOZ_ASSERT(kind < ParseNodeKind::Limit);
MOZ_ASSERT(hasExpectedArity());
memset(&pn_u, 0, sizeof pn_u);
}
@ -636,7 +629,6 @@ class ParseNode
ParseNodeKind getKind() const {
MOZ_ASSERT(pn_type < ParseNodeKind::Limit);
MOZ_ASSERT(hasExpectedArity());
return pn_type;
}
void setKind(ParseNodeKind kind) {
@ -645,12 +637,8 @@ class ParseNode
}
bool isKind(ParseNodeKind kind) const { return getKind() == kind; }
ParseNodeArity getArity() const { return ParseNodeArity(pn_arity); }
#ifdef DEBUG
bool hasExpectedArity() const { return isArity(ParseNodeKindArity[size_t(pn_type)]); }
#endif
ParseNodeArity getArity() const { return ParseNodeKindArity[size_t(getKind())]; }
bool isArity(ParseNodeArity a) const { return getArity() == a; }
void setArity(ParseNodeArity a) { pn_arity = a; MOZ_ASSERT(hasExpectedArity()); }
bool isBinaryOperation() const {
ParseNodeKind kind = getKind();
@ -816,10 +804,16 @@ class NullaryNode : public ParseNode
{
public:
NullaryNode(ParseNodeKind kind, const TokenPos& pos)
: ParseNode(kind, JSOP_NOP, PN_NULLARY, pos) {}
: ParseNode(kind, JSOP_NOP, pos)
{
MOZ_ASSERT(is<NullaryNode>());
}
NullaryNode(ParseNodeKind kind, JSOp op, const TokenPos& pos)
: ParseNode(kind, op, PN_NULLARY, pos) {}
: ParseNode(kind, op, pos)
{
MOZ_ASSERT(is<NullaryNode>());
}
static bool test(const ParseNode& node) {
return node.isArity(PN_NULLARY);
@ -834,18 +828,20 @@ class NameNode : public ParseNode
{
protected:
NameNode(ParseNodeKind kind, JSOp op, JSAtom* atom, ParseNode* initOrStmt, const TokenPos& pos)
: ParseNode(kind, op, PN_NAME, pos)
: ParseNode(kind, op, pos)
{
pn_u.name.atom = atom;
pn_u.name.initOrStmt = initOrStmt;
MOZ_ASSERT(is<NameNode>());
}
public:
NameNode(ParseNodeKind kind, JSOp op, JSAtom* atom, const TokenPos& pos)
: ParseNode(kind, op, PN_NAME, pos)
: ParseNode(kind, op, pos)
{
pn_u.name.atom = atom;
pn_u.name.initOrStmt = nullptr;
MOZ_ASSERT(is<NameNode>());
}
static bool test(const ParseNode& node) {
@ -893,9 +889,10 @@ class UnaryNode : public ParseNode
{
public:
UnaryNode(ParseNodeKind kind, const TokenPos& pos, ParseNode* kid)
: ParseNode(kind, JSOP_NOP, PN_UNARY, pos)
: ParseNode(kind, JSOP_NOP, pos)
{
pn_u.unary.kid = kid;
MOZ_ASSERT(is<UnaryNode>());
}
static bool test(const ParseNode& node) {
@ -952,17 +949,19 @@ class BinaryNode : public ParseNode
{
public:
BinaryNode(ParseNodeKind kind, JSOp op, const TokenPos& pos, ParseNode* left, ParseNode* right)
: ParseNode(kind, op, PN_BINARY, pos)
: ParseNode(kind, op, pos)
{
pn_u.binary.left = left;
pn_u.binary.right = right;
MOZ_ASSERT(is<BinaryNode>());
}
BinaryNode(ParseNodeKind kind, JSOp op, ParseNode* left, ParseNode* right)
: ParseNode(kind, op, PN_BINARY, TokenPos::box(left->pn_pos, right->pn_pos))
: ParseNode(kind, op, TokenPos::box(left->pn_pos, right->pn_pos))
{
pn_u.binary.left = left;
pn_u.binary.right = right;
MOZ_ASSERT(is<BinaryNode>());
}
static bool test(const ParseNode& node) {
@ -1052,11 +1051,12 @@ class TernaryNode : public ParseNode
TernaryNode(ParseNodeKind kind, ParseNode* kid1, ParseNode* kid2, ParseNode* kid3,
const TokenPos& pos)
: ParseNode(kind, JSOP_NOP, PN_TERNARY, pos)
: ParseNode(kind, JSOP_NOP, pos)
{
pn_u.ternary.kid1 = kid1;
pn_u.ternary.kid2 = kid2;
pn_u.ternary.kid3 = kid3;
MOZ_ASSERT(is<TernaryNode>());
}
static bool test(const ParseNode& node) {
@ -1127,19 +1127,21 @@ class ListNode : public ParseNode
public:
ListNode(ParseNodeKind kind, const TokenPos& pos)
: ParseNode(kind, JSOP_NOP, PN_LIST, pos)
: ParseNode(kind, JSOP_NOP, pos)
{
makeEmpty();
MOZ_ASSERT(is<ListNode>());
}
ListNode(ParseNodeKind kind, JSOp op, const TokenPos& pos)
: ParseNode(kind, op, PN_LIST, pos)
: ParseNode(kind, op, pos)
{
makeEmpty();
MOZ_ASSERT(is<ListNode>());
}
ListNode(ParseNodeKind kind, JSOp op, ParseNode* kid)
: ParseNode(kind, op, PN_LIST, kid->pn_pos)
: ParseNode(kind, op, kid->pn_pos)
{
if (kid->pn_pos.begin < pn_pos.begin) {
pn_pos.begin = kid->pn_pos.begin;
@ -1150,6 +1152,7 @@ class ListNode : public ParseNode
pn_u.list.tail = &kid->pn_next;
pn_u.list.count = 1;
pn_u.list.xflags = 0;
MOZ_ASSERT(is<ListNode>());
}
static bool test(const ParseNode& node) {
@ -1434,7 +1437,7 @@ class CodeNode : public ParseNode
{
public:
CodeNode(ParseNodeKind kind, JSOp op, const TokenPos& pos)
: ParseNode(kind, op, PN_CODE, pos)
: ParseNode(kind, op, pos)
{
MOZ_ASSERT(kind == ParseNodeKind::Function || kind == ParseNodeKind::Module);
MOZ_ASSERT_IF(kind == ParseNodeKind::Module, op == JSOP_NOP);
@ -1443,6 +1446,7 @@ class CodeNode : public ParseNode
op == JSOP_LAMBDA); // expression, method, accessor, &c.
MOZ_ASSERT(!pn_u.code.body);
MOZ_ASSERT(!pn_u.code.funbox);
MOZ_ASSERT(is<CodeNode>());
}
static bool test(const ParseNode& node) {
@ -1493,7 +1497,7 @@ class NumericLiteral : public ParseNode
{
public:
NumericLiteral(double value, DecimalPoint decimalPoint, const TokenPos& pos)
: ParseNode(ParseNodeKind::Number, JSOP_NOP, PN_NUMBER, pos)
: ParseNode(ParseNodeKind::Number, JSOP_NOP, pos)
{
pn_u.number.value = value;
pn_u.number.decimalPoint = decimalPoint;
@ -1526,7 +1530,7 @@ class LexicalScopeNode : public ParseNode
{
public:
LexicalScopeNode(LexicalScope::Data* bindings, ParseNode* body)
: ParseNode(ParseNodeKind::LexicalScope, JSOP_NOP, PN_SCOPE, body->pn_pos)
: ParseNode(ParseNodeKind::LexicalScope, JSOP_NOP, body->pn_pos)
{
pn_u.scope.bindings = bindings;
pn_u.scope.body = body;
@ -1628,10 +1632,11 @@ class LoopControlStatement : public ParseNode
{
protected:
LoopControlStatement(ParseNodeKind kind, PropertyName* label, const TokenPos& pos)
: ParseNode(kind, JSOP_NOP, PN_LOOP, pos)
: ParseNode(kind, JSOP_NOP, pos)
{
MOZ_ASSERT(kind == ParseNodeKind::Break || kind == ParseNodeKind::Continue);
pn_u.loopControl.label = label;
MOZ_ASSERT(is<LoopControlStatement>());
}
public:
@ -1822,7 +1827,7 @@ class RegExpLiteral : public ParseNode
{
public:
RegExpLiteral(ObjectBox* reobj, const TokenPos& pos)
: ParseNode(ParseNodeKind::RegExp, JSOP_REGEXP, PN_REGEXP, pos)
: ParseNode(ParseNodeKind::RegExp, JSOP_REGEXP, pos)
{
pn_u.regexp.objbox = reobj;
}
@ -1979,7 +1984,7 @@ class ClassField : public ParseNode
{
public:
ClassField(ParseNode* name, ParseNode* initializer)
: ParseNode(ParseNodeKind::ClassField, JSOP_NOP, PN_FIELD,
: ParseNode(ParseNodeKind::ClassField, JSOP_NOP,
initializer == nullptr ? name->pn_pos : TokenPos::box(name->pn_pos, initializer->pn_pos))
{
pn_u.field.name = name;