feat(3p/nix): Add function to allocate a Value in traceable memory
Backported from:b3e5eea4a9
fcd048a526
Intentionally skipped because we have not backported the JSON changes:9f46f54de4
Did not apply changes ni primops.cc, because those look suspect and are also based on something that we don't have in our tree. Change-Id: I837787ce9f2c90267bc39fce15177980d209d4e9 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1253 Tested-by: BuildkiteCI Reviewed-by: isomer <isomer@tvl.fyi>
This commit is contained in:
parent
014436eb4a
commit
80eaa1eaf9
5 changed files with 19 additions and 10 deletions
7
third_party/nix/src/libexpr/eval.cc
vendored
7
third_party/nix/src/libexpr/eval.cc
vendored
|
@ -5,10 +5,13 @@
|
|||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <new>
|
||||
#include <optional>
|
||||
#include <variant>
|
||||
|
||||
#define GC_INCLUDE_NEW
|
||||
|
||||
#include <absl/strings/match.h>
|
||||
#include <gc/gc.h>
|
||||
#include <gc/gc_cpp.h>
|
||||
|
@ -40,6 +43,10 @@ static char* dupString(const char* s) {
|
|||
return t;
|
||||
}
|
||||
|
||||
std::shared_ptr<Value*> 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) {
|
||||
checkInterrupt();
|
||||
|
|
1
third_party/nix/src/libexpr/nixexpr.hh
vendored
1
third_party/nix/src/libexpr/nixexpr.hh
vendored
|
@ -3,6 +3,7 @@
|
|||
#include <map>
|
||||
#include <optional>
|
||||
#include <variant>
|
||||
|
||||
#include <absl/container/flat_hash_map.h>
|
||||
|
||||
#include "libexpr/symbol-table.hh"
|
||||
|
|
2
third_party/nix/src/libexpr/value.hh
vendored
2
third_party/nix/src/libexpr/value.hh
vendored
|
@ -247,4 +247,6 @@ typedef std::map<Symbol, Value*, std::less<Symbol>,
|
|||
traceable_allocator<std::pair<const Symbol, Value*>>>
|
||||
ValueMap;
|
||||
|
||||
std::shared_ptr<Value*> allocRootValue(Value* v);
|
||||
|
||||
} // namespace nix
|
||||
|
|
3
third_party/nix/src/nix/command.hh
vendored
3
third_party/nix/src/nix/command.hh
vendored
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "libexpr/common-eval-args.hh"
|
||||
#include "libutil/args.hh"
|
||||
|
||||
|
@ -81,7 +82,7 @@ struct SourceExprCommand : virtual Args, StoreCommand, MixEvalArgs {
|
|||
|
||||
private:
|
||||
std::shared_ptr<EvalState> evalState;
|
||||
std::shared_ptr<Value> vSourceExpr;
|
||||
std::shared_ptr<Value*> vSourceExpr;
|
||||
};
|
||||
|
||||
enum RealiseMode { Build, NoBuild, DryRun };
|
||||
|
|
16
third_party/nix/src/nix/installables.cc
vendored
16
third_party/nix/src/nix/installables.cc
vendored
|
@ -1,8 +1,6 @@
|
|||
#include <regex>
|
||||
#include <utility>
|
||||
|
||||
#include <gc/gc.h>
|
||||
|
||||
#include "libexpr/attr-path.hh"
|
||||
#include "libexpr/common-eval-args.hh"
|
||||
#include "libexpr/eval-inline.hh"
|
||||
|
@ -26,7 +24,7 @@ SourceExprCommand::SourceExprCommand() {
|
|||
|
||||
Value* SourceExprCommand::getSourceExpr(EvalState& state) {
|
||||
if (vSourceExpr != nullptr) {
|
||||
return vSourceExpr.get();
|
||||
return *vSourceExpr;
|
||||
}
|
||||
|
||||
auto sToplevel = state.symbols.Create("_toplevel");
|
||||
|
@ -34,18 +32,18 @@ Value* SourceExprCommand::getSourceExpr(EvalState& state) {
|
|||
// 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.empty()) {
|
||||
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;
|
||||
|
||||
|
@ -61,7 +59,7 @@ Value* SourceExprCommand::getSourceExpr(EvalState& state) {
|
|||
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);
|
||||
};
|
||||
|
||||
|
@ -79,7 +77,7 @@ Value* SourceExprCommand::getSourceExpr(EvalState& state) {
|
|||
}
|
||||
}
|
||||
|
||||
return vSourceExpr.get();
|
||||
return *vSourceExpr;
|
||||
}
|
||||
|
||||
ref<EvalState> SourceExprCommand::getEvalState() {
|
||||
|
|
Loading…
Reference in a new issue