From 9563b509ff6e30410cf3da2b1fc952119a99118a Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Sun, 1 Jun 2025 21:16:01 +0000 Subject: [PATCH] libexpr: Deduplicate `Value::primOpAppPrimOp` `getPrimOp` function was basically identical to existing `Value::primOpAppPrimOp` modulo some trivial differences. Makes sense to reuse existing code for that. --- src/libexpr/eval.cc | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index ce35901b1..eacbf4c9b 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -94,15 +94,6 @@ void Value::print(EvalState & state, std::ostream & str, PrintOptions 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) { #define WA(a, w) withArticle ? a " " w : w @@ -133,7 +124,7 @@ std::string showType(const Value & v) case tPrimOp: return fmt("the built-in function '%s'", std::string(v.payload.primOp->name)); 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 tThunk: return v.isBlackhole() ? "a black hole" : "a thunk"; case tApp: return "a function application"; @@ -535,6 +526,8 @@ const PrimOp * Value::primOpAppPrimOp() const if (!left) return nullptr; + + assert(left->isPrimOp()); return left->primOp(); }