Skip to content

Commit c5c6855

Browse files
authored
Merge pull request #11550 from DeterminateSystems/traceable-allocator-alias
Alias traceable_allocator to std::allocator when building without GC
2 parents ca3fc16 + b2bb92e commit c5c6855

File tree

12 files changed

+31
-98
lines changed

12 files changed

+31
-98
lines changed

src/libcmd/command.cc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,9 @@ ref<EvalState> EvalCommand::getEvalState()
127127
{
128128
if (!evalState) {
129129
evalState =
130-
#if HAVE_BOEHMGC
131130
std::allocate_shared<EvalState>(
132131
traceable_allocator<EvalState>(),
133-
#else
134-
std::make_shared<EvalState>(
135-
#endif
136-
lookupPath, getEvalStore(), fetchSettings, evalSettings, getStore())
137-
;
132+
lookupPath, getEvalStore(), fetchSettings, evalSettings, getStore());
138133

139134
evalState->repair = repair;
140135

src/libcmd/repl.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@
2929
#include "ref.hh"
3030
#include "value.hh"
3131

32-
#if HAVE_BOEHMGC
33-
#define GC_INCLUDE_NEW
34-
#include <gc/gc_cpp.h>
35-
#endif
36-
3732
#include "strings.hh"
3833

3934
namespace nix {
@@ -62,9 +57,7 @@ enum class ProcessLineResult {
6257
struct NixRepl
6358
: AbstractNixRepl
6459
, detail::ReplCompleterMixin
65-
#if HAVE_BOEHMGC
6660
, gc
67-
#endif
6861
{
6962
size_t debugTraceIndex;
7063

src/libexpr-c/nix_api_external.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@
1414

1515
#include <nlohmann/json.hpp>
1616

17-
#if HAVE_BOEHMGC
18-
# include "gc/gc.h"
19-
# define GC_INCLUDE_NEW 1
20-
# include "gc_cpp.h"
21-
#endif
22-
2317
void nix_set_string_return(nix_string_return * str, const char * c)
2418
{
2519
str->str = c;

src/libexpr-c/nix_api_value.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@
1414
#include "nix_api_value.h"
1515
#include "value/context.hh"
1616

17-
#if HAVE_BOEHMGC
18-
# include "gc/gc.h"
19-
# define GC_INCLUDE_NEW 1
20-
# include "gc_cpp.h"
21-
#endif
22-
2317
// Internal helper functions to check [in] and [out] `Value *` parameters
2418
static const nix::Value & check_value_not_null(const nix_value * value)
2519
{

src/libexpr/eval-gc.hh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,32 @@
33

44
#include <cstddef>
55

6+
#if HAVE_BOEHMGC
7+
8+
# define GC_INCLUDE_NEW
9+
10+
# include <gc/gc.h>
11+
# include <gc/gc_cpp.h>
12+
# include <gc/gc_allocator.h>
13+
14+
#else
15+
16+
/* Some dummy aliases for Boehm GC definitions to reduce the number of
17+
#ifdefs. */
18+
19+
template<typename T>
20+
using traceable_allocator = std::allocator<T>;
21+
22+
template<typename T>
23+
using gc_allocator = std::allocator<T>;
24+
25+
# define GC_MALLOC_ATOMIC std::malloc
26+
# define GC_STRDUP std::strdup
27+
struct gc
28+
{};
29+
30+
#endif
31+
632
namespace nix {
733

834
/**

src/libexpr/eval.cc

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "eval.hh"
2-
#include "eval-gc.hh"
32
#include "eval-settings.hh"
43
#include "primops.hh"
54
#include "print-options.hh"
@@ -39,16 +38,6 @@
3938
# include <sys/resource.h>
4039
#endif
4140

42-
#if HAVE_BOEHMGC
43-
44-
# define GC_INCLUDE_NEW
45-
46-
# include <gc/gc.h>
47-
# include <gc/gc_cpp.h>
48-
# include <gc/gc_allocator.h>
49-
50-
#endif
51-
5241
#include "strings-inline.hh"
5342

5443
using json = nlohmann::json;
@@ -58,11 +47,7 @@ namespace nix {
5847
static char * allocString(size_t size)
5948
{
6049
char * t;
61-
#if HAVE_BOEHMGC
6250
t = (char *) GC_MALLOC_ATOMIC(size);
63-
#else
64-
t = (char *) malloc(size);
65-
#endif
6651
if (!t) throw std::bad_alloc();
6752
return t;
6853
}
@@ -71,11 +56,7 @@ static char * allocString(size_t size)
7156
static char * dupString(const char * s)
7257
{
7358
char * t;
74-
#if HAVE_BOEHMGC
7559
t = GC_STRDUP(s);
76-
#else
77-
t = strdup(s);
78-
#endif
7960
if (!t) throw std::bad_alloc();
8061
return t;
8162
}
@@ -99,11 +80,7 @@ static const char * makeImmutableString(std::string_view s)
9980

10081
RootValue allocRootValue(Value * v)
10182
{
102-
#if HAVE_BOEHMGC
10383
return std::allocate_shared<Value *>(traceable_allocator<Value *>(), v);
104-
#else
105-
return std::make_shared<Value *>(v);
106-
#endif
10784
}
10885

10986
// Pretty print types for assertion errors

src/libexpr/eval.hh

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,7 @@ struct Constant
139139
bool impureOnly = false;
140140
};
141141

142-
#if HAVE_BOEHMGC
143-
typedef std::map<std::string, Value *, std::less<std::string>, traceable_allocator<std::pair<const std::string, Value *> > > ValMap;
144-
#else
145-
typedef std::map<std::string, Value *> ValMap;
146-
#endif
142+
typedef std::map<std::string, Value *, std::less<std::string>, traceable_allocator<std::pair<const std::string, Value *> > > ValMap;
147143

148144
typedef std::unordered_map<PosIdx, DocComment> DocCommentMap;
149145

@@ -329,21 +325,13 @@ private:
329325
/**
330326
* A cache from path names to parse trees.
331327
*/
332-
#if HAVE_BOEHMGC
333328
typedef std::unordered_map<SourcePath, Expr *, std::hash<SourcePath>, std::equal_to<SourcePath>, traceable_allocator<std::pair<const SourcePath, Expr *>>> FileParseCache;
334-
#else
335-
typedef std::unordered_map<SourcePath, Expr *> FileParseCache;
336-
#endif
337329
FileParseCache fileParseCache;
338330

339331
/**
340332
* A cache from path names to values.
341333
*/
342-
#if HAVE_BOEHMGC
343334
typedef std::unordered_map<SourcePath, Value, std::hash<SourcePath>, std::equal_to<SourcePath>, traceable_allocator<std::pair<const SourcePath, Value>>> FileEvalCache;
344-
#else
345-
typedef std::unordered_map<SourcePath, Value> FileEvalCache;
346-
#endif
347335
FileEvalCache fileEvalCache;
348336

349337
/**

src/libexpr/gc-small-vector.hh

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,15 @@
22

33
#include <boost/container/small_vector.hpp>
44

5-
#if HAVE_BOEHMGC
6-
7-
#include <gc/gc.h>
8-
#include <gc/gc_cpp.h>
9-
#include <gc/gc_allocator.h>
10-
11-
#endif
5+
#include "value.hh"
126

137
namespace nix {
148

15-
struct Value;
16-
179
/**
1810
* A GC compatible vector that may used a reserved portion of `nItems` on the stack instead of allocating on the heap.
1911
*/
20-
#if HAVE_BOEHMGC
2112
template <typename T, size_t nItems>
2213
using SmallVector = boost::container::small_vector<T, nItems, traceable_allocator<T>>;
23-
#else
24-
template <typename T, size_t nItems>
25-
using SmallVector = boost::container::small_vector<T, nItems>;
26-
#endif
2714

2815
/**
2916
* A vector of value pointers. See `SmallVector`.
@@ -39,4 +26,4 @@ using SmallValueVector = SmallVector<Value *, nItems>;
3926
template <size_t nItems>
4027
using SmallTemporaryValueVector = SmallVector<Value, nItems>;
4128

42-
}
29+
}

src/libexpr/get-drvs.hh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,7 @@ public:
8383
};
8484

8585

86-
#if HAVE_BOEHMGC
8786
typedef std::list<PackageInfo, traceable_allocator<PackageInfo>> PackageInfos;
88-
#else
89-
typedef std::list<PackageInfo> PackageInfos;
90-
#endif
9187

9288

9389
/**

src/libexpr/primops.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -631,11 +631,7 @@ struct CompareValues
631631
};
632632

633633

634-
#if HAVE_BOEHMGC
635634
typedef std::list<Value *, gc_allocator<Value *>> ValueList;
636-
#else
637-
typedef std::list<Value *> ValueList;
638-
#endif
639635

640636

641637
static Bindings::const_iterator getAttr(
@@ -3136,11 +3132,7 @@ static void prim_zipAttrsWith(EvalState & state, const PosIdx pos, Value * * arg
31363132
std::optional<ListBuilder> list;
31373133
};
31383134

3139-
#if HAVE_BOEHMGC
31403135
std::map<Symbol, Item, std::less<Symbol>, traceable_allocator<std::pair<const Symbol, Item>>> attrsSeen;
3141-
#else
3142-
std::map<Symbol, Item> attrsSeen;
3143-
#endif
31443136

31453137
state.forceFunction(*args[0], pos, "while evaluating the first argument passed to builtins.zipAttrsWith");
31463138
state.forceList(*args[1], pos, "while evaluating the second argument passed to builtins.zipAttrsWith");

src/libexpr/value.hh

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
#include <cassert>
55
#include <span>
66

7+
#include "eval-gc.hh"
78
#include "symbol-table.hh"
89
#include "value/context.hh"
910
#include "source-path.hh"
1011
#include "print-options.hh"
1112
#include "checked-arithmetic.hh"
1213

13-
#if HAVE_BOEHMGC
14-
#include <gc/gc_allocator.h>
15-
#endif
1614
#include <nlohmann/json_fwd.hpp>
1715

1816
namespace nix {
@@ -498,15 +496,9 @@ void Value::mkBlackhole()
498496
}
499497

500498

501-
#if HAVE_BOEHMGC
502499
typedef std::vector<Value *, traceable_allocator<Value *>> ValueVector;
503500
typedef std::unordered_map<Symbol, Value *, std::hash<Symbol>, std::equal_to<Symbol>, traceable_allocator<std::pair<const Symbol, Value *>>> ValueMap;
504501
typedef std::map<Symbol, ValueVector, std::less<Symbol>, traceable_allocator<std::pair<const Symbol, ValueVector>>> ValueVectorMap;
505-
#else
506-
typedef std::vector<Value *> ValueVector;
507-
typedef std::unordered_map<Symbol, Value *> ValueMap;
508-
typedef std::map<Symbol, ValueVector> ValueVectorMap;
509-
#endif
510502

511503

512504
/**

src/nix/main.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#include "current-process.hh"
33
#include "command.hh"
44
#include "common-args.hh"
5-
#include "eval-gc.hh"
65
#include "eval.hh"
76
#include "eval-settings.hh"
87
#include "globals.hh"

0 commit comments

Comments
 (0)