fix(3p/nix): Use a proper pointer in Env to carry with-attrs
This eliminates the value-smuggling that would trip up the GC. Change-Id: I8057df78cf0bf6bea9faf1b44233aa9820ae44f5 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1504 Tested-by: BuildkiteCI Reviewed-by: glittershark <grfn@gws.fyi> Reviewed-by: tazjin <mail@tazj.in>
This commit is contained in:
parent
dc4c0bad65
commit
770034042a
2 changed files with 9 additions and 5 deletions
13
third_party/nix/src/libexpr/eval.cc
vendored
13
third_party/nix/src/libexpr/eval.cc
vendored
|
|
@ -600,10 +600,13 @@ inline Value* EvalState::lookupVar(Env* env, const ExprVar& var, bool noEval) {
|
||||||
if (noEval) {
|
if (noEval) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
if (!env->withAttrsExpr) {
|
||||||
|
CHECK(false) << "HasWithExpr evaluated twice";
|
||||||
|
}
|
||||||
Value* v = allocValue();
|
Value* v = allocValue();
|
||||||
// TODO(kanepyork): Here's the other end of the cast smuggle.
|
evalAttrs(*env->up, env->withAttrsExpr, *v);
|
||||||
evalAttrs(*env->up, reinterpret_cast<Expr*>(env->values[0]), *v);
|
|
||||||
env->values[0] = v;
|
env->values[0] = v;
|
||||||
|
env->withAttrsExpr = nullptr;
|
||||||
env->type = Env::HasWithAttrs;
|
env->type = Env::HasWithAttrs;
|
||||||
}
|
}
|
||||||
Bindings::iterator j = env->values[0]->attrs->find(var.name);
|
Bindings::iterator j = env->values[0]->attrs->find(var.name);
|
||||||
|
|
@ -1179,9 +1182,9 @@ void ExprWith::eval(EvalState& state, Env& env, Value& v) {
|
||||||
env2.up = &env;
|
env2.up = &env;
|
||||||
env2.prevWith = prevWith;
|
env2.prevWith = prevWith;
|
||||||
env2.type = Env::HasWithExpr;
|
env2.type = Env::HasWithExpr;
|
||||||
// TODO(kanepyork): Figure out what's going on here. `Expr* attrs` is not
|
/* placeholder for result of attrs */
|
||||||
// layout-compatible with Value*.
|
env2.values[0] = nullptr;
|
||||||
env2.values[0] = reinterpret_cast<Value*>(attrs);
|
env2.withAttrsExpr = this->attrs;
|
||||||
|
|
||||||
body->eval(state, env2, v);
|
body->eval(state, env2, v);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
1
third_party/nix/src/libexpr/eval.hh
vendored
1
third_party/nix/src/libexpr/eval.hh
vendored
|
|
@ -42,6 +42,7 @@ struct Env : public gc {
|
||||||
unsigned short prevWith : 14; // nr of levels up to next `with' environment
|
unsigned short prevWith : 14; // nr of levels up to next `with' environment
|
||||||
enum { Plain = 0, HasWithExpr, HasWithAttrs } type : 2;
|
enum { Plain = 0, HasWithExpr, HasWithAttrs } type : 2;
|
||||||
std::vector<Value*, traceable_allocator<Value*>> values;
|
std::vector<Value*, traceable_allocator<Value*>> values;
|
||||||
|
Expr* withAttrsExpr = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
Value& mkString(Value& v, const std::string& s,
|
Value& mkString(Value& v, const std::string& s,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue