1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-16 07:22:43 +01:00

Garbage-collect paths

This commit is contained in:
Eelco Dolstra 2019-04-29 15:34:05 +02:00
parent 2995f9c48f
commit 6d118419f2
8 changed files with 14 additions and 44 deletions

View file

@ -24,19 +24,6 @@ namespace nix {
SymbolTable symbols; SymbolTable symbols;
unsigned long stringBytes = 0;
// FIXME
static char * dupString(const char * s)
{
char * t;
stringBytes += strlen(s) + 1;
t = strdup(s);
if (!t) throw std::bad_alloc();
return t;
}
static void printValue(std::ostream & str, std::set<const Value *> & active, const Value & v) static void printValue(std::ostream & str, std::set<const Value *> & active, const Value & v)
{ {
checkInterrupt(); checkInterrupt();
@ -67,7 +54,7 @@ static void printValue(std::ostream & str, std::set<const Value *> & active, con
str << "\""; str << "\"";
break; break;
case tPath: case tPath:
str << v.path; // !!! escaping? str << v.path->s; // !!! escaping?
break; break;
case tNull: case tNull:
str << "null"; str << "null";
@ -500,12 +487,6 @@ Value & mkString(Value & v, const string & s, const PathSet & context)
} }
void mkPath(Value & v, const char * s)
{
mkPathNoCopy(v, dupString(s));
}
inline Value * EvalState::lookupVar(Env * env, const ExprVar & var, bool noEval) inline Value * EvalState::lookupVar(Env * env, const ExprVar & var, bool noEval)
{ {
for (size_t l = var.level; l; --l, env = env->up) ; for (size_t l = var.level; l; --l, env = env->up) ;
@ -1492,7 +1473,7 @@ string EvalState::coerceToString(const Pos & pos, Value & v, PathSet & context,
} }
if (v.type == tPath) { if (v.type == tPath) {
Path path(canonPath(v.path)); Path path(canonPath(v.path->s));
return copyToStore ? copyPathToStore(context, path) : path; return copyToStore ? copyPathToStore(context, path) : path;
} }
@ -1603,7 +1584,7 @@ bool EvalState::eqValues(Value & v1, Value & v2)
return v1.boolean == v2.boolean; return v1.boolean == v2.boolean;
case tPath: case tPath:
return strcmp(v1.path, v2.path) == 0; return strcmp(v1.path->s, v2.path->s) == 0;
case tNull: case tNull:
return true; return true;
@ -1719,7 +1700,6 @@ void EvalState::printStats()
topObj.attr("nrLookups", nrLookups); topObj.attr("nrLookups", nrLookups);
topObj.attr("nrPrimOpCalls", nrPrimOpCalls); topObj.attr("nrPrimOpCalls", nrPrimOpCalls);
topObj.attr("nrFunctionCalls", nrFunctionCalls); topObj.attr("nrFunctionCalls", nrFunctionCalls);
topObj.attr("stringBytes", stringBytes);
if (countCalls) { if (countCalls) {
{ {
@ -1770,12 +1750,6 @@ size_t valueSize(Value & v)
{ {
std::set<const void *> seen; std::set<const void *> seen;
auto doString = [&](const char * s) -> size_t {
if (seen.find(s) != seen.end()) return 0;
seen.insert(s);
return strlen(s) + 1;
};
std::function<size_t(Value & v)> doValue; std::function<size_t(Value & v)> doValue;
std::function<size_t(Env & v)> doEnv; std::function<size_t(Env & v)> doEnv;
@ -1790,7 +1764,7 @@ size_t valueSize(Value & v)
sz += v.string.s->words() * WORD_SIZE; sz += v.string.s->words() * WORD_SIZE;
break; break;
case tPath: case tPath:
sz += doString(v.path); sz += v.path->words() * WORD_SIZE;
break; break;
case tAttrs: case tAttrs:
if (seen.find(v.attrs) == seen.end()) { if (seen.find(v.attrs) == seen.end()) {

View file

@ -167,7 +167,7 @@ void GC::gc()
} }
case tPath: case tPath:
// FIXME push(((Value *) obj)->path);
break; break;
case tAttrs: case tAttrs:

View file

@ -80,7 +80,7 @@ void ExprString::show(std::ostream & str) const
void ExprPath::show(std::ostream & str) const void ExprPath::show(std::ostream & str) const
{ {
str << s; str << v->path->s;
} }
void ExprVar::show(std::ostream & str) const void ExprVar::show(std::ostream & str) const

View file

@ -134,11 +134,10 @@ struct ExprIndStr : Expr
struct ExprPath : Expr struct ExprPath : Expr
{ {
string s;
Ptr<Value> v; Ptr<Value> v;
ExprPath(const string & s) : s(s) { ExprPath(const string & s) {
v = gc.alloc<Value>(Value::words()); v = gc.alloc<Value>(Value::words());
mkPathNoCopy(v, this->s.c_str()); mkPath(v, s);
}; };
COMMON_METHODS COMMON_METHODS
Ptr<Value> maybeThunk(EvalState & state, Env & env) override; Ptr<Value> maybeThunk(EvalState & state, Env & env) override;

View file

@ -344,7 +344,7 @@ struct CompareValues
case tFloat: case tFloat:
return v1->fpoint < v2->fpoint; return v1->fpoint < v2->fpoint;
case tPath: case tPath:
return strcmp(v1->path, v2->path) < 0; return strcmp(v1->path->s, v2->path->s) < 0;
default: default:
throw EvalError(format("cannot compare %1% with %2%") % showType(*v1) % showType(*v2)); throw EvalError(format("cannot compare %1% with %2%") % showType(*v1) % showType(*v2));
} }

View file

@ -34,7 +34,7 @@ void printValueAsJSON(EvalState & state, bool strict,
break; break;
case tPath: case tPath:
out.write(state.copyPathToStore(context, v.path)); out.write(state.copyPathToStore(context, v.path->s));
break; break;
case tNull: case tNull:

View file

@ -77,7 +77,7 @@ static void printValueAsXML(EvalState & state, bool strict, bool location,
break; break;
case tPath: case tPath:
doc.writeEmptyElement("path", singletonAttrs("value", v.path)); doc.writeEmptyElement("path", singletonAttrs("value", v.path->s));
break; break;
case tNull: case tNull:

View file

@ -120,7 +120,7 @@ struct Value : Object
Context * context; Context * context;
} string; } string;
const char * staticString; const char * staticString;
const char * path; String * path;
Bindings * attrs; Bindings * attrs;
PtrList<Value> * bigList; PtrList<Value> * bigList;
Value * smallList[2]; Value * smallList[2];
@ -288,16 +288,13 @@ static inline void mkString(Value & v, const Symbol & s)
} }
static inline void mkPathNoCopy(Value & v, const char * s) static inline void mkPath(Value & v, const std::string & s)
{ {
v.path = String::alloc(s.c_str());
v.type = tPath; v.type = tPath;
v.path = s;
} }
void mkPath(Value & v, const char * s);
/* Compute the size in bytes of the given value, including all values /* Compute the size in bytes of the given value, including all values
and environments reachable from it. Static expressions (Exprs) are and environments reachable from it. Static expressions (Exprs) are
not included. */ not included. */