diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 48aff9e3f64..6bcde92832e 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -232,15 +232,6 @@ EvalMemory::EvalMemory() assertGCInitialized(); } -Value * EvalMemory::allocInt(NixInt::Inner n) -{ - if (n >= 0 && n < (NixInt::Inner) Value::vSmallInts.size()) - return &Value::vSmallInts[n]; - Value * v = allocValue(); - v->mkInt(NixInt(n)); - return v; -} - EvalState::EvalState( const LookupPath & lookupPathFromArguments, ref store, diff --git a/src/libexpr/include/nix/expr/eval.hh b/src/libexpr/include/nix/expr/eval.hh index 840881bf148..b70c9db789d 100644 --- a/src/libexpr/include/nix/expr/eval.hh +++ b/src/libexpr/include/nix/expr/eval.hh @@ -357,8 +357,6 @@ public: return stats; } - Value * allocInt(NixInt::Inner n); - /** * Storage for the AST nodes */ diff --git a/src/libexpr/include/nix/expr/value.hh b/src/libexpr/include/nix/expr/value.hh index 226bf19a7de..6f533b73b20 100644 --- a/src/libexpr/include/nix/expr/value.hh +++ b/src/libexpr/include/nix/expr/value.hh @@ -1016,13 +1016,6 @@ struct Value : public ValueStorage */ static Value vFalse; - /** - * Small pre-allocated integer constants. - * - * These are _not_ singletons. Pointer equality is _not_ sufficient. - */ - static std::array vSmallInts; - private: template bool isa() const noexcept diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 4d6957c288a..98b4c129627 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -3161,7 +3161,8 @@ static struct LazyPosAccessors void operator()(EvalState & state, const PosIdx pos, Value & line, Value & column) { - auto posV = state.mem.allocInt(pos.id); + Value * posV = state.allocValue(); + posV->mkInt(pos.id); line.mkApp(&lineOfPos, posV); column.mkApp(&columnOfPos, posV); } @@ -3965,8 +3966,11 @@ static void prim_genList(EvalState & state, const PosIdx pos, Value ** args, Val state.forceFunction(*args[0], noPos, "while evaluating the first argument passed to builtins.genList"); auto list = state.buildList(len); - for (const auto & [n, v] : enumerate(list)) - (v = state.allocValue())->mkApp(args[0], state.mem.allocInt(n)); + for (const auto & [n, v] : enumerate(list)) { + auto arg = state.allocValue(); + arg->mkInt(n); + (v = state.allocValue())->mkApp(args[0], arg); + } v.mkList(list); } diff --git a/src/libexpr/primops/imap.cc b/src/libexpr/primops/imap.cc deleted file mode 100644 index 465796cf217..00000000000 --- a/src/libexpr/primops/imap.cc +++ /dev/null @@ -1,44 +0,0 @@ -#include "nix/expr/primops.hh" - -namespace nix { - -static void prim_imap(EvalState & state, const PosIdx pos, Value ** args, Value & v) -{ - auto shift = state.forceInt(*args[0], pos, "while evaluating the first argument passed to 'builtins.imap'").value; - Value & f = *args[1]; - Value & list = *args[2]; - - state.forceList(list, pos, "while evaluating the third argument passed to 'builtins.imap'"); - - if (list.listSize() == 0) { - v = list; - return; - } - - auto outList = state.buildList(list.listSize()); - for (const auto & [n, v] : enumerate(outList)) { - v = state.allocValue(); - Value * args[] = {state.mem.allocInt(n + shift), list.listView()[n]}; - state.callFunction(f, args, *v, pos); - } - - v.mkList(outList); -} - -static RegisterPrimOp primop_imap( - {.name = "__imap", - .args = {"shift", "f", "list"}, - .doc = R"( - Apply the function *f* to each element in the list *list*. The function *f* is called with two arguments: the index of the element (plus *shift*) and the element itself. - - For example, - - ```nix - builtins.imap 1 (i: v: "${v}-${toString i}") ["a" "b"] - ``` - - evaluates to `[ "a-1" "b-2" ]`. - )", - .fun = prim_imap}); - -} // namespace nix diff --git a/src/libexpr/primops/meson.build b/src/libexpr/primops/meson.build index 73fa3911d1b..b8abc6409af 100644 --- a/src/libexpr/primops/meson.build +++ b/src/libexpr/primops/meson.build @@ -9,5 +9,4 @@ sources += files( 'fetchMercurial.cc', 'fetchTree.cc', 'fromTOML.cc', - 'imap.cc', ) diff --git a/src/libexpr/value.cc b/src/libexpr/value.cc index ec39ce43153..07d036b0dd4 100644 --- a/src/libexpr/value.cc +++ b/src/libexpr/value.cc @@ -26,11 +26,4 @@ Value Value::vFalse = []() { return res; }(); -std::array Value::vSmallInts = []() { - decltype(Value::vSmallInts) arr; - for (size_t i = 0; i < arr.size(); ++i) - arr[i].mkInt(i); - return arr; -}(); - } // namespace nix diff --git a/tests/functional/lang/eval-okay-imap.exp b/tests/functional/lang/eval-okay-imap.exp deleted file mode 100644 index 5ede7fa1955..00000000000 --- a/tests/functional/lang/eval-okay-imap.exp +++ /dev/null @@ -1 +0,0 @@ -[ "a-0" "b-1" "a-1" "b-2" ] diff --git a/tests/functional/lang/eval-okay-imap.nix b/tests/functional/lang/eval-okay-imap.nix deleted file mode 100644 index 63a9ffb2682..00000000000 --- a/tests/functional/lang/eval-okay-imap.nix +++ /dev/null @@ -1,8 +0,0 @@ -(builtins.imap 0 (i: v: "${v}-${toString i}") [ - "a" - "b" -]) -++ (builtins.imap 1 (i: v: "${v}-${toString i}") [ - "a" - "b" -])