Allow building with GDC 10.3

This commit is contained in:
Eugen Wissner 2021-05-26 10:29:03 +02:00
parent 938a1bb5b4
commit 4f48544297
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
10 changed files with 213 additions and 66 deletions

View File

@ -101,7 +101,11 @@ mixin template DefaultAllocator()
* Precondition: $(D_INLINECODE allocator_ !is null) * Precondition: $(D_INLINECODE allocator_ !is null)
*/ */
this(shared Allocator allocator) @nogc nothrow pure @safe this(shared Allocator allocator) @nogc nothrow pure @safe
in (allocator !is null) in
{
assert(allocator !is null);
}
do
{ {
this.allocator_ = allocator; this.allocator_ = allocator;
} }
@ -115,7 +119,11 @@ mixin template DefaultAllocator()
* Postcondition: $(D_INLINECODE allocator !is null) * Postcondition: $(D_INLINECODE allocator !is null)
*/ */
@property shared(Allocator) allocator() @nogc nothrow pure @safe @property shared(Allocator) allocator() @nogc nothrow pure @safe
out (allocator; allocator !is null) out (allocator)
{
assert(allocator !is null);
}
do
{ {
if (allocator_ is null) if (allocator_ is null)
{ {
@ -126,7 +134,11 @@ mixin template DefaultAllocator()
/// ditto /// ditto
@property shared(Allocator) allocator() const @nogc nothrow pure @trusted @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) if (allocator_ is null)
{ {
@ -162,7 +174,11 @@ private shared(Allocator) getAllocatorInstance() @nogc nothrow
* Postcondition: $(D_INLINECODE allocator !is null). * Postcondition: $(D_INLINECODE allocator !is null).
*/ */
@property shared(Allocator) defaultAllocator() @nogc nothrow pure @trusted @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)(); return (cast(GetPureInstance!Allocator) &getAllocatorInstance)();
} }
@ -176,7 +192,11 @@ out (allocator; allocator !is null)
* Precondition: $(D_INLINECODE allocator !is null). * Precondition: $(D_INLINECODE allocator !is null).
*/ */
@property void defaultAllocator(shared(Allocator) allocator) @nogc nothrow @safe @property void defaultAllocator(shared(Allocator) allocator) @nogc nothrow @safe
in (allocator !is null) in
{
assert(allocator !is null);
}
do
{ {
.allocator = allocator; .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) T make(T, A...)(shared Allocator allocator, auto ref A args)
if (is(T == class)) if (is(T == class))
in (allocator !is null) in
{
assert(allocator !is null);
}
do
{ {
auto mem = (() @trusted => allocator.allocate(stateSize!T))(); auto mem = (() @trusted => allocator.allocate(stateSize!T))();
if (mem is null) if (mem is null)
@ -290,7 +314,11 @@ in (allocator !is null)
*/ */
T* make(T, A...)(shared Allocator allocator, auto ref A args) T* make(T, A...)(shared Allocator allocator, auto ref A args)
if (!isPolymorphicType!T && !isAssociativeArray!T && !isArray!T) if (!isPolymorphicType!T && !isAssociativeArray!T && !isArray!T)
in (allocator !is null) in
{
assert(allocator !is null);
}
do
{ {
auto mem = (() @trusted => allocator.allocate(stateSize!T))(); auto mem = (() @trusted => allocator.allocate(stateSize!T))();
if (mem is null) if (mem is null)
@ -327,8 +355,12 @@ in (allocator !is null)
* && n <= size_t.max / E.sizeof) * && n <= size_t.max / E.sizeof)
*/ */
T make(T : E[], E)(shared Allocator allocator, size_t n) T make(T : E[], E)(shared Allocator allocator, size_t n)
in (allocator !is null) in
in (n <= size_t.max / E.sizeof) {
assert(allocator !is null);
assert(n <= size_t.max / E.sizeof);
}
do
{ {
auto ret = allocator.resize!E(null, n); auto ret = allocator.resize!E(null, n);

View File

@ -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) T emplace(T, U, Args...)(void[] memory, U outer, auto ref Args args)
if (!isAbstractClass!T && isInnerClass!T && is(typeof(T.outer) == U)) if (!isAbstractClass!T && isInnerClass!T && is(typeof(T.outer) == U))
in (memory.length >= stateSize!T) in
out (result; memory.ptr is (() @trusted => cast(void*) result)()) {
assert(memory.length >= stateSize!T);
}
out (result)
{
assert(memory.ptr is (() @trusted => cast(void*) result)());
}
do
{ {
import tanya.memory.op : copy; import tanya.memory.op : copy;
@ -82,8 +89,15 @@ out (result; memory.ptr is (() @trusted => cast(void*) result)())
/// ditto /// ditto
T emplace(T, Args...)(void[] memory, auto ref Args args) T emplace(T, Args...)(void[] memory, auto ref Args args)
if (is(T == class) && !isAbstractClass!T && !isInnerClass!T) if (is(T == class) && !isAbstractClass!T && !isInnerClass!T)
in (memory.length == stateSize!T) in
out (result; memory.ptr is (() @trusted => cast(void*) result)()) {
assert(memory.length == stateSize!T);
}
out (result)
{
assert(memory.ptr is (() @trusted => cast(void*) result)());
}
do
{ {
import tanya.memory.op : copy; import tanya.memory.op : copy;
@ -128,8 +142,15 @@ out (result; memory.ptr is (() @trusted => cast(void*) result)())
/// ditto /// ditto
T* emplace(T, Args...)(void[] memory, auto ref Args args) T* emplace(T, Args...)(void[] memory, auto ref Args args)
if (!isAggregateType!T && (Args.length <= 1)) if (!isAggregateType!T && (Args.length <= 1))
in (memory.length >= T.sizeof) in
out (result; memory.ptr is result) {
assert(memory.length >= T.sizeof);
}
out (result)
{
assert(memory.ptr is result);
}
do
{ {
auto result = (() @trusted => cast(T*) memory.ptr)(); auto result = (() @trusted => cast(T*) memory.ptr)();
static if (Args.length == 1) static if (Args.length == 1)
@ -166,8 +187,15 @@ private void initializeOne(T)(ref void[] memory, ref T* result) @trusted
/// ditto /// ditto
T* emplace(T, Args...)(void[] memory, auto ref Args args) T* emplace(T, Args...)(void[] memory, auto ref Args args)
if (!isPolymorphicType!T && isAggregateType!T) if (!isPolymorphicType!T && isAggregateType!T)
in (memory.length >= T.sizeof) in
out (result; memory.ptr is result) {
assert(memory.length >= T.sizeof);
}
out (result)
{
assert(memory.ptr is result);
}
do
{ {
auto result = (() @trusted => cast(T*) memory.ptr)(); auto result = (() @trusted => cast(T*) memory.ptr)();
@ -291,7 +319,11 @@ private void deinitialize(bool zero, T)(ref T value)
* Precondition: `&source !is &target`. * Precondition: `&source !is &target`.
*/ */
void moveEmplace(T)(ref T source, ref T target) @system 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) static if (is(T == struct) || isStaticArray!T)
{ {

View File

@ -36,9 +36,13 @@ private enum alignMask = size_t.sizeof - 1;
* Precondition: $(D_INLINECODE source.length <= target.length). * Precondition: $(D_INLINECODE source.length <= target.length).
*/ */
void copy(const void[] source, void[] target) @nogc nothrow pure @trusted void copy(const void[] source, void[] target) @nogc nothrow pure @trusted
in (source.length <= target.length) in
in (source.length == 0 || source.ptr !is null) {
in (target.length == 0 || target.ptr !is null) 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); memcpy(target.ptr, source.ptr, source.length);
} }
@ -75,7 +79,11 @@ private template filledBytes(ubyte Byte, ubyte I = 0)
* memory = Memory block. * memory = Memory block.
*/ */
void fill(ubyte c = 0)(void[] memory) @trusted 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); 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). * Precondition: $(D_INLINECODE source.length <= target.length).
*/ */
void copyBackward(const void[] source, void[] target) @nogc nothrow pure @trusted void copyBackward(const void[] source, void[] target) @nogc nothrow pure @trusted
in (source.length <= target.length) in
in (source.length == 0 || source.ptr !is null) {
in (target.length == 0 || target.ptr !is null) 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); 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) inout(void[]) find(return inout void[] haystack, ubyte needle)
@nogc nothrow pure @trusted @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; auto length = haystack.length;
const size_t needleWord = size_t.max * needle; 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) inout(char[]) findNullTerminated(return inout char[] haystack)
@nogc nothrow pure @trusted @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; auto length = haystack.length;
enum size_t highBits = filledBytes!(0x01, 0); enum size_t highBits = filledBytes!(0x01, 0);
@ -290,8 +310,12 @@ in (haystack.length == 0 || haystack.ptr !is null)
* $(D_KEYWORD false) otherwise. * $(D_KEYWORD false) otherwise.
*/ */
bool equal(const void[] r1, const void[] r2) @nogc nothrow pure @trusted bool equal(const void[] r1, const void[] r2) @nogc nothrow pure @trusted
in (r1.length == 0 || r1.ptr !is null) in
in (r2.length == 0 || r2.ptr !is null) {
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; return r1.length == r2.length && memcmp(r1.ptr, r2.ptr, r1.length) == 0;
} }

View File

@ -46,7 +46,11 @@ private final class RefCountedStore(T)
size_t opUnary(string op)() size_t opUnary(string op)()
if (op == "--" || op == "++") if (op == "--" || op == "++")
in (this.counter > 0) in
{
assert(this.counter > 0);
}
do
{ {
mixin("return " ~ op ~ "counter;"); mixin("return " ~ op ~ "counter;");
} }
@ -127,7 +131,11 @@ struct RefCounted(T)
/// ditto /// ditto
this(shared Allocator allocator) this(shared Allocator allocator)
in (allocator !is null) in
{
assert(allocator !is null);
}
do
{ {
this.allocator_ = allocator; this.allocator_ = allocator;
} }
@ -231,7 +239,11 @@ struct RefCounted(T)
* Precondition: $(D_INLINECODE cound > 0). * Precondition: $(D_INLINECODE cound > 0).
*/ */
inout(Payload!T) get() inout 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; return this.storage.payload;
} }
@ -321,7 +333,11 @@ struct RefCounted(T)
RefCounted!T refCounted(T, A...)(shared Allocator allocator, auto ref A args) RefCounted!T refCounted(T, A...)(shared Allocator allocator, auto ref A args)
if (!is(T == interface) && !isAbstractClass!T if (!is(T == interface) && !isAbstractClass!T
&& !isAssociativeArray!T && !isArray!T) && !isAssociativeArray!T && !isArray!T)
in (allocator !is null) in
{
assert(allocator !is null);
}
do
{ {
auto rc = typeof(return)(allocator); 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) RefCounted!T refCounted(T : E[], E)(shared Allocator allocator, size_t size)
@trusted @trusted
in (allocator !is null) in
in (size <= size_t.max / E.sizeof) {
assert(allocator !is null);
assert(size <= size_t.max / E.sizeof);
}
do
{ {
return RefCounted!T(allocator.make!T(size), allocator); return RefCounted!T(allocator.make!T(size), allocator);
} }
@ -423,7 +443,11 @@ struct Unique(T)
/// ditto /// ditto
this(shared Allocator allocator) this(shared Allocator allocator)
in (allocator !is null) in
{
assert(allocator !is null);
}
do
{ {
this.allocator_ = allocator; this.allocator_ = allocator;
} }
@ -604,7 +628,11 @@ struct Unique(T)
Unique!T unique(T, A...)(shared Allocator allocator, auto ref A args) Unique!T unique(T, A...)(shared Allocator allocator, auto ref A args)
if (!is(T == interface) && !isAbstractClass!T if (!is(T == interface) && !isAbstractClass!T
&& !isAssociativeArray!T && !isArray!T) && !isAssociativeArray!T && !isArray!T)
in (allocator !is null) in
{
assert(allocator !is null);
}
do
{ {
auto payload = allocator.make!(T, A)(args); auto payload = allocator.make!(T, A)(args);
return Unique!T(payload, allocator); 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) Unique!T unique(T : E[], E)(shared Allocator allocator, size_t size)
@trusted @trusted
in (allocator !is null) in
in (size <= size_t.max / E.sizeof) {
assert(allocator !is null);
assert(size <= size_t.max / E.sizeof);
}
do
{ {
auto payload = allocator.resize!E(null, size); auto payload = allocator.resize!E(null, size);
return Unique!T(payload, allocator); return Unique!T(payload, allocator);

View File

@ -91,11 +91,7 @@ abstract class EntropySource
* Postcondition: Returned length is less than or equal to * Postcondition: Returned length is less than or equal to
* $(D_PARAM output) length. * $(D_PARAM output) length.
*/ */
Nullable!ubyte poll(out ubyte[maxGather] output) @nogc Nullable!ubyte poll(out ubyte[maxGather] output) @nogc;
out (length)
{
assert(length.isNull || length.get <= maxGather);
}
} }
version (CRuntime_Bionic) version (CRuntime_Bionic)
@ -156,6 +152,11 @@ version (linux)
* or nothing on error. * or nothing on error.
*/ */
override Nullable!ubyte poll(out ubyte[maxGather] output) @nogc nothrow 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); // int getrandom(void *buf, size_t buflen, unsigned int flags);
import mir.linux._asm.unistd : NR_getrandom; import mir.linux._asm.unistd : NR_getrandom;
@ -208,6 +209,11 @@ else version (SecureARC4Random)
*/ */
override Nullable!ubyte poll(out ubyte[maxGather] output) override Nullable!ubyte poll(out ubyte[maxGather] output)
@nogc nothrow @safe @nogc nothrow @safe
out (length)
{
assert(length.isNull || length.get <= maxGather);
}
do
{ {
(() @trusted => arc4random_buf(output.ptr, output.length))(); (() @trusted => arc4random_buf(output.ptr, output.length))();
return Nullable!ubyte(cast(ubyte) (output.length)); return Nullable!ubyte(cast(ubyte) (output.length));
@ -316,6 +322,11 @@ else version (Windows)
*/ */
override Nullable!ubyte poll(out ubyte[maxGather] output) override Nullable!ubyte poll(out ubyte[maxGather] output)
@nogc nothrow @safe @nogc nothrow @safe
out (length)
{
assert(length.isNull || length.get <= maxGather);
}
do
{ {
Nullable!ubyte ret; Nullable!ubyte ret;

View File

@ -133,7 +133,7 @@ do
* *
* Precondition: $(D_INLINECODE array.length > 0). * Precondition: $(D_INLINECODE array.length > 0).
*/ */
void popFront(T)(scope ref inout(T)[] array) void popFront(T)(ref inout(T)[] array)
in in
{ {
assert(array.length > 0); assert(array.length > 0);
@ -144,7 +144,7 @@ do
} }
/// ditto /// ditto
void popBack(T)(scope ref inout(T)[] array) void popBack(T)(ref inout(T)[] array)
in in
{ {
assert(array.length > 0); assert(array.length > 0);

View File

@ -396,7 +396,7 @@ if (isTypeTuple!Specs && NoDuplicates!Specs.length == Specs.length)
* Returns: $(D_KEYWORD true) if this $(D_PSYMBOL Variant) is equal to * Returns: $(D_KEYWORD true) if this $(D_PSYMBOL Variant) is equal to
* $(D_PARAM that), $(D_KEYWORD false) otherwise. * $(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) if (this.tag != that.tag)
{ {

View File

@ -146,7 +146,11 @@ mixin template InputRangeStub(E = int)
} }
void popFront() @nogc nothrow pure @safe void popFront() @nogc nothrow pure @safe
in (!empty) in
{
assert(!empty);
}
do
{ {
static if (!infinite) static if (!infinite)
{ {
@ -157,7 +161,11 @@ mixin template InputRangeStub(E = int)
static if (withLvalueElements) static if (withLvalueElements)
{ {
ref E front() @nogc nothrow pure @safe ref E front() @nogc nothrow pure @safe
in (!empty) in
{
assert(!empty);
}
do
{ {
return *this.element; return *this.element;
} }
@ -165,7 +173,11 @@ mixin template InputRangeStub(E = int)
else else
{ {
E front() @nogc nothrow pure @safe E front() @nogc nothrow pure @safe
in (!empty) in
{
assert(!empty);
}
do
{ {
return E.init; return E.init;
} }
@ -216,7 +228,11 @@ mixin template BidirectionalRangeStub(E = int)
mixin ForwardRangeStub!E; mixin ForwardRangeStub!E;
void popBack() @nogc nothrow pure @safe void popBack() @nogc nothrow pure @safe
in (!empty) in
{
assert(!empty);
}
do
{ {
static if (!infinite) static if (!infinite)
{ {
@ -227,7 +243,11 @@ mixin template BidirectionalRangeStub(E = int)
static if (withLvalueElements) static if (withLvalueElements)
{ {
ref E back() @nogc nothrow pure @safe ref E back() @nogc nothrow pure @safe
in (!empty) in
{
assert(!empty);
}
do
{ {
return *this.element; return *this.element;
} }
@ -235,7 +255,11 @@ mixin template BidirectionalRangeStub(E = int)
else else
{ {
E back() @nogc nothrow pure @safe E back() @nogc nothrow pure @safe
in (!empty) in
{
assert(!empty);
}
do
{ {
return E.init; return E.init;
} }

View File

@ -39,7 +39,11 @@ import tanya.test.stub;
int value; int value;
void opCall(int value) @nogc nothrow pure @safe void opCall(int value) @nogc nothrow pure @safe
in (this.value == 0) in
{
assert(this.value == 0);
}
do
{ {
this.value = value; this.value = value;
} }

View File

@ -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 @nogc nothrow pure @safe unittest
{ {
Container container; Container container;