mirror of
https://github.com/NixOS/nix
synced 2025-06-25 02:21:16 +02:00
Merge pull request #13311 from xokdvium/dedup-prim-op-app-prim-op
libexpr: Deduplicate `Value::primOpAppPrimOp`
This commit is contained in:
commit
16e4b3b7df
1 changed files with 3 additions and 10 deletions
|
@ -94,15 +94,6 @@ void Value::print(EvalState & state, std::ostream & str, PrintOptions options)
|
||||||
printValue(state, str, *this, options);
|
printValue(state, str, *this, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Value * getPrimOp(const Value &v) {
|
|
||||||
const Value * primOp = &v;
|
|
||||||
while (primOp->isPrimOpApp()) {
|
|
||||||
primOp = primOp->payload.primOpApp.left;
|
|
||||||
}
|
|
||||||
assert(primOp->isPrimOp());
|
|
||||||
return primOp;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string_view showType(ValueType type, bool withArticle)
|
std::string_view showType(ValueType type, bool withArticle)
|
||||||
{
|
{
|
||||||
#define WA(a, w) withArticle ? a " " w : w
|
#define WA(a, w) withArticle ? a " " w : w
|
||||||
|
@ -133,7 +124,7 @@ std::string showType(const Value & v)
|
||||||
case tPrimOp:
|
case tPrimOp:
|
||||||
return fmt("the built-in function '%s'", std::string(v.payload.primOp->name));
|
return fmt("the built-in function '%s'", std::string(v.payload.primOp->name));
|
||||||
case tPrimOpApp:
|
case tPrimOpApp:
|
||||||
return fmt("the partially applied built-in function '%s'", std::string(getPrimOp(v)->payload.primOp->name));
|
return fmt("the partially applied built-in function '%s'", v.primOpAppPrimOp()->name);
|
||||||
case tExternal: return v.external()->showType();
|
case tExternal: return v.external()->showType();
|
||||||
case tThunk: return v.isBlackhole() ? "a black hole" : "a thunk";
|
case tThunk: return v.isBlackhole() ? "a black hole" : "a thunk";
|
||||||
case tApp: return "a function application";
|
case tApp: return "a function application";
|
||||||
|
@ -535,6 +526,8 @@ const PrimOp * Value::primOpAppPrimOp() const
|
||||||
|
|
||||||
if (!left)
|
if (!left)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
assert(left->isPrimOp());
|
||||||
return left->primOp();
|
return left->primOp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue