Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 13cd2c7

Browse files
committed
make use of traits(getPointerBitmap)
avoid recursive Unqual
1 parent e10438f commit 13cd2c7

File tree

3 files changed

+61
-31
lines changed

3 files changed

+61
-31
lines changed

src/gc/rtinfo.d

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
module gc.rtinfo;
1010

11-
// version = RTInfoPRINTF; // want some compile time debug output?
11+
//version = RTInfoPRINTF; // want some compile time debug output?
1212
enum bool RTInfoMark__Monitor = false; // is __monitor GC allocated?
1313
enum bool supportTypedef = false; // causes deprecation warning
1414

@@ -17,28 +17,33 @@ enum bool supportTypedef = false; // causes deprecation warning
1717
// supposed to trigger @@@BUG1308@@@, see std.traits.Unqual)
1818
template Unqual(T)
1919
{
20-
static if (is(T U == immutable U)) alias Unqual = Unqual!U;
21-
else static if (is(T U == shared inout const U)) alias Unqual = Unqual!U;
22-
else static if (is(T U == shared inout U)) alias Unqual = Unqual!U;
23-
else static if (is(T U == shared const U)) alias Unqual = Unqual!U;
24-
else static if (is(T U == shared U)) alias Unqual = Unqual!U;
25-
else static if (is(T U == inout const U)) alias Unqual = Unqual!U;
26-
else static if (is(T U == inout U)) alias Unqual = Unqual!U;
27-
else static if (is(T U == const U)) alias Unqual = Unqual!U;
28-
else static if (is(T U == enum)) alias Unqual = Unqual!U;
20+
static if (is(T U == immutable U)) alias Unqual = Unenum!U;
21+
else static if (is(T U == shared inout const U)) alias Unqual = Unenum!U;
22+
else static if (is(T U == shared inout U)) alias Unqual = Unenum!U;
23+
else static if (is(T U == shared const U)) alias Unqual = Unenum!U;
24+
else static if (is(T U == shared U)) alias Unqual = Unenum!U;
25+
else static if (is(T U == inout const U)) alias Unqual = Unenum!U;
26+
else static if (is(T U == inout U)) alias Unqual = Unenum!U;
27+
else static if (is(T U == const U)) alias Unqual = Unenum!U;
28+
else alias Unqual = Unenum!T;
29+
}
30+
31+
template Unenum(T)
32+
{
33+
static if (is(T U == enum)) alias Unenum = U;
2934
else
3035
{
3136
static if(supportTypedef)
3237
{
3338
static if (mixin("is(T U == typedef)"))
3439
{
35-
alias Unqual = Unqual!U;
40+
alias Unenum = Unenum!U;
3641
}
3742
else
38-
alias Unqual = T;
43+
alias Unenum = T;
3944
}
4045
else
41-
alias Unqual = T;
46+
alias Unenum = T;
4247
}
4348
}
4449

src/object.di

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
*/
1313
module object;
1414

15-
private import gc.rtinfo;
16-
17-
enum void* rtinfoNoPointers = null;
18-
enum void* rtinfoHasPointers = cast(void*)1;
19-
2015
private
2116
{
2217
extern(C) void rt_finalize(void *ptr, bool det=true);
@@ -656,10 +651,29 @@ bool _xopCmp(in void* ptr, in void* ptr);
656651
void __ctfeWrite(T...)(auto ref T) {}
657652
void __ctfeWriteln(T...)(auto ref T values) { __ctfeWrite(values, "\n"); }
658653

659-
template RTInfo(T)
654+
///////////////////////////////////////
655+
private enum hasTraitPointerBitmap = __traits(compiles, __traits(getPointerBitmap, int));
656+
657+
enum void* rtinfoNoPointers = null;
658+
enum void* rtinfoHasPointers = cast(void*)1;
659+
660+
static if (hasTraitPointerBitmap)
660661
{
661-
enum RTInfo = gc.rtinfo.RTInfoImpl!T;
662+
template RTInfo(T)
663+
{
664+
enum RTInfo = __traits(getPointerBitmap,T).ptr;
665+
}
666+
}
667+
else
668+
{
669+
import gc.rtinfo;
670+
671+
template RTInfo(T)
672+
{
673+
enum RTInfo = gc.rtinfo.RTInfoImpl!T;
674+
}
662675
}
676+
///////////////////////////////////////
663677

664678
/// Provide the .dup array property.
665679
@property auto dup(T)(T[] a)

src/object_.d

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,6 @@ private
3535
extern (C) void rt_finalize(void *data, bool det=true);
3636
}
3737

38-
import gc.rtinfo;
39-
40-
/**
41-
* shortcuts for the precise GC, also generated by the compiler
42-
* used instead of the actual pointer bitmap
43-
*/
44-
enum void* rtinfoNoPointers = null;
45-
enum void* rtinfoHasPointers = cast(void*)1;
46-
4738
// NOTE: For some reason, this declaration method doesn't work
4839
// in this particular file (and this file only). It must
4940
// be a DMD thing.
@@ -2795,11 +2786,31 @@ bool _xopCmp(in void*, in void*)
27952786
* Create RTInfo for type T
27962787
*/
27972788

2798-
template RTInfo(T)
2789+
private enum hasTraitPointerBitmap = __traits(compiles, __traits(getPointerBitmap, int));
2790+
2791+
/**
2792+
* shortcuts for the precise GC, also generated by the compiler
2793+
* used instead of the actual pointer bitmap
2794+
*/
2795+
enum void* rtinfoNoPointers = null;
2796+
enum void* rtinfoHasPointers = cast(void*)1;
2797+
2798+
static if (hasTraitPointerBitmap)
27992799
{
2800-
enum RTInfo = gc.rtinfo.RTInfoImpl!T;
2800+
template RTInfo(T)
2801+
{
2802+
enum RTInfo = __traits(getPointerBitmap,T).ptr;
2803+
}
28012804
}
2805+
else
2806+
{
2807+
import gc.rtinfo;
28022808

2809+
template RTInfo(T)
2810+
{
2811+
enum RTInfo = gc.rtinfo.RTInfoImpl!T;
2812+
}
2813+
}
28032814

28042815
// Helper functions
28052816

0 commit comments

Comments
 (0)