From 0aaf1ea00f577b5257013e7ed66eebd6bf3ed7c4 Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Sat, 5 Sep 2020 17:16:03 -0400 Subject: [PATCH 01/18] Simplified TypeInfo, take 2: factor common code in --- mak/SRCS | 38 --- src/core/internal/array/operations.d | 1 - src/rt/typeinfo/ti_Acdouble.d | 47 --- src/rt/typeinfo/ti_Acfloat.d | 47 --- src/rt/typeinfo/ti_Acreal.d | 47 --- src/rt/typeinfo/ti_Adouble.d | 61 ---- src/rt/typeinfo/ti_Afloat.d | 61 ---- src/rt/typeinfo/ti_Ag.d | 154 ---------- src/rt/typeinfo/ti_Aint.d | 151 --------- src/rt/typeinfo/ti_Along.d | 103 ------- src/rt/typeinfo/ti_Areal.d | 61 ---- src/rt/typeinfo/ti_Ashort.d | 113 ------- src/rt/typeinfo/ti_C.d | 75 ----- src/rt/typeinfo/ti_byte.d | 62 ---- src/rt/typeinfo/ti_cdouble.d | 77 ----- src/rt/typeinfo/ti_cent.d | 74 ----- src/rt/typeinfo/ti_cfloat.d | 76 ----- src/rt/typeinfo/ti_char.d | 64 ---- src/rt/typeinfo/ti_creal.d | 77 ----- src/rt/typeinfo/ti_dchar.d | 64 ---- src/rt/typeinfo/ti_delegate.d | 65 ---- src/rt/typeinfo/ti_double.d | 72 ----- src/rt/typeinfo/ti_float.d | 67 ---- src/rt/typeinfo/ti_idouble.d | 27 -- src/rt/typeinfo/ti_ifloat.d | 27 -- src/rt/typeinfo/ti_int.d | 66 ---- src/rt/typeinfo/ti_ireal.d | 27 -- src/rt/typeinfo/ti_long.d | 75 ----- src/rt/typeinfo/ti_n.d | 61 ---- src/rt/typeinfo/ti_ptr.d | 67 ---- src/rt/typeinfo/ti_real.d | 75 ----- src/rt/typeinfo/ti_short.d | 62 ---- src/rt/typeinfo/ti_ubyte.d | 72 ----- src/rt/typeinfo/ti_ucent.d | 73 ----- src/rt/typeinfo/ti_uint.d | 66 ---- src/rt/typeinfo/ti_ulong.d | 75 ----- src/rt/typeinfo/ti_ushort.d | 62 ---- src/rt/typeinfo/ti_void.d | 65 ---- src/rt/typeinfo/ti_wchar.d | 64 ---- src/rt/util/typeinfo.d | 442 +++++++++++++++++++++++++++ 40 files changed, 442 insertions(+), 2621 deletions(-) delete mode 100644 src/rt/typeinfo/ti_Acdouble.d delete mode 100644 src/rt/typeinfo/ti_Acfloat.d delete mode 100644 src/rt/typeinfo/ti_Acreal.d delete mode 100644 src/rt/typeinfo/ti_Adouble.d delete mode 100644 src/rt/typeinfo/ti_Afloat.d delete mode 100644 src/rt/typeinfo/ti_Ag.d delete mode 100644 src/rt/typeinfo/ti_Aint.d delete mode 100644 src/rt/typeinfo/ti_Along.d delete mode 100644 src/rt/typeinfo/ti_Areal.d delete mode 100644 src/rt/typeinfo/ti_Ashort.d delete mode 100644 src/rt/typeinfo/ti_C.d delete mode 100644 src/rt/typeinfo/ti_byte.d delete mode 100644 src/rt/typeinfo/ti_cdouble.d delete mode 100644 src/rt/typeinfo/ti_cent.d delete mode 100644 src/rt/typeinfo/ti_cfloat.d delete mode 100644 src/rt/typeinfo/ti_char.d delete mode 100644 src/rt/typeinfo/ti_creal.d delete mode 100644 src/rt/typeinfo/ti_dchar.d delete mode 100644 src/rt/typeinfo/ti_delegate.d delete mode 100644 src/rt/typeinfo/ti_double.d delete mode 100644 src/rt/typeinfo/ti_float.d delete mode 100644 src/rt/typeinfo/ti_idouble.d delete mode 100644 src/rt/typeinfo/ti_ifloat.d delete mode 100644 src/rt/typeinfo/ti_int.d delete mode 100644 src/rt/typeinfo/ti_ireal.d delete mode 100644 src/rt/typeinfo/ti_long.d delete mode 100644 src/rt/typeinfo/ti_n.d delete mode 100644 src/rt/typeinfo/ti_ptr.d delete mode 100644 src/rt/typeinfo/ti_real.d delete mode 100644 src/rt/typeinfo/ti_short.d delete mode 100644 src/rt/typeinfo/ti_ubyte.d delete mode 100644 src/rt/typeinfo/ti_ucent.d delete mode 100644 src/rt/typeinfo/ti_uint.d delete mode 100644 src/rt/typeinfo/ti_ulong.d delete mode 100644 src/rt/typeinfo/ti_ushort.d delete mode 100644 src/rt/typeinfo/ti_void.d delete mode 100644 src/rt/typeinfo/ti_wchar.d diff --git a/mak/SRCS b/mak/SRCS index e69ed6f82e..0dac688712 100644 --- a/mak/SRCS +++ b/mak/SRCS @@ -544,42 +544,4 @@ SRCS=\ src\rt\util\container\hashtab.d \ src\rt\util\container\treap.d \ \ - src\rt\typeinfo\ti_Acdouble.d \ - src\rt\typeinfo\ti_Acfloat.d \ - src\rt\typeinfo\ti_Acreal.d \ - src\rt\typeinfo\ti_Adouble.d \ - src\rt\typeinfo\ti_Afloat.d \ - src\rt\typeinfo\ti_Ag.d \ - src\rt\typeinfo\ti_Aint.d \ - src\rt\typeinfo\ti_Along.d \ - src\rt\typeinfo\ti_Areal.d \ - src\rt\typeinfo\ti_Ashort.d \ - src\rt\typeinfo\ti_byte.d \ - src\rt\typeinfo\ti_C.d \ - src\rt\typeinfo\ti_cdouble.d \ - src\rt\typeinfo\ti_cent.d \ - src\rt\typeinfo\ti_cfloat.d \ - src\rt\typeinfo\ti_char.d \ - src\rt\typeinfo\ti_creal.d \ - src\rt\typeinfo\ti_dchar.d \ - src\rt\typeinfo\ti_delegate.d \ - src\rt\typeinfo\ti_double.d \ - src\rt\typeinfo\ti_float.d \ - src\rt\typeinfo\ti_idouble.d \ - src\rt\typeinfo\ti_ifloat.d \ - src\rt\typeinfo\ti_int.d \ - src\rt\typeinfo\ti_ireal.d \ - src\rt\typeinfo\ti_long.d \ - src\rt\typeinfo\ti_n.d \ - src\rt\typeinfo\ti_ptr.d \ - src\rt\typeinfo\ti_real.d \ - src\rt\typeinfo\ti_short.d \ - src\rt\typeinfo\ti_ubyte.d \ - src\rt\typeinfo\ti_ucent.d \ - src\rt\typeinfo\ti_uint.d \ - src\rt\typeinfo\ti_ulong.d \ - src\rt\typeinfo\ti_ushort.d \ - src\rt\typeinfo\ti_void.d \ - src\rt\typeinfo\ti_wchar.d \ - \ src\etc\linux\memoryerror.d diff --git a/src/core/internal/array/operations.d b/src/core/internal/array/operations.d index 240d1807d8..0e38d2cefa 100644 --- a/src/core/internal/array/operations.d +++ b/src/core/internal/array/operations.d @@ -228,7 +228,6 @@ else version (X86_64) unittest { - pragma(msg, vectorizeable!(double[], const(double)[], double[], "+", "=")); static assert(vectorizeable!(double[], const(double)[], double[], "+", "=")); static assert(!vectorizeable!(double[], const(ulong)[], double[], "+", "=")); // Vector type are (atm.) not implicitly convertible and would require diff --git a/src/rt/typeinfo/ti_Acdouble.d b/src/rt/typeinfo/ti_Acdouble.d deleted file mode 100644 index 50debaca25..0000000000 --- a/src/rt/typeinfo/ti_Acdouble.d +++ /dev/null @@ -1,47 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_Acdouble; - -private import rt.util.typeinfo; - -// cdouble[] - -class TypeInfo_Ar : TypeInfo_Array -{ - alias F = cdouble; - - override bool opEquals(Object o) { return TypeInfo.opEquals(o); } - - override string toString() const { return (F[]).stringof; } - - override size_t getHash(scope const void* p) @trusted const - { - return Array!F.hashOf(*cast(F[]*)p); - } - - override bool equals(in void* p1, in void* p2) const - { - return Array!F.equals(*cast(F[]*)p1, *cast(F[]*)p2); - } - - override int compare(in void* p1, in void* p2) const - { - return Array!F.compare(*cast(F[]*)p1, *cast(F[]*)p2); - } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(F); - } -} diff --git a/src/rt/typeinfo/ti_Acfloat.d b/src/rt/typeinfo/ti_Acfloat.d deleted file mode 100644 index dadec10df7..0000000000 --- a/src/rt/typeinfo/ti_Acfloat.d +++ /dev/null @@ -1,47 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_Acfloat; - -private import rt.util.typeinfo; - -// cfloat[] - -class TypeInfo_Aq : TypeInfo_Array -{ - alias F = cfloat; - - override bool opEquals(Object o) { return TypeInfo.opEquals(o); } - - override string toString() const { return (F[]).stringof; } - - override size_t getHash(scope const void* p) @trusted const - { - return Array!F.hashOf(*cast(F[]*)p); - } - - override bool equals(in void* p1, in void* p2) const - { - return Array!F.equals(*cast(F[]*)p1, *cast(F[]*)p2); - } - - override int compare(in void* p1, in void* p2) const - { - return Array!F.compare(*cast(F[]*)p1, *cast(F[]*)p2); - } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(F); - } -} diff --git a/src/rt/typeinfo/ti_Acreal.d b/src/rt/typeinfo/ti_Acreal.d deleted file mode 100644 index 650b89b4ed..0000000000 --- a/src/rt/typeinfo/ti_Acreal.d +++ /dev/null @@ -1,47 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_Acreal; - -private import rt.util.typeinfo; - -// creal[] - -class TypeInfo_Ac : TypeInfo_Array -{ - alias F = creal; - - override bool opEquals(Object o) { return TypeInfo.opEquals(o); } - - override string toString() const { return (F[]).stringof; } - - override size_t getHash(scope const void* p) @trusted const - { - return Array!F.hashOf(*cast(F[]*)p); - } - - override bool equals(in void* p1, in void* p2) const - { - return Array!F.equals(*cast(F[]*)p1, *cast(F[]*)p2); - } - - override int compare(in void* p1, in void* p2) const - { - return Array!F.compare(*cast(F[]*)p1, *cast(F[]*)p2); - } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(F); - } -} diff --git a/src/rt/typeinfo/ti_Adouble.d b/src/rt/typeinfo/ti_Adouble.d deleted file mode 100644 index 9712f8a822..0000000000 --- a/src/rt/typeinfo/ti_Adouble.d +++ /dev/null @@ -1,61 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_Adouble; - -private import rt.util.typeinfo; - -// double[] - -class TypeInfo_Ad : TypeInfo_Array -{ - alias F = double; - - override bool opEquals(Object o) { return TypeInfo.opEquals(o); } - - override string toString() const { return (F[]).stringof; } - - override size_t getHash(scope const void* p) @trusted const - { - return Array!F.hashOf(*cast(F[]*)p); - } - - override bool equals(in void* p1, in void* p2) const - { - return Array!F.equals(*cast(F[]*)p1, *cast(F[]*)p2); - } - - override int compare(in void* p1, in void* p2) const - { - return Array!F.compare(*cast(F[]*)p1, *cast(F[]*)p2); - } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(F); - } -} - -// idouble[] - -class TypeInfo_Ap : TypeInfo_Ad -{ - alias F = idouble; - - override string toString() const { return (F[]).stringof; } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(F); - } -} diff --git a/src/rt/typeinfo/ti_Afloat.d b/src/rt/typeinfo/ti_Afloat.d deleted file mode 100644 index 9a95abd3b5..0000000000 --- a/src/rt/typeinfo/ti_Afloat.d +++ /dev/null @@ -1,61 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_Afloat; - -private import rt.util.typeinfo; - -// float[] - -class TypeInfo_Af : TypeInfo_Array -{ - alias F = float; - - override bool opEquals(Object o) { return TypeInfo.opEquals(o); } - - override string toString() const { return (F[]).stringof; } - - override size_t getHash(scope const void* p) @trusted const - { - return Array!F.hashOf(*cast(F[]*)p); - } - - override bool equals(in void* p1, in void* p2) const - { - return Array!F.equals(*cast(F[]*)p1, *cast(F[]*)p2); - } - - override int compare(in void* p1, in void* p2) const - { - return Array!F.compare(*cast(F[]*)p1, *cast(F[]*)p2); - } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(F); - } -} - -// ifloat[] - -class TypeInfo_Ao : TypeInfo_Af -{ - alias F = ifloat; - - override string toString() const { return (F[]).stringof; } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(F); - } -} diff --git a/src/rt/typeinfo/ti_Ag.d b/src/rt/typeinfo/ti_Ag.d deleted file mode 100644 index bdb0553698..0000000000 --- a/src/rt/typeinfo/ti_Ag.d +++ /dev/null @@ -1,154 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_Ag; - -private import core.stdc.string; -private import core.internal.string; - -// byte[] - -class TypeInfo_Ag : TypeInfo_Array -{ - override bool opEquals(Object o) { return TypeInfo.opEquals(o); } - - override string toString() const { return "byte[]"; } - - override size_t getHash(scope const void* p) @trusted const - { - const s = *cast(const void[]*)p; - return hashOf(s); - } - - override bool equals(in void* p1, in void* p2) const - { - byte[] s1 = *cast(byte[]*)p1; - byte[] s2 = *cast(byte[]*)p2; - - return s1.length == s2.length && - memcmp(cast(byte *)s1, cast(byte *)s2, s1.length) == 0; - } - - override int compare(in void* p1, in void* p2) const - { - byte[] s1 = *cast(byte[]*)p1; - byte[] s2 = *cast(byte[]*)p2; - size_t len = s1.length; - - if (s2.length < len) - len = s2.length; - for (size_t u = 0; u < len; u++) - { - int result = s1[u] - s2[u]; - if (result) - return result; - } - if (s1.length < s2.length) - return -1; - else if (s1.length > s2.length) - return 1; - return 0; - } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(byte); - } -} - - -// ubyte[] - -class TypeInfo_Ah : TypeInfo_Ag -{ - override string toString() const { return "ubyte[]"; } - - override int compare(in void* p1, in void* p2) const - { - char[] s1 = *cast(char[]*)p1; - char[] s2 = *cast(char[]*)p2; - - return dstrcmp(s1, s2); - } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(ubyte); - } -} - -// void[] - -class TypeInfo_Av : TypeInfo_Ah -{ - override string toString() const { return "void[]"; } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(void); - } -} - -// bool[] - -class TypeInfo_Ab : TypeInfo_Ah -{ - override string toString() const { return "bool[]"; } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(bool); - } -} - -// char[] - -class TypeInfo_Aa : TypeInfo_Ah -{ - override string toString() const { return "char[]"; } - - override size_t getHash(scope const void* p) @trusted const - { - char[] s = *cast(char[]*)p; - return hashOf(s); - } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(char); - } -} - -// string - -class TypeInfo_Aya : TypeInfo_Aa -{ - override string toString() const { return "immutable(char)[]"; } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(immutable(char)); - } -} - -// const(char)[] - -class TypeInfo_Axa : TypeInfo_Aa -{ - override string toString() const { return "const(char)[]"; } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(const(char)); - } -} diff --git a/src/rt/typeinfo/ti_Aint.d b/src/rt/typeinfo/ti_Aint.d deleted file mode 100644 index ebe8d80f93..0000000000 --- a/src/rt/typeinfo/ti_Aint.d +++ /dev/null @@ -1,151 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_Aint; - -private import core.stdc.string; - -extern (C) void[] _adSort(void[] a, TypeInfo ti); - -// int[] - -class TypeInfo_Ai : TypeInfo_Array -{ - override bool opEquals(Object o) { return TypeInfo.opEquals(o); } - - override string toString() const { return "int[]"; } - - override size_t getHash(scope const void* p) @trusted const - { - // Hash as if unsigned. - const s = *cast(const uint[]*)p; - return hashOf(s); - } - - override bool equals(in void* p1, in void* p2) const - { - int[] s1 = *cast(int[]*)p1; - int[] s2 = *cast(int[]*)p2; - - return s1.length == s2.length && - memcmp(cast(void *)s1, cast(void *)s2, s1.length * int.sizeof) == 0; - } - - override int compare(in void* p1, in void* p2) const - { - int[] s1 = *cast(int[]*)p1; - int[] s2 = *cast(int[]*)p2; - size_t len = s1.length; - - if (s2.length < len) - len = s2.length; - for (size_t u = 0; u < len; u++) - { - if (s1[u] < s2[u]) - return -1; - else if (s1[u] > s2[u]) - return 1; - } - if (s1.length < s2.length) - return -1; - else if (s1.length > s2.length) - return 1; - return 0; - } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(int); - } -} - -unittest -{ - int[][] a = [[5,3,8,7], [2,5,3,8,7]]; - _adSort(*cast(void[]*)&a, typeid(a[0])); - assert(a == [[2,5,3,8,7], [5,3,8,7]]); - - a = [[5,3,8,7], [5,3,8]]; - _adSort(*cast(void[]*)&a, typeid(a[0])); - assert(a == [[5,3,8], [5,3,8,7]]); -} - -unittest -{ - // Issue 13073: original code uses int subtraction which is susceptible to - // integer overflow, causing the following case to fail. - int[] a = [int.max, int.max]; - int[] b = [int.min, int.min]; - assert(a > b); - assert(b < a); -} - -// uint[] - -class TypeInfo_Ak : TypeInfo_Ai -{ - override string toString() const { return "uint[]"; } - - override int compare(in void* p1, in void* p2) const - { - uint[] s1 = *cast(uint[]*)p1; - uint[] s2 = *cast(uint[]*)p2; - size_t len = s1.length; - - if (s2.length < len) - len = s2.length; - for (size_t u = 0; u < len; u++) - { - if (s1[u] < s2[u]) - return -1; - else if (s1[u] > s2[u]) - return 1; - } - if (s1.length < s2.length) - return -1; - else if (s1.length > s2.length) - return 1; - return 0; - } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(uint); - } -} - -unittest -{ - // Original test case from issue 13073 - uint x = 0x22_DF_FF_FF; - uint y = 0xA2_DF_FF_FF; - assert(!(x < y && y < x)); - uint[] a = [x]; - uint[] b = [y]; - assert(!(a < b && b < a)); // Original failing case - uint[1] a1 = [x]; - uint[1] b1 = [y]; - assert(!(a1 < b1 && b1 < a1)); // Original failing case -} - -// dchar[] - -class TypeInfo_Aw : TypeInfo_Ak -{ - override string toString() const { return "dchar[]"; } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(dchar); - } -} diff --git a/src/rt/typeinfo/ti_Along.d b/src/rt/typeinfo/ti_Along.d deleted file mode 100644 index b67bb995ba..0000000000 --- a/src/rt/typeinfo/ti_Along.d +++ /dev/null @@ -1,103 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_Along; - -private import core.stdc.string; - -// long[] - -class TypeInfo_Al : TypeInfo_Array -{ - override bool opEquals(Object o) { return TypeInfo.opEquals(o); } - - override string toString() const { return "long[]"; } - - override size_t getHash(scope const void* p) @trusted const - { - // Hash as if unsigned. - const s = *cast(const ulong[]*)p; - return hashOf(s); - } - - override bool equals(in void* p1, in void* p2) const - { - long[] s1 = *cast(long[]*)p1; - long[] s2 = *cast(long[]*)p2; - - return s1.length == s2.length && - memcmp(cast(void *)s1, cast(void *)s2, s1.length * long.sizeof) == 0; - } - - override int compare(in void* p1, in void* p2) const - { - long[] s1 = *cast(long[]*)p1; - long[] s2 = *cast(long[]*)p2; - size_t len = s1.length; - - if (s2.length < len) - len = s2.length; - for (size_t u = 0; u < len; u++) - { - if (s1[u] < s2[u]) - return -1; - else if (s1[u] > s2[u]) - return 1; - } - if (s1.length < s2.length) - return -1; - else if (s1.length > s2.length) - return 1; - return 0; - } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(long); - } -} - - -// ulong[] - -class TypeInfo_Am : TypeInfo_Al -{ - override string toString() const { return "ulong[]"; } - - override int compare(in void* p1, in void* p2) const - { - ulong[] s1 = *cast(ulong[]*)p1; - ulong[] s2 = *cast(ulong[]*)p2; - size_t len = s1.length; - - if (s2.length < len) - len = s2.length; - for (size_t u = 0; u < len; u++) - { - if (s1[u] < s2[u]) - return -1; - else if (s1[u] > s2[u]) - return 1; - } - if (s1.length < s2.length) - return -1; - else if (s1.length > s2.length) - return 1; - return 0; - } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(ulong); - } -} diff --git a/src/rt/typeinfo/ti_Areal.d b/src/rt/typeinfo/ti_Areal.d deleted file mode 100644 index 5280f81fe6..0000000000 --- a/src/rt/typeinfo/ti_Areal.d +++ /dev/null @@ -1,61 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_Areal; - -private import rt.util.typeinfo; - -// real[] - -class TypeInfo_Ae : TypeInfo_Array -{ - alias F = real; - - override bool opEquals(Object o) { return TypeInfo.opEquals(o); } - - override string toString() const { return (F[]).stringof; } - - override size_t getHash(scope const void* p) @trusted const - { - return Array!F.hashOf(*cast(F[]*)p); - } - - override bool equals(in void* p1, in void* p2) const - { - return Array!F.equals(*cast(F[]*)p1, *cast(F[]*)p2); - } - - override int compare(in void* p1, in void* p2) const - { - return Array!F.compare(*cast(F[]*)p1, *cast(F[]*)p2); - } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(F); - } -} - -// ireal[] - -class TypeInfo_Aj : TypeInfo_Ae -{ - alias F = ireal; - - override string toString() const { return (F[]).stringof; } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(F); - } -} diff --git a/src/rt/typeinfo/ti_Ashort.d b/src/rt/typeinfo/ti_Ashort.d deleted file mode 100644 index aea4be7704..0000000000 --- a/src/rt/typeinfo/ti_Ashort.d +++ /dev/null @@ -1,113 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_Ashort; - -private import core.stdc.string; - -// short[] - -class TypeInfo_As : TypeInfo_Array -{ - override bool opEquals(Object o) { return TypeInfo.opEquals(o); } - - override string toString() const { return "short[]"; } - - override size_t getHash(scope const void* p) @trusted const - { - // Hash as if unsigned. - const s = *cast(const ushort[]*)p; - return hashOf(s); - } - - override bool equals(in void* p1, in void* p2) const - { - short[] s1 = *cast(short[]*)p1; - short[] s2 = *cast(short[]*)p2; - - return s1.length == s2.length && - memcmp(cast(void *)s1, cast(void *)s2, s1.length * short.sizeof) == 0; - } - - override int compare(in void* p1, in void* p2) const - { - short[] s1 = *cast(short[]*)p1; - short[] s2 = *cast(short[]*)p2; - size_t len = s1.length; - - if (s2.length < len) - len = s2.length; - for (size_t u = 0; u < len; u++) - { - int result = s1[u] - s2[u]; - if (result) - return result; - } - if (s1.length < s2.length) - return -1; - else if (s1.length > s2.length) - return 1; - return 0; - } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(short); - } -} - - -// ushort[] - -class TypeInfo_At : TypeInfo_As -{ - override string toString() const { return "ushort[]"; } - - override int compare(in void* p1, in void* p2) const - { - ushort[] s1 = *cast(ushort[]*)p1; - ushort[] s2 = *cast(ushort[]*)p2; - size_t len = s1.length; - - if (s2.length < len) - len = s2.length; - for (size_t u = 0; u < len; u++) - { - int result = s1[u] - s2[u]; - if (result) - return result; - } - if (s1.length < s2.length) - return -1; - else if (s1.length > s2.length) - return 1; - return 0; - } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(ushort); - } -} - -// wchar[] - -class TypeInfo_Au : TypeInfo_At -{ - override string toString() const { return "wchar[]"; } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(wchar); - } -} diff --git a/src/rt/typeinfo/ti_C.d b/src/rt/typeinfo/ti_C.d deleted file mode 100644 index 912774cb99..0000000000 --- a/src/rt/typeinfo/ti_C.d +++ /dev/null @@ -1,75 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_C; - -// Object - -class TypeInfo_C : TypeInfo -{ - @trusted: - const: - //pure: - //nothrow: - - override size_t getHash(scope const void* p) - { - Object o = *cast(Object*)p; - return o ? o.toHash() : 0; - } - - override bool equals(in void* p1, in void* p2) - { - Object o1 = *cast(Object*)p1; - Object o2 = *cast(Object*)p2; - - return o1 == o2; - } - - override int compare(in void* p1, in void* p2) - { - Object o1 = *cast(Object*)p1; - Object o2 = *cast(Object*)p2; - int c = 0; - - // Regard null references as always being "less than" - if (!(o1 is o2)) - { - if (o1) - { - if (!o2) - c = 1; - else - c = o1.opCmp(o2); - } - else - c = -1; - } - return c; - } - - override @property size_t tsize() nothrow pure - { - return Object.sizeof; - } - - override const(void)[] initializer() const @trusted - { - return (cast(void *)null)[0 .. Object.sizeof]; - } - - override @property uint flags() nothrow pure - { - return 1; - } -} diff --git a/src/rt/typeinfo/ti_byte.d b/src/rt/typeinfo/ti_byte.d deleted file mode 100644 index 9793fef65e..0000000000 --- a/src/rt/typeinfo/ti_byte.d +++ /dev/null @@ -1,62 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_byte; - -// byte - -class TypeInfo_g : TypeInfo -{ - @trusted: - const: - pure: - nothrow: - - override string toString() const pure nothrow @safe { return "byte"; } - - override size_t getHash(scope const void* p) - { - return *cast(const byte *)p; - } - - override bool equals(in void* p1, in void* p2) - { - return *cast(byte *)p1 == *cast(byte *)p2; - } - - override int compare(in void* p1, in void* p2) - { - return *cast(byte *)p1 - *cast(byte *)p2; - } - - override @property size_t tsize() nothrow pure - { - return byte.sizeof; - } - - override const(void)[] initializer() @trusted - { - return (cast(void *)null)[0 .. byte.sizeof]; - } - - override void swap(void *p1, void *p2) - { - byte t; - - t = *cast(byte *)p1; - *cast(byte *)p1 = *cast(byte *)p2; - *cast(byte *)p2 = t; - } - - override @property immutable(void)* rtInfo() nothrow pure const @safe { return rtinfoNoPointers; } -} diff --git a/src/rt/typeinfo/ti_cdouble.d b/src/rt/typeinfo/ti_cdouble.d deleted file mode 100644 index e738f7b576..0000000000 --- a/src/rt/typeinfo/ti_cdouble.d +++ /dev/null @@ -1,77 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_cdouble; - -private import rt.util.typeinfo; - -// cdouble - -class TypeInfo_r : TypeInfo -{ - pure: - nothrow: - @safe: - - alias F = cdouble; - - override string toString() const { return F.stringof; } - - override size_t getHash(scope const void* p) const @trusted - { - return Floating!F.hashOf(*cast(F*)p); - } - - override bool equals(in void* p1, in void* p2) const @trusted - { - return Floating!F.equals(*cast(F*)p1, *cast(F*)p2); - } - - override int compare(in void* p1, in void* p2) const @trusted - { - return Floating!F.compare(*cast(F*)p1, *cast(F*)p2); - } - - override @property size_t tsize() const - { - return F.sizeof; - } - - override void swap(void *p1, void *p2) const @trusted - { - F t = *cast(F*)p1; - *cast(F*)p1 = *cast(F*)p2; - *cast(F*)p2 = t; - } - - override const(void)[] initializer() const @trusted - { - static immutable F r; - return (&r)[0 .. 1]; - } - - override @property size_t talign() const - { - return F.alignof; - } - - static if (__traits(hasMember, TypeInfo, "argTypes")) - override int argTypes(out TypeInfo arg1, out TypeInfo arg2) - { - arg1 = typeid(double); - arg2 = typeid(double); - return 0; - } - - override @property immutable(void)* rtInfo() nothrow pure const @safe { return rtinfoNoPointers; } -} diff --git a/src/rt/typeinfo/ti_cent.d b/src/rt/typeinfo/ti_cent.d deleted file mode 100644 index fb4766ef78..0000000000 --- a/src/rt/typeinfo/ti_cent.d +++ /dev/null @@ -1,74 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2015. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2015. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_cent; - -static if (is(cent)): - -// cent - -class TypeInfo_zi : TypeInfo -{ - @trusted: - const: - pure: - nothrow: - - override string toString() const pure nothrow @safe { return "cent"; } - - override size_t getHash(scope const void* p) - { - // cent & ucent hash the same if ucent.sizeof >= size_t.sizeof. - return hashOf(*cast(const ucent*) p); - } - - override bool equals(in void* p1, in void* p2) - { - return *cast(cent *)p1 == *cast(cent *)p2; - } - - override int compare(in void* p1, in void* p2) - { - if (*cast(cent *)p1 < *cast(cent *)p2) - return -1; - else if (*cast(cent *)p1 > *cast(cent *)p2) - return 1; - return 0; - } - - override @property size_t tsize() nothrow pure - { - return cent.sizeof; - } - - override const(void)[] initializer() const @trusted - { - return (cast(void *)null)[0 .. cent.sizeof]; - } - - override void swap(void *p1, void *p2) - { - cent t; - - t = *cast(cent *)p1; - *cast(cent *)p1 = *cast(cent *)p2; - *cast(cent *)p2 = t; - } - - override @property size_t talign() nothrow pure - { - return cent.alignof; - } - - override @property immutable(void)* rtInfo() nothrow pure const @safe { return rtinfoNoPointers; } -} diff --git a/src/rt/typeinfo/ti_cfloat.d b/src/rt/typeinfo/ti_cfloat.d deleted file mode 100644 index fa673715f5..0000000000 --- a/src/rt/typeinfo/ti_cfloat.d +++ /dev/null @@ -1,76 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_cfloat; - -private import rt.util.typeinfo; - -// cfloat - -class TypeInfo_q : TypeInfo -{ - pure: - nothrow: - @safe: - - alias F = cfloat; - - override string toString() const { return F.stringof; } - - override size_t getHash(scope const void* p) const @trusted - { - return Floating!F.hashOf(*cast(F*)p); - } - - override bool equals(in void* p1, in void* p2) const @trusted - { - return Floating!F.equals(*cast(F*)p1, *cast(F*)p2); - } - - override int compare(in void* p1, in void* p2) const @trusted - { - return Floating!F.compare(*cast(F*)p1, *cast(F*)p2); - } - - override @property size_t tsize() const - { - return F.sizeof; - } - - override void swap(void *p1, void *p2) const @trusted - { - F t = *cast(F*)p1; - *cast(F*)p1 = *cast(F*)p2; - *cast(F*)p2 = t; - } - - override const(void)[] initializer() const @trusted - { - static immutable F r; - return (&r)[0 .. 1]; - } - - override @property size_t talign() const - { - return F.alignof; - } - - static if (__traits(hasMember, TypeInfo, "argTypes")) - override int argTypes(out TypeInfo arg1, out TypeInfo arg2) - { - arg1 = typeid(double); - return 0; - } - - override @property immutable(void)* rtInfo() nothrow pure const @safe { return rtinfoNoPointers; } -} diff --git a/src/rt/typeinfo/ti_char.d b/src/rt/typeinfo/ti_char.d deleted file mode 100644 index 9633bb9eac..0000000000 --- a/src/rt/typeinfo/ti_char.d +++ /dev/null @@ -1,64 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_char; - -// char - -class TypeInfo_a : TypeInfo -{ - @trusted: - const: - pure: - nothrow: - - override string toString() const pure nothrow @safe { return "char"; } - - override size_t getHash(scope const void* p) - { - return *cast(const char *)p; - } - - override bool equals(in void* p1, in void* p2) - { - return *cast(char *)p1 == *cast(char *)p2; - } - - override int compare(in void* p1, in void* p2) - { - return *cast(char *)p1 - *cast(char *)p2; - } - - override @property size_t tsize() nothrow pure - { - return char.sizeof; - } - - override void swap(void *p1, void *p2) - { - char t; - - t = *cast(char *)p1; - *cast(char *)p1 = *cast(char *)p2; - *cast(char *)p2 = t; - } - - override const(void)[] initializer() const @trusted - { - static immutable char c; - - return (&c)[0 .. 1]; - } - - override @property immutable(void)* rtInfo() nothrow pure const @safe { return rtinfoNoPointers; } -} diff --git a/src/rt/typeinfo/ti_creal.d b/src/rt/typeinfo/ti_creal.d deleted file mode 100644 index e2201b17d9..0000000000 --- a/src/rt/typeinfo/ti_creal.d +++ /dev/null @@ -1,77 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_creal; - -private import rt.util.typeinfo; - -// creal - -class TypeInfo_c : TypeInfo -{ - pure: - nothrow: - @safe: - - alias F = creal; - - override string toString() const { return F.stringof; } - - override size_t getHash(scope const void* p) const @trusted - { - return Floating!F.hashOf(*cast(F*)p); - } - - override bool equals(in void* p1, in void* p2) const @trusted - { - return Floating!F.equals(*cast(F*)p1, *cast(F*)p2); - } - - override int compare(in void* p1, in void* p2) const @trusted - { - return Floating!F.compare(*cast(F*)p1, *cast(F*)p2); - } - - override @property size_t tsize() const - { - return F.sizeof; - } - - override void swap(void *p1, void *p2) const @trusted - { - F t = *cast(F*)p1; - *cast(F*)p1 = *cast(F*)p2; - *cast(F*)p2 = t; - } - - override const(void)[] initializer() const @trusted - { - static immutable F r; - return (&r)[0 .. 1]; - } - - override @property size_t talign() const - { - return F.alignof; - } - - static if (__traits(hasMember, TypeInfo, "argTypes")) - override int argTypes(out TypeInfo arg1, out TypeInfo arg2) - { - arg1 = typeid(real); - arg2 = typeid(real); - return 0; - } - - override @property immutable(void)* rtInfo() nothrow pure const @safe { return rtinfoNoPointers; } -} diff --git a/src/rt/typeinfo/ti_dchar.d b/src/rt/typeinfo/ti_dchar.d deleted file mode 100644 index 7329946199..0000000000 --- a/src/rt/typeinfo/ti_dchar.d +++ /dev/null @@ -1,64 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_dchar; - -// dchar - -class TypeInfo_w : TypeInfo -{ - @trusted: - const: - pure: - nothrow: - - override string toString() const pure nothrow @safe { return "dchar"; } - - override size_t getHash(scope const void* p) - { - return *cast(const dchar *)p; - } - - override bool equals(in void* p1, in void* p2) - { - return *cast(dchar *)p1 == *cast(dchar *)p2; - } - - override int compare(in void* p1, in void* p2) - { - return *cast(dchar *)p1 - *cast(dchar *)p2; - } - - override @property size_t tsize() nothrow pure - { - return dchar.sizeof; - } - - override void swap(void *p1, void *p2) - { - dchar t; - - t = *cast(dchar *)p1; - *cast(dchar *)p1 = *cast(dchar *)p2; - *cast(dchar *)p2 = t; - } - - override const(void)[] initializer() const @trusted - { - static immutable dchar c; - - return (&c)[0 .. 1]; - } - - override @property immutable(void)* rtInfo() nothrow pure const @safe { return rtinfoNoPointers; } -} diff --git a/src/rt/typeinfo/ti_delegate.d b/src/rt/typeinfo/ti_delegate.d deleted file mode 100644 index d712be08a9..0000000000 --- a/src/rt/typeinfo/ti_delegate.d +++ /dev/null @@ -1,65 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_delegate; - - -// delegate - -alias void delegate(int) dg; - -class TypeInfo_D : TypeInfo -{ - @trusted: - const: - pure: - nothrow: - - override size_t getHash(scope const void* p) - { - return hashOf(*cast(dg*)p); - } - - override bool equals(in void* p1, in void* p2) - { - return *cast(dg *)p1 == *cast(dg *)p2; - } - - override @property size_t tsize() nothrow pure - { - return dg.sizeof; - } - - override void swap(void *p1, void *p2) - { - dg t; - - t = *cast(dg *)p1; - *cast(dg *)p1 = *cast(dg *)p2; - *cast(dg *)p2 = t; - } - - override const(void)[] initializer() const @trusted - { - static immutable dg d; - - return (cast(void *)null)[0 .. dg.sizeof]; - } - - override @property uint flags() nothrow pure - { - return 1; - } - - override @property immutable(void)* rtInfo() nothrow pure const @safe { return RTInfo!(dg); } -} diff --git a/src/rt/typeinfo/ti_double.d b/src/rt/typeinfo/ti_double.d deleted file mode 100644 index 3aed7a09fa..0000000000 --- a/src/rt/typeinfo/ti_double.d +++ /dev/null @@ -1,72 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_double; - -private import rt.util.typeinfo; - -// double - -class TypeInfo_d : TypeInfo -{ - pure: - nothrow: - @safe: - - alias F = double; - - override string toString() const { return F.stringof; } - - override size_t getHash(scope const void* p) const @trusted - { - return Floating!F.hashOf(*cast(F*)p); - } - - override bool equals(in void* p1, in void* p2) const @trusted - { - return Floating!F.equals(*cast(F*)p1, *cast(F*)p2); - } - - override int compare(in void* p1, in void* p2) const @trusted - { - return Floating!F.compare(*cast(F*)p1, *cast(F*)p2); - } - - override @property size_t tsize() const - { - return F.sizeof; - } - - override void swap(void *p1, void *p2) const @trusted - { - F t = *cast(F*)p1; - *cast(F*)p1 = *cast(F*)p2; - *cast(F*)p2 = t; - } - - override const(void)[] initializer() const @trusted - { - static immutable F r; - return (&r)[0 .. 1]; - } - - override @property size_t talign() const - { - return F.alignof; - } - - override @property immutable(void)* rtInfo() nothrow pure const @safe { return rtinfoNoPointers; } - - // passed in SIMD register - override @property uint flags() const { return 2; } -} diff --git a/src/rt/typeinfo/ti_float.d b/src/rt/typeinfo/ti_float.d deleted file mode 100644 index 710ce1bd40..0000000000 --- a/src/rt/typeinfo/ti_float.d +++ /dev/null @@ -1,67 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_float; - -private import rt.util.typeinfo; - -// float - -class TypeInfo_f : TypeInfo -{ - pure: - nothrow: - @safe: - - alias F = float; - - override string toString() const { return F.stringof; } - - override size_t getHash(scope const void* p) const @trusted - { - return Floating!F.hashOf(*cast(F*)p); - } - - override bool equals(in void* p1, in void* p2) const @trusted - { - return Floating!F.equals(*cast(F*)p1, *cast(F*)p2); - } - - override int compare(in void* p1, in void* p2) const @trusted - { - return Floating!F.compare(*cast(F*)p1, *cast(F*)p2); - } - - override @property size_t tsize() const - { - return F.sizeof; - } - - override void swap(void *p1, void *p2) const @trusted - { - F t = *cast(F*)p1; - *cast(F*)p1 = *cast(F*)p2; - *cast(F*)p2 = t; - } - - override const(void)[] initializer() const @trusted - { - static immutable F r; - return (&r)[0 .. 1]; - } - - override @property immutable(void)* rtInfo() nothrow pure const @safe { return rtinfoNoPointers; } - - // passed in SIMD register - override @property uint flags() const { return 2; } -} diff --git a/src/rt/typeinfo/ti_idouble.d b/src/rt/typeinfo/ti_idouble.d deleted file mode 100644 index 9820cabec8..0000000000 --- a/src/rt/typeinfo/ti_idouble.d +++ /dev/null @@ -1,27 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_idouble; - -private import rt.typeinfo.ti_double; - -// idouble - -class TypeInfo_p : TypeInfo_d -{ - pure: - nothrow: - @safe: - - override string toString() const { return idouble.stringof; } -} diff --git a/src/rt/typeinfo/ti_ifloat.d b/src/rt/typeinfo/ti_ifloat.d deleted file mode 100644 index c16358522b..0000000000 --- a/src/rt/typeinfo/ti_ifloat.d +++ /dev/null @@ -1,27 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_ifloat; - -private import rt.typeinfo.ti_float; - -// ifloat - -class TypeInfo_o : TypeInfo_f -{ - pure: - nothrow: - @safe: - - override string toString() const { return ifloat.stringof; } -} diff --git a/src/rt/typeinfo/ti_int.d b/src/rt/typeinfo/ti_int.d deleted file mode 100644 index da3b5cad6f..0000000000 --- a/src/rt/typeinfo/ti_int.d +++ /dev/null @@ -1,66 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_int; - -// int - -class TypeInfo_i : TypeInfo -{ - @trusted: - const: - pure: - nothrow: - - override string toString() const pure nothrow @safe { return "int"; } - - override size_t getHash(scope const void* p) - { - return *cast(const int *)p; - } - - override bool equals(in void* p1, in void* p2) - { - return *cast(uint *)p1 == *cast(uint *)p2; - } - - override int compare(in void* p1, in void* p2) - { - if (*cast(int*) p1 < *cast(int*) p2) - return -1; - else if (*cast(int*) p1 > *cast(int*) p2) - return 1; - return 0; - } - - override @property size_t tsize() nothrow pure - { - return int.sizeof; - } - - override const(void)[] initializer() const @trusted - { - return (cast(void *)null)[0 .. int.sizeof]; - } - - override void swap(void *p1, void *p2) - { - int t; - - t = *cast(int *)p1; - *cast(int *)p1 = *cast(int *)p2; - *cast(int *)p2 = t; - } - - override @property immutable(void)* rtInfo() nothrow pure const @safe { return rtinfoNoPointers; } -} diff --git a/src/rt/typeinfo/ti_ireal.d b/src/rt/typeinfo/ti_ireal.d deleted file mode 100644 index 6d7dd18e4f..0000000000 --- a/src/rt/typeinfo/ti_ireal.d +++ /dev/null @@ -1,27 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_ireal; - -private import rt.typeinfo.ti_real; - -// ireal - -class TypeInfo_j : TypeInfo_e -{ - pure: - nothrow: - @safe: - - override string toString() const { return ireal.stringof; } -} diff --git a/src/rt/typeinfo/ti_long.d b/src/rt/typeinfo/ti_long.d deleted file mode 100644 index 336b99433b..0000000000 --- a/src/rt/typeinfo/ti_long.d +++ /dev/null @@ -1,75 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_long; - -// long - -class TypeInfo_l : TypeInfo -{ - @trusted: - const: - pure: - nothrow: - - override string toString() const pure nothrow @safe { return "long"; } - - override size_t getHash(scope const void* p) - { - static if (ulong.sizeof <= size_t.sizeof) - return *cast(const long*)p; - else - // long & ulong hash the same if ulong.sizeof > size_t.sizeof. - return hashOf(*cast(const ulong*)p); - } - - override bool equals(in void* p1, in void* p2) - { - return *cast(long *)p1 == *cast(long *)p2; - } - - override int compare(in void* p1, in void* p2) - { - if (*cast(long *)p1 < *cast(long *)p2) - return -1; - else if (*cast(long *)p1 > *cast(long *)p2) - return 1; - return 0; - } - - override @property size_t tsize() nothrow pure - { - return long.sizeof; - } - - override const(void)[] initializer() const @trusted - { - return (cast(void *)null)[0 .. long.sizeof]; - } - - override void swap(void *p1, void *p2) - { - long t; - - t = *cast(long *)p1; - *cast(long *)p1 = *cast(long *)p2; - *cast(long *)p2 = t; - } - - override @property size_t talign() nothrow pure - { - return long.alignof; - } - - override @property immutable(void)* rtInfo() nothrow pure const @safe { return rtinfoNoPointers; } -} diff --git a/src/rt/typeinfo/ti_n.d b/src/rt/typeinfo/ti_n.d deleted file mode 100644 index 3baed08350..0000000000 --- a/src/rt/typeinfo/ti_n.d +++ /dev/null @@ -1,61 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2016. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Kenji Hara - */ - -/* Copyright Digital Mars 2016. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_n; - -// typeof(null) - -class TypeInfo_n : TypeInfo -{ - override string toString() const @safe { return "typeof(null)"; } - - override size_t getHash(scope const void* p) const - { - return 0; - } - - override bool equals(in void* p1, in void* p2) const @trusted - { - //return *cast(typeof(null)*)p1 is *cast(typeof(null)*)p2; - return true; - } - - override int compare(in void* p1, in void* p2) const @trusted - { - //if (*cast(int*) p1 < *cast(int*) p2) - // return -1; - //else if (*cast(int*) p1 > *cast(int*) p2) - // return 1; - return 0; - } - - override @property size_t tsize() const - { - return typeof(null).sizeof; - } - - override const(void)[] initializer() const @trusted - { - __gshared immutable void[typeof(null).sizeof] init; - return init[]; - } - - override void swap(void *p1, void *p2) const @trusted - { - //auto t = *cast(typeof(null)*)p1; - //*cast(typeof(null)*)p1 = *cast(typeof(null)*)p2; - //*cast(typeof(null)*)p2 = t; - } - - override @property immutable(void)* rtInfo() nothrow pure const @safe { return rtinfoNoPointers; } -} diff --git a/src/rt/typeinfo/ti_ptr.d b/src/rt/typeinfo/ti_ptr.d deleted file mode 100644 index c27d907dc5..0000000000 --- a/src/rt/typeinfo/ti_ptr.d +++ /dev/null @@ -1,67 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_ptr; - -// internal typeinfo for any pointer type -// please keep in sync with TypeInfo_Pointer - -class TypeInfo_P : TypeInfo -{ - @trusted: - const: - pure: - nothrow: - - override size_t getHash(scope const void* p) - { - size_t addr = cast(size_t) *cast(const void**)p; - return addr ^ (addr >> 4); - } - - override bool equals(in void* p1, in void* p2) - { - return *cast(void**)p1 == *cast(void**)p2; - } - - override int compare(in void* p1, in void* p2) - { - if (*cast(void**)p1 < *cast(void**)p2) - return -1; - else if (*cast(void**)p1 > *cast(void**)p2) - return 1; - else - return 0; - } - - override @property size_t tsize() nothrow pure - { - return (void*).sizeof; - } - - override const(void)[] initializer() const @trusted - { - return (cast(void *)null)[0 .. (void*).sizeof]; - } - - override void swap(void *p1, void *p2) - { - void* tmp = *cast(void**)p1; - *cast(void**)p1 = *cast(void**)p2; - *cast(void**)p2 = tmp; - } - - override @property uint flags() nothrow pure const { return 1; } - - override @property immutable(void)* rtInfo() nothrow pure const @safe { return rtinfoHasPointers; } -} diff --git a/src/rt/typeinfo/ti_real.d b/src/rt/typeinfo/ti_real.d deleted file mode 100644 index dfd944fbc8..0000000000 --- a/src/rt/typeinfo/ti_real.d +++ /dev/null @@ -1,75 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_real; - -private import rt.util.typeinfo; - -// real - -class TypeInfo_e : TypeInfo -{ - pure: - nothrow: - @safe: - - alias F = real; - - override string toString() const { return F.stringof; } - - override size_t getHash(scope const void* p) const @trusted - { - return Floating!F.hashOf(*cast(F*)p); - } - - override bool equals(in void* p1, in void* p2) const @trusted - { - return Floating!F.equals(*cast(F*)p1, *cast(F*)p2); - } - - override int compare(in void* p1, in void* p2) const @trusted - { - return Floating!F.compare(*cast(F*)p1, *cast(F*)p2); - } - - override @property size_t tsize() const - { - return F.sizeof; - } - - override void swap(void *p1, void *p2) const @trusted - { - F t = *cast(F*)p1; - *cast(F*)p1 = *cast(F*)p2; - *cast(F*)p2 = t; - } - - override const(void)[] initializer() const @trusted - { - static immutable F r; - return (&r)[0 .. 1]; - } - - override @property size_t talign() const - { - return F.alignof; - } - - override @property immutable(void)* rtInfo() nothrow pure const @safe { return rtinfoNoPointers; } - - static if (real.mant_dig != 64) // exclude 80-bit X87 - { - // passed in SIMD register - override @property uint flags() const { return 2; } - } -} diff --git a/src/rt/typeinfo/ti_short.d b/src/rt/typeinfo/ti_short.d deleted file mode 100644 index ebafe9a1df..0000000000 --- a/src/rt/typeinfo/ti_short.d +++ /dev/null @@ -1,62 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_short; - -// short - -class TypeInfo_s : TypeInfo -{ - @trusted: - const: - pure: - nothrow: - - override string toString() const pure nothrow @safe { return "short"; } - - override size_t getHash(scope const void* p) - { - return *cast(const short *)p; - } - - override bool equals(in void* p1, in void* p2) - { - return *cast(short *)p1 == *cast(short *)p2; - } - - override int compare(in void* p1, in void* p2) - { - return *cast(short *)p1 - *cast(short *)p2; - } - - override @property size_t tsize() nothrow pure - { - return short.sizeof; - } - - override const(void)[] initializer() const @trusted - { - return (cast(void *)null)[0 .. short.sizeof]; - } - - override void swap(void *p1, void *p2) - { - short t; - - t = *cast(short *)p1; - *cast(short *)p1 = *cast(short *)p2; - *cast(short *)p2 = t; - } - - override @property immutable(void)* rtInfo() nothrow pure const @safe { return rtinfoNoPointers; } -} diff --git a/src/rt/typeinfo/ti_ubyte.d b/src/rt/typeinfo/ti_ubyte.d deleted file mode 100644 index 860592fdf8..0000000000 --- a/src/rt/typeinfo/ti_ubyte.d +++ /dev/null @@ -1,72 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_ubyte; - -// ubyte - -class TypeInfo_h : TypeInfo -{ - @trusted: - const: - pure: - nothrow: - - override string toString() const pure nothrow @safe { return "ubyte"; } - - override size_t getHash(scope const void* p) - { - return *cast(const ubyte *)p; - } - - override bool equals(in void* p1, in void* p2) - { - return *cast(ubyte *)p1 == *cast(ubyte *)p2; - } - - override int compare(in void* p1, in void* p2) - { - return *cast(ubyte *)p1 - *cast(ubyte *)p2; - } - - override @property size_t tsize() nothrow pure - { - return ubyte.sizeof; - } - - override const(void)[] initializer() const @trusted - { - return (cast(void *)null)[0 .. ubyte.sizeof]; - } - - override void swap(void *p1, void *p2) - { - ubyte t; - - t = *cast(ubyte *)p1; - *cast(ubyte *)p1 = *cast(ubyte *)p2; - *cast(ubyte *)p2 = t; - } - - override @property immutable(void)* rtInfo() nothrow pure const @safe { return rtinfoNoPointers; } -} - -class TypeInfo_b : TypeInfo_h -{ - @trusted: - const: - pure: - nothrow: - - override string toString() const pure nothrow @safe { return "bool"; } -} diff --git a/src/rt/typeinfo/ti_ucent.d b/src/rt/typeinfo/ti_ucent.d deleted file mode 100644 index 52fa8280b3..0000000000 --- a/src/rt/typeinfo/ti_ucent.d +++ /dev/null @@ -1,73 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2015. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2015. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_ucent; - -static if (is(ucent)): - -// ucent - -class TypeInfo_zk : TypeInfo -{ - @trusted: - const: - pure: - nothrow: - - override string toString() const pure nothrow @safe { return "ucent"; } - - override size_t getHash(scope const void* p) - { - return hashOf(*cast(const ucent*) p); - } - - override bool equals(in void* p1, in void* p2) - { - return *cast(ucent *)p1 == *cast(ucent *)p2; - } - - override int compare(in void* p1, in void* p2) - { - if (*cast(ucent *)p1 < *cast(ucent *)p2) - return -1; - else if (*cast(ucent *)p1 > *cast(ucent *)p2) - return 1; - return 0; - } - - override @property size_t tsize() nothrow pure - { - return ucent.sizeof; - } - - override const(void)[] initializer() const @trusted - { - return (cast(void *)null)[0 .. ucent.sizeof]; - } - - override void swap(void *p1, void *p2) - { - ucent t; - - t = *cast(ucent *)p1; - *cast(ucent *)p1 = *cast(ucent *)p2; - *cast(ucent *)p2 = t; - } - - override @property size_t talign() nothrow pure - { - return ucent.alignof; - } - - override @property immutable(void)* rtInfo() nothrow pure const @safe { return rtinfoNoPointers; } -} diff --git a/src/rt/typeinfo/ti_uint.d b/src/rt/typeinfo/ti_uint.d deleted file mode 100644 index 3ae043277d..0000000000 --- a/src/rt/typeinfo/ti_uint.d +++ /dev/null @@ -1,66 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_uint; - -// uint - -class TypeInfo_k : TypeInfo -{ - @trusted: - const: - pure: - nothrow: - - override string toString() const pure nothrow @safe { return "uint"; } - - override size_t getHash(scope const void* p) - { - return *cast(const uint *)p; - } - - override bool equals(in void* p1, in void* p2) - { - return *cast(uint *)p1 == *cast(uint *)p2; - } - - override int compare(in void* p1, in void* p2) - { - if (*cast(uint*) p1 < *cast(uint*) p2) - return -1; - else if (*cast(uint*) p1 > *cast(uint*) p2) - return 1; - return 0; - } - - override @property size_t tsize() nothrow pure - { - return uint.sizeof; - } - - override const(void)[] initializer() const @trusted - { - return (cast(void *)null)[0 .. uint.sizeof]; - } - - override void swap(void *p1, void *p2) - { - int t; - - t = *cast(uint *)p1; - *cast(uint *)p1 = *cast(uint *)p2; - *cast(uint *)p2 = t; - } - - override @property immutable(void)* rtInfo() nothrow pure const @safe { return rtinfoNoPointers; } -} diff --git a/src/rt/typeinfo/ti_ulong.d b/src/rt/typeinfo/ti_ulong.d deleted file mode 100644 index 6b067f2c49..0000000000 --- a/src/rt/typeinfo/ti_ulong.d +++ /dev/null @@ -1,75 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_ulong; - - -// ulong - -class TypeInfo_m : TypeInfo -{ - @trusted: - const: - pure: - nothrow: - - override string toString() const pure nothrow @safe { return "ulong"; } - - override size_t getHash(scope const void* p) - { - static if (ulong.sizeof <= size_t.sizeof) - return *cast(const ulong*)p; - else - return hashOf(*cast(const ulong*)p); - } - - override bool equals(in void* p1, in void* p2) - { - return *cast(ulong *)p1 == *cast(ulong *)p2; - } - - override int compare(in void* p1, in void* p2) - { - if (*cast(ulong *)p1 < *cast(ulong *)p2) - return -1; - else if (*cast(ulong *)p1 > *cast(ulong *)p2) - return 1; - return 0; - } - - override @property size_t tsize() nothrow pure - { - return ulong.sizeof; - } - - override const(void)[] initializer() const @trusted - { - return (cast(void *)null)[0 .. ulong.sizeof]; - } - - override void swap(void *p1, void *p2) - { - ulong t; - - t = *cast(ulong *)p1; - *cast(ulong *)p1 = *cast(ulong *)p2; - *cast(ulong *)p2 = t; - } - - override @property size_t talign() nothrow pure - { - return ulong.alignof; - } - - override @property immutable(void)* rtInfo() nothrow pure const @safe { return rtinfoNoPointers; } -} diff --git a/src/rt/typeinfo/ti_ushort.d b/src/rt/typeinfo/ti_ushort.d deleted file mode 100644 index f90b4ab972..0000000000 --- a/src/rt/typeinfo/ti_ushort.d +++ /dev/null @@ -1,62 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_ushort; - -// ushort - -class TypeInfo_t : TypeInfo -{ - @trusted: - const: - pure: - nothrow: - - override string toString() const pure nothrow @safe { return "ushort"; } - - override size_t getHash(scope const void* p) - { - return *cast(const ushort *)p; - } - - override bool equals(in void* p1, in void* p2) - { - return *cast(ushort *)p1 == *cast(ushort *)p2; - } - - override int compare(in void* p1, in void* p2) - { - return *cast(ushort *)p1 - *cast(ushort *)p2; - } - - override @property size_t tsize() nothrow pure - { - return ushort.sizeof; - } - - override const(void)[] initializer() const @trusted - { - return (cast(void *)null)[0 .. ushort.sizeof]; - } - - override void swap(void *p1, void *p2) - { - ushort t; - - t = *cast(ushort *)p1; - *cast(ushort *)p1 = *cast(ushort *)p2; - *cast(ushort *)p2 = t; - } - - override @property immutable(void)* rtInfo() nothrow pure const @safe { return rtinfoNoPointers; } -} diff --git a/src/rt/typeinfo/ti_void.d b/src/rt/typeinfo/ti_void.d deleted file mode 100644 index c35de7b88d..0000000000 --- a/src/rt/typeinfo/ti_void.d +++ /dev/null @@ -1,65 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_void; - -// void - -class TypeInfo_v : TypeInfo -{ - @trusted: - const: - pure: - nothrow: - - override string toString() const pure nothrow @safe { return "void"; } - - override size_t getHash(scope const void* p) - { - assert(0); - } - - override bool equals(in void* p1, in void* p2) - { - return *cast(byte *)p1 == *cast(byte *)p2; - } - - override int compare(in void* p1, in void* p2) - { - return *cast(byte *)p1 - *cast(byte *)p2; - } - - override @property size_t tsize() nothrow pure - { - return void.sizeof; - } - - override const(void)[] initializer() const @trusted - { - return (cast(void *)null)[0 .. void.sizeof]; - } - - override void swap(void *p1, void *p2) - { - byte t; - - t = *cast(byte *)p1; - *cast(byte *)p1 = *cast(byte *)p2; - *cast(byte *)p2 = t; - } - - override @property uint flags() nothrow pure - { - return 1; - } -} diff --git a/src/rt/typeinfo/ti_wchar.d b/src/rt/typeinfo/ti_wchar.d deleted file mode 100644 index 7d278abaac..0000000000 --- a/src/rt/typeinfo/ti_wchar.d +++ /dev/null @@ -1,64 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_wchar; - -// wchar - -class TypeInfo_u : TypeInfo -{ - @trusted: - const: - pure: - nothrow: - - override string toString() { return "wchar"; } - - override size_t getHash(scope const void* p) - { - return *cast(const wchar *)p; - } - - override bool equals(in void* p1, in void* p2) - { - return *cast(wchar *)p1 == *cast(wchar *)p2; - } - - override int compare(in void* p1, in void* p2) - { - return *cast(wchar *)p1 - *cast(wchar *)p2; - } - - override @property size_t tsize() - { - return wchar.sizeof; - } - - override void swap(void *p1, void *p2) - { - wchar t; - - t = *cast(wchar *)p1; - *cast(wchar *)p1 = *cast(wchar *)p2; - *cast(wchar *)p2 = t; - } - - override const(void)[] initializer() const @trusted - { - static immutable wchar c; - - return (&c)[0 .. 1]; - } - - override @property immutable(void)* rtInfo() nothrow pure const @safe { return rtinfoNoPointers; } -} diff --git a/src/rt/util/typeinfo.d b/src/rt/util/typeinfo.d index 641c721716..89e50a8739 100644 --- a/src/rt/util/typeinfo.d +++ b/src/rt/util/typeinfo.d @@ -266,3 +266,445 @@ unittest } }(); } + +private class TypeInfoGeneric(T) : TypeInfo +{ + static if (is(T == ifloat)) private alias Real = float; + else static if (is(T == idouble)) private alias Real = double; + else static if (is(T == ireal)) private alias Real = real; + else private alias Real = T; + + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return T.stringof; } + + override size_t getHash(scope const void* p) + { + static if (__traits(isFloating, T)) + return Floating!Real.hashOf(*cast(Real*)p); + else + return hashOf(*cast(const T *)p); + } + + override bool equals(in void* p1, in void* p2) + { + static if (__traits(isFloating, T)) + return Floating!Real.equals(*cast(Real*)p1, *cast(Real*)p2); + else + return *cast(T *)p1 == *cast(T *)p2; + } + + override int compare(in void* p1, in void* p2) + { + static if (__traits(isFloating, T)) + { + return Floating!Real.compare(*cast(Real*)p1, *cast(Real*)p2); + } + else static if (T.sizeof < int.sizeof) + { + return *cast(T *)p1 - *cast(T *)p2; + } + else + { + if (*cast(T *)p1 < *cast(T *)p2) + return -1; + if (*cast(T *)p1 > *cast(T *)p2) + return 1; + return 0; + } + } + + override @property size_t tsize() nothrow pure + { + return T.sizeof; + } + + override @property size_t talign() nothrow pure + { + return T.alignof; + } + + override const(void)[] initializer() @trusted + { + static if (__traits(isZeroInit, T)) + { + return (cast(void *)null)[0 .. T.sizeof]; + } + else + { + static immutable T[1] c; + return c; + } + } + + override void swap(void *p1, void *p2) + { + T t; + + t = *cast(T *)p1; + *cast(T *)p1 = *cast(T *)p2; + *cast(T *)p2 = t; + } + + override @property immutable(void)* rtInfo() nothrow pure const @safe + { + return RTInfo!T; + } + + static if (__traits(isFloating, T)) + static if (is(immutable Real == immutable real) && T.mant_dig != 64) // exclude 80-bit X87 + // passed in SIMD register + override @property uint flags() const { return 2; } +} + +private class TypeInfoArrayGeneric(T) : TypeInfo_Array +{ + static if (is(T == ifloat)) private alias Real = float; + else static if (is(T == idouble)) private alias Real = double; + else static if (is(T == ireal)) private alias Real = real; + else private alias Real = T; + + override bool opEquals(Object o) { return TypeInfo.opEquals(o); } + + override string toString() const { return (T[]).stringof; } + + override size_t getHash(scope const void* p) @trusted const + { + static if (__traits(isFloating, T)) + return Array!Real.hashOf(*cast(Real[]*)p); + else + { + return hashOf(*cast(const void[]*) p); + } + } + + override bool equals(in void* p1, in void* p2) const + { + static if (__traits(isFloating, T)) + { + return Array!Real.equals(*cast(Real[]*)p1, *cast(Real[]*)p2); + } + else + { + import core.stdc.string; + auto s1 = *cast(T[]*)p1; + auto s2 = *cast(T[]*)p2; + return s1.length == s2.length && + memcmp(s1.ptr, s2.ptr, s1.length) == 0; + } + } + + override int compare(in void* p1, in void* p2) const + { + static if (__traits(isFloating, T)) + { + return Array!Real.compare(*cast(Real[]*)p1, *cast(Real[]*)p2); + } + else + { + auto s1 = *cast(T[]*)p1; + auto s2 = *cast(T[]*)p2; + auto len = s1.length; + + if (s2.length < len) + len = s2.length; + for (size_t u = 0; u < len; u++) + { + if (int result = (s1[u] > s2[u]) - (s1[u] < s2[u])) + return result; + } + return (s1.length > s2.length) - (s1.length < s2.length); + } + } + + override @property inout(TypeInfo) next() inout + { + return cast(inout) typeid(T); + } +} + +//////////////////////////////////////////////////////////////////////////////// +// Predefined TypeInfos +//////////////////////////////////////////////////////////////////////////////// + +// All integrals. +class TypeInfo_b : TypeInfoGeneric!bool {} +class TypeInfo_g : TypeInfoGeneric!byte {} +class TypeInfo_h : TypeInfoGeneric!ubyte {} +class TypeInfo_a : TypeInfoGeneric!char {} +class TypeInfo_u : TypeInfoGeneric!wchar {} +class TypeInfo_w : TypeInfoGeneric!dchar {} +class TypeInfo_s : TypeInfoGeneric!short {} +class TypeInfo_t : TypeInfoGeneric!ushort {} +class TypeInfo_i : TypeInfoGeneric!int {} +class TypeInfo_k : TypeInfoGeneric!uint {} +class TypeInfo_l : TypeInfoGeneric!long {} +class TypeInfo_m : TypeInfoGeneric!ulong {} +static if (is(cent)) class TypeInfo_zi : TypeInfoGeneric!cent {} +static if (is(ucent)) class TypeInfo_zk : TypeInfoGeneric!ucent {} + +// All simple floating-point types. +class TypeInfo_f : TypeInfoGeneric!float {} +class TypeInfo_o : TypeInfoGeneric!ifloat {} +class TypeInfo_d : TypeInfoGeneric!double {} +class TypeInfo_p : TypeInfoGeneric!idouble {} +class TypeInfo_e : TypeInfoGeneric!real {} +class TypeInfo_j : TypeInfoGeneric!ireal {} + +// All complex floating-point types. + +// cfloat +class TypeInfo_q : TypeInfoGeneric!cfloat +{ + const: nothrow: pure: @trusted: + static if (__traits(hasMember, TypeInfo, "argTypes")) + override int argTypes(out TypeInfo arg1, out TypeInfo arg2) + { + arg1 = typeid(double); + return 0; + } +} + +// cdouble +class TypeInfo_r : TypeInfoGeneric!cdouble +{ + const: nothrow: pure: @trusted: + static if (__traits(hasMember, TypeInfo, "argTypes")) + override int argTypes(out TypeInfo arg1, out TypeInfo arg2) + { + arg1 = typeid(double); + arg2 = typeid(double); + return 0; + } +} + +// creal +class TypeInfo_c : TypeInfoGeneric!creal +{ + const: nothrow: pure: @trusted: + static if (__traits(hasMember, TypeInfo, "argTypes")) + override int argTypes(out TypeInfo arg1, out TypeInfo arg2) + { + arg1 = typeid(real); + arg2 = typeid(real); + return 0; + } +} + +// All pointer types are represented by `TypeInfo_P`. +// Please keep in sync with `TypeInfo_Pointer`. +class TypeInfo_P : TypeInfoGeneric!(void*) +{ + const: nothrow: pure: @trusted: + + override size_t getHash(scope const void* p) + { + size_t addr = cast(size_t) *cast(const void**)p; + return addr ^ (addr >> 4); + } + + override @property uint flags() nothrow pure const { return 1; } +} + +// Arrays of all integrals. +class TypeInfo_Ab : TypeInfoArrayGeneric!bool {} +class TypeInfo_Ag : TypeInfoArrayGeneric!byte {} +class TypeInfo_Ah : TypeInfoArrayGeneric!ubyte {} +class TypeInfo_Aa : TypeInfoArrayGeneric!char {} +class TypeInfo_Axa : TypeInfoArrayGeneric!(const char) {} +class TypeInfo_Aya : TypeInfoArrayGeneric!(immutable char) {} +class TypeInfo_As : TypeInfoArrayGeneric!short {} +class TypeInfo_At : TypeInfoArrayGeneric!ushort {} +class TypeInfo_Au : TypeInfoArrayGeneric!wchar {} +class TypeInfo_Ai : TypeInfoArrayGeneric!int {} +class TypeInfo_Ak : TypeInfoArrayGeneric!uint {} +class TypeInfo_Aw : TypeInfoArrayGeneric!dchar {} +class TypeInfo_Al : TypeInfoArrayGeneric!long {} +class TypeInfo_Am : TypeInfoArrayGeneric!ulong {} + +extern (C) void[] _adSort(void[] a, TypeInfo ti); + +unittest +{ + int[][] a = [[5,3,8,7], [2,5,3,8,7]]; + _adSort(*cast(void[]*)&a, typeid(a[0])); + assert(a == [[2,5,3,8,7], [5,3,8,7]]); + + a = [[5,3,8,7], [5,3,8]]; + _adSort(*cast(void[]*)&a, typeid(a[0])); + assert(a == [[5,3,8], [5,3,8,7]]); +} + +unittest +{ + // Issue 13073: original code uses int subtraction which is susceptible to + // integer overflow, causing the following case to fail. + int[] a = [int.max, int.max]; + int[] b = [int.min, int.min]; + assert(a > b); + assert(b < a); +} + +unittest +{ + // Original test case from issue 13073 + uint x = 0x22_DF_FF_FF; + uint y = 0xA2_DF_FF_FF; + assert(!(x < y && y < x)); + uint[] a = [x]; + uint[] b = [y]; + assert(!(a < b && b < a)); // Original failing case + uint[1] a1 = [x]; + uint[1] b1 = [y]; + assert(!(a1 < b1 && b1 < a1)); // Original failing case +} + +// Arrays of all floating point types. +class TypeInfo_Af : TypeInfoArrayGeneric!float {} +class TypeInfo_Ao : TypeInfoArrayGeneric!ifloat {} +class TypeInfo_Ad : TypeInfoArrayGeneric!double {} +class TypeInfo_Ap : TypeInfoArrayGeneric!idouble {} +class TypeInfo_Ae : TypeInfoArrayGeneric!real {} +class TypeInfo_Aj : TypeInfoArrayGeneric!ireal {} +class TypeInfo_Aq : TypeInfoArrayGeneric!cfloat {} +class TypeInfo_Ar : TypeInfoArrayGeneric!cdouble {} +class TypeInfo_Ac : TypeInfoArrayGeneric!creal {} + +// void[] is a bit different, behaves like ubyte[] for comparison purposes. +class TypeInfo_Av : TypeInfo_Ah +{ + override string toString() const { return "void[]"; } + override @property inout(TypeInfo) next() inout + { + return cast(inout) typeid(void); + } +} + +// void +class TypeInfo_v : TypeInfoGeneric!ubyte +{ + const: nothrow: pure: @trusted: + + override string toString() const pure nothrow @safe { return "void"; } + + override size_t getHash(scope const void* p) + { + assert(0); + } + + override @property uint flags() nothrow pure + { + return 1; + } +} + +// all delegates +class TypeInfo_D : TypeInfoGeneric!(void delegate(int)) +{ + const: nothrow: pure: @trusted: + override @property uint flags() nothrow pure + { + return 1; + } +} + +// typeof(null) +class TypeInfo_n : TypeInfo +{ + override string toString() const @safe { return "typeof(null)"; } + + override size_t getHash(scope const void* p) const + { + return 0; + } + + override bool equals(in void* p1, in void* p2) const @trusted + { + return true; + } + + override int compare(in void* p1, in void* p2) const @trusted + { + return 0; + } + + override @property size_t tsize() const + { + return typeof(null).sizeof; + } + + override const(void)[] initializer() const @trusted + { + __gshared immutable void[typeof(null).sizeof] init; + return init; + } + + override void swap(void *p1, void *p2) const @trusted + { + } + + override @property immutable(void)* rtInfo() nothrow pure const @safe { return rtinfoNoPointers; } +} + +// Object +class TypeInfo_C : TypeInfo +{ + @trusted: + const: + //pure: + //nothrow: + + override size_t getHash(scope const void* p) + { + Object o = *cast(Object*)p; + return o ? o.toHash() : 0; + } + + override bool equals(in void* p1, in void* p2) + { + Object o1 = *cast(Object*)p1; + Object o2 = *cast(Object*)p2; + + return o1 == o2; + } + + override int compare(in void* p1, in void* p2) + { + Object o1 = *cast(Object*)p1; + Object o2 = *cast(Object*)p2; + int c = 0; + + // Regard null references as always being "less than" + if (o1 !is o2) + { + if (o1) + { + if (!o2) + c = 1; + else + c = o1.opCmp(o2); + } + else + c = -1; + } + return c; + } + + override @property size_t tsize() nothrow pure + { + return Object.sizeof; + } + + override const(void)[] initializer() const @trusted + { + return (cast(void *)null)[0 .. Object.sizeof]; + } + + override @property uint flags() nothrow pure + { + return 1; + } +} From 3f2a646d03bcfb0938f9ae65305ab803ea8c4c83 Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Sat, 5 Sep 2020 18:39:22 -0400 Subject: [PATCH 02/18] Remove documentation of deleted modules --- mak/DOCS | 38 -------------------------------------- 1 file changed, 38 deletions(-) diff --git a/mak/DOCS b/mak/DOCS index b249d2fe68..130cd4e022 100644 --- a/mak/DOCS +++ b/mak/DOCS @@ -129,44 +129,6 @@ DOCS=\ $(DOCDIR)\rt_trace.html \ $(DOCDIR)\rt_tracegc.html \ \ - $(DOCDIR)\rt_typeinfo_ti_Acdouble.html \ - $(DOCDIR)\rt_typeinfo_ti_Acfloat.html \ - $(DOCDIR)\rt_typeinfo_ti_Acreal.html \ - $(DOCDIR)\rt_typeinfo_ti_Adouble.html \ - $(DOCDIR)\rt_typeinfo_ti_Afloat.html \ - $(DOCDIR)\rt_typeinfo_ti_Ag.html \ - $(DOCDIR)\rt_typeinfo_ti_Aint.html \ - $(DOCDIR)\rt_typeinfo_ti_Along.html \ - $(DOCDIR)\rt_typeinfo_ti_Areal.html \ - $(DOCDIR)\rt_typeinfo_ti_Ashort.html \ - $(DOCDIR)\rt_typeinfo_ti_byte.html \ - $(DOCDIR)\rt_typeinfo_ti_C.html \ - $(DOCDIR)\rt_typeinfo_ti_cdouble.html \ - $(DOCDIR)\rt_typeinfo_ti_cent.html \ - $(DOCDIR)\rt_typeinfo_ti_cfloat.html \ - $(DOCDIR)\rt_typeinfo_ti_char.html \ - $(DOCDIR)\rt_typeinfo_ti_creal.html \ - $(DOCDIR)\rt_typeinfo_ti_dchar.html \ - $(DOCDIR)\rt_typeinfo_ti_delegate.html \ - $(DOCDIR)\rt_typeinfo_ti_double.html \ - $(DOCDIR)\rt_typeinfo_ti_float.html \ - $(DOCDIR)\rt_typeinfo_ti_idouble.html \ - $(DOCDIR)\rt_typeinfo_ti_ifloat.html \ - $(DOCDIR)\rt_typeinfo_ti_int.html \ - $(DOCDIR)\rt_typeinfo_ti_ireal.html \ - $(DOCDIR)\rt_typeinfo_ti_long.html \ - $(DOCDIR)\rt_typeinfo_ti_n.html \ - $(DOCDIR)\rt_typeinfo_ti_ptr.html \ - $(DOCDIR)\rt_typeinfo_ti_real.html \ - $(DOCDIR)\rt_typeinfo_ti_short.html \ - $(DOCDIR)\rt_typeinfo_ti_ubyte.html \ - $(DOCDIR)\rt_typeinfo_ti_ucent.html \ - $(DOCDIR)\rt_typeinfo_ti_uint.html \ - $(DOCDIR)\rt_typeinfo_ti_ulong.html \ - $(DOCDIR)\rt_typeinfo_ti_ushort.html \ - $(DOCDIR)\rt_typeinfo_ti_void.html \ - $(DOCDIR)\rt_typeinfo_ti_wchar.html \ - \ $(DOCDIR)\rt_unwind.html \ \ $(DOCDIR)\rt_util_container_array.html \ From e5e562ea010f42186e3acfc489fa813eb7441607 Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Sat, 5 Sep 2020 18:52:05 -0400 Subject: [PATCH 03/18] Fix name of string --- src/rt/util/typeinfo.d | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/rt/util/typeinfo.d b/src/rt/util/typeinfo.d index 89e50a8739..aeb9e7cb13 100644 --- a/src/rt/util/typeinfo.d +++ b/src/rt/util/typeinfo.d @@ -515,7 +515,11 @@ class TypeInfo_Ag : TypeInfoArrayGeneric!byte {} class TypeInfo_Ah : TypeInfoArrayGeneric!ubyte {} class TypeInfo_Aa : TypeInfoArrayGeneric!char {} class TypeInfo_Axa : TypeInfoArrayGeneric!(const char) {} -class TypeInfo_Aya : TypeInfoArrayGeneric!(immutable char) {} +class TypeInfo_Aya : TypeInfoArrayGeneric!(immutable char) +{ + // Must override this, otherwise "string" is returned. + override string toString() const { return "immutable(char)[]"; } +} class TypeInfo_As : TypeInfoArrayGeneric!short {} class TypeInfo_At : TypeInfoArrayGeneric!ushort {} class TypeInfo_Au : TypeInfoArrayGeneric!wchar {} @@ -529,6 +533,7 @@ extern (C) void[] _adSort(void[] a, TypeInfo ti); unittest { + assert(typeid(string).toString() == "immutable(char)[]"); int[][] a = [[5,3,8,7], [2,5,3,8,7]]; _adSort(*cast(void[]*)&a, typeid(a[0])); assert(a == [[2,5,3,8,7], [5,3,8,7]]); From d0d891f09c1d795b8c721f0faf493fe03c0a01b5 Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Sat, 5 Sep 2020 19:35:32 -0400 Subject: [PATCH 04/18] Fix hash function for arrays --- src/rt/util/typeinfo.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rt/util/typeinfo.d b/src/rt/util/typeinfo.d index aeb9e7cb13..90e0afd3da 100644 --- a/src/rt/util/typeinfo.d +++ b/src/rt/util/typeinfo.d @@ -377,7 +377,7 @@ private class TypeInfoArrayGeneric(T) : TypeInfo_Array return Array!Real.hashOf(*cast(Real[]*)p); else { - return hashOf(*cast(const void[]*) p); + return hashOf(*cast(const T[]*) p); } } From 40f69064da92fdddfacda701718d7f36356c17e3 Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Sat, 5 Sep 2020 20:43:38 -0400 Subject: [PATCH 05/18] Add unittests for improving coverage --- src/rt/util/typeinfo.d | 44 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/src/rt/util/typeinfo.d b/src/rt/util/typeinfo.d index 90e0afd3da..4f5a4b2231 100644 --- a/src/rt/util/typeinfo.d +++ b/src/rt/util/typeinfo.d @@ -342,9 +342,7 @@ private class TypeInfoGeneric(T) : TypeInfo override void swap(void *p1, void *p2) { - T t; - - t = *cast(T *)p1; + auto t = *cast(T *) p1; *cast(T *)p1 = *cast(T *)p2; *cast(T *)p2 = t; } @@ -360,6 +358,30 @@ private class TypeInfoGeneric(T) : TypeInfo override @property uint flags() const { return 2; } } +unittest +{ + assert(typeid(int).toString == "int"); + double a = 42, b = 43; + assert(typeid(double).equals(&a, &a)); + assert(!typeid(double).equals(&a, &b)); + assert(typeid(double).compare(&a, &a) == 0); + assert(typeid(double).compare(&a, &b) == -1); + assert(typeid(double).compare(&b, &a) == 1); + + short c = 42, d = 43; + assert(typeid(short).equals(&c, &c)); + assert(!typeid(short).equals(&c, &b)); + assert(typeid(short).compare(&c, &c) == 0); + assert(typeid(short).compare(&c, &d) == -1); + assert(typeid(short).compare(&d, &c) == 1); + + assert(typeid(int).initializer.ptr is null); + assert(typeid(int).initializer.length == int.sizeof); + + typeid(short).swap(&d, &c); + assert(c == 43 && d == 42); +} + private class TypeInfoArrayGeneric(T) : TypeInfo_Array { static if (is(T == ifloat)) private alias Real = float; @@ -426,6 +448,22 @@ private class TypeInfoArrayGeneric(T) : TypeInfo_Array } } +unittest +{ + assert(typeid(int[]) == typeid(int[])); + assert(typeid(int[]) != typeid(uint[])); + assert(typeid(int[]).toString == "int[]"); + + double[] a = [ 1, 2, 3 ], b = [ 2, 3 ]; + + assert(typeid(double[]).equals(&a, &a)); + assert(!typeid(double[]).equals(&a, &b)); + + assert(typeid(double[]).compare(&a, &a) == 0); + assert(typeid(double[]).compare(&a, &b) == -1); + assert(typeid(double[]).compare(&b, &a) == 1); +} + //////////////////////////////////////////////////////////////////////////////// // Predefined TypeInfos //////////////////////////////////////////////////////////////////////////////// From f2f44bd99be20c05701ac7ebdedebc7f72ef3b3f Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Sat, 5 Sep 2020 21:20:33 -0400 Subject: [PATCH 06/18] More unittests --- src/rt/util/typeinfo.d | 131 +++++++++++++++++++++++++++++++---------- 1 file changed, 99 insertions(+), 32 deletions(-) diff --git a/src/rt/util/typeinfo.d b/src/rt/util/typeinfo.d index 4f5a4b2231..98a6d92c42 100644 --- a/src/rt/util/typeinfo.d +++ b/src/rt/util/typeinfo.d @@ -468,6 +468,30 @@ unittest // Predefined TypeInfos //////////////////////////////////////////////////////////////////////////////// +// void +class TypeInfo_v : TypeInfoGeneric!ubyte +{ + const: nothrow: pure: @trusted: + + override string toString() const pure nothrow @safe { return "void"; } + + override size_t getHash(scope const void* p) + { + assert(0); + } + + override @property uint flags() nothrow pure + { + return 1; + } + + unittest + { + assert(typeid(void).toString == "void"); + assert(typeid(void).flags == 1); + } +} + // All integrals. class TypeInfo_b : TypeInfoGeneric!bool {} class TypeInfo_g : TypeInfoGeneric!byte {} @@ -547,6 +571,17 @@ class TypeInfo_P : TypeInfoGeneric!(void*) override @property uint flags() nothrow pure const { return 1; } } +unittest +{ + with (typeid(int*)) + { + int x; + int* p = &x; + assert(getHash(&p) != 0); + assert(flags == 1); + } +} + // Arrays of all integrals. class TypeInfo_Ab : TypeInfoArrayGeneric!bool {} class TypeInfo_Ag : TypeInfoArrayGeneric!byte {} @@ -620,27 +655,16 @@ class TypeInfo_Ac : TypeInfoArrayGeneric!creal {} class TypeInfo_Av : TypeInfo_Ah { override string toString() const { return "void[]"; } + override @property inout(TypeInfo) next() inout { return cast(inout) typeid(void); } -} - -// void -class TypeInfo_v : TypeInfoGeneric!ubyte -{ - const: nothrow: pure: @trusted: - - override string toString() const pure nothrow @safe { return "void"; } - - override size_t getHash(scope const void* p) - { - assert(0); - } - override @property uint flags() nothrow pure + unittest { - return 1; + assert(typeid(void[]).toString == "void[]"); + assert(typeid(void[]).next == typeid(void)); } } @@ -652,6 +676,11 @@ class TypeInfo_D : TypeInfoGeneric!(void delegate(int)) { return 1; } + + unittest + { + assert(typeid(int delegate(string)).flags == 1); + } } // typeof(null) @@ -690,6 +719,20 @@ class TypeInfo_n : TypeInfo } override @property immutable(void)* rtInfo() nothrow pure const @safe { return rtinfoNoPointers; } + + unittest + { + with (typeid(typeof(null))) + { + assert(toString == "typeof(null)"); + assert(getHash(null) == 0); + assert(equals(null, null)); + assert(compare(null, null) == 0); + assert(tsize == typeof(null).sizeof); + assert(initializer == new ubyte[(void*).sizeof]); + assert(rtInfo == rtinfoNoPointers); + } + } } // Object @@ -718,22 +761,11 @@ class TypeInfo_C : TypeInfo { Object o1 = *cast(Object*)p1; Object o2 = *cast(Object*)p2; - int c = 0; - - // Regard null references as always being "less than" - if (o1 !is o2) - { - if (o1) - { - if (!o2) - c = 1; - else - c = o1.opCmp(o2); - } - else - c = -1; - } - return c; + if (o1 is o2) + return 0; // includes the case null vs null + if (int result = (o1 !is null) - (o2 !is null)) + return result; + return o1.opCmp(o2); } override @property size_t tsize() nothrow pure @@ -743,11 +775,46 @@ class TypeInfo_C : TypeInfo override const(void)[] initializer() const @trusted { - return (cast(void *)null)[0 .. Object.sizeof]; + assert(0); } override @property uint flags() nothrow pure { return 1; } + + unittest + { + static class Bacon + { + int sizzle = 1; + override int opCmp(Object rhs) const + { + if (auto rhsb = cast(Bacon) rhs) + return (sizzle > rhsb.sizzle) - (sizzle < rhsb.sizzle); + return 0; + } + } + Object obj = new Bacon; + Bacon obj2 = new Bacon; + obj2.sizzle = 2; + auto dummy = new Object; + with (typeid(obj)) + { + assert(toString[$ - 6 .. $] == ".Bacon"); + assert(getHash(&obj) != 0); + assert(equals(&obj, &obj)); + assert(!equals(&obj, &obj2)); + assert(compare(&obj, &dummy) == 0); + assert(compare(&obj, &obj) == 0); + assert(compare(&obj, &obj2) == -1); + assert(compare(&obj2, &obj) == 1); + assert(tsize == Object.sizeof); + assert(rtInfo == RTInfo!Bacon); + assert(tsize == Object.sizeof); + assert(initializer.ptr !is null); + assert(initializer.length == __traits(classInstanceSize, Bacon)); + assert(flags == 1); + } + } } From 77dbb0c719b2b0512c9a31934c4441cc9ea5cc0d Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Sat, 5 Sep 2020 22:20:45 -0400 Subject: [PATCH 07/18] Rule of silence --- posix.mak | 1 - 1 file changed, 1 deletion(-) diff --git a/posix.mak b/posix.mak index c8865c27c6..4d7bf155ae 100644 --- a/posix.mak +++ b/posix.mak @@ -276,7 +276,6 @@ endif .PHONY : unittest ifeq (1,$(BUILD_WAS_SPECIFIED)) unittest : $(UT_MODULES) $(addsuffix /.run,$(ADDITIONAL_TESTS)) - @echo done else unittest : unittest-debug unittest-release unittest-%: target From 793e3a771e4cef1092a1f29f8fb32bd151b3d2ab Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Sat, 5 Sep 2020 22:36:46 -0400 Subject: [PATCH 08/18] More attempts to get coverage right --- src/rt/util/typeinfo.d | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rt/util/typeinfo.d b/src/rt/util/typeinfo.d index 98a6d92c42..d69aec20e4 100644 --- a/src/rt/util/typeinfo.d +++ b/src/rt/util/typeinfo.d @@ -573,7 +573,7 @@ class TypeInfo_P : TypeInfoGeneric!(void*) unittest { - with (typeid(int*)) + with (new TypeInfo_P) { int x; int* p = &x; @@ -679,7 +679,7 @@ class TypeInfo_D : TypeInfoGeneric!(void delegate(int)) unittest { - assert(typeid(int delegate(string)).flags == 1); + assert(typeid(void delegate(int)).flags == 1); } } From f07a4085209143f404617f78946376492193343d Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Sat, 5 Sep 2020 23:15:36 -0400 Subject: [PATCH 09/18] Turns out TypeInfo_C was dead code after all... --- src/rt/util/typeinfo.d | 106 +++++++++++------------------------------ 1 file changed, 29 insertions(+), 77 deletions(-) diff --git a/src/rt/util/typeinfo.d b/src/rt/util/typeinfo.d index d69aec20e4..0c7c3f0076 100644 --- a/src/rt/util/typeinfo.d +++ b/src/rt/util/typeinfo.d @@ -735,86 +735,38 @@ class TypeInfo_n : TypeInfo } } -// Object -class TypeInfo_C : TypeInfo +// Test typeinfo for classes. +unittest { - @trusted: - const: - //pure: - //nothrow: - - override size_t getHash(scope const void* p) - { - Object o = *cast(Object*)p; - return o ? o.toHash() : 0; - } - - override bool equals(in void* p1, in void* p2) - { - Object o1 = *cast(Object*)p1; - Object o2 = *cast(Object*)p2; - - return o1 == o2; - } - - override int compare(in void* p1, in void* p2) - { - Object o1 = *cast(Object*)p1; - Object o2 = *cast(Object*)p2; - if (o1 is o2) - return 0; // includes the case null vs null - if (int result = (o1 !is null) - (o2 !is null)) - return result; - return o1.opCmp(o2); - } - - override @property size_t tsize() nothrow pure + static class Bacon { - return Object.sizeof; - } - - override const(void)[] initializer() const @trusted - { - assert(0); - } - - override @property uint flags() nothrow pure - { - return 1; - } - - unittest - { - static class Bacon + int sizzle = 1; + override int opCmp(Object rhs) const { - int sizzle = 1; - override int opCmp(Object rhs) const - { - if (auto rhsb = cast(Bacon) rhs) - return (sizzle > rhsb.sizzle) - (sizzle < rhsb.sizzle); - return 0; - } - } - Object obj = new Bacon; - Bacon obj2 = new Bacon; - obj2.sizzle = 2; - auto dummy = new Object; - with (typeid(obj)) - { - assert(toString[$ - 6 .. $] == ".Bacon"); - assert(getHash(&obj) != 0); - assert(equals(&obj, &obj)); - assert(!equals(&obj, &obj2)); - assert(compare(&obj, &dummy) == 0); - assert(compare(&obj, &obj) == 0); - assert(compare(&obj, &obj2) == -1); - assert(compare(&obj2, &obj) == 1); - assert(tsize == Object.sizeof); - assert(rtInfo == RTInfo!Bacon); - assert(tsize == Object.sizeof); - assert(initializer.ptr !is null); - assert(initializer.length == __traits(classInstanceSize, Bacon)); - assert(flags == 1); + if (auto rhsb = cast(Bacon) rhs) + return (sizzle > rhsb.sizzle) - (sizzle < rhsb.sizzle); + return 0; } } + Object obj = new Bacon; + Bacon obj2 = new Bacon; + obj2.sizzle = 2; + auto dummy = new Object; + with (typeid(obj)) + { + assert(toString[$ - 6 .. $] == ".Bacon"); + assert(getHash(&obj) != 0); + assert(equals(&obj, &obj)); + assert(!equals(&obj, &obj2)); + assert(compare(&obj, &dummy) == 0); + assert(compare(&obj, &obj) == 0); + assert(compare(&obj, &obj2) == -1); + assert(compare(&obj2, &obj) == 1); + assert(tsize == Object.sizeof); + assert(rtInfo == RTInfo!Bacon); + assert(tsize == Object.sizeof); + assert(initializer.ptr !is null); + assert(initializer.length == __traits(classInstanceSize, Bacon)); + assert(flags == 1); + } } From e4affa13691bcac960e7cb991f2cfac4e8f124f3 Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Sat, 5 Sep 2020 23:57:15 -0400 Subject: [PATCH 10/18] Even more unittests --- src/rt/util/typeinfo.d | 72 ++++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 27 deletions(-) diff --git a/src/rt/util/typeinfo.d b/src/rt/util/typeinfo.d index 0c7c3f0076..e1070c4f8d 100644 --- a/src/rt/util/typeinfo.d +++ b/src/rt/util/typeinfo.d @@ -361,25 +361,30 @@ private class TypeInfoGeneric(T) : TypeInfo unittest { assert(typeid(int).toString == "int"); - double a = 42, b = 43; - assert(typeid(double).equals(&a, &a)); - assert(!typeid(double).equals(&a, &b)); - assert(typeid(double).compare(&a, &a) == 0); - assert(typeid(double).compare(&a, &b) == -1); - assert(typeid(double).compare(&b, &a) == 1); - - short c = 42, d = 43; - assert(typeid(short).equals(&c, &c)); - assert(!typeid(short).equals(&c, &b)); - assert(typeid(short).compare(&c, &c) == 0); - assert(typeid(short).compare(&c, &d) == -1); - assert(typeid(short).compare(&d, &c) == 1); - - assert(typeid(int).initializer.ptr is null); - assert(typeid(int).initializer.length == int.sizeof); - - typeid(short).swap(&d, &c); - assert(c == 43 && d == 42); + + with (typeid(double)) + { + double a = 42, b = 43; + assert(equals(&a, &a)); + assert(!equals(&a, &b)); + assert(compare(&a, &a) == 0); + assert(compare(&a, &b) == -1); + assert(compare(&b, &a) == 1); + } + + with (typeid(short)) + { + short c = 42, d = 43; + assert(equals(&c, &c)); + assert(!equals(&c, &d)); + assert(compare(&c, &c) == 0); + assert(compare(&c, &d) == -1); + assert(compare(&d, &c) == 1); + assert(initializer.ptr is null); + assert(initializer.length == short.sizeof); + swap(&d, &c); + assert(c == 43 && d == 42); + } } private class TypeInfoArrayGeneric(T) : TypeInfo_Array @@ -454,14 +459,15 @@ unittest assert(typeid(int[]) != typeid(uint[])); assert(typeid(int[]).toString == "int[]"); - double[] a = [ 1, 2, 3 ], b = [ 2, 3 ]; - - assert(typeid(double[]).equals(&a, &a)); - assert(!typeid(double[]).equals(&a, &b)); - - assert(typeid(double[]).compare(&a, &a) == 0); - assert(typeid(double[]).compare(&a, &b) == -1); - assert(typeid(double[]).compare(&b, &a) == 1); + with (typeid(double[])) + { + double[] a = [ 1, 2, 3 ], b = [ 2, 3 ]; + assert(equals(&a, &a)); + assert(!equals(&a, &b)); + assert(compare(&a, &a) == 0); + assert(compare(&a, &b) == -1); + assert(compare(&b, &a) == 1); + } } //////////////////////////////////////////////////////////////////////////////// @@ -556,6 +562,18 @@ class TypeInfo_c : TypeInfoGeneric!creal } } +static if (__traits(hasMember, TypeInfo, "argTypes")) + unittest + { + TypeInfo t1, t2; + assert(typeid(cfloat).argTypes(t1, t2) == 0 && t1 == typeid(double) && + t2 is null); + assert(typeid(cdouble).argTypes(t1, t2) == 0 && t1 == typeid(double) && + t2 == typeid(double)); + assert(typeid(creal).argTypes(t1, t2) == 0 && t1 == typeid(real) && + t2 == typeid(real)); + } + // All pointer types are represented by `TypeInfo_P`. // Please keep in sync with `TypeInfo_Pointer`. class TypeInfo_P : TypeInfoGeneric!(void*) From 76a15b91b39b098008eb73f40681ca760edd0952 Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Sat, 5 Sep 2020 23:59:08 -0400 Subject: [PATCH 11/18] Typeinfo_D also seems to be unneeded --- src/rt/util/typeinfo.d | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/rt/util/typeinfo.d b/src/rt/util/typeinfo.d index e1070c4f8d..fb2e53e34b 100644 --- a/src/rt/util/typeinfo.d +++ b/src/rt/util/typeinfo.d @@ -687,18 +687,9 @@ class TypeInfo_Av : TypeInfo_Ah } // all delegates -class TypeInfo_D : TypeInfoGeneric!(void delegate(int)) +unittest { - const: nothrow: pure: @trusted: - override @property uint flags() nothrow pure - { - return 1; - } - - unittest - { - assert(typeid(void delegate(int)).flags == 1); - } + assert(typeid(void delegate(int)).flags == 1); } // typeof(null) From e6e3f6af3b08907db8c3d43c109d2834cdffd34b Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Sun, 6 Sep 2020 01:13:46 -0400 Subject: [PATCH 12/18] Guard definition of Real to avoid confusion --- src/rt/util/typeinfo.d | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/rt/util/typeinfo.d b/src/rt/util/typeinfo.d index fb2e53e34b..f37007bf5b 100644 --- a/src/rt/util/typeinfo.d +++ b/src/rt/util/typeinfo.d @@ -269,10 +269,13 @@ unittest private class TypeInfoGeneric(T) : TypeInfo { - static if (is(T == ifloat)) private alias Real = float; - else static if (is(T == idouble)) private alias Real = double; - else static if (is(T == ireal)) private alias Real = real; - else private alias Real = T; + static if (__traits(isFloating, T)) + { + static if (is(T == ifloat)) private alias Real = float; + else static if (is(T == idouble)) private alias Real = double; + else static if (is(T == ireal)) private alias Real = real; + else private alias Real = T; + } @trusted: const: @@ -389,10 +392,13 @@ unittest private class TypeInfoArrayGeneric(T) : TypeInfo_Array { - static if (is(T == ifloat)) private alias Real = float; - else static if (is(T == idouble)) private alias Real = double; - else static if (is(T == ireal)) private alias Real = real; - else private alias Real = T; + static if (__traits(isFloating, T)) + { + static if (is(T == ifloat)) private alias Real = float; + else static if (is(T == idouble)) private alias Real = double; + else static if (is(T == ireal)) private alias Real = real; + else private alias Real = T; + } override bool opEquals(Object o) { return TypeInfo.opEquals(o); } From b835543422e3d5a2791f0c112b9521915f95757c Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Sun, 6 Sep 2020 11:19:32 -0400 Subject: [PATCH 13/18] Reduce code generation by reusing layout and behavior --- src/rt/util/typeinfo.d | 88 ++++++++++++++++++++++++++++-------------- 1 file changed, 59 insertions(+), 29 deletions(-) diff --git a/src/rt/util/typeinfo.d b/src/rt/util/typeinfo.d index f37007bf5b..468badeb41 100644 --- a/src/rt/util/typeinfo.d +++ b/src/rt/util/typeinfo.d @@ -267,27 +267,19 @@ unittest }(); } +/** +TypeInfo information for built-in types. +*/ private class TypeInfoGeneric(T) : TypeInfo { - static if (__traits(isFloating, T)) - { - static if (is(T == ifloat)) private alias Real = float; - else static if (is(T == idouble)) private alias Real = double; - else static if (is(T == ireal)) private alias Real = real; - else private alias Real = T; - } - - @trusted: - const: - pure: - nothrow: + const: nothrow: pure: @trusted: override string toString() const pure nothrow @safe { return T.stringof; } override size_t getHash(scope const void* p) { static if (__traits(isFloating, T)) - return Floating!Real.hashOf(*cast(Real*)p); + return Floating!T.hashOf(*cast(T*)p); else return hashOf(*cast(const T *)p); } @@ -295,7 +287,7 @@ private class TypeInfoGeneric(T) : TypeInfo override bool equals(in void* p1, in void* p2) { static if (__traits(isFloating, T)) - return Floating!Real.equals(*cast(Real*)p1, *cast(Real*)p2); + return Floating!T.equals(*cast(T*)p1, *cast(T*)p2); else return *cast(T *)p1 == *cast(T *)p2; } @@ -304,7 +296,7 @@ private class TypeInfoGeneric(T) : TypeInfo { static if (__traits(isFloating, T)) { - return Floating!Real.compare(*cast(Real*)p1, *cast(Real*)p2); + return Floating!T.compare(*cast(T*)p1, *cast(T*)p2); } else static if (T.sizeof < int.sizeof) { @@ -356,11 +348,51 @@ private class TypeInfoGeneric(T) : TypeInfo } static if (__traits(isFloating, T)) - static if (is(immutable Real == immutable real) && T.mant_dig != 64) // exclude 80-bit X87 + static if (is(immutable T == immutable real) && T.mant_dig != 64) // exclude 80-bit X87 // passed in SIMD register override @property uint flags() const { return 2; } } +/** +Type `T` has the same layout and alignment as type `Base`, but slightly different behavior. +Example: `float` and `ifloat` or `char` and `ubyte`. +We assume the two types hash the same, swap the same, have the same ABI flags, and compare the same for +equality. For ordering comparisons, we detect during compilation whether they have different min and max +values (e.g. signed vs. unsigned) and override appropriately. For initializer, we detect if we need to +override. The overriding initializer should be nonzero. +*/ +private class TypeInfoGeneric(T, Base) : TypeInfoGeneric!Base +if (T.sizeof == Base.sizeof && T.alignof == Base.alignof) +{ + const: nothrow: pure: @trusted: + override string toString() { return T.stringof; } + static if (T.max != Base.max) + // Must override comparison, signedness is different + override int compare(in void* p1, in void* p2) + { + static if (T.sizeof < int.sizeof) + { + return *cast(T *)p1 - *cast(T *)p2; + } + else + { + if (*cast(T *)p1 < *cast(T *)p2) + return -1; + if (*cast(T *)p1 > *cast(T *)p2) + return 1; + return 0; + } + } + static if (T.init != Base.init) + // Must override initializer. + override const(void)[] initializer() @trusted + { + static assert(!__traits(isZeroInit, T), "Please inherit the other way"); + static immutable T[1] c; + return c; + } +} + unittest { assert(typeid(int).toString == "int"); @@ -409,9 +441,7 @@ private class TypeInfoArrayGeneric(T) : TypeInfo_Array static if (__traits(isFloating, T)) return Array!Real.hashOf(*cast(Real[]*)p); else - { return hashOf(*cast(const T[]*) p); - } } override bool equals(in void* p1, in void* p2) const @@ -505,28 +535,28 @@ class TypeInfo_v : TypeInfoGeneric!ubyte } // All integrals. -class TypeInfo_b : TypeInfoGeneric!bool {} +class TypeInfo_b : TypeInfoGeneric!(bool, ubyte) {} class TypeInfo_g : TypeInfoGeneric!byte {} -class TypeInfo_h : TypeInfoGeneric!ubyte {} -class TypeInfo_a : TypeInfoGeneric!char {} -class TypeInfo_u : TypeInfoGeneric!wchar {} -class TypeInfo_w : TypeInfoGeneric!dchar {} +class TypeInfo_h : TypeInfoGeneric!(ubyte, byte) {} +class TypeInfo_a : TypeInfoGeneric!(char, ubyte) {} +class TypeInfo_u : TypeInfoGeneric!(wchar, ushort) {} +class TypeInfo_w : TypeInfoGeneric!(dchar, uint) {} class TypeInfo_s : TypeInfoGeneric!short {} -class TypeInfo_t : TypeInfoGeneric!ushort {} +class TypeInfo_t : TypeInfoGeneric!(ushort, short) {} class TypeInfo_i : TypeInfoGeneric!int {} -class TypeInfo_k : TypeInfoGeneric!uint {} +class TypeInfo_k : TypeInfoGeneric!(uint, int) {} class TypeInfo_l : TypeInfoGeneric!long {} -class TypeInfo_m : TypeInfoGeneric!ulong {} +class TypeInfo_m : TypeInfoGeneric!(ulong, long) {} static if (is(cent)) class TypeInfo_zi : TypeInfoGeneric!cent {} static if (is(ucent)) class TypeInfo_zk : TypeInfoGeneric!ucent {} // All simple floating-point types. class TypeInfo_f : TypeInfoGeneric!float {} -class TypeInfo_o : TypeInfoGeneric!ifloat {} +class TypeInfo_o : TypeInfoGeneric!(ifloat, float) {} class TypeInfo_d : TypeInfoGeneric!double {} -class TypeInfo_p : TypeInfoGeneric!idouble {} +class TypeInfo_p : TypeInfoGeneric!(idouble, double) {} class TypeInfo_e : TypeInfoGeneric!real {} -class TypeInfo_j : TypeInfoGeneric!ireal {} +class TypeInfo_j : TypeInfoGeneric!(ireal, real) {} // All complex floating-point types. From 48a457092437d42a9cf49c0dbd621c11475b4ba4 Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Sun, 6 Sep 2020 14:39:20 -0400 Subject: [PATCH 14/18] Consolidate versions of TypeInfoGeneric --- src/rt/util/typeinfo.d | 176 +++++++++++++++++++---------------------- 1 file changed, 81 insertions(+), 95 deletions(-) diff --git a/src/rt/util/typeinfo.d b/src/rt/util/typeinfo.d index 468badeb41..c145023cdb 100644 --- a/src/rt/util/typeinfo.d +++ b/src/rt/util/typeinfo.d @@ -267,130 +267,116 @@ unittest }(); } +private template Select(bool cond, T, U) +{ + static if (cond) alias Select = T; + else alias Select = U; +} + /** TypeInfo information for built-in types. + +Type `T` has the same layout and alignment as type `Base`, but slightly different behavior. +Example: `float` and `ifloat` or `char` and `ubyte`. +We assume the two types hash the same, swap the same, have the same ABI flags, and compare the same for +equality. For ordering comparisons, we detect during compilation whether they have different min and max +values (e.g. signed vs. unsigned) and override appropriately. For initializer, we detect if we need to +override. The overriding initializer should be nonzero. */ -private class TypeInfoGeneric(T) : TypeInfo +private class TypeInfoGeneric(T, Base = T) : Select!(is(T == Base), TypeInfo, TypeInfoGeneric!Base) +if (T.sizeof == Base.sizeof && T.alignof == Base.alignof) { const: nothrow: pure: @trusted: + // Returns the type name. override string toString() const pure nothrow @safe { return T.stringof; } - override size_t getHash(scope const void* p) - { - static if (__traits(isFloating, T)) - return Floating!T.hashOf(*cast(T*)p); - else - return hashOf(*cast(const T *)p); - } - - override bool equals(in void* p1, in void* p2) - { - static if (__traits(isFloating, T)) - return Floating!T.equals(*cast(T*)p1, *cast(T*)p2); - else - return *cast(T *)p1 == *cast(T *)p2; - } - - override int compare(in void* p1, in void* p2) - { - static if (__traits(isFloating, T)) + // `getHash` is the same for `Base` and `T`, introduce it just once. + static if (is(T == Base)) + override size_t getHash(scope const void* p) { - return Floating!T.compare(*cast(T*)p1, *cast(T*)p2); + static if (__traits(isFloating, T)) + return Floating!T.hashOf(*cast(T*)p); + else + return hashOf(*cast(const T *)p); } - else static if (T.sizeof < int.sizeof) + + // `equals` is the same for `Base` and `T`, introduce it just once. + static if (is(T == Base)) + override bool equals(in void* p1, in void* p2) { - return *cast(T *)p1 - *cast(T *)p2; + static if (__traits(isFloating, T)) + return Floating!T.equals(*cast(T*)p1, *cast(T*)p2); + else + return *cast(T *)p1 == *cast(T *)p2; } - else + + // `T` and `Base` may have different signedness, so this function is introduced conditionally. + static if (is(T == Base) || (__traits(isIntegral, T) && T.max != Base.max)) + override int compare(in void* p1, in void* p2) { - if (*cast(T *)p1 < *cast(T *)p2) - return -1; - if (*cast(T *)p1 > *cast(T *)p2) - return 1; - return 0; + static if (__traits(isFloating, T)) + { + return Floating!T.compare(*cast(T*)p1, *cast(T*)p2); + } + else static if (T.sizeof < int.sizeof) + { + // Taking the difference will always fit in an int. + return int(*cast(T *) p1) - int(*cast(T *) p2); + } + else + { + auto lhs = *cast(T *) p1, rhs = *cast(T *) p2; + return (lhs > rhs) - (lhs < rhs); + } } - } - - override @property size_t tsize() nothrow pure - { - return T.sizeof; - } - override @property size_t talign() nothrow pure - { - return T.alignof; - } - - override const(void)[] initializer() @trusted - { - static if (__traits(isZeroInit, T)) + static if (is(T == Base)) + override @property size_t tsize() nothrow pure { - return (cast(void *)null)[0 .. T.sizeof]; + return T.sizeof; } - else + + static if (is(T == Base)) + override @property size_t talign() nothrow pure { - static immutable T[1] c; - return c; + return T.alignof; } - } - override void swap(void *p1, void *p2) - { - auto t = *cast(T *) p1; - *cast(T *)p1 = *cast(T *)p2; - *cast(T *)p2 = t; - } - - override @property immutable(void)* rtInfo() nothrow pure const @safe - { - return RTInfo!T; - } - - static if (__traits(isFloating, T)) - static if (is(immutable T == immutable real) && T.mant_dig != 64) // exclude 80-bit X87 - // passed in SIMD register - override @property uint flags() const { return 2; } -} - -/** -Type `T` has the same layout and alignment as type `Base`, but slightly different behavior. -Example: `float` and `ifloat` or `char` and `ubyte`. -We assume the two types hash the same, swap the same, have the same ABI flags, and compare the same for -equality. For ordering comparisons, we detect during compilation whether they have different min and max -values (e.g. signed vs. unsigned) and override appropriately. For initializer, we detect if we need to -override. The overriding initializer should be nonzero. -*/ -private class TypeInfoGeneric(T, Base) : TypeInfoGeneric!Base -if (T.sizeof == Base.sizeof && T.alignof == Base.alignof) -{ - const: nothrow: pure: @trusted: - override string toString() { return T.stringof; } - static if (T.max != Base.max) - // Must override comparison, signedness is different - override int compare(in void* p1, in void* p2) + // Override initializer only if necessary. + static if (is(T == Base) || T.init != Base.init) + override const(void)[] initializer() @trusted { - static if (T.sizeof < int.sizeof) + static if (__traits(isZeroInit, T)) { - return *cast(T *)p1 - *cast(T *)p2; + return (cast(void *)null)[0 .. T.sizeof]; } else { - if (*cast(T *)p1 < *cast(T *)p2) - return -1; - if (*cast(T *)p1 > *cast(T *)p2) - return 1; - return 0; + static immutable T[1] c; + return c; } } - static if (T.init != Base.init) - // Must override initializer. - override const(void)[] initializer() @trusted + + // `swap` is the same for `Base` and `T`, so introduce only once. + static if (is(T == Base)) + override void swap(void *p1, void *p2) + { + auto t = *cast(T *) p1; + *cast(T *)p1 = *cast(T *)p2; + *cast(T *)p2 = t; + } + + static if (is(T == Base) || RTInfo!T != RTInfo!Base) + override @property immutable(void)* rtInfo() nothrow pure const @safe { - static assert(!__traits(isZeroInit, T), "Please inherit the other way"); - static immutable T[1] c; - return c; + return RTInfo!T; } + + static if (is(T == Base) && __traits(isFloating, T)) + static if (is(immutable T == immutable real) && T.mant_dig != 64) // exclude 80-bit X87 + // passed in SIMD register + override @property uint flags() const { return 2; } } unittest From f14c296202fe3f5ec5c6b26b3a7016dc6bbf3e4c Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Sun, 6 Sep 2020 15:00:41 -0400 Subject: [PATCH 15/18] Review --- src/rt/util/typeinfo.d | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/src/rt/util/typeinfo.d b/src/rt/util/typeinfo.d index c145023cdb..5df773139d 100644 --- a/src/rt/util/typeinfo.d +++ b/src/rt/util/typeinfo.d @@ -596,32 +596,6 @@ static if (__traits(hasMember, TypeInfo, "argTypes")) t2 == typeid(real)); } -// All pointer types are represented by `TypeInfo_P`. -// Please keep in sync with `TypeInfo_Pointer`. -class TypeInfo_P : TypeInfoGeneric!(void*) -{ - const: nothrow: pure: @trusted: - - override size_t getHash(scope const void* p) - { - size_t addr = cast(size_t) *cast(const void**)p; - return addr ^ (addr >> 4); - } - - override @property uint flags() nothrow pure const { return 1; } -} - -unittest -{ - with (new TypeInfo_P) - { - int x; - int* p = &x; - assert(getHash(&p) != 0); - assert(flags == 1); - } -} - // Arrays of all integrals. class TypeInfo_Ab : TypeInfoArrayGeneric!bool {} class TypeInfo_Ag : TypeInfoArrayGeneric!byte {} @@ -642,7 +616,7 @@ class TypeInfo_Aw : TypeInfoArrayGeneric!dchar {} class TypeInfo_Al : TypeInfoArrayGeneric!long {} class TypeInfo_Am : TypeInfoArrayGeneric!ulong {} -extern (C) void[] _adSort(void[] a, TypeInfo ti); +private extern (C) void[] _adSort(void[] a, TypeInfo ti); unittest { @@ -658,7 +632,7 @@ unittest unittest { - // Issue 13073: original code uses int subtraction which is susceptible to + // https://issues.dlang.org/show_bug.cgi?id=13073: original code uses int subtraction which is susceptible to // integer overflow, causing the following case to fail. int[] a = [int.max, int.max]; int[] b = [int.min, int.min]; From f6620070b72c70b07ec28099109600c6ba604b0d Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Sun, 6 Sep 2020 15:12:42 -0400 Subject: [PATCH 16/18] Also reuse common implementation fragments for arrays --- src/rt/util/typeinfo.d | 155 +++++++++++++++++++++-------------------- 1 file changed, 81 insertions(+), 74 deletions(-) diff --git a/src/rt/util/typeinfo.d b/src/rt/util/typeinfo.d index 5df773139d..57d3f08cc2 100644 --- a/src/rt/util/typeinfo.d +++ b/src/rt/util/typeinfo.d @@ -267,21 +267,22 @@ unittest }(); } +// Reduces to `T` if `cond` is `true` or `U` otherwise. private template Select(bool cond, T, U) { static if (cond) alias Select = T; else alias Select = U; } -/** +/* TypeInfo information for built-in types. -Type `T` has the same layout and alignment as type `Base`, but slightly different behavior. -Example: `float` and `ifloat` or `char` and `ubyte`. -We assume the two types hash the same, swap the same, have the same ABI flags, and compare the same for -equality. For ordering comparisons, we detect during compilation whether they have different min and max -values (e.g. signed vs. unsigned) and override appropriately. For initializer, we detect if we need to -override. The overriding initializer should be nonzero. +A `Base` type may be specified, which must be a type with the same layout, alignment, hashing, and +equality comparison as type `T`. This saves on code size because parts of `Base` will be reused. Example: +`float` and `ifloat` or `char` and `ubyte`. The implementation assumes `Base` and `T` hash the same, swap +the same, have the same ABI flags, and compare the same for equality. For ordering comparisons, we detect +during compilation whether they have different signedness and override appropriately. For initializer, we +detect if we need to override. The overriding initializer should be nonzero. */ private class TypeInfoGeneric(T, Base = T) : Select!(is(T == Base), TypeInfo, TypeInfoGeneric!Base) if (T.sizeof == Base.sizeof && T.alignof == Base.alignof) @@ -373,7 +374,7 @@ if (T.sizeof == Base.sizeof && T.alignof == Base.alignof) return RTInfo!T; } - static if (is(T == Base) && __traits(isFloating, T)) + static if (is(T == Base)) static if (is(immutable T == immutable real) && T.mant_dig != 64) // exclude 80-bit X87 // passed in SIMD register override @property uint flags() const { return 2; } @@ -408,66 +409,72 @@ unittest } } -private class TypeInfoArrayGeneric(T) : TypeInfo_Array -{ - static if (__traits(isFloating, T)) - { - static if (is(T == ifloat)) private alias Real = float; - else static if (is(T == idouble)) private alias Real = double; - else static if (is(T == ireal)) private alias Real = real; - else private alias Real = T; - } +/*¡ +TypeInfo information for arrays of built-in types. - override bool opEquals(Object o) { return TypeInfo.opEquals(o); } +A `Base` type may be specified, which must be a type with the same layout, alignment, hashing, and +equality comparison as type `T`. This saves on code size because parts of `Base` will be reused. Example: +`float` and `ifloat` or `char` and `ubyte`. The implementation assumes `Base` and `T` hash the same, swap +the same, have the same ABI flags, and compare the same for equality. For ordering comparisons, we detect +during compilation whether they have different signedness and override appropriately. For initializer, we +detect if we need to override. The overriding initializer should be nonzero. +*/ +private class TypeInfoArrayGeneric(T, Base = T) : Select!(is(T == Base), TypeInfo_Array, TypeInfoArrayGeneric!Base) +{ + static if (is(T == Base)) + override bool opEquals(Object o) { return TypeInfo.opEquals(o); } override string toString() const { return (T[]).stringof; } - override size_t getHash(scope const void* p) @trusted const - { - static if (__traits(isFloating, T)) - return Array!Real.hashOf(*cast(Real[]*)p); - else - return hashOf(*cast(const T[]*) p); - } - - override bool equals(in void* p1, in void* p2) const - { - static if (__traits(isFloating, T)) - { - return Array!Real.equals(*cast(Real[]*)p1, *cast(Real[]*)p2); - } - else + static if (is(T == Base)) + override size_t getHash(scope const void* p) @trusted const { - import core.stdc.string; - auto s1 = *cast(T[]*)p1; - auto s2 = *cast(T[]*)p2; - return s1.length == s2.length && - memcmp(s1.ptr, s2.ptr, s1.length) == 0; + static if (__traits(isFloating, T)) + return Array!T.hashOf(*cast(T[]*)p); + else + return hashOf(*cast(const T[]*) p); } - } - override int compare(in void* p1, in void* p2) const - { - static if (__traits(isFloating, T)) + static if (is(T == Base)) + override bool equals(in void* p1, in void* p2) const { - return Array!Real.compare(*cast(Real[]*)p1, *cast(Real[]*)p2); + static if (__traits(isFloating, T)) + { + return Array!T.equals(*cast(T[]*)p1, *cast(T[]*)p2); + } + else + { + import core.stdc.string; + auto s1 = *cast(T[]*)p1; + auto s2 = *cast(T[]*)p2; + return s1.length == s2.length && + memcmp(s1.ptr, s2.ptr, s1.length) == 0; + } } - else - { - auto s1 = *cast(T[]*)p1; - auto s2 = *cast(T[]*)p2; - auto len = s1.length; - if (s2.length < len) - len = s2.length; - for (size_t u = 0; u < len; u++) + static if (is(T == Base) || (__traits(isIntegral, T) && T.max != Base.max)) + override int compare(in void* p1, in void* p2) const + { + static if (__traits(isFloating, T)) { - if (int result = (s1[u] > s2[u]) - (s1[u] < s2[u])) - return result; + return Array!T.compare(*cast(T[]*)p1, *cast(T[]*)p2); + } + else + { + auto s1 = *cast(T[]*)p1; + auto s2 = *cast(T[]*)p2; + auto len = s1.length; + + if (s2.length < len) + len = s2.length; + for (size_t u = 0; u < len; u++) + { + if (int result = (s1[u] > s2[u]) - (s1[u] < s2[u])) + return result; + } + return (s1.length > s2.length) - (s1.length < s2.length); } - return (s1.length > s2.length) - (s1.length < s2.length); } - } override @property inout(TypeInfo) next() inout { @@ -521,18 +528,18 @@ class TypeInfo_v : TypeInfoGeneric!ubyte } // All integrals. +class TypeInfo_h : TypeInfoGeneric!ubyte {} class TypeInfo_b : TypeInfoGeneric!(bool, ubyte) {} -class TypeInfo_g : TypeInfoGeneric!byte {} -class TypeInfo_h : TypeInfoGeneric!(ubyte, byte) {} +class TypeInfo_g : TypeInfoGeneric!(byte, ubyte) {} class TypeInfo_a : TypeInfoGeneric!(char, ubyte) {} +class TypeInfo_t : TypeInfoGeneric!ushort {} +class TypeInfo_s : TypeInfoGeneric!(short, ushort) {} class TypeInfo_u : TypeInfoGeneric!(wchar, ushort) {} class TypeInfo_w : TypeInfoGeneric!(dchar, uint) {} -class TypeInfo_s : TypeInfoGeneric!short {} -class TypeInfo_t : TypeInfoGeneric!(ushort, short) {} -class TypeInfo_i : TypeInfoGeneric!int {} -class TypeInfo_k : TypeInfoGeneric!(uint, int) {} -class TypeInfo_l : TypeInfoGeneric!long {} -class TypeInfo_m : TypeInfoGeneric!(ulong, long) {} +class TypeInfo_k : TypeInfoGeneric!uint {} +class TypeInfo_i : TypeInfoGeneric!(int, uint) {} +class TypeInfo_m : TypeInfoGeneric!ulong {} +class TypeInfo_l : TypeInfoGeneric!(long, ulong) {} static if (is(cent)) class TypeInfo_zi : TypeInfoGeneric!cent {} static if (is(ucent)) class TypeInfo_zk : TypeInfoGeneric!ucent {} @@ -597,24 +604,24 @@ static if (__traits(hasMember, TypeInfo, "argTypes")) } // Arrays of all integrals. -class TypeInfo_Ab : TypeInfoArrayGeneric!bool {} -class TypeInfo_Ag : TypeInfoArrayGeneric!byte {} class TypeInfo_Ah : TypeInfoArrayGeneric!ubyte {} -class TypeInfo_Aa : TypeInfoArrayGeneric!char {} +class TypeInfo_Ab : TypeInfoArrayGeneric!(bool, ubyte) {} +class TypeInfo_Ag : TypeInfoArrayGeneric!(byte, ubyte) {} +class TypeInfo_Aa : TypeInfoArrayGeneric!(char, ubyte) {} class TypeInfo_Axa : TypeInfoArrayGeneric!(const char) {} class TypeInfo_Aya : TypeInfoArrayGeneric!(immutable char) { // Must override this, otherwise "string" is returned. override string toString() const { return "immutable(char)[]"; } } -class TypeInfo_As : TypeInfoArrayGeneric!short {} class TypeInfo_At : TypeInfoArrayGeneric!ushort {} -class TypeInfo_Au : TypeInfoArrayGeneric!wchar {} -class TypeInfo_Ai : TypeInfoArrayGeneric!int {} +class TypeInfo_As : TypeInfoArrayGeneric!(short, ushort) {} +class TypeInfo_Au : TypeInfoArrayGeneric!(wchar, ushort) {} class TypeInfo_Ak : TypeInfoArrayGeneric!uint {} -class TypeInfo_Aw : TypeInfoArrayGeneric!dchar {} -class TypeInfo_Al : TypeInfoArrayGeneric!long {} +class TypeInfo_Ai : TypeInfoArrayGeneric!(int, uint) {} +class TypeInfo_Aw : TypeInfoArrayGeneric!(dchar, uint) {} class TypeInfo_Am : TypeInfoArrayGeneric!ulong {} +class TypeInfo_Al : TypeInfoArrayGeneric!(long, ulong) {} private extern (C) void[] _adSort(void[] a, TypeInfo ti); @@ -656,11 +663,11 @@ unittest // Arrays of all floating point types. class TypeInfo_Af : TypeInfoArrayGeneric!float {} -class TypeInfo_Ao : TypeInfoArrayGeneric!ifloat {} +class TypeInfo_Ao : TypeInfoArrayGeneric!(ifloat, float) {} class TypeInfo_Ad : TypeInfoArrayGeneric!double {} -class TypeInfo_Ap : TypeInfoArrayGeneric!idouble {} +class TypeInfo_Ap : TypeInfoArrayGeneric!(idouble, double) {} class TypeInfo_Ae : TypeInfoArrayGeneric!real {} -class TypeInfo_Aj : TypeInfoArrayGeneric!ireal {} +class TypeInfo_Aj : TypeInfoArrayGeneric!(ireal, real) {} class TypeInfo_Aq : TypeInfoArrayGeneric!cfloat {} class TypeInfo_Ar : TypeInfoArrayGeneric!cdouble {} class TypeInfo_Ac : TypeInfoArrayGeneric!creal {} From 74071a9acc82c55579791da421389a04c7a64495 Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Sun, 6 Sep 2020 18:20:29 -0400 Subject: [PATCH 17/18] Fix bug revealed by undeaD unittests --- src/rt/util/typeinfo.d | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rt/util/typeinfo.d b/src/rt/util/typeinfo.d index 57d3f08cc2..e6c389fa29 100644 --- a/src/rt/util/typeinfo.d +++ b/src/rt/util/typeinfo.d @@ -375,8 +375,8 @@ if (T.sizeof == Base.sizeof && T.alignof == Base.alignof) } static if (is(T == Base)) - static if (is(immutable T == immutable real) && T.mant_dig != 64) // exclude 80-bit X87 - // passed in SIMD register + static if (__traits(isFloating, T) && T.mant_dig != 64) + // FP types except 80-bit X87 are passed in SIMD register. override @property uint flags() const { return 2; } } From 1aa63364f9d88afaeaaa848a0f29f28cadcc5e6a Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Sun, 6 Sep 2020 18:24:21 -0400 Subject: [PATCH 18/18] Review --- src/rt/util/typeinfo.d | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/rt/util/typeinfo.d b/src/rt/util/typeinfo.d index e6c389fa29..0a13a7513c 100644 --- a/src/rt/util/typeinfo.d +++ b/src/rt/util/typeinfo.d @@ -409,7 +409,7 @@ unittest } } -/*¡ +/* TypeInfo information for arrays of built-in types. A `Base` type may be specified, which must be a type with the same layout, alignment, hashing, and @@ -623,7 +623,8 @@ class TypeInfo_Aw : TypeInfoArrayGeneric!(dchar, uint) {} class TypeInfo_Am : TypeInfoArrayGeneric!ulong {} class TypeInfo_Al : TypeInfoArrayGeneric!(long, ulong) {} -private extern (C) void[] _adSort(void[] a, TypeInfo ti); +version (CoreUnittest) + private extern (C) void[] _adSort(void[] a, TypeInfo ti); unittest {