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

Commit 94bd5bc

Browse files
kinkedlang-bot
authored andcommitted
Use new __traits(classInstanceAlignment)
Tackling the druntime part of issue 16508.
1 parent 91d3266 commit 94bd5bc

File tree

5 files changed

+10
-14
lines changed

5 files changed

+10
-14
lines changed

src/core/internal/traits.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ if (Ts.length > 0)
234234
template classInstanceAlignment(T)
235235
if (is(T == class))
236236
{
237-
alias classInstanceAlignment = maxAlignment!(void*, typeof(T.tupleof));
237+
enum classInstanceAlignment = __traits(classInstanceAlignment, T);
238238
}
239239

240240
/// See $(REF hasElaborateMove, std,traits)

src/core/lifetime.d

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,10 @@ Returns: The newly constructed object.
200200
T emplace(T, Args...)(void[] chunk, auto ref Args args)
201201
if (is(T == class))
202202
{
203-
import core.internal.traits : maxAlignment;
204-
205203
enum classSize = __traits(classInstanceSize, T);
206204
assert(chunk.length >= classSize, "chunk size too small.");
207205

208-
enum alignment = maxAlignment!(void*, typeof(T.tupleof));
206+
enum alignment = __traits(classInstanceAlignment, T);
209207
assert((cast(size_t) chunk.ptr) % alignment == 0, "chunk is not aligned.");
210208

211209
return emplace!T(cast(T)(chunk.ptr), forward!args);
@@ -242,9 +240,7 @@ T emplace(T, Args...)(void[] chunk, auto ref Args args)
242240
int virtualGetI() { return i; }
243241
}
244242

245-
import core.internal.traits : classInstanceAlignment;
246-
247-
align(classInstanceAlignment!C) byte[__traits(classInstanceSize, C)] buffer;
243+
align(__traits(classInstanceAlignment, C)) byte[__traits(classInstanceSize, C)] buffer;
248244
C c = emplace!C(buffer[], 42);
249245
assert(c.virtualGetI() == 42);
250246
}
@@ -290,7 +286,8 @@ T emplace(T, Args...)(void[] chunk, auto ref Args args)
290286
}
291287

292288
int var = 6;
293-
align(__conv_EmplaceTestClass.alignof) ubyte[__traits(classInstanceSize, __conv_EmplaceTestClass)] buf;
289+
align(__traits(classInstanceAlignment, __conv_EmplaceTestClass))
290+
ubyte[__traits(classInstanceSize, __conv_EmplaceTestClass)] buf;
294291
auto support = (() @trusted => cast(__conv_EmplaceTestClass)(buf.ptr))();
295292

296293
auto fromRval = emplace!__conv_EmplaceTestClass(support, 1);
@@ -1198,7 +1195,7 @@ pure nothrow @safe /* @nogc */ unittest
11981195
}
11991196
void[] buf;
12001197

1201-
static align(A.alignof) byte[__traits(classInstanceSize, A)] sbuf;
1198+
static align(__traits(classInstanceAlignment, A)) byte[__traits(classInstanceSize, A)] sbuf;
12021199
buf = sbuf[];
12031200
auto a = emplace!A(buf, 55);
12041201
assert(a.x == 55 && a.y == 55);

src/core/thread/osthread.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2002,7 +2002,7 @@ extern (C) void thread_init() @nogc
20022002
}
20032003

20042004
private alias MainThreadStore = void[__traits(classInstanceSize, Thread)];
2005-
package __gshared align(Thread.alignof) MainThreadStore _mainThreadStore;
2005+
package __gshared align(__traits(classInstanceAlignment, Thread)) MainThreadStore _mainThreadStore;
20062006

20072007
/**
20082008
* Terminates the thread module. No other thread routine may be called

src/core/thread/threadbase.d

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ private
7777
{
7878
// Handling unaligned mutexes are not supported on all platforms, so we must
7979
// ensure that the address of all shared data are appropriately aligned.
80-
import core.internal.traits : classInstanceAlignment;
81-
82-
enum mutexAlign = classInstanceAlignment!Mutex;
80+
enum mutexAlign = __traits(classInstanceAlignment, Mutex);
8381
enum mutexClassInstanceSize = __traits(classInstanceSize, Mutex);
8482

8583
alias swapContext = externDFunc!("core.thread.osthread.swapContext", void* function(void*) nothrow @nogc);

test/init_fini/src/custom_gc.d

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ nothrow @nogc:
2626
{
2727
import core.stdc.string : memcpy;
2828

29-
__gshared ubyte[__traits(classInstanceSize, MallocGC)] buf;
29+
__gshared align(__traits(classInstanceAlignment, MallocGC))
30+
ubyte[__traits(classInstanceSize, MallocGC)] buf;
3031

3132
auto init = typeid(MallocGC).initializer();
3233
assert(init.length == buf.length);

0 commit comments

Comments
 (0)