forked from lix-project/lix
Get rid of some unnecessary ExprConcatStrings nodes in dynamic attrs
This gives a ~18% speedup in NixOS evaluation (after converting most calls to hasAttr/getAttr to dynamic attrs).
This commit is contained in:
parent
1418806969
commit
b6809608cc
|
@ -701,13 +701,10 @@ void ExprAttrs::eval(EvalState & state, Env & env, Value & v)
|
||||||
/* Dynamic attrs apply *after* rec and __overrides. */
|
/* Dynamic attrs apply *after* rec and __overrides. */
|
||||||
foreach (DynamicAttrDefs::iterator, i, dynamicAttrs) {
|
foreach (DynamicAttrDefs::iterator, i, dynamicAttrs) {
|
||||||
Value nameVal;
|
Value nameVal;
|
||||||
if (i->nameExpr->es->size() == 1) {
|
|
||||||
i->nameExpr->es->front()->eval(state, *dynamicEnv, nameVal);
|
|
||||||
state.forceValue(nameVal);
|
|
||||||
if (nameVal.type == tNull)
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
i->nameExpr->eval(state, *dynamicEnv, nameVal);
|
i->nameExpr->eval(state, *dynamicEnv, nameVal);
|
||||||
|
state.forceValue(nameVal);
|
||||||
|
if (nameVal.type == tNull)
|
||||||
|
continue;
|
||||||
state.forceStringNoCtx(nameVal);
|
state.forceStringNoCtx(nameVal);
|
||||||
Symbol nameSym = state.symbols.create(nameVal.string.s);
|
Symbol nameSym = state.symbols.create(nameVal.string.s);
|
||||||
Bindings::iterator j = v.attrs->find(nameSym);
|
Bindings::iterator j = v.attrs->find(nameSym);
|
||||||
|
|
|
@ -53,16 +53,15 @@ struct Env;
|
||||||
struct Value;
|
struct Value;
|
||||||
class EvalState;
|
class EvalState;
|
||||||
struct StaticEnv;
|
struct StaticEnv;
|
||||||
struct ExprConcatStrings;
|
|
||||||
|
|
||||||
|
|
||||||
/* An attribute path is a sequence of attribute names. */
|
/* An attribute path is a sequence of attribute names. */
|
||||||
struct AttrName
|
struct AttrName
|
||||||
{
|
{
|
||||||
Symbol symbol;
|
Symbol symbol;
|
||||||
ExprConcatStrings * expr;
|
Expr * expr;
|
||||||
AttrName(const Symbol & s) : symbol(s) {};
|
AttrName(const Symbol & s) : symbol(s) {};
|
||||||
AttrName(ExprConcatStrings * e) : expr(e) {};
|
AttrName(Expr * e) : expr(e) {};
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<AttrName> AttrPath;
|
typedef std::vector<AttrName> AttrPath;
|
||||||
|
@ -173,16 +172,17 @@ struct ExprAttrs : Expr
|
||||||
Expr * e;
|
Expr * e;
|
||||||
Pos pos;
|
Pos pos;
|
||||||
unsigned int displ; // displacement
|
unsigned int displ; // displacement
|
||||||
AttrDef(Expr * e, const Pos & pos, bool inherited=false) : inherited(inherited), e(e), pos(pos) { };
|
AttrDef(Expr * e, const Pos & pos, bool inherited=false)
|
||||||
|
: inherited(inherited), e(e), pos(pos) { };
|
||||||
AttrDef() { };
|
AttrDef() { };
|
||||||
};
|
};
|
||||||
typedef std::map<Symbol, AttrDef> AttrDefs;
|
typedef std::map<Symbol, AttrDef> AttrDefs;
|
||||||
AttrDefs attrs;
|
AttrDefs attrs;
|
||||||
struct DynamicAttrDef {
|
struct DynamicAttrDef {
|
||||||
ExprConcatStrings * nameExpr;
|
Expr * nameExpr, * valueExpr;
|
||||||
Expr * valueExpr;
|
|
||||||
Pos pos;
|
Pos pos;
|
||||||
DynamicAttrDef(ExprConcatStrings * nameExpr, Expr * valueExpr, const Pos & pos) : nameExpr(nameExpr), valueExpr(valueExpr), pos(pos) { };
|
DynamicAttrDef(Expr * nameExpr, Expr * valueExpr, const Pos & pos)
|
||||||
|
: nameExpr(nameExpr), valueExpr(valueExpr), pos(pos) { };
|
||||||
};
|
};
|
||||||
typedef std::vector<DynamicAttrDef> DynamicAttrDefs;
|
typedef std::vector<DynamicAttrDef> DynamicAttrDefs;
|
||||||
DynamicAttrDefs dynamicAttrs;
|
DynamicAttrDefs dynamicAttrs;
|
||||||
|
|
|
@ -341,11 +341,7 @@ expr_op
|
||||||
| expr_op UPDATE expr_op { $$ = new ExprOpUpdate(CUR_POS, $1, $3); }
|
| expr_op UPDATE expr_op { $$ = new ExprOpUpdate(CUR_POS, $1, $3); }
|
||||||
| expr_op '?' attrpath { $$ = new ExprOpHasAttr($1, *$3); }
|
| expr_op '?' attrpath { $$ = new ExprOpHasAttr($1, *$3); }
|
||||||
| expr_op '+' expr_op
|
| expr_op '+' expr_op
|
||||||
{ vector<Expr *> * l = new vector<Expr *>;
|
{ $$ = new ExprConcatStrings(CUR_POS, false, new vector<Expr *>({$1, $3})); }
|
||||||
l->push_back($1);
|
|
||||||
l->push_back($3);
|
|
||||||
$$ = new ExprConcatStrings(CUR_POS, false, l);
|
|
||||||
}
|
|
||||||
| expr_op '-' expr_op { $$ = new ExprApp(CUR_POS, new ExprApp(new ExprVar(data->symbols.create("__sub")), $1), $3); }
|
| expr_op '-' expr_op { $$ = new ExprApp(CUR_POS, new ExprApp(new ExprVar(data->symbols.create("__sub")), $1), $3); }
|
||||||
| expr_op '*' expr_op { $$ = new ExprApp(CUR_POS, new ExprApp(new ExprVar(data->symbols.create("__mul")), $1), $3); }
|
| expr_op '*' expr_op { $$ = new ExprApp(CUR_POS, new ExprApp(new ExprVar(data->symbols.create("__mul")), $1), $3); }
|
||||||
| expr_op '/' expr_op { $$ = new ExprApp(CUR_POS, new ExprApp(new ExprVar(data->symbols.create("__div")), $1), $3); }
|
| expr_op '/' expr_op { $$ = new ExprApp(CUR_POS, new ExprApp(new ExprVar(data->symbols.create("__div")), $1), $3); }
|
||||||
|
@ -461,13 +457,13 @@ attrs
|
||||||
: attrs attr { $$ = $1; $1->push_back(AttrName(data->symbols.create($2))); }
|
: attrs attr { $$ = $1; $1->push_back(AttrName(data->symbols.create($2))); }
|
||||||
| attrs string_attr
|
| attrs string_attr
|
||||||
{ $$ = $1;
|
{ $$ = $1;
|
||||||
ExprString *str = dynamic_cast<ExprString *>($2);
|
ExprString * str = dynamic_cast<ExprString *>($2);
|
||||||
if (str) {
|
if (str) {
|
||||||
$$->push_back(AttrName(str->s));
|
$$->push_back(AttrName(str->s));
|
||||||
delete str;
|
delete str;
|
||||||
} else
|
} else
|
||||||
throw ParseError(format("dynamic attributes not allowed in inherit at %1%")
|
throw ParseError(format("dynamic attributes not allowed in inherit at %1%")
|
||||||
% makeCurPos(@2, data));
|
% makeCurPos(@2, data));
|
||||||
}
|
}
|
||||||
| { $$ = new AttrPath; }
|
| { $$ = new AttrPath; }
|
||||||
;
|
;
|
||||||
|
@ -476,12 +472,12 @@ attrpath
|
||||||
: attrpath '.' attr { $$ = $1; $1->push_back(AttrName(data->symbols.create($3))); }
|
: attrpath '.' attr { $$ = $1; $1->push_back(AttrName(data->symbols.create($3))); }
|
||||||
| attrpath '.' string_attr
|
| attrpath '.' string_attr
|
||||||
{ $$ = $1;
|
{ $$ = $1;
|
||||||
ExprString *str = dynamic_cast<ExprString *>($3);
|
ExprString * str = dynamic_cast<ExprString *>($3);
|
||||||
if (str) {
|
if (str) {
|
||||||
$$->push_back(AttrName(str->s));
|
$$->push_back(AttrName(str->s));
|
||||||
delete str;
|
delete str;
|
||||||
} else
|
} else
|
||||||
$$->push_back(AttrName(static_cast<ExprConcatStrings *>($3)));
|
$$->push_back(AttrName($3));
|
||||||
}
|
}
|
||||||
| attr { $$ = new vector<AttrName>; $$->push_back(AttrName(data->symbols.create($1))); }
|
| attr { $$ = new vector<AttrName>; $$->push_back(AttrName(data->symbols.create($1))); }
|
||||||
| string_attr
|
| string_attr
|
||||||
|
@ -491,7 +487,7 @@ attrpath
|
||||||
$$->push_back(AttrName(str->s));
|
$$->push_back(AttrName(str->s));
|
||||||
delete str;
|
delete str;
|
||||||
} else
|
} else
|
||||||
$$->push_back(AttrName(static_cast<ExprConcatStrings *>($1)));
|
$$->push_back(AttrName($1));
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -502,7 +498,7 @@ attr
|
||||||
|
|
||||||
string_attr
|
string_attr
|
||||||
: '"' string_parts '"' { $$ = $2; }
|
: '"' string_parts '"' { $$ = $2; }
|
||||||
| DOLLAR_CURLY expr '}' { $$ = new ExprConcatStrings(CUR_POS, true, new vector<Expr*>(1, $2)); }
|
| DOLLAR_CURLY expr '}' { $$ = $2; }
|
||||||
;
|
;
|
||||||
|
|
||||||
expr_list
|
expr_list
|
||||||
|
|
Loading…
Reference in a new issue