Add support for DMD 2.094 -preview=in switch

This will allow users to use -preview=in as soon as it's released.
This commit is contained in:
Geod24 2020-08-31 11:17:55 +09:00 committed by Mathias LANG
parent 258342163f
commit 9a685523f9
3 changed files with 27 additions and 6 deletions

View file

@ -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) {

View file

@ -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;
}
}

View file

@ -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); } ();
}
}