Merge pull request #14894 from NixOS/undo-push
Undo accidental push to master
This commit is contained in:
@@ -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> store,
|
||||
|
||||
@@ -357,8 +357,6 @@ public:
|
||||
return stats;
|
||||
}
|
||||
|
||||
Value * allocInt(NixInt::Inner n);
|
||||
|
||||
/**
|
||||
* Storage for the AST nodes
|
||||
*/
|
||||
|
||||
@@ -1016,13 +1016,6 @@ struct Value : public ValueStorage<sizeof(void *)>
|
||||
*/
|
||||
static Value vFalse;
|
||||
|
||||
/**
|
||||
* Small pre-allocated integer constants.
|
||||
*
|
||||
* These are _not_ singletons. Pointer equality is _not_ sufficient.
|
||||
*/
|
||||
static std::array<Value, 32> vSmallInts;
|
||||
|
||||
private:
|
||||
template<InternalType... discriminator>
|
||||
bool isa() const noexcept
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -9,5 +9,4 @@ sources += files(
|
||||
'fetchMercurial.cc',
|
||||
'fetchTree.cc',
|
||||
'fromTOML.cc',
|
||||
'imap.cc',
|
||||
)
|
||||
|
||||
@@ -26,11 +26,4 @@ Value Value::vFalse = []() {
|
||||
return res;
|
||||
}();
|
||||
|
||||
std::array<Value, 32> Value::vSmallInts = []() {
|
||||
decltype(Value::vSmallInts) arr;
|
||||
for (size_t i = 0; i < arr.size(); ++i)
|
||||
arr[i].mkInt(i);
|
||||
return arr;
|
||||
}();
|
||||
|
||||
} // namespace nix
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
[ "a-0" "b-1" "a-1" "b-2" ]
|
||||
@@ -1,8 +0,0 @@
|
||||
(builtins.imap 0 (i: v: "${v}-${toString i}") [
|
||||
"a"
|
||||
"b"
|
||||
])
|
||||
++ (builtins.imap 1 (i: v: "${v}-${toString i}") [
|
||||
"a"
|
||||
"b"
|
||||
])
|
||||
Reference in New Issue
Block a user