Merge remote-tracking branch 'origin/master' into flakes

This commit is contained in:
Eelco Dolstra 2020-04-16 18:33:10 +02:00
commit f89349f07e
7 changed files with 59 additions and 50 deletions

View file

@ -23,6 +23,8 @@
#if HAVE_BOEHMGC #if HAVE_BOEHMGC
#define GC_INCLUDE_NEW
#include <gc/gc.h> #include <gc/gc.h>
#include <gc/gc_cpp.h> #include <gc/gc_cpp.h>
@ -57,6 +59,12 @@ static char * dupStringWithLen(const char * s, size_t size)
} }
RootValue allocRootValue(Value * v)
{
return std::allocate_shared<Value *>(traceable_allocator<Value *>(), v);
}
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();

View file

@ -4,7 +4,6 @@
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
using json = nlohmann::json; using json = nlohmann::json;
using std::unique_ptr;
namespace nix { namespace nix {
@ -13,30 +12,30 @@ namespace nix {
class JSONSax : nlohmann::json_sax<json> { class JSONSax : nlohmann::json_sax<json> {
class JSONState { class JSONState {
protected: protected:
unique_ptr<JSONState> parent; std::unique_ptr<JSONState> parent;
Value * v; RootValue v;
public: public:
virtual unique_ptr<JSONState> resolve(EvalState &) virtual std::unique_ptr<JSONState> resolve(EvalState &)
{ {
throw std::logic_error("tried to close toplevel json parser state"); throw std::logic_error("tried to close toplevel json parser state");
}; }
explicit JSONState(unique_ptr<JSONState>&& p) : parent(std::move(p)), v(nullptr) {}; explicit JSONState(std::unique_ptr<JSONState> && p) : parent(std::move(p)) {}
explicit JSONState(Value* v) : v(v) {}; explicit JSONState(Value * v) : v(allocRootValue(v)) {}
JSONState(JSONState & p) = delete; JSONState(JSONState & p) = delete;
Value & value(EvalState & state) Value & value(EvalState & state)
{ {
if (v == nullptr) if (!v)
v = state.allocValue(); v = allocRootValue(state.allocValue());
return *v; return **v;
}; }
virtual ~JSONState() {}; virtual ~JSONState() {}
virtual void add() {}; virtual void add() {}
}; };
class JSONObjectState : public JSONState { class JSONObjectState : public JSONState {
using JSONState::JSONState; using JSONState::JSONState;
ValueMap attrs = ValueMap(); ValueMap attrs;
virtual unique_ptr<JSONState> resolve(EvalState & state) override std::unique_ptr<JSONState> resolve(EvalState & state) override
{ {
Value & v = parent->value(state); Value & v = parent->value(state);
state.mkAttrs(v, attrs.size()); state.mkAttrs(v, attrs.size());
@ -44,17 +43,17 @@ class JSONSax : nlohmann::json_sax<json> {
v.attrs->push_back(Attr(i.first, i.second)); v.attrs->push_back(Attr(i.first, i.second));
return std::move(parent); return std::move(parent);
} }
virtual void add() override { v = nullptr; }; void add() override { v = nullptr; }
public: public:
void key(string_t & name, EvalState & state) void key(string_t & name, EvalState & state)
{ {
attrs[state.symbols.create(name)] = &value(state); attrs.insert_or_assign(state.symbols.create(name), &value(state));
} }
}; };
class JSONListState : public JSONState { class JSONListState : public JSONState {
ValueVector values = ValueVector(); ValueVector values;
virtual unique_ptr<JSONState> resolve(EvalState & state) override std::unique_ptr<JSONState> resolve(EvalState & state) override
{ {
Value & v = parent->value(state); Value & v = parent->value(state);
state.mkList(v, values.size()); state.mkList(v, values.size());
@ -63,19 +62,19 @@ class JSONSax : nlohmann::json_sax<json> {
} }
return std::move(parent); return std::move(parent);
} }
virtual void add() override { void add() override {
values.push_back(v); values.push_back(*v);
v = nullptr; v = nullptr;
}; }
public: public:
JSONListState(unique_ptr<JSONState>&& p, std::size_t reserve) : JSONState(std::move(p)) JSONListState(std::unique_ptr<JSONState> && p, std::size_t reserve) : JSONState(std::move(p))
{ {
values.reserve(reserve); values.reserve(reserve);
} }
}; };
EvalState & state; EvalState & state;
unique_ptr<JSONState> rs; std::unique_ptr<JSONState> rs;
template<typename T, typename... Args> inline bool handle_value(T f, Args... args) template<typename T, typename... Args> inline bool handle_value(T f, Args... args)
{ {

View file

@ -122,16 +122,16 @@ static void prim_scopedImport(EvalState & state, const Pos & pos, Value * * args
} }
w.attrs->sort(); w.attrs->sort();
static Value * fun = nullptr; static RootValue fun;
if (!fun) { if (!fun) {
fun = state.allocValue(); fun = allocRootValue(state.allocValue());
state.eval(state.parseExprFromString( state.eval(state.parseExprFromString(
#include "imported-drv-to-derivation.nix.gen.hh" #include "imported-drv-to-derivation.nix.gen.hh"
, "/"), *fun); , "/"), **fun);
} }
state.forceFunction(*fun, pos); state.forceFunction(**fun, pos);
mkApp(v, *fun, w); mkApp(v, **fun, w);
state.forceAttrs(v, pos); state.forceAttrs(v, pos);
} else { } else {
state.forceAttrs(*args[0]); state.forceAttrs(*args[0]);

View file

@ -54,15 +54,14 @@ static void prim_fetchMercurial(EvalState & state, const Pos & pos, Value * * ar
if (evalSettings.pureEval && !rev) if (evalSettings.pureEval && !rev)
throw Error("in pure evaluation mode, 'fetchMercurial' requires a Mercurial revision"); throw Error("in pure evaluation mode, 'fetchMercurial' requires a Mercurial revision");
auto parsedUrl = parseURL( fetchers::Attrs attrs;
url.find("://") != std::string::npos attrs.insert_or_assign("type", "hg");
? "hg+" + url attrs.insert_or_assign("url", url.find("://") != std::string::npos ? url : "file://" + url);
: "hg+file://" + url); if (ref) attrs.insert_or_assign("ref", *ref);
if (rev) parsedUrl.query.insert_or_assign("rev", rev->gitRev()); if (rev) attrs.insert_or_assign("rev", rev->gitRev());
if (ref) parsedUrl.query.insert_or_assign("ref", *ref); auto input = fetchers::inputFromAttrs(attrs);
// FIXME: use name
auto input = fetchers::inputFromURL(parsedUrl);
// FIXME: use name
auto [tree, input2] = input->fetchTree(state.store); auto [tree, input2] = input->fetchTree(state.store);
state.mkAttrs(v, 8); state.mkAttrs(v, 8);

View file

@ -258,12 +258,17 @@ void mkPath(Value & v, const char * s);
#if HAVE_BOEHMGC #if HAVE_BOEHMGC
typedef std::vector<Value *, gc_allocator<Value *> > ValueVector; typedef std::vector<Value *, traceable_allocator<Value *> > ValueVector;
typedef std::map<Symbol, Value *, std::less<Symbol>, gc_allocator<std::pair<const Symbol, Value *> > > ValueMap; typedef std::map<Symbol, Value *, std::less<Symbol>, traceable_allocator<std::pair<const Symbol, Value *> > > ValueMap;
#else #else
typedef std::vector<Value *> ValueVector; typedef std::vector<Value *> ValueVector;
typedef std::map<Symbol, Value *> ValueMap; typedef std::map<Symbol, Value *> ValueMap;
#endif #endif
/* A value allocated in traceable memory. */
typedef std::shared_ptr<Value *> RootValue;
RootValue allocRootValue(Value * v);
} }

View file

@ -12,8 +12,6 @@
#include "flake/eval-cache.hh" #include "flake/eval-cache.hh"
#include "url.hh" #include "url.hh"
#include <gc/gc.h>
#include <regex> #include <regex>
#include <queue> #include <queue>

View file

@ -23,7 +23,7 @@ struct CmdShowConfig : Command, MixJSON
std::map<std::string, Config::SettingInfo> settings; std::map<std::string, Config::SettingInfo> settings;
globalConfig.getSettings(settings); globalConfig.getSettings(settings);
for (auto & s : settings) for (auto & s : settings)
logger->stdout(s.first + " = " + s.second.value); logger->stdout("%s = %s", s.first, s.second.value);
} }
} }
}; };