Skip to content

Commit

Permalink
Merge pull request #4307 from JackStouffer/allocator
Browse files Browse the repository at this point in the history
Move Ternary from std.experimental.allocator.common to std.typecons
  • Loading branch information
andralex committed May 24, 2016
2 parents 8f24656 + b7165c0 commit b940264
Show file tree
Hide file tree
Showing 15 changed files with 206 additions and 157 deletions.
2 changes: 2 additions & 0 deletions changelog.dd
Expand Up @@ -45,6 +45,8 @@ $(BUGSTITLE Library Changes,
$(XREF conv, to) instead.)
$(LI $(RELATIVE_LINK2 min-max-element,
`std.algorithm.searching.{min,max}Element` for ranges have been added.))
$(LI $(XREF Ternary, std,typecons) was added to represent three valued
logic.)
)

$(BUGSTITLE Library Changes,
Expand Down
Expand Up @@ -20,6 +20,7 @@ struct AffixAllocator(Allocator, Prefix, Suffix = void)
{
import std.conv, std.experimental.allocator.common, std.traits;
import std.algorithm : min;
import std.typecons : Ternary;

static assert(
!stateSize!Prefix || Allocator.alignment >= Prefix.alignof,
Expand Down
2 changes: 2 additions & 0 deletions std/experimental/allocator/building_blocks/allocator_list.d
Expand Up @@ -65,6 +65,7 @@ struct AllocatorList(Factory, BookkeepingAllocator = GCAllocator)
import std.traits : hasMember;
import std.conv : emplace;
import std.algorithm : min, move;
import std.typecons : Ternary;
import std.experimental.allocator.building_blocks.stats_collector
: StatsCollector, Options;

Expand Down Expand Up @@ -608,6 +609,7 @@ unittest
{
import std.algorithm : max;
import std.experimental.allocator.building_blocks.region : Region;
import std.typecons : Ternary;
AllocatorList!((n) => Region!()(new void[max(n, 1024 * 4096)])) a;
auto b1 = a.allocate(1024 * 8192);
assert(b1 !is null);
Expand Down
2 changes: 2 additions & 0 deletions std/experimental/allocator/building_blocks/bitmapped_block.d
Expand Up @@ -48,6 +48,7 @@ struct BitmappedBlock(size_t theBlockSize, uint theAlignment = platformAlignment
import std.traits : hasMember;
version(unittest) import std.stdio;
import std.conv : text;
import std.typecons : Ternary;

unittest
{
Expand Down Expand Up @@ -861,6 +862,7 @@ struct BitmappedBlockWithInternalPointers(
ParentAllocator = NullAllocator)
{
import std.conv : text;
import std.typecons : Ternary;
unittest
{
import std.experimental.allocator.mallocator : AlignedMallocator;
Expand Down
7 changes: 4 additions & 3 deletions std/experimental/allocator/building_blocks/bucketizer.d
Expand Up @@ -18,8 +18,8 @@ struct Bucketizer(Allocator, size_t min, size_t max, size_t step)
{
import std.traits : hasMember;
import common = std.experimental.allocator.common : roundUpToMultipleOf,
reallocate,
Ternary;
reallocate;
import std.typecons : Ternary;

static assert((max - (min - 1)) % step == 0,
"Invalid limits when instantiating " ~ Bucketizer.stringof);
Expand Down Expand Up @@ -227,7 +227,8 @@ unittest
import std.experimental.allocator.building_blocks.free_list : FreeList;
import std.experimental.allocator.building_blocks.region : Region;
import std.experimental.allocator.mallocator : Mallocator;
import std.experimental.allocator.common : unbounded, Ternary;
import std.experimental.allocator.common : unbounded;
import std.typecons : Ternary;
import std.algorithm : max;
Bucketizer!(
FreeList!(
Expand Down
Expand Up @@ -21,6 +21,7 @@ struct FallbackAllocator(Primary, Fallback)
{
import std.algorithm.comparison : min;
import std.traits : hasMember;
import std.typecons : Ternary;

unittest
{
Expand Down Expand Up @@ -262,6 +263,7 @@ unittest
import std.experimental.allocator.building_blocks.region : InSituRegion;
import std.experimental.allocator.gc_allocator : GCAllocator;
import std.conv : text;
import std.typecons : Ternary;
FallbackAllocator!(InSituRegion!16_384, GCAllocator) a;
// This allocation uses the stack
auto b1 = a.allocate(1024);
Expand Down Expand Up @@ -347,6 +349,7 @@ unittest
{
import std.experimental.allocator.building_blocks.region : Region;
import std.experimental.allocator.gc_allocator : GCAllocator;
import std.typecons : Ternary;
auto a = fallbackAllocator(Region!GCAllocator(1024), GCAllocator.instance);
auto b1 = a.allocate(1020);
assert(b1.length == 1020);
Expand Down
4 changes: 4 additions & 0 deletions std/experimental/allocator/building_blocks/free_list.d
Expand Up @@ -30,6 +30,7 @@ struct FreeList(ParentAllocator,
import std.conv : text;
import std.exception : enforce;
import std.traits : hasMember;
import std.typecons : Ternary;

static assert(minSize != unbounded, "Use minSize = 0 for no low bound.");
static assert(maxSize >= (void*).sizeof,
Expand Down Expand Up @@ -426,6 +427,7 @@ struct ContiguousFreeList(ParentAllocator,
import std.experimental.allocator.building_blocks.stats_collector
: StatsCollector, Options;
import std.traits : hasMember;
import std.typecons : Ternary;

alias Impl = FreeList!(NullAllocator, minSize, maxSize);
enum unchecked = minSize == 0 && maxSize == unbounded;
Expand Down Expand Up @@ -680,6 +682,7 @@ unittest
{
import std.experimental.allocator.building_blocks.null_allocator
: NullAllocator;
import std.typecons : Ternary;
alias A = ContiguousFreeList!(NullAllocator, 0, 64);
auto a = A(new void[1024]);

Expand All @@ -704,6 +707,7 @@ unittest
{
import std.experimental.allocator.building_blocks.region : Region;
import std.experimental.allocator.gc_allocator : GCAllocator;
import std.typecons : Ternary;
alias A = ContiguousFreeList!(Region!GCAllocator, 0, 64);
auto a = A(Region!GCAllocator(1024 * 4), 1024);

Expand Down
11 changes: 6 additions & 5 deletions std/experimental/allocator/building_blocks/kernighan_ritchie.d
Expand Up @@ -94,8 +94,9 @@ information is available in client code at deallocation time.)
*/
struct KRRegion(ParentAllocator = NullAllocator)
{
import std.experimental.allocator.common : stateSize, alignedAt, Ternary;
import std.experimental.allocator.common : stateSize, alignedAt;
import std.traits : hasMember;
import std.typecons : Ternary;

private static struct Node
{
Expand Down Expand Up @@ -597,7 +598,7 @@ unittest
import std.experimental.allocator.gc_allocator : GCAllocator;
import std.experimental.allocator.building_blocks.fallback_allocator
: fallbackAllocator;
import std.experimental.allocator.common : Ternary;
import std.typecons : Ternary;
// KRRegion fronting a general-purpose allocator
ubyte[1024 * 128] buf;
auto alloc = fallbackAllocator(KRRegion!()(buf), GCAllocator.instance);
Expand Down Expand Up @@ -630,7 +631,7 @@ unittest
{
import std.algorithm : max;
import std.experimental.allocator.gc_allocator : GCAllocator;
import std.experimental.allocator.common : Ternary;
import std.typecons : Ternary;
import std.experimental.allocator.mallocator : Mallocator;
import std.experimental.allocator.building_blocks.allocator_list
: AllocatorList;
Expand Down Expand Up @@ -663,7 +664,7 @@ unittest
{
import std.algorithm : max;
import std.experimental.allocator.gc_allocator : GCAllocator;
import std.experimental.allocator.common : Ternary;
import std.typecons : Ternary;
import std.experimental.allocator.mmap_allocator : MmapAllocator;
import std.experimental.allocator.building_blocks.allocator_list
: AllocatorList;
Expand Down Expand Up @@ -729,7 +730,7 @@ unittest
unittest
{
import std.experimental.allocator.gc_allocator : GCAllocator;
import std.experimental.allocator.common : Ternary;
import std.typecons : Ternary;
auto alloc = KRRegion!()(GCAllocator.instance.allocate(1024 * 1024));
const store = alloc.allocate(KRRegion!().sizeof);
auto p = cast(KRRegion!()* ) store.ptr;
Expand Down
4 changes: 2 additions & 2 deletions std/experimental/allocator/building_blocks/null_allocator.d
Expand Up @@ -7,7 +7,7 @@ composite allocators.
*/
struct NullAllocator
{
import std.experimental.allocator.common : Ternary;
import std.typecons : Ternary;
/**
$(D NullAllocator) advertises a relatively large _alignment equal to 64 KB.
This is because $(D NullAllocator) never actually needs to honor this
Expand Down Expand Up @@ -68,6 +68,6 @@ unittest
assert(b is null);
NullAllocator.instance.deallocate(b);
NullAllocator.instance.deallocateAll();
import std.experimental.allocator.common : Ternary;
import std.typecons : Ternary;
assert(NullAllocator.instance.owns(null) == Ternary.no);
}
4 changes: 4 additions & 0 deletions std/experimental/allocator/building_blocks/region.d
Expand Up @@ -33,6 +33,7 @@ struct Region(ParentAllocator = NullAllocator,
static assert(ParentAllocator.alignment >= minAlign);

import std.traits : hasMember;
import std.typecons : Ternary;

// state
/**
Expand Down Expand Up @@ -379,6 +380,7 @@ struct InSituRegion(size_t size, size_t minAlign = platformAlignment)
import std.algorithm : max;
import std.conv : to;
import std.traits : hasMember;
import std.typecons : Ternary;

static assert(minAlign.isGoodStaticAlignment);
static assert(size >= minAlign);
Expand Down Expand Up @@ -594,6 +596,7 @@ version(Posix) struct SbrkRegion(uint minAlign = platformAlignment)
pthread_mutex_t, pthread_mutex_lock, pthread_mutex_unlock,
PTHREAD_MUTEX_INITIALIZER;
private static shared pthread_mutex_t sbrkMutex = PTHREAD_MUTEX_INITIALIZER;
import std.typecons : Ternary;

// workaround for https://issues.dlang.org/show_bug.cgi?id=14617
version(OSX)
Expand Down Expand Up @@ -780,6 +783,7 @@ version(Posix) unittest

version(Posix) unittest
{
import std.typecons : Ternary;
alias alloc = SbrkRegion!(8).instance;
auto a = alloc.alignedAllocate(2001, 4096);
assert(a.length == 2001);
Expand Down
2 changes: 2 additions & 0 deletions std/experimental/allocator/building_blocks/scoped_allocator.d
Expand Up @@ -24,6 +24,7 @@ struct ScopedAllocator(ParentAllocator)
private import std.experimental.allocator.building_blocks.affix_allocator
: AffixAllocator;
private import std.traits : hasMember;
import std.typecons : Ternary;

private struct Node
{
Expand Down Expand Up @@ -189,6 +190,7 @@ struct ScopedAllocator(ParentAllocator)
unittest
{
import std.experimental.allocator.mallocator : Mallocator;
import std.typecons : Ternary;
ScopedAllocator!Mallocator alloc;
assert(alloc.empty == Ternary.yes);
const b = alloc.allocate(10);
Expand Down
1 change: 1 addition & 0 deletions std/experimental/allocator/building_blocks/segregator.d
Expand Up @@ -15,6 +15,7 @@ struct Segregator(size_t threshold, SmallAllocator, LargeAllocator)
{
import std.algorithm : min;
import std.traits : hasMember;
import std.typecons : Ternary;

static if (stateSize!SmallAllocator) private SmallAllocator _small;
else private alias _small = SmallAllocator.instance;
Expand Down
Expand Up @@ -159,6 +159,7 @@ struct StatsCollector(Allocator, ulong flags = Options.all,
{
private:
import std.traits : hasMember, Signed;
import std.typecons : Ternary;

static string define(string type, string[] names...)
{
Expand Down

0 comments on commit b940264

Please sign in to comment.