refactor(3p/tvix): convert NixList usage to shared_ptr

Starting to reclaim memory. Fairly simple mechanical replacement.

Change-Id: I6b4c5c5596729470d1a049eba61e69e8097decf4
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1971
Tested-by: BuildkiteCI
Reviewed-by: glittershark <grfn@gws.fyi>
This commit is contained in:
Kane York 2020-09-12 08:09:18 -07:00 committed by kanepyork
parent 381ce8a666
commit 2c19bd6662
4 changed files with 12 additions and 12 deletions

View file

@ -598,15 +598,15 @@ Env& EvalState::allocEnv(size_t size) {
return *env; return *env;
} }
void EvalState::mkList(Value& v, NixList* list) { void EvalState::mkList(Value& v, std::shared_ptr<NixList> list) {
nrListElems += list->size();
clearValue(v); clearValue(v);
v.type = tList; v.type = tList;
v.list = list; v.list = list;
nrListElems += list->size();
} }
void EvalState::mkList(Value& v, size_t size) { void EvalState::mkList(Value& v, size_t size) {
EvalState::mkList(v, new NixList(size)); EvalState::mkList(v, std::make_shared<NixList>(size));
} }
unsigned long nrThunks = 0; unsigned long nrThunks = 0;
@ -1224,7 +1224,7 @@ void ExprOpConcatLists::eval(EvalState& state, Env& env, Value& v) {
void EvalState::concatLists(Value& v, const NixList& lists, const Pos& pos) { void EvalState::concatLists(Value& v, const NixList& lists, const Pos& pos) {
nrListConcats++; nrListConcats++;
auto outlist = new NixList(); auto outlist = std::make_shared<NixList>();
for (Value* list : lists) { for (Value* list : lists) {
forceList(*list, pos); forceList(*list, pos);
@ -1816,8 +1816,8 @@ size_t valueSize(const Value& v) {
} }
break; break;
case tList: case tList:
if (seenLists.find(v.list) == seenLists.end()) { if (seenLists.find(v.list.get()) == seenLists.end()) {
seenLists.insert(v.list); seenLists.insert(v.list.get());
sz += v.listSize() * sizeof(Value*); sz += v.listSize() * sizeof(Value*);
for (const Value* v : *v.list) { for (const Value* v : *v.list) {
sz += doValue(*v); sz += doValue(*v);

View file

@ -258,7 +258,7 @@ class EvalState {
Value* allocAttr(Value& vAttrs, const Symbol& name); Value* allocAttr(Value& vAttrs, const Symbol& name);
// Create a list value from the specified vector. // Create a list value from the specified vector.
void mkList(Value& v, NixList* list); void mkList(Value& v, std::shared_ptr<NixList> list);
// Create a list value, allocating as many elements as specified in // Create a list value, allocating as many elements as specified in
// size. This is used for the many cases in this codebase where // size. This is used for the many cases in this codebase where

View file

@ -1603,7 +1603,7 @@ static void prim_sort(EvalState& state, const Pos& pos, Value** args,
// Copy of the input list which can be sorted in place. // Copy of the input list which can be sorted in place.
v.type = tList; v.type = tList;
v.list = new NixList(*args[1]->list); v.list = std::make_shared<NixList>(*args[1]->list);
std::for_each(v.list->begin(), v.list->end(), std::for_each(v.list->begin(), v.list->end(),
[&](Value* val) { state.forceValue(*val); }); [&](Value* val) { state.forceValue(*val); });
@ -1633,8 +1633,8 @@ static void prim_partition(EvalState& state, const Pos& pos, Value** args,
state.forceFunction(*args[0], pos); state.forceFunction(*args[0], pos);
state.forceList(*args[1], pos); state.forceList(*args[1], pos);
NixList* right = new NixList(); std::shared_ptr<NixList> right = std::make_shared<NixList>();
NixList* wrong = new NixList(); std::shared_ptr<NixList> wrong = std::make_shared<NixList>();
for (Value* elem : *args[1]->list) { for (Value* elem : *args[1]->list) {
state.forceValue(*elem, pos); state.forceValue(*elem, pos);
@ -1664,7 +1664,7 @@ static void prim_concatMap(EvalState& state, const Pos& pos, Value** args,
state.forceFunction(*args[0], pos); state.forceFunction(*args[0], pos);
state.forceList(*args[1], pos); state.forceList(*args[1], pos);
NixList* outlist = new NixList; std::shared_ptr<NixList> outlist = std::make_shared<NixList>();
for (Value* elem : *args[1]->list) { for (Value* elem : *args[1]->list) {
auto out = state.allocValue(); auto out = state.allocValue();

View file

@ -96,7 +96,7 @@ struct Value {
NixString string; NixString string;
const char* path; const char* path;
std::shared_ptr<Bindings> attrs; std::shared_ptr<Bindings> attrs;
NixList* list; std::shared_ptr<NixList> list;
NixThunk thunk; NixThunk thunk;
NixApp app; // TODO(tazjin): "app"? NixApp app; // TODO(tazjin): "app"?
NixLambda lambda; NixLambda lambda;