Merge "primops: change to std::function, allowing the passing of user data" into main

This commit is contained in:
puck 2024-05-17 21:37:41 +00:00 committed by Gerrit Code Review
commit 23c92f0815
2 changed files with 7 additions and 3 deletions

View file

@ -17,6 +17,7 @@
#include <optional> #include <optional>
#include <unordered_map> #include <unordered_map>
#include <mutex> #include <mutex>
#include <functional>
namespace nix { namespace nix {
@ -71,7 +72,7 @@ struct PrimOp
/** /**
* Implementation of the primop. * Implementation of the primop.
*/ */
PrimOpFun fun; std::function<std::remove_pointer<PrimOpFun>::type> fun;
/** /**
* Optional experimental for this to be gated on. * Optional experimental for this to be gated on.

View file

@ -3329,8 +3329,11 @@ static void prim_sort(EvalState & state, const PosIdx pos, Value * * args, Value
callFunction. */ callFunction. */
/* TODO: (layus) this is absurd. An optimisation like this /* TODO: (layus) this is absurd. An optimisation like this
should be outside the lambda creation */ should be outside the lambda creation */
if (args[0]->isPrimOp() && args[0]->primOp->fun == prim_lessThan) if (args[0]->isPrimOp()) {
return CompareValues(state, noPos, "while evaluating the ordering function passed to builtins.sort")(a, b); auto ptr = args[0]->primOp->fun.target<decltype(&prim_lessThan)>();
if (ptr && *ptr == prim_lessThan)
return CompareValues(state, noPos, "while evaluating the ordering function passed to builtins.sort")(a, b);
}
Value * vs[] = {a, b}; Value * vs[] = {a, b};
Value vBool; Value vBool;