From 94bb66c8678260e904a23be50706d5e13c613c60 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Wed, 27 Nov 2024 02:09:08 +0100 Subject: [PATCH] libexpr: remove maxPrimOpArity this was only used to enable an optimization we no longer need such strong guarantees for: SmallVector can be used with a dynamic size. Change-Id: I4513fb7e665827fe363ce6308448656e6c5badb7 --- lix/libexpr/eval.cc | 13 +++---------- lix/libexpr/eval.hh | 13 ------------- lix/libexpr/value.cc | 2 -- 3 files changed, 3 insertions(+), 25 deletions(-) diff --git a/lix/libexpr/eval.cc b/lix/libexpr/eval.cc index 12c4828dd..d6e72cc7e 100644 --- a/lix/libexpr/eval.cc +++ b/lix/libexpr/eval.cc @@ -458,14 +458,6 @@ void EvalState::addConstant(const std::string & name, Value * v, Constant info) } -void PrimOp::check() -{ - if (arity > maxPrimOpArity) { - throw Error("primop arity must not exceed %1%", maxPrimOpArity); - } -} - - std::ostream & operator<<(std::ostream & output, PrimOp & primOp) { output << "primop " << primOp.name; @@ -1636,7 +1628,8 @@ void EvalState::callFunction(Value & fun, size_t nrArgs, Value * * args, Value & /* We have all the arguments, so call the primop with the previous and new arguments. */ - Value * vArgs[maxPrimOpArity]; + // max arity as of writing is 3. even 4 seems excessive though. + SmallVector vArgs(arity); auto n = argsDone; for (Value * arg = &vCur; arg->isPrimOpApp(); arg = arg->primOpApp.left) vArgs[--n] = arg->primOpApp.right; @@ -1653,7 +1646,7 @@ void EvalState::callFunction(Value & fun, size_t nrArgs, Value * * args, Value & // 1. Unify this and above code. Heavily redundant. // 2. Create a fake env (arg1, arg2, etc.) and a fake expr (arg1: arg2: etc: builtins.name arg1 arg2 etc) // so the debugger allows to inspect the wrong parameters passed to the builtin. - fn->fun(*this, vCur.determinePos(noPos), vArgs, vCur); + fn->fun(*this, vCur.determinePos(noPos), vArgs.data(), vCur); } catch (Error & e) { e.addTrace(positions[pos], "while calling the '%1%' builtin", fn->name); throw; diff --git a/lix/libexpr/eval.hh b/lix/libexpr/eval.hh index 85e1a899c..6dde9e1f7 100644 --- a/lix/libexpr/eval.hh +++ b/lix/libexpr/eval.hh @@ -22,13 +22,6 @@ namespace nix { -/** - * We put a limit on primop arity because it lets us use a fixed size array on - * the stack. 8 is already an impractical number of arguments. Use an attrset - * argument for such overly complicated functions. - */ -constexpr size_t maxPrimOpArity = 8; - class Store; class EvalState; class StorePath; @@ -82,12 +75,6 @@ struct PrimOp * Optional experimental for this to be gated on. */ std::optional experimentalFeature; - - /** - * Validity check to be performed by functions that introduce primops, - * such as RegisterPrimOp() and Value::mkPrimOp(). - */ - void check(); }; std::ostream & operator<<(std::ostream & output, PrimOp & primOp); diff --git a/lix/libexpr/value.cc b/lix/libexpr/value.cc index 9d293146f..22f1f33d1 100644 --- a/lix/libexpr/value.cc +++ b/lix/libexpr/value.cc @@ -27,7 +27,6 @@ Value::Value(primop_t, PrimOp & primop) , primOp(&primop) , _primop_pad(0) { - primop.check(); } @@ -76,7 +75,6 @@ PrimOp * Value::primOpAppPrimOp() const void Value::mkPrimOp(PrimOp * p) { - p->check(); clearValue(); internalType = tPrimOp; primOp = p;