Skip to content

Commit

Permalink
Use RootValue
Browse files Browse the repository at this point in the history
  • Loading branch information
edolstra committed Apr 16, 2020
1 parent 9f46f54 commit fcd048a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
10 changes: 5 additions & 5 deletions src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,16 @@ static void prim_scopedImport(EvalState & state, const Pos & pos, Value * * args
}
w.attrs->sort();

static Value * fun = nullptr;
static RootValue fun;
if (!fun) {
fun = state.allocValue();
fun = allocRootValue(state.allocValue());
state.eval(state.parseExprFromString(
#include "imported-drv-to-derivation.nix.gen.hh"
, "/"), *fun);
, "/"), **fun);
}

state.forceFunction(*fun, pos);
mkApp(v, *fun, w);
state.forceFunction(**fun, pos);
mkApp(v, **fun, w);
state.forceAttrs(v, pos);
} else {
state.forceAttrs(*args[0]);
Expand Down
2 changes: 1 addition & 1 deletion src/nix/command.hh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private:

std::shared_ptr<EvalState> evalState;

std::shared_ptr<Value> vSourceExpr;
RootValue vSourceExpr;
};

enum RealiseMode { Build, NoBuild, DryRun };
Expand Down
21 changes: 8 additions & 13 deletions src/nix/installables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include "store-api.hh"
#include "shared.hh"

#include <gc/gc.h>

#include <regex>

namespace nix {
Expand All @@ -27,27 +25,24 @@ SourceExprCommand::SourceExprCommand()

Value * SourceExprCommand::getSourceExpr(EvalState & state)
{
if (vSourceExpr) return vSourceExpr.get();
if (vSourceExpr) return *vSourceExpr;

auto sToplevel = state.symbols.create("_toplevel");

// Allocate the vSourceExpr Value as uncollectable. Boehm GC doesn't
// consider the member variable "alive" during execution causing it to be
// GC'ed in the middle of evaluation.
vSourceExpr = std::allocate_shared<Value>(traceable_allocator<Value>());
vSourceExpr = allocRootValue(state.allocValue());

if (file != "")
state.evalFile(lookupFileArg(state, file), *vSourceExpr);
state.evalFile(lookupFileArg(state, file), **vSourceExpr);

else {

/* Construct the installation source from $NIX_PATH. */

auto searchPath = state.getSearchPath();

state.mkAttrs(*vSourceExpr, 1024);
state.mkAttrs(**vSourceExpr, 1024);

mkBool(*state.allocAttr(*vSourceExpr, sToplevel), true);
mkBool(*state.allocAttr(**vSourceExpr, sToplevel), true);

std::unordered_set<std::string> seen;

Expand All @@ -58,7 +53,7 @@ Value * SourceExprCommand::getSourceExpr(EvalState & state)
mkPrimOpApp(*v1, state.getBuiltin("findFile"), state.getBuiltin("nixPath"));
Value * v2 = state.allocValue();
mkApp(*v2, *v1, mkString(*state.allocValue(), name));
mkApp(*state.allocAttr(*vSourceExpr, state.symbols.create(name)),
mkApp(*state.allocAttr(**vSourceExpr, state.symbols.create(name)),
state.getBuiltin("import"), *v2);
};

Expand All @@ -72,10 +67,10 @@ Value * SourceExprCommand::getSourceExpr(EvalState & state)
} else
addEntry(i.first);

vSourceExpr->attrs->sort();
(*vSourceExpr)->attrs->sort();
}

return vSourceExpr.get();
return *vSourceExpr;
}

ref<EvalState> SourceExprCommand::getEvalState()
Expand Down

0 comments on commit fcd048a

Please sign in to comment.