Skip to content

Commit

Permalink
Add support for DMD 2.094 -preview=in switch
Browse files Browse the repository at this point in the history
This will allow users to use -preview=in as soon as it's released.
  • Loading branch information
Geod24 committed Aug 31, 2020
1 parent 2583421 commit 9a68552
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
15 changes: 14 additions & 1 deletion source/vibe/core/file.d
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,20 @@ struct DirectoryWatcher { // TODO: avoid all those heap allocations!
LocalManualEvent changeEvent;
shared(NativeEventDriver) driver;

void onChange(WatcherID, in ref FileChange change)
// Support for `-preview=in`
static if (!is(typeof(mixin(q{(in ref int a) => a}))))
{
void onChange(WatcherID id, in FileChange change) nothrow {
this.onChangeImpl(id, change);
}
} else {
mixin(q{
void onChange(WatcherID id, in ref FileChange change) nothrow {
this.onChangeImpl(id, change);
}});
}

void onChangeImpl(WatcherID, const scope ref FileChange change)
nothrow {
DirectoryChangeType ct;
final switch (change.kind) {
Expand Down
11 changes: 9 additions & 2 deletions source/vibe/core/task.d
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,15 @@ struct Task {
return app.data;
}

bool opEquals(in ref Task other) const @safe nothrow { return m_fiber is other.m_fiber && m_taskCounter == other.m_taskCounter; }
bool opEquals(in Task other) const @safe nothrow { return m_fiber is other.m_fiber && m_taskCounter == other.m_taskCounter; }
// Remove me when `-preview=in` becomes the default
static if (is(typeof(mixin(q{(in ref int a) => a}))))
mixin(q{
bool opEquals(in ref Task other) const @safe nothrow {
return m_fiber is other.m_fiber && m_taskCounter == other.m_taskCounter;
}});
bool opEquals(in Task other) const @safe nothrow {
return m_fiber is other.m_fiber && m_taskCounter == other.m_taskCounter;
}
}


Expand Down
7 changes: 4 additions & 3 deletions source/vibe/internal/hashmap.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ struct DefaultHashMapTraits(Key) {
static if (is(Key == class)) return a is b;
else return a == b;
}
static size_t hashOf(in ref Key k)

static size_t hashOf(const scope ref Key k)
{
static if (is(Key == class) && &Key.toHash == &Object.toHash)
return cast(size_t)cast(void*)k;
Expand All @@ -31,11 +32,11 @@ struct DefaultHashMapTraits(Key) {
else {
// evil casts to be able to get the most basic operations of
// HashMap nothrow and @nogc
static size_t hashWrapper(in ref Key k) {
static size_t hashWrapper(scope const ref Key k) {
static typeinfo = typeid(Key);
return typeinfo.getHash(&k);
}
static @nogc nothrow size_t properlyTypedWrapper(in ref Key k) { return 0; }
static @nogc nothrow size_t properlyTypedWrapper(scope const ref Key k) { return 0; }
return () @trusted { return (cast(typeof(&properlyTypedWrapper))&hashWrapper)(k); } ();
}
}
Expand Down

0 comments on commit 9a68552

Please sign in to comment.