Moved a bunch of building blocks into a new package building_blocks

This commit is contained in:
Andrei Alexandrescu 2015-06-21 23:25:45 -07:00
parent e0ad05d7b0
commit 499ecfedc5
19 changed files with 116 additions and 94 deletions

View file

@ -151,7 +151,8 @@ P2MODULES=$(foreach P,$1,$(addprefix $P/,$(PACKAGE_$(subst /,_,$P))))
# xy/zz is in variable PACKAGE_xy_zz. This allows automation in iterating
# packages and their modules.
STD_PACKAGES = std $(addprefix std/,\
algorithm container digest experimental/allocator experimental/logger net \
algorithm container digest experimental/allocator \
experimental/allocator/building_blocks experimental/logger net \
range regex)
# Modules broken down per package
@ -169,10 +170,12 @@ PACKAGE_std_digest = crc digest hmac md ripemd sha
PACKAGE_std_experimental_logger = core filelogger \
nulllogger multilogger package
PACKAGE_std_experimental_allocator = \
affix_allocator allocator_list bucketizer building_blocks common \
fallback_allocator free_list free_tree gc_allocator bitmapped_block \
kernighan_ritchie mallocator mmap_allocator null_allocator package quantizer \
region scoped_allocator segregator showcase stats_collector typed
common gc_allocator mallocator mmap_allocator package showcase typed
PACKAGE_std_experimental_allocator_building_blocks = \
affix_allocator allocator_list bucketizer \
fallback_allocator free_list free_tree bitmapped_block \
kernighan_ritchie null_allocator package quantizer \
region scoped_allocator segregator stats_collector
PACKAGE_std_net = curl isemail
PACKAGE_std_range = interfaces package primitives
PACKAGE_std_regex = package $(addprefix internal/,generator ir parser \

View file

@ -1,4 +1,4 @@
module std.experimental.allocator.affix_allocator;
module std.experimental.allocator.building_blocks.affix_allocator;
/**
@ -268,7 +268,8 @@ unittest
unittest
{
import std.experimental.allocator.bitmapped_block : BitmappedBlock;
import std.experimental.allocator.building_blocks.bitmapped_block
: BitmappedBlock;
import std.experimental.allocator.common : testAllocator;
testAllocator!({
auto a = AffixAllocator!(BitmappedBlock!128, ulong, ulong)
@ -285,7 +286,8 @@ unittest
A.instance.prefix(b) = 10;
assert(A.instance.prefix(b) == 10);
import std.experimental.allocator.null_allocator : NullAllocator;
import std.experimental.allocator.building_blocks.null_allocator
: NullAllocator;
alias B = AffixAllocator!(NullAllocator, size_t);
b = B.instance.allocate(100);
assert(b is null);

View file

@ -1,7 +1,7 @@
module std.experimental.allocator.allocator_list;
module std.experimental.allocator.building_blocks.allocator_list;
import std.experimental.allocator.common;
import std.experimental.allocator.null_allocator;
import std.experimental.allocator.building_blocks.null_allocator;
import std.experimental.allocator.gc_allocator;
version(unittest) import std.stdio;
@ -65,7 +65,8 @@ struct AllocatorList(Factory, BookkeepingAllocator = GCAllocator)
import std.traits : hasMember;
import std.conv : emplace;
import std.algorithm : min, move;
import std.experimental.allocator.stats_collector : StatsCollector, Options;
import std.experimental.allocator.building_blocks.stats_collector
: StatsCollector, Options;
private enum ouroboros = is(BookkeepingAllocator == NullAllocator);
@ -523,10 +524,11 @@ template AllocatorList(alias factoryFunction,
version(Posix) unittest
{
import std.algorithm : max;
import std.experimental.allocator.region : Region;
import std.experimental.allocator.building_blocks.region : Region;
import std.experimental.allocator.mmap_allocator : MmapAllocator;
import std.experimental.allocator.segregator : Segregator;
import std.experimental.allocator.free_list : ContiguousFreeList;
import std.experimental.allocator.building_blocks.segregator : Segregator;
import std.experimental.allocator.building_blocks.free_list
: ContiguousFreeList;
// Ouroboros allocator list based upon 4MB regions, fetched directly from
// mmap. All memory is released upon destruction.
@ -565,7 +567,7 @@ unittest
{
// Create an allocator based upon 4MB regions, fetched from the GC heap.
import std.algorithm : max;
import std.experimental.allocator.region : Region;
import std.experimental.allocator.building_blocks.region : Region;
AllocatorList!((n) => Region!GCAllocator(new void[max(n, 1024 * 4096)]),
NullAllocator) a;
const b1 = a.allocate(1024 * 8192);
@ -579,7 +581,7 @@ unittest
{
// Create an allocator based upon 4MB regions, fetched from the GC heap.
import std.algorithm : max;
import std.experimental.allocator.region : Region;
import std.experimental.allocator.building_blocks.region : Region;
AllocatorList!((n) => Region!()(new void[max(n, 1024 * 4096)])) a;
auto b1 = a.allocate(1024 * 8192);
assert(b1 !is null); // still works due to overdimensioning
@ -591,7 +593,7 @@ unittest
unittest
{
import std.algorithm : max;
import std.experimental.allocator.region : Region;
import std.experimental.allocator.building_blocks.region : Region;
AllocatorList!((n) => Region!()(new void[max(n, 1024 * 4096)])) a;
auto b1 = a.allocate(1024 * 8192);
assert(b1 !is null);

View file

@ -1,7 +1,7 @@
module std.experimental.allocator.bitmapped_block;
module std.experimental.allocator.building_blocks.bitmapped_block;
import std.experimental.allocator.common;
import std.experimental.allocator.null_allocator;
import std.experimental.allocator.building_blocks.null_allocator;
/**
@ -711,7 +711,7 @@ struct BitmappedBlock(size_t theBlockSize, uint theAlignment = platformAlignment
unittest
{
// Create a block allocator on top of a 10KB stack region.
import std.experimental.allocator.region : InSituRegion;
import std.experimental.allocator.building_blocks.region : InSituRegion;
import std.traits : hasMember;
InSituRegion!(10_240, 64) r;
auto a = BitmappedBlock!(64, 64)(r.allocateAll());

View file

@ -1,4 +1,4 @@
module std.experimental.allocator.bucketizer;
module std.experimental.allocator.building_blocks.bucketizer;
/**
@ -231,7 +231,7 @@ struct Bucketizer(Allocator, size_t min, size_t max, size_t step)
///
unittest
{
import std.experimental.allocator.free_list : FreeList;
import std.experimental.allocator.building_blocks.free_list : FreeList;
import std.experimental.allocator.mallocator : Mallocator;
import std.experimental.allocator.common : unbounded;
Bucketizer!(FreeList!(Mallocator, 0, unbounded),

View file

@ -1,4 +1,4 @@
module std.experimental.allocator.fallback_allocator;
module std.experimental.allocator.building_blocks.fallback_allocator;
import std.experimental.allocator.common;
@ -257,7 +257,7 @@ struct FallbackAllocator(Primary, Fallback)
unittest
{
import std.experimental.allocator.region : InSituRegion;
import std.experimental.allocator.building_blocks.region : InSituRegion;
import std.experimental.allocator.gc_allocator : GCAllocator;
import std.conv : text;
FallbackAllocator!(InSituRegion!16_384, GCAllocator) a;
@ -343,7 +343,7 @@ fallbackAllocator(Primary, Fallback)(auto ref Primary p, auto ref Fallback f)
///
unittest
{
import std.experimental.allocator.region : Region;
import std.experimental.allocator.building_blocks.region : Region;
import std.experimental.allocator.gc_allocator : GCAllocator;
auto a = fallbackAllocator(Region!GCAllocator(1024), GCAllocator.instance);
auto b1 = a.allocate(1020);

View file

@ -1,4 +1,4 @@
module std.experimental.allocator.free_list;
module std.experimental.allocator.building_blocks.free_list;
import std.experimental.allocator.common;
import std.typecons : Flag, Yes, No;
@ -424,8 +424,10 @@ available for $(D ContiguousFreeList).
struct ContiguousFreeList(ParentAllocator,
size_t minSize, size_t maxSize = minSize)
{
import std.experimental.allocator.null_allocator : NullAllocator;
import std.experimental.allocator.stats_collector : StatsCollector, Options;
import std.experimental.allocator.building_blocks.null_allocator
: NullAllocator;
import std.experimental.allocator.building_blocks.stats_collector
: StatsCollector, Options;
import std.traits : hasMember;
alias Impl = FreeList!(NullAllocator, minSize, maxSize);
@ -668,7 +670,8 @@ struct ContiguousFreeList(ParentAllocator,
unittest
{
import std.experimental.allocator.gc_allocator : GCAllocator;
import std.experimental.allocator.allocator_list : AllocatorList;
import std.experimental.allocator.building_blocks.allocator_list
: AllocatorList;
alias ScalableFreeList = AllocatorList!((n) =>
ContiguousFreeList!(GCAllocator, 0, unbounded)(4096)
@ -677,7 +680,8 @@ unittest
unittest
{
import std.experimental.allocator.null_allocator : NullAllocator;
import std.experimental.allocator.building_blocks.null_allocator
: NullAllocator;
alias A = ContiguousFreeList!(NullAllocator, 0, 64);
auto a = A(new void[1024]);
@ -700,7 +704,7 @@ unittest
unittest
{
import std.experimental.allocator.region : Region;
import std.experimental.allocator.building_blocks.region : Region;
import std.experimental.allocator.gc_allocator : GCAllocator;
alias A = ContiguousFreeList!(Region!GCAllocator, 0, 64);
auto a = A(Region!GCAllocator(1024 * 4), 1024);

View file

@ -1,4 +1,4 @@
module std.experimental.allocator.free_tree;
module std.experimental.allocator.building_blocks.free_tree;
import std.experimental.allocator.common;

View file

@ -1,5 +1,5 @@
module std.experimental.allocator.kernighan_ritchie;
import std.experimental.allocator.null_allocator;
module std.experimental.allocator.building_blocks.kernighan_ritchie;
import std.experimental.allocator.building_blocks.null_allocator;
//debug = KRRegion;
debug(KRRegion) import std.stdio;
@ -597,7 +597,8 @@ fronting the GC allocator.
unittest
{
import std.experimental.allocator.gc_allocator : GCAllocator;
import std.experimental.allocator.fallback_allocator : fallbackAllocator;
import std.experimental.allocator.building_blocks.fallback_allocator
: fallbackAllocator;
import std.experimental.allocator.common : Ternary;
// KRRegion fronting a general-purpose allocator
ubyte[1024 * 128] buf;
@ -622,7 +623,8 @@ unittest
import std.algorithm : max;
import std.experimental.allocator.gc_allocator : GCAllocator;
import std.experimental.allocator.mmap_allocator : MmapAllocator;
import std.experimental.allocator.allocator_list : AllocatorList;
import std.experimental.allocator.building_blocks.allocator_list
: AllocatorList;
AllocatorList!(n => KRRegion!MmapAllocator(max(n * 16, 1024 * 1024))) alloc;
}
@ -632,7 +634,8 @@ unittest
import std.experimental.allocator.gc_allocator : GCAllocator;
import std.experimental.allocator.common : Ternary;
import std.experimental.allocator.mallocator : Mallocator;
import std.experimental.allocator.allocator_list : AllocatorList;
import std.experimental.allocator.building_blocks.allocator_list
: AllocatorList;
/*
Create a scalable allocator consisting of 1 MB (or larger) blocks fetched
from the garbage-collected heap. Each block is organized as a KR-style
@ -664,7 +667,8 @@ unittest
import std.experimental.allocator.gc_allocator : GCAllocator;
import std.experimental.allocator.common : Ternary;
import std.experimental.allocator.mmap_allocator : MmapAllocator;
import std.experimental.allocator.allocator_list : AllocatorList;
import std.experimental.allocator.building_blocks.allocator_list
: AllocatorList;
/*
Create a scalable allocator consisting of 1 MB (or larger) blocks fetched
from the garbage-collected heap. Each block is organized as a KR-style
@ -698,7 +702,8 @@ unittest
unittest
{
import std.experimental.allocator.gc_allocator : GCAllocator;
import std.experimental.allocator.allocator_list : AllocatorList;
import std.experimental.allocator.building_blocks.allocator_list
: AllocatorList;
import std.algorithm : max;
import std.experimental.allocator.common : testAllocator;
testAllocator!(() => AllocatorList!(

View file

@ -1,4 +1,4 @@
module std.experimental.allocator.null_allocator;
module std.experimental.allocator.building_blocks.null_allocator;
/*
_ _ _ _ _ _ _

View file

@ -202,7 +202,7 @@ or `import` `std.experimental.building_blocks`, which imports them all
combined with your own. For a collection of typical and useful preassembled
allocators and for inspiration in defining more such assemblies, refer to
$(LINK2 std_experimental_allocator_showcase.html,
`std.experimental.allocator.showcase`).)
`std.experimental.allocator.building_blocks.showcase`).)
$(BOOKTABLE,
$(TR $(TH Allocator$(BR)) $(TH Description))
@ -284,7 +284,7 @@ MYREF = $(LINK2 std_experimental_allocator_$2.html, $1) 
MYREF2 = $(LINK2 std_experimental_allocator_$2.html#$1, $1) 
TDC = $(T td nowrap, $(D $1)$+)
TDC2 = $(T td nowrap, $(D $(MYREF2 $1,$+))$(BR)$(SMALL
$(D std.experimental.allocator.$2)))
$(D std.experimental.allocator.building_blocks.$2)))
TDC3 = $(T td nowrap, $(D $(MYREF2 $1,$+)))
RES = $(I result)
POST = $(BR)$(SMALL $(I Post:) $(BLUE $(D $0)))
@ -293,19 +293,19 @@ POST = $(BR)$(SMALL $(I Post:) $(BLUE $(D $0)))
module std.experimental.allocator.building_blocks;
public import
std.experimental.allocator.affix_allocator,
std.experimental.allocator.allocator_list,
std.experimental.allocator.bucketizer,
std.experimental.allocator.fallback_allocator,
std.experimental.allocator.free_list,
std.experimental.allocator.free_tree,
std.experimental.allocator.building_blocks.affix_allocator,
std.experimental.allocator.building_blocks.allocator_list,
std.experimental.allocator.building_blocks.bucketizer,
std.experimental.allocator.building_blocks.fallback_allocator,
std.experimental.allocator.building_blocks.free_list,
std.experimental.allocator.building_blocks.free_tree,
std.experimental.allocator.gc_allocator,
std.experimental.allocator.bitmapped_block,
std.experimental.allocator.kernighan_ritchie,
std.experimental.allocator.building_blocks.bitmapped_block,
std.experimental.allocator.building_blocks.kernighan_ritchie,
std.experimental.allocator.mallocator,
std.experimental.allocator.mmap_allocator,
std.experimental.allocator.null_allocator,
std.experimental.allocator.quantizer,
std.experimental.allocator.region,
std.experimental.allocator.segregator,
std.experimental.allocator.stats_collector;
std.experimental.allocator.building_blocks.null_allocator,
std.experimental.allocator.building_blocks.quantizer,
std.experimental.allocator.building_blocks.region,
std.experimental.allocator.building_blocks.segregator,
std.experimental.allocator.building_blocks.stats_collector;

View file

@ -1,4 +1,4 @@
module std.experimental.allocator.quantizer;
module std.experimental.allocator.building_blocks.quantizer;
import std.experimental.allocator.common;
@ -214,7 +214,7 @@ struct Quantizer(ParentAllocator, alias roundingFunction)
///
unittest
{
import std.experimental.allocator.free_tree : FreeTree;
import std.experimental.allocator.building_blocks.free_tree : FreeTree;
import std.experimental.allocator.gc_allocator : GCAllocator;
// Quantize small allocations to a multiple of cache line, large ones to a
// multiple of page size

View file

@ -1,7 +1,7 @@
module std.experimental.allocator.region;
module std.experimental.allocator.building_blocks.region;
import std.experimental.allocator.common;
import std.experimental.allocator.null_allocator;
import std.experimental.allocator.building_blocks.null_allocator;
import std.typecons : Flag, Yes, No;
/**
@ -330,7 +330,8 @@ struct Region(ParentAllocator = NullAllocator,
unittest
{
import std.experimental.allocator.mallocator : Mallocator;
import std.experimental.allocator.allocator_list : AllocatorList;
import std.experimental.allocator.building_blocks.allocator_list
: AllocatorList;
import std.algorithm : max;
// Create a scalable list of regions. Each gets at least 1MB at a time by
// using malloc.
@ -533,10 +534,13 @@ unittest
assert(a1.length == 101);
// 128KB region, with fallback to the garbage collector.
import std.experimental.allocator.fallback_allocator : FallbackAllocator;
import std.experimental.allocator.free_list : FreeList;
import std.experimental.allocator.building_blocks.fallback_allocator
: FallbackAllocator;
import std.experimental.allocator.building_blocks.free_list
: FreeList;
import std.experimental.allocator.gc_allocator : GCAllocator;
import std.experimental.allocator.bitmapped_block : BitmappedBlock;
import std.experimental.allocator.building_blocks.bitmapped_block
: BitmappedBlock;
FallbackAllocator!(InSituRegion!(128 * 1024), GCAllocator) r2;
const a2 = r2.allocate(102);
assert(a2.length == 102);

View file

@ -1,4 +1,4 @@
module std.experimental.allocator.scoped_allocator;
module std.experimental.allocator.building_blocks.scoped_allocator;
import std.experimental.allocator.common;
@ -21,7 +21,8 @@ struct ScopedAllocator(ParentAllocator)
testAllocator!(() => ScopedAllocator());
}
private import std.experimental.allocator.affix_allocator : AffixAllocator;
private import std.experimental.allocator.building_blocks.affix_allocator
: AffixAllocator;
private import std.traits : hasMember;
private struct Node

View file

@ -1,4 +1,4 @@
module std.experimental.allocator.segregator;
module std.experimental.allocator.building_blocks.segregator;
import std.experimental.allocator.common;
@ -274,7 +274,7 @@ struct Segregator(size_t threshold, SmallAllocator, LargeAllocator)
///
unittest
{
import std.experimental.allocator.free_list : FreeList;
import std.experimental.allocator.building_blocks.free_list : FreeList;
import std.experimental.allocator.mallocator : Mallocator;
import std.experimental.allocator.gc_allocator : GCAllocator;
alias A =
@ -347,7 +347,7 @@ template Segregator(Args...) if (Args.length > 3)
///
unittest
{
import std.experimental.allocator.free_list : FreeList;
import std.experimental.allocator.building_blocks.free_list : FreeList;
import std.experimental.allocator.mallocator : Mallocator;
import std.experimental.allocator.gc_allocator : GCAllocator;
alias A =

View file

@ -1,4 +1,4 @@
module std.experimental.allocator.stats_collector;
module std.experimental.allocator.building_blocks.stats_collector;
import std.experimental.allocator.common;
@ -643,7 +643,7 @@ public:
unittest
{
import std.experimental.allocator.gc_allocator : GCAllocator;
import std.experimental.allocator.free_list : FreeList;
import std.experimental.allocator.building_blocks.free_list : FreeList;
alias Allocator = StatsCollector!(GCAllocator, Options.all, Options.all);
Allocator alloc;
@ -693,7 +693,7 @@ unittest
}
import std.experimental.allocator.gc_allocator : GCAllocator;
import std.experimental.allocator.free_list : FreeList;
import std.experimental.allocator.building_blocks.free_list : FreeList;
test!(StatsCollector!(GCAllocator, Options.all, Options.all));
test!(StatsCollector!(FreeList!(GCAllocator, 128), Options.all,
Options.all));
@ -717,6 +717,6 @@ unittest
a.deallocate(b3);
}
import std.experimental.allocator.gc_allocator : GCAllocator;
import std.experimental.allocator.free_list : FreeList;
import std.experimental.allocator.building_blocks.free_list : FreeList;
test!(StatsCollector!(GCAllocator, 0, 0));
}

View file

@ -559,7 +559,7 @@ bool alignedReallocate(Allocator)(ref Allocator alloc,
/**
Forwards each of the methods in `funs` (if defined) to `member`.
*/
package string forwardToMember(string member, string[] funs...)
/*package*/ string forwardToMember(string member, string[] funs...)
{
string result = " import std.traits : hasMember, ParameterTypeTuple;\n";
foreach (fun; funs)

View file

@ -50,25 +50,22 @@ Source: $(PHOBOSSRC std/experimental/_allocator)
module std.experimental.allocator;
public import
std.experimental.allocator.affix_allocator,
std.experimental.allocator.allocator_list,
std.experimental.allocator.bucketizer,
//std.experimental.allocator.building_blocks,
std.experimental.allocator.common,
std.experimental.allocator.fallback_allocator,
std.experimental.allocator.free_list,
std.experimental.allocator.gc_allocator,
std.experimental.allocator.bitmapped_block,
std.experimental.allocator.mallocator,
std.experimental.allocator.mmap_allocator,
std.experimental.allocator.null_allocator,
std.experimental.allocator.region,
std.experimental.allocator.segregator,
std.experimental.allocator.stats_collector,
std.experimental.allocator.typed;
// Example in the synopsis above
unittest
{
import std.experimental.allocator.building_blocks.free_list : FreeList;
import std.experimental.allocator.gc_allocator : GCAllocator;
import std.experimental.allocator.building_blocks.segregator : Segregator;
import std.experimental.allocator.building_blocks.bucketizer : Bucketizer;
import std.experimental.allocator.building_blocks.allocator_list
: AllocatorList;
import std.experimental.allocator.building_blocks.bitmapped_block
: BitmappedBlock;
alias FList = FreeList!(GCAllocator, 0, unbounded);
alias A = Segregator!(
8, FreeList!(GCAllocator, 0, 8),
@ -231,7 +228,7 @@ in turn uses the garbage collected heap.
unittest
{
// Install a new allocator that is faster for 128-byte allocations.
import std.experimental.allocator.free_list : FreeList;
import std.experimental.allocator.building_blocks.free_list : FreeList;
import std.experimental.allocator.gc_allocator : GCAllocator;
auto oldAllocator = theAllocator;
scope(exit) theAllocator = oldAllocator;
@ -1049,7 +1046,7 @@ unittest
assert(a.deallocate(b));
// The in-situ region must be used by pointer
import std.experimental.allocator.region : InSituRegion;
import std.experimental.allocator.building_blocks.region : InSituRegion;
auto r = InSituRegion!1024();
a = allocatorObject(&r);
b = a.allocate(200);

View file

@ -7,9 +7,9 @@ facilities, or import individual heap building blocks and assemble them.
*/
module std.experimental.allocator.showcase;
import std.experimental.allocator.fallback_allocator,
import std.experimental.allocator.building_blocks.fallback_allocator,
std.experimental.allocator.gc_allocator,
std.experimental.allocator.region;
std.experimental.allocator.building_blocks.region;
import std.traits : hasMember;
/**
@ -62,8 +62,10 @@ auto mmapRegionList(size_t bytesPerRegion)
{
size_t bytesPerRegion;
private import std.algorithm : max;
private import std.experimental.allocator.region : Region;
private import std.experimental.allocator.mmap_allocator : MmapAllocator;
private import std.experimental.allocator.building_blocks.region
: Region;
private import std.experimental.allocator.mmap_allocator
: MmapAllocator;
this(size_t n)
{
bytesPerRegion = n;
@ -73,8 +75,10 @@ auto mmapRegionList(size_t bytesPerRegion)
return Region!MmapAllocator(max(n, bytesPerRegion));
}
}
import std.experimental.allocator.allocator_list : AllocatorList;
import std.experimental.allocator.null_allocator : NullAllocator;
import std.experimental.allocator.building_blocks.allocator_list
: AllocatorList;
import std.experimental.allocator.building_blocks.null_allocator
: NullAllocator;
auto shop = Factory(bytesPerRegion);
return AllocatorList!(Factory, NullAllocator)(shop);
}