From a88bbd6405fa3431e6bfec8616ca4d0aa7a13889 Mon Sep 17 00:00:00 2001 From: Daniel Smith Date: Wed, 15 Jul 2020 23:33:01 +0000 Subject: [PATCH] s/fake/declval/ --- bindings/flow/tester/Tester.actor.cpp | 6 +++--- bindings/flow/tester/Tester.actor.h | 20 ++++++++++-------- fdbclient/RunTransaction.actor.h | 26 +++++++++++++---------- flow/IRandom.h | 9 +++++--- flow/Platform.h | 3 --- flow/ThreadHelper.actor.h | 30 +++++++++++++-------------- flow/actorcompiler/ActorCompiler.cs | 2 +- flow/flow.h | 12 +++++------ flow/genericactors.actor.h | 15 +++++++------- 9 files changed, 64 insertions(+), 59 deletions(-) diff --git a/bindings/flow/tester/Tester.actor.cpp b/bindings/flow/tester/Tester.actor.cpp index a190299747..c98f9c8f4b 100644 --- a/bindings/flow/tester/Tester.actor.cpp +++ b/bindings/flow/tester/Tester.actor.cpp @@ -1365,12 +1365,12 @@ const char* StartThreadFunc::name = "START_THREAD"; REGISTER_INSTRUCTION_FUNC(StartThreadFunc); ACTOR template -Future()(Reference()).getValue())> read(Reference db, - Function func) { +Future()(Reference()).getValue())> read(Reference db, + Function func) { state Reference tr = db->createTransaction(); loop { try { - state decltype(fake()(Reference()).getValue()) result = wait(func(tr)); + state decltype(std::declval()(Reference()).getValue()) result = wait(func(tr)); return result; } catch (Error& e) { wait(tr->onError(e)); diff --git a/bindings/flow/tester/Tester.actor.h b/bindings/flow/tester/Tester.actor.h index 29c7066ac2..6f0596684f 100644 --- a/bindings/flow/tester/Tester.actor.h +++ b/bindings/flow/tester/Tester.actor.h @@ -27,6 +27,8 @@ #pragma once +#include + #include "flow/IDispatched.h" #include "bindings/flow/fdb_flow.h" #include "bindings/flow/IDirectory.h" @@ -57,7 +59,7 @@ struct FlowTesterStack { void push(Future> value) { data.push_back(StackItem(index, value)); } - + void push(Standalone value) { push(Future>(value)); } @@ -86,10 +88,10 @@ struct FlowTesterStack { items.push_back(data.back()); data.pop_back(); count--; - } + } return items; } - + Future> waitAndPop(int count); Future waitAndPop(); @@ -106,7 +108,7 @@ struct FlowTesterStack { struct InstructionData : public ReferenceCounted { bool isDatabase; - bool isSnapshot; + bool isSnapshot; StringRef instruction; Reference tr; @@ -153,7 +155,7 @@ struct DirectoryOrSubspace { return "DirectorySubspace"; } else if(directory.present()) { - return "IDirectory"; + return "IDirectory"; } else if(subspace.present()) { return "Subspace"; @@ -169,10 +171,10 @@ struct DirectoryTesterData { int directoryListIndex; int directoryErrorIndex; - Reference directory() { + Reference directory() { ASSERT(directoryListIndex < directoryList.size()); ASSERT(directoryList[directoryListIndex].directory.present()); - return directoryList[directoryListIndex].directory.get(); + return directoryList[directoryListIndex].directory.get(); } FDB::Subspace* subspace() { @@ -220,10 +222,10 @@ struct FlowTesterData : public ReferenceCounted { std::string tupleToString(FDB::Tuple const& tuple); ACTOR template -Future()().getValue())> executeMutation(Reference instruction, F func) { +Future()().getValue())> executeMutation(Reference instruction, F func) { loop { try { - state decltype(fake()().getValue()) result = wait(func()); + state decltype(std::declval()().getValue()) result = wait(func()); if(instruction->isDatabase) { wait(instruction->tr->commit()); } diff --git a/fdbclient/RunTransaction.actor.h b/fdbclient/RunTransaction.actor.h index 0e79378d39..86b3f6582a 100644 --- a/fdbclient/RunTransaction.actor.h +++ b/fdbclient/RunTransaction.actor.h @@ -27,18 +27,21 @@ #elif !defined(FDBCLIENT_RUNTRANSACTION_ACTOR_H) #define FDBCLIENT_RUNTRANSACTION_ACTOR_H +#include + #include "flow/flow.h" #include "fdbclient/ReadYourWrites.h" #include "flow/actorcompiler.h" // This must be the last #include. -ACTOR template < class Function > -Future()(Reference()).getValue())> -runRYWTransaction(Database cx, Function func) { +ACTOR template +Future()(Reference()).getValue())> runRYWTransaction( + Database cx, Function func) { state Reference tr(new ReadYourWritesTransaction(cx)); loop{ try { // func should be idempodent; otherwise, retry will get undefined result - state decltype( fake()( Reference() ).getValue()) result = wait(func(tr)); + state decltype(std::declval()(Reference()).getValue()) result = + wait(func(tr)); wait(tr->commit()); return result; } @@ -48,13 +51,14 @@ runRYWTransaction(Database cx, Function func) { } } -ACTOR template < class Function > -Future()(Reference()).getValue())> +ACTOR template +Future()(Reference()).getValue())> runRYWTransactionFailIfLocked(Database cx, Function func) { state Reference tr(new ReadYourWritesTransaction(cx)); loop{ try { - state decltype( fake()( Reference() ).getValue()) result = wait(func(tr)); + state decltype(std::declval()(Reference()).getValue()) result = + wait(func(tr)); wait(tr->commit()); return result; } @@ -66,11 +70,11 @@ runRYWTransactionFailIfLocked(Database cx, Function func) { } } -ACTOR template < class Function > -Future()(Reference()).getValue())> -runRYWTransactionNoRetry(Database cx, Function func) { +ACTOR template +Future()(Reference()).getValue())> runRYWTransactionNoRetry( + Database cx, Function func) { state Reference tr(new ReadYourWritesTransaction(cx)); - state decltype(fake()(Reference()).getValue()) result = wait(func(tr)); + state decltype(std::declval()(Reference()).getValue()) result = wait(func(tr)); wait(tr->commit()); return result; } diff --git a/flow/IRandom.h b/flow/IRandom.h index d8bd244990..f33997c36b 100644 --- a/flow/IRandom.h +++ b/flow/IRandom.h @@ -33,6 +33,7 @@ #include #endif #include +#include // Until we move to C++20, we'll need something to take the place of operator<=>. // This is as good a place as any, I guess. @@ -137,7 +138,9 @@ public: // The following functions have fixed implementations for now: template - decltype((fake()[0])) randomChoice( const C& c ) { return c[randomInt(0,(int)c.size())]; } + decltype((std::declval()[0])) randomChoice(const C& c) { + return c[randomInt(0, (int)c.size())]; + } template void randomShuffle( C& container ) { @@ -158,13 +161,13 @@ extern FILE* randLog; // Sets the seed for the deterministic random number generator on the current thread void setThreadLocalDeterministicRandomSeed(uint32_t seed); -// Returns the random number generator that can be seeded. This generator should only +// Returns the random number generator that can be seeded. This generator should only // be used in contexts where the choice to call it is deterministic. // // This generator is only deterministic if given a seed using setThreadLocalDeterministicRandomSeed Reference deterministicRandom(); -// A random number generator that cannot be manually seeded and may be called in +// A random number generator that cannot be manually seeded and may be called in // non-deterministic contexts. Reference nondeterministicRandom(); diff --git a/flow/Platform.h b/flow/Platform.h index eaf84e635c..d670a3041d 100644 --- a/flow/Platform.h +++ b/flow/Platform.h @@ -135,9 +135,6 @@ do { \ #include #endif -// fake() is for use in decltype expressions only - there is no implementation -template T fake(); - // g++ requires that non-dependent names have to be looked up at // template definition, which makes circular dependencies a royal // pain. (For whatever it's worth, g++ appears to be adhering to spec diff --git a/flow/ThreadHelper.actor.h b/flow/ThreadHelper.actor.h index 3744a11754..a7f6392adc 100644 --- a/flow/ThreadHelper.actor.h +++ b/flow/ThreadHelper.actor.h @@ -28,6 +28,8 @@ #elif !defined(FLOW_THREADHELPER_ACTOR_H) #define FLOW_THREADHELPER_ACTOR_H +#include + #include "flow/flow.h" #include "flow/actorcompiler.h" // This must be the last #include. @@ -163,12 +165,12 @@ public: Error error; ThreadCallback *callback; - bool isReady() { + bool isReady() { ThreadSpinLockHolder holder(mutex); return isReadyUnsafe(); } - bool isError() { + bool isError() { ThreadSpinLockHolder holder(mutex); return isErrorUnsafe(); } @@ -180,7 +182,7 @@ public: return error.code(); } - bool canBeSet() { + bool canBeSet() { ThreadSpinLockHolder holder(mutex); return canBeSetUnsafe(); } @@ -203,8 +205,8 @@ public: } ThreadSingleAssignmentVarBase() : status(Unset), callback(NULL), valueReferenceCount(0) {} //, referenceCount(1) {} - ~ThreadSingleAssignmentVarBase() { - this->mutex.assertNotEntered(); + ~ThreadSingleAssignmentVarBase() { + this->mutex.assertNotEntered(); if(callback) callback->destroy(); @@ -229,7 +231,7 @@ public: ASSERT(false); // Promise fulfilled twice } error = err; - status = ErrorSet; + status = ErrorSet; if (!callback) { this->mutex.leave(); return; @@ -461,11 +463,7 @@ public: ThreadFuture(ThreadFuture&& rhs) BOOST_NOEXCEPT : sav(rhs.sav) { rhs.sav = 0; } - ThreadFuture( const T& presentValue ) - : sav(new ThreadSingleAssignmentVar()) - { - sav->send(presentValue); - } + ThreadFuture(const T& presentValue) : sav(new ThreadSingleAssignmentVar()) { sav->send(presentValue); } ThreadFuture( Never ) : sav(new ThreadSingleAssignmentVar()) { @@ -575,14 +573,16 @@ ACTOR template void doOnMainThreadVoid( Future signal, F f, Erro } } -template ThreadFuture< decltype(fake()().getValue()) > onMainThread( F f ) { +template +ThreadFuture()().getValue())> onMainThread(F f) { Promise signal; - auto returnValue = new ThreadSingleAssignmentVar< decltype(fake()().getValue()) >(); + auto returnValue = new ThreadSingleAssignmentVar()().getValue())>(); returnValue->addref(); // For the ThreadFuture we return - Future cancelFuture = doOnMainThread()().getValue()), F>( signal.getFuture(), f, returnValue ); + Future cancelFuture = + doOnMainThread()().getValue()), F>(signal.getFuture(), f, returnValue); returnValue->setCancel( std::move(cancelFuture) ); g_network->onMainThread( std::move(signal), TaskPriority::DefaultOnMainThread ); - return ThreadFuture()().getValue())>( returnValue ); + return ThreadFuture()().getValue())>(returnValue); } template diff --git a/flow/actorcompiler/ActorCompiler.cs b/flow/actorcompiler/ActorCompiler.cs index b02d8d5c0a..7aef82a42e 100644 --- a/flow/actorcompiler/ActorCompiler.cs +++ b/flow/actorcompiler/ActorCompiler.cs @@ -713,7 +713,7 @@ namespace actorcompiler } var iter = getIteratorName(cx); - state.Add(new StateVar { SourceLine = stmt.FirstSourceLine, name = iter, type = "decltype(std::begin(fake<" + container.type + ">()))", initializer = null }); + state.Add(new StateVar { SourceLine = stmt.FirstSourceLine, name = iter, type = "decltype(std::begin(std::declval<" + container.type + ">()))", initializer = null }); var equivalent = new ForStatement { initExpression = iter + " = std::begin(" + stmt.rangeExpression + ")", condExpression = iter + " != std::end(" + stmt.rangeExpression + ")", diff --git a/flow/flow.h b/flow/flow.h index 8890ad13b8..dfa1822ea1 100644 --- a/flow/flow.h +++ b/flow/flow.h @@ -880,20 +880,20 @@ private: }; template -decltype(fake().reply) const& getReplyPromise(Request const& r) { return r.reply; } - - +decltype(std::declval().reply) const& getReplyPromise(Request const& r) { + return r.reply; +} // Neither of these implementations of REPLY_TYPE() works on both MSVC and g++, so... #ifdef __GNUG__ -#define REPLY_TYPE(RequestType) decltype( getReplyPromise( fake() ).getFuture().getValue() ) -//#define REPLY_TYPE(RequestType) decltype( getReplyFuture( fake() ).getValue() ) +#define REPLY_TYPE(RequestType) decltype(getReplyPromise(std::declval()).getFuture().getValue()) +//#define REPLY_TYPE(RequestType) decltype( getReplyFuture( std::declval() ).getValue() ) #else template struct ReplyType { // Doing this calculation directly in the return value declaration for PromiseStream::getReply() // breaks IntelliSense in VS2010; this is a workaround. - typedef decltype(fake().reply.getFuture().getValue()) Type; + typedef decltype(std::declval().reply.getFuture().getValue()) Type; }; template class ReplyPromise; template diff --git a/flow/genericactors.actor.h b/flow/genericactors.actor.h index 728e877dc2..06a6cce72e 100644 --- a/flow/genericactors.actor.h +++ b/flow/genericactors.actor.h @@ -28,6 +28,7 @@ #define GENERICACTORS_ACTOR_H #include +#include #include "flow/flow.h" #include "flow/Knobs.h" @@ -299,9 +300,8 @@ Future storeOrThrow(T &out, Future> what, Error e = key_not_fo } //Waits for a future to be ready, and then applies an asynchronous function to it. -ACTOR template()(fake()).getValue() )> -Future mapAsync(Future what, F actorFunc) -{ +ACTOR template ()(std::declval()).getValue())> +Future mapAsync(Future what, F actorFunc) { T val = wait(what); U ret = wait(actorFunc(val)); return ret; @@ -318,8 +318,8 @@ std::vector>> mapAsync(std::vector> } //maps a stream with an asynchronous function -ACTOR template()(fake()).getValue() )> -Future mapAsync( FutureStream input, F actorFunc, PromiseStream output ) { +ACTOR template ()(std::declval()).getValue())> +Future mapAsync(FutureStream input, F actorFunc, PromiseStream output) { state Deque> futures; loop { @@ -861,7 +861,7 @@ Future ioTimeoutError( Future what, double time ) { Future end = lowPriorityDelay( time ); choose { when( T t = wait( what ) ) { return t; } - when( wait( end ) ) { + when(wait(end)) { Error err = io_timeout(); if(g_network->isSimulated()) { err = err.asInjectedFault(); @@ -1364,8 +1364,7 @@ struct NotifiedInt { NotifiedInt( int64_t val = 0 ) : val(val) {} Future whenAtLeast( int64_t limit ) { - if (val >= limit) - return Void(); + if (val >= limit) return Void(); Promise p; waiting.push( std::make_pair(limit,p) ); return p.getFuture();