diff --git a/middle/tanya/memory/allocator.d b/middle/tanya/memory/allocator.d index bde97d2..064ab37 100644 --- a/middle/tanya/memory/allocator.d +++ b/middle/tanya/memory/allocator.d @@ -101,7 +101,11 @@ mixin template DefaultAllocator() * Precondition: $(D_INLINECODE allocator_ !is null) */ this(shared Allocator allocator) @nogc nothrow pure @safe - in (allocator !is null) + in + { + assert(allocator !is null); + } + do { this.allocator_ = allocator; } @@ -115,7 +119,11 @@ mixin template DefaultAllocator() * Postcondition: $(D_INLINECODE allocator !is null) */ @property shared(Allocator) allocator() @nogc nothrow pure @safe - out (allocator; allocator !is null) + out (allocator) + { + assert(allocator !is null); + } + do { if (allocator_ is null) { @@ -126,7 +134,11 @@ mixin template DefaultAllocator() /// ditto @property shared(Allocator) allocator() const @nogc nothrow pure @trusted - out (allocator; allocator !is null) + out (allocator) + { + assert(allocator !is null); + } + do { if (allocator_ is null) { @@ -162,7 +174,11 @@ private shared(Allocator) getAllocatorInstance() @nogc nothrow * Postcondition: $(D_INLINECODE allocator !is null). */ @property shared(Allocator) defaultAllocator() @nogc nothrow pure @trusted -out (allocator; allocator !is null) +out (allocator) +{ + assert(allocator !is null); +} +do { return (cast(GetPureInstance!Allocator) &getAllocatorInstance)(); } @@ -176,7 +192,11 @@ out (allocator; allocator !is null) * Precondition: $(D_INLINECODE allocator !is null). */ @property void defaultAllocator(shared(Allocator) allocator) @nogc nothrow @safe -in (allocator !is null) +in +{ + assert(allocator !is null); +} +do { .allocator = allocator; } @@ -258,7 +278,11 @@ void dispose(T)(shared Allocator allocator, auto ref T p) */ T make(T, A...)(shared Allocator allocator, auto ref A args) if (is(T == class)) -in (allocator !is null) +in +{ + assert(allocator !is null); +} +do { auto mem = (() @trusted => allocator.allocate(stateSize!T))(); if (mem is null) @@ -290,7 +314,11 @@ in (allocator !is null) */ T* make(T, A...)(shared Allocator allocator, auto ref A args) if (!isPolymorphicType!T && !isAssociativeArray!T && !isArray!T) -in (allocator !is null) +in +{ + assert(allocator !is null); +} +do { auto mem = (() @trusted => allocator.allocate(stateSize!T))(); if (mem is null) @@ -327,8 +355,12 @@ in (allocator !is null) * && n <= size_t.max / E.sizeof) */ T make(T : E[], E)(shared Allocator allocator, size_t n) -in (allocator !is null) -in (n <= size_t.max / E.sizeof) +in +{ + assert(allocator !is null); + assert(n <= size_t.max / E.sizeof); +} +do { auto ret = allocator.resize!E(null, n); diff --git a/middle/tanya/memory/lifetime.d b/middle/tanya/memory/lifetime.d index d5a028f..8a8cfe9 100644 --- a/middle/tanya/memory/lifetime.d +++ b/middle/tanya/memory/lifetime.d @@ -61,8 +61,15 @@ package(tanya) void destroyAllImpl(R, E)(R p) */ T emplace(T, U, Args...)(void[] memory, U outer, auto ref Args args) if (!isAbstractClass!T && isInnerClass!T && is(typeof(T.outer) == U)) -in (memory.length >= stateSize!T) -out (result; memory.ptr is (() @trusted => cast(void*) result)()) +in +{ + assert(memory.length >= stateSize!T); +} +out (result) +{ + assert(memory.ptr is (() @trusted => cast(void*) result)()); +} +do { import tanya.memory.op : copy; @@ -82,8 +89,15 @@ out (result; memory.ptr is (() @trusted => cast(void*) result)()) /// ditto T emplace(T, Args...)(void[] memory, auto ref Args args) if (is(T == class) && !isAbstractClass!T && !isInnerClass!T) -in (memory.length == stateSize!T) -out (result; memory.ptr is (() @trusted => cast(void*) result)()) +in +{ + assert(memory.length == stateSize!T); +} +out (result) +{ + assert(memory.ptr is (() @trusted => cast(void*) result)()); +} +do { import tanya.memory.op : copy; @@ -128,8 +142,15 @@ out (result; memory.ptr is (() @trusted => cast(void*) result)()) /// ditto T* emplace(T, Args...)(void[] memory, auto ref Args args) if (!isAggregateType!T && (Args.length <= 1)) -in (memory.length >= T.sizeof) -out (result; memory.ptr is result) +in +{ + assert(memory.length >= T.sizeof); +} +out (result) +{ + assert(memory.ptr is result); +} +do { auto result = (() @trusted => cast(T*) memory.ptr)(); static if (Args.length == 1) @@ -166,8 +187,15 @@ private void initializeOne(T)(ref void[] memory, ref T* result) @trusted /// ditto T* emplace(T, Args...)(void[] memory, auto ref Args args) if (!isPolymorphicType!T && isAggregateType!T) -in (memory.length >= T.sizeof) -out (result; memory.ptr is result) +in +{ + assert(memory.length >= T.sizeof); +} +out (result) +{ + assert(memory.ptr is result); +} +do { auto result = (() @trusted => cast(T*) memory.ptr)(); @@ -291,7 +319,11 @@ private void deinitialize(bool zero, T)(ref T value) * Precondition: `&source !is &target`. */ void moveEmplace(T)(ref T source, ref T target) @system -in (&source !is &target, "Source and target must be different") +in +{ + assert(&source !is &target, "Source and target must be different"); +} +do { static if (is(T == struct) || isStaticArray!T) { diff --git a/middle/tanya/memory/op.d b/middle/tanya/memory/op.d index fdbff38..a41149b 100644 --- a/middle/tanya/memory/op.d +++ b/middle/tanya/memory/op.d @@ -36,9 +36,13 @@ private enum alignMask = size_t.sizeof - 1; * Precondition: $(D_INLINECODE source.length <= target.length). */ void copy(const void[] source, void[] target) @nogc nothrow pure @trusted -in (source.length <= target.length) -in (source.length == 0 || source.ptr !is null) -in (target.length == 0 || target.ptr !is null) +in +{ + assert(source.length <= target.length); + assert(source.length == 0 || source.ptr !is null); + assert(target.length == 0 || target.ptr !is null); +} +do { memcpy(target.ptr, source.ptr, source.length); } @@ -75,7 +79,11 @@ private template filledBytes(ubyte Byte, ubyte I = 0) * memory = Memory block. */ void fill(ubyte c = 0)(void[] memory) @trusted -in (memory.length == 0 || memory.ptr !is null) +in +{ + assert(memory.length == 0 || memory.ptr !is null); +} +do { memset(memory.ptr, c, memory.length); } @@ -114,9 +122,13 @@ in (memory.length == 0 || memory.ptr !is null) * Precondition: $(D_INLINECODE source.length <= target.length). */ void copyBackward(const void[] source, void[] target) @nogc nothrow pure @trusted -in (source.length <= target.length) -in (source.length == 0 || source.ptr !is null) -in (target.length == 0 || target.ptr !is null) +in +{ + assert(source.length <= target.length); + assert(source.length == 0 || source.ptr !is null); + assert(target.length == 0 || target.ptr !is null); +} +do { memmove(target.ptr, source.ptr, source.length); } @@ -145,7 +157,11 @@ in (target.length == 0 || target.ptr !is null) */ inout(void[]) find(return inout void[] haystack, ubyte needle) @nogc nothrow pure @trusted -in (haystack.length == 0 || haystack.ptr !is null) +in +{ + assert(haystack.length == 0 || haystack.ptr !is null); +} +do { auto length = haystack.length; const size_t needleWord = size_t.max * needle; @@ -223,7 +239,11 @@ in (haystack.length == 0 || haystack.ptr !is null) */ inout(char[]) findNullTerminated(return inout char[] haystack) @nogc nothrow pure @trusted -in (haystack.length == 0 || haystack.ptr !is null) +in +{ + assert(haystack.length == 0 || haystack.ptr !is null); +} +do { auto length = haystack.length; enum size_t highBits = filledBytes!(0x01, 0); @@ -290,8 +310,12 @@ in (haystack.length == 0 || haystack.ptr !is null) * $(D_KEYWORD false) otherwise. */ bool equal(const void[] r1, const void[] r2) @nogc nothrow pure @trusted -in (r1.length == 0 || r1.ptr !is null) -in (r2.length == 0 || r2.ptr !is null) +in +{ + assert(r1.length == 0 || r1.ptr !is null); + assert(r2.length == 0 || r2.ptr !is null); +} +do { return r1.length == r2.length && memcmp(r1.ptr, r2.ptr, r1.length) == 0; } diff --git a/middle/tanya/memory/smartref.d b/middle/tanya/memory/smartref.d index 7c14d4b..b6ec374 100644 --- a/middle/tanya/memory/smartref.d +++ b/middle/tanya/memory/smartref.d @@ -46,7 +46,11 @@ private final class RefCountedStore(T) size_t opUnary(string op)() if (op == "--" || op == "++") - in (this.counter > 0) + in + { + assert(this.counter > 0); + } + do { mixin("return " ~ op ~ "counter;"); } @@ -127,7 +131,11 @@ struct RefCounted(T) /// ditto this(shared Allocator allocator) - in (allocator !is null) + in + { + assert(allocator !is null); + } + do { this.allocator_ = allocator; } @@ -231,7 +239,11 @@ struct RefCounted(T) * Precondition: $(D_INLINECODE cound > 0). */ inout(Payload!T) get() inout - in (count > 0, "Attempted to access an uninitialized reference") + in + { + assert(count > 0, "Attempted to access an uninitialized reference"); + } + do { return this.storage.payload; } @@ -321,7 +333,11 @@ struct RefCounted(T) RefCounted!T refCounted(T, A...)(shared Allocator allocator, auto ref A args) if (!is(T == interface) && !isAbstractClass!T && !isAssociativeArray!T && !isArray!T) -in (allocator !is null) +in +{ + assert(allocator !is null); +} +do { auto rc = typeof(return)(allocator); @@ -361,8 +377,12 @@ in (allocator !is null) */ RefCounted!T refCounted(T : E[], E)(shared Allocator allocator, size_t size) @trusted -in (allocator !is null) -in (size <= size_t.max / E.sizeof) +in +{ + assert(allocator !is null); + assert(size <= size_t.max / E.sizeof); +} +do { return RefCounted!T(allocator.make!T(size), allocator); } @@ -423,7 +443,11 @@ struct Unique(T) /// ditto this(shared Allocator allocator) - in (allocator !is null) + in + { + assert(allocator !is null); + } + do { this.allocator_ = allocator; } @@ -604,7 +628,11 @@ struct Unique(T) Unique!T unique(T, A...)(shared Allocator allocator, auto ref A args) if (!is(T == interface) && !isAbstractClass!T && !isAssociativeArray!T && !isArray!T) -in (allocator !is null) +in +{ + assert(allocator !is null); +} +do { auto payload = allocator.make!(T, A)(args); return Unique!T(payload, allocator); @@ -627,8 +655,12 @@ in (allocator !is null) */ Unique!T unique(T : E[], E)(shared Allocator allocator, size_t size) @trusted -in (allocator !is null) -in (size <= size_t.max / E.sizeof) +in +{ + assert(allocator !is null); + assert(size <= size_t.max / E.sizeof); +} +do { auto payload = allocator.resize!E(null, size); return Unique!T(payload, allocator); diff --git a/source/tanya/math/random.d b/source/tanya/math/random.d index ae199f6..6ee4300 100644 --- a/source/tanya/math/random.d +++ b/source/tanya/math/random.d @@ -91,11 +91,7 @@ abstract class EntropySource * Postcondition: Returned length is less than or equal to * $(D_PARAM output) length. */ - Nullable!ubyte poll(out ubyte[maxGather] output) @nogc - out (length) - { - assert(length.isNull || length.get <= maxGather); - } + Nullable!ubyte poll(out ubyte[maxGather] output) @nogc; } version (CRuntime_Bionic) @@ -156,6 +152,11 @@ version (linux) * or nothing on error. */ override Nullable!ubyte poll(out ubyte[maxGather] output) @nogc nothrow + out (length) + { + assert(length.isNull || length.get <= maxGather); + } + do { // int getrandom(void *buf, size_t buflen, unsigned int flags); import mir.linux._asm.unistd : NR_getrandom; @@ -208,6 +209,11 @@ else version (SecureARC4Random) */ override Nullable!ubyte poll(out ubyte[maxGather] output) @nogc nothrow @safe + out (length) + { + assert(length.isNull || length.get <= maxGather); + } + do { (() @trusted => arc4random_buf(output.ptr, output.length))(); return Nullable!ubyte(cast(ubyte) (output.length)); @@ -316,6 +322,11 @@ else version (Windows) */ override Nullable!ubyte poll(out ubyte[maxGather] output) @nogc nothrow @safe + out (length) + { + assert(length.isNull || length.get <= maxGather); + } + do { Nullable!ubyte ret; diff --git a/source/tanya/range/array.d b/source/tanya/range/array.d index 6104a91..bd47fb9 100644 --- a/source/tanya/range/array.d +++ b/source/tanya/range/array.d @@ -133,7 +133,7 @@ do * * Precondition: $(D_INLINECODE array.length > 0). */ -void popFront(T)(scope ref inout(T)[] array) +void popFront(T)(ref inout(T)[] array) in { assert(array.length > 0); @@ -144,7 +144,7 @@ do } /// ditto -void popBack(T)(scope ref inout(T)[] array) +void popBack(T)(ref inout(T)[] array) in { assert(array.length > 0); diff --git a/source/tanya/typecons.d b/source/tanya/typecons.d index d1402cf..5e570f6 100644 --- a/source/tanya/typecons.d +++ b/source/tanya/typecons.d @@ -396,7 +396,7 @@ if (isTypeTuple!Specs && NoDuplicates!Specs.length == Specs.length) * Returns: $(D_KEYWORD true) if this $(D_PSYMBOL Variant) is equal to * $(D_PARAM that), $(D_KEYWORD false) otherwise. */ - bool opEquals()(auto ref inout Variant that) inout + bool opEquals()(auto ref inout(Variant) that) inout { if (this.tag != that.tag) { diff --git a/test/tanya/test/stub.d b/test/tanya/test/stub.d index 07f65c1..99630e6 100644 --- a/test/tanya/test/stub.d +++ b/test/tanya/test/stub.d @@ -146,7 +146,11 @@ mixin template InputRangeStub(E = int) } void popFront() @nogc nothrow pure @safe - in (!empty) + in + { + assert(!empty); + } + do { static if (!infinite) { @@ -157,7 +161,11 @@ mixin template InputRangeStub(E = int) static if (withLvalueElements) { ref E front() @nogc nothrow pure @safe - in (!empty) + in + { + assert(!empty); + } + do { return *this.element; } @@ -165,7 +173,11 @@ mixin template InputRangeStub(E = int) else { E front() @nogc nothrow pure @safe - in (!empty) + in + { + assert(!empty); + } + do { return E.init; } @@ -216,7 +228,11 @@ mixin template BidirectionalRangeStub(E = int) mixin ForwardRangeStub!E; void popBack() @nogc nothrow pure @safe - in (!empty) + in + { + assert(!empty); + } + do { static if (!infinite) { @@ -227,7 +243,11 @@ mixin template BidirectionalRangeStub(E = int) static if (withLvalueElements) { ref E back() @nogc nothrow pure @safe - in (!empty) + in + { + assert(!empty); + } + do { return *this.element; } @@ -235,7 +255,11 @@ mixin template BidirectionalRangeStub(E = int) else { E back() @nogc nothrow pure @safe - in (!empty) + in + { + assert(!empty); + } + do { return E.init; } diff --git a/tests/tanya/algorithm/tests/mutation.d b/tests/tanya/algorithm/tests/mutation.d index 19ab636..4403dd7 100644 --- a/tests/tanya/algorithm/tests/mutation.d +++ b/tests/tanya/algorithm/tests/mutation.d @@ -39,7 +39,11 @@ import tanya.test.stub; int value; void opCall(int value) @nogc nothrow pure @safe - in (this.value == 0) + in + { + assert(this.value == 0); + } + do { this.value = value; } diff --git a/tests/tanya/range/tests/adapter.d b/tests/tanya/range/tests/adapter.d index 4ebffab..cdd90a1 100644 --- a/tests/tanya/range/tests/adapter.d +++ b/tests/tanya/range/tests/adapter.d @@ -12,18 +12,6 @@ private struct Container } } -// Broken test because of the issue #20006. -@nogc nothrow pure @safe unittest -{ - auto func()() - { - Container container; - return backInserter(container); - } - // static assert(!is(typeof(func!()))); - static assert(is(typeof(func!()))); -} - @nogc nothrow pure @safe unittest { Container container;