From 9a685523f9e8bc5888adb60df3871d2b43c0b81f Mon Sep 17 00:00:00 2001 From: Geod24 Date: Mon, 31 Aug 2020 11:17:55 +0900 Subject: [PATCH] Add support for DMD 2.094 -preview=in switch This will allow users to use -preview=in as soon as it's released. --- source/vibe/core/file.d | 15 ++++++++++++++- source/vibe/core/task.d | 11 +++++++++-- source/vibe/internal/hashmap.d | 7 ++++--- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/source/vibe/core/file.d b/source/vibe/core/file.d index 697f439..bce1f93 100644 --- a/source/vibe/core/file.d +++ b/source/vibe/core/file.d @@ -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) { diff --git a/source/vibe/core/task.d b/source/vibe/core/task.d index ef113e7..9dfbfbc 100644 --- a/source/vibe/core/task.d +++ b/source/vibe/core/task.d @@ -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; + } } diff --git a/source/vibe/internal/hashmap.d b/source/vibe/internal/hashmap.d index d803eb6..b0b427f 100644 --- a/source/vibe/internal/hashmap.d +++ b/source/vibe/internal/hashmap.d @@ -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; @@ -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); } (); } }