From 89426d19bc24c57e5fddfd8e836f4f413b48db9c Mon Sep 17 00:00:00 2001 From: Ilia Ki Date: Wed, 2 Aug 2023 21:08:40 +0700 Subject: [PATCH] update for newer compilers --- source/mir/algebraic.d | 9 +++++---- source/mir/conv.d | 3 ++- source/mir/exception.d | 26 +++++++++++++++++++++++++- source/mir/internal/meta.d | 17 +++++++++++++---- source/mir/reflection.d | 20 ++++++++++++++++++-- 5 files changed, 63 insertions(+), 12 deletions(-) diff --git a/source/mir/algebraic.d b/source/mir/algebraic.d index a0d9c9a..8c01ab8 100644 --- a/source/mir/algebraic.d +++ b/source/mir/algebraic.d @@ -122,6 +122,7 @@ module mir.algebraic; import mir.internal.meta; import mir.functional: naryFun; +import mir.exception: toMutable; /++ The attribute is used to define a permanent member field in an anlgebraic type. @@ -1759,7 +1760,7 @@ struct Algebraic(T__...) import mir.utility: _expect; if (_expect(!identifier__, false)) { - throw variantNullException; + throw variantNullException.toMutable; } static if (AllowedTypes.length != 2) { @@ -1976,7 +1977,7 @@ struct Algebraic(T__...) return Ret(trustedGet!T); } default: - throw variantMemberException; + throw variantMemberException.toMutable; } } } @@ -2124,7 +2125,7 @@ struct Algebraic(T__...) { if (_expect(i != identifier__, false)) { - throw variantException; + throw variantException.toMutable; } } return trustedGet!T; @@ -4022,7 +4023,7 @@ private noreturn throwMe(T...)(auto ref T args) { enum simpleThrow = false; static if (simpleThrow) { - throw args[0]; + throw args[0].toMutable; } else { diff --git a/source/mir/conv.d b/source/mir/conv.d index 5d6b199..d2874ea 100644 --- a/source/mir/conv.d +++ b/source/mir/conv.d @@ -6,6 +6,7 @@ Authors: Ilia Ki +/ module mir.conv; +import mir.exception: toMutable; public import core.lifetime: emplace; import std.traits; @@ -71,7 +72,7 @@ template to(T) version (D_Exceptions) { static immutable Exception exc = new Exception(msg); - throw exc; + throw exc.toMutable; } else { diff --git a/source/mir/exception.d b/source/mir/exception.d index c69cbf1..3c220c6 100644 --- a/source/mir/exception.d +++ b/source/mir/exception.d @@ -20,6 +20,30 @@ package template staticException(string fmt, string file, int line) static immutable staticException = new Exception(fmt, file, line); } +@trusted pure nothrow @nogc +Exception toMutable()(immutable Exception e) +{ + return cast() e; +} + +@trusted pure nothrow @nogc +Error toMutable()(immutable Error e) +{ + return cast() e; +} + +@trusted pure nothrow @nogc +Exception toMutable()(const Exception e) +{ + return cast() e; +} + +@trusted pure nothrow @nogc +Error toMutable()(const Error e) +{ + return cast() e; +} + /// auto ref enforce(string fmt, string file = __FILE__, int line = __LINE__, Expr)(scope auto return ref Expr arg) @trusted { @@ -36,7 +60,7 @@ auto ref enforce(string fmt, string file = __FILE__, int line = __LINE__, Expr)( if (_expect(cast(bool)arg, true)) return forward!arg; } - throw staticException!(fmt, file, line); + throw staticException!(fmt, file, line).toMutable; } /// diff --git a/source/mir/internal/meta.d b/source/mir/internal/meta.d index 8fcb712..ee4529e 100644 --- a/source/mir/internal/meta.d +++ b/source/mir/internal/meta.d @@ -265,21 +265,30 @@ template getUDAs(T, string member, alias attribute) import std.meta : Filter, AliasSeq, staticMap; private __gshared T* aggregate; static if (!__traits(hasMember, T, member)) + { alias getUDAs = AliasSeq!(); + } else - static if (!__traits(compiles, __traits(getMember, *aggregate, member))) + static if (is(T == union) && !__traits(compiles, __traits(getMember, aggregate, member))) + { + alias getUDAs = AliasSeq!(); + } else static if (AliasSeq!(__traits(getMember, T, member)).length != 1) + { alias getUDAs = AliasSeq!(); + } else - static if (__traits(getOverloads, T, member).length > 1) + static if (__traits(getOverloads, T, member, true).length >= 1) { alias getUDAsImpl(alias overload) = Filter!(isDesiredUDA!attribute, autoGetUDAs!overload); - alias getUDAs = staticMap!(getUDAsImpl, __traits(getOverloads, T, member)); + alias getUDAs = staticMap!(getUDAsImpl, __traits(getOverloads, T, member, true)); } else - alias getUDAs = Filter!(isDesiredUDA!attribute, __traits(getAttributes, __traits(getMember, *aggregate, member))); + { + alias getUDAs = Filter!(isDesiredUDA!attribute, __traits(getAttributes, __traits(getMember, T, member))); + } } /++ diff --git a/source/mir/reflection.d b/source/mir/reflection.d index df2f5d0..22411a8 100644 --- a/source/mir/reflection.d +++ b/source/mir/reflection.d @@ -11,6 +11,7 @@ import std.meta; import std.traits: Parameters, isSomeFunction, FunctionAttribute, functionAttributes, EnumMembers, isAggregateType; import mir.internal.meta: hasUDA, getUDAs; import mir.functional: Tuple; +import mir.exception: toMutable; deprecated package alias isSomeStruct = isAggregateType; @@ -422,6 +423,21 @@ template getUDA(alias symbol, alias attribute) } } +/// ditto +template getUDA(T, string member, alias attribute) +{ + private alias all = getUDAs!(T, member, attribute); + static if (all.length != 1) + static assert(0, "Exactly one " ~ attribute.stringof ~ " attribute is required, " ~ "got " ~ all.length.stringof); + else + { + static if (is(typeof(all[0]))) + enum getUDA = all[0]; + else + alias getUDA = all[0]; + } +} + /++ Checks if T has a field member. +/ @@ -605,7 +621,7 @@ Note: The implementation ignores templates. template getSetters(T, string member) { static if (__traits(hasMember, T, member)) - alias getSetters = Filter!(hasSingleArgument, Filter!(isPropertyImpl, __traits(getOverloads, T, member))); + alias getSetters = Filter!(hasSingleArgument, Filter!(isPropertyImpl, __traits(getOverloads, T, member, true))); else alias getSetters = AliasSeq!(); } @@ -897,7 +913,7 @@ private template isGetter(T, string member) { static if (isSomeFunction!(__traits(getMember, *aggregate, member))) { - enum bool isGetter = Filter!(hasZeroArguments, Filter!(isPropertyImpl, __traits(getOverloads, T, member))).length == 1; + enum bool isGetter = Filter!(hasZeroArguments, Filter!(isPropertyImpl, __traits(getOverloads, T, member, true))).length == 1; } else {