[WTF] Add Invocable concept for callbacks and start adoption
ed879d3520c048a360bf7b520799f149a4283e66
[WTF] Add Invocable concept for callbacks and start adoption https://bugs.webkit.org/show_bug.cgi?id=275398 rdar://129668606 Reviewed by NOBODY (OOPS!). Right now in WebKit if you want to have a callback the standard practice is to write your function as: `template<typename Functor> foo(const Functor& callback)` or `foo(const auto& callback)` this tends to make it unclear what the expected signature of the callback is. Now that we have concepts it would have been nice to do something like: `foo(const std::invocable<...> auto& callback)` however that doesn't provide a clean way to declare the return type, as far as I could tell. This patch adds a new concept to WTF, which should, make this a bit cleaner, `Invocable`. Invocable can be used like the following: `foo(const Invocable<T(U, const V&, ...)> auto& callback)` This allows us to use function declaration like syntax to tell folks what type of callback we're expecting. In the process of adding Invocable concepts to arguments there were two other notable changes: 1) HashTable/Map/Set took functions by r-value reference, which seemed weird so I tried changing it. I then noticed that a lot of users of `ensure` were passing lambdas that capture variables by copy rather than reference. Since `ensure`'s use of the lambda is scoped to the call there's no reason to copy data in. 2) the HashTranslator versions of add now take a callback rather than a arbitrary r-value reference type. This makes the logic of the code a bit easier to follow and allows adding invocable concepts. Since the new wrapper lambdas are marked ALWAYS_INLINE_LAMBDA there shouldn't be any performance overhead. * Source/JavaScriptCore/b3/B3LowerToAir.cpp: * Source/JavaScriptCore/dfg/DFGTierUpCheckInjectionPhase.cpp: (JSC::DFG::TierUpCheckInjectionPhase::run): * Source/WTF/wtf/FixedVector.h: * Source/WTF/wtf/FunctionTraits.h: * Source/WTF/wtf/HashMap.h: (WTF::HashMapTranslator::hash): (WTF::HashMapTranslator::equal): (WTF::HashMapTranslator::translate): (WTF::HashMapEnsureTranslator::hash): (WTF::HashMapEnsureTranslator::equal): (WTF::HashMapEnsureTranslator::translate): (WTF::HashMapTranslatorAdapter::hash): (WTF::HashMapTranslatorAdapter::equal): (WTF::HashMapTranslatorAdapter::translate): (WTF::HashMapEnsureTranslatorAdapter::hash): (WTF::HashMapEnsureTranslatorAdapter::equal): (WTF::HashMapEnsureTranslatorAdapter::translate): (WTF::TableTraitsArg>::inlineAdd): (WTF::TableTraitsArg>::inlineEnsure): (WTF::TableTraitsArg>::ensure): (WTF::TableTraitsArg>::add): (WTF::Y>::removeIf): * Source/WTF/wtf/HashSet.h: (WTF::HashSetTranslator::hash): (WTF::HashSetTranslator::equal): (WTF::HashSetTranslator::translate): (WTF::HashSetTranslatorAdapter::hash): (WTF::HashSetTranslatorAdapter::equal): (WTF::HashSetTranslatorAdapter::translate): (WTF::HashSetEnsureTranslatorAdaptor::hash): (WTF::HashSetEnsureTranslatorAdaptor::equal): (WTF::HashSetEnsureTranslatorAdaptor::translate): (WTF::TableTraits>::ensure): (WTF::TableTraits>::add): (WTF::W>::removeIf): * Source/WTF/wtf/HashTable.h: (WTF::IdentityHashTranslator::hash): (WTF::IdentityHashTranslator::equal): (WTF::IdentityHashTranslator::translate): (WTF::HashTable::add): (WTF::KeyTraits>::addUniqueForInitialization): (WTF::KeyTraits>::add): (WTF::KeyTraits>::addPassingHashCode): (WTF::KeyTraits>::HashTable): * Source/WTF/wtf/ListHashSet.h: (WTF::U>::add): (WTF::U>::appendOrMoveToLast): (WTF::U>::prependOrMoveToFirst): (WTF::U>::insertBefore): * Source/WTF/wtf/LocklessBag.h: * Source/WTF/wtf/PriorityQueue.h: * Source/WTF/wtf/RobinHoodHashTable.h: (WTF::RobinHoodHashTable::add): (WTF::SizePolicy>::add): (WTF::SizePolicy>::addPassingHashCode): * Source/WTF/wtf/StdLibExtras.h: (WTF::requires): * Source/WTF/wtf/TinyPtrSet.h: (WTF::TinyPtrSet::forEach const): (WTF::TinyPtrSet::genericFilter): * Source/WTF/wtf/Vector.h: (WTF::Vector::containsIf const): (WTF::Malloc>::contains const): (WTF::Malloc>::findIf const): (WTF::Malloc>::find const): (WTF::Malloc>::reverseFind const): (WTF::Malloc>::reverseFindIf const): (WTF::Malloc>::appendIfNotContains): (WTF::Malloc>::appendUsingFunctor): (WTF::Malloc>::removeFirst): (WTF::template<Signature<bool): (WTF::Malloc>::removeLast): (WTF::Malloc>::removeLastMatching): (WTF::Malloc>::removeAll): (WTF::Malloc>::map const): (WTF:: const const): (WTF::Malloc>::removeFirstMatching): Deleted. (WTF::Malloc>::removeAllMatching): Deleted. (WTF::Malloc>::map const const): Deleted. (WTF::Malloc>::map const const const): Deleted. * Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp: (WebCore::LibWebRTCMediaEndpoint::mediaStreamFromRTCStreamId): * Source/WebCore/platform/xr/openxr/OpenXRSwapchain.cpp: (PlatformXR::OpenXRSwapchain::create): * Source/WebCore/svg/SVGToOTFFontConversion.cpp: (WebCore::SVGToOTFFontConverter::SVGToOTFFontConverter): * Source/WebCore/workers/service/background-fetch/BackgroundFetchEngine.cpp: (WebCore::BackgroundFetchEngine::startBackgroundFetch): * Source/WebCore/workers/service/background-fetch/BackgroundFetchManager.cpp: (WebCore::BackgroundFetchManager::backgroundFetchRegistrationInstance): * Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp: (WebKit::GPUConnectionToWebProcess::createRenderingBackend): (WebKit::GPUConnectionToWebProcess::createGraphicsContextGL): (WebKit::GPUConnectionToWebProcess::createGPU): * Source/WebKit/Platform/IPC/ThreadSafeObjectHeap.h: (IPC::HeldType>::add): * Source/WebKit/UIProcess/DeviceIdHashSaltStorage.cpp: (WebKit::DeviceIdHashSaltStorage::loadStorageFromDisk): (WebKit::DeviceIdHashSaltStorage::completeDeviceIdHashSaltForOriginCall): * Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp: (TestWebKitAPI::TEST(WTF_HashMap, Ref_Value)): * Tools/TestWebKitAPI/Tests/WTF/RobinHoodHashMap.cpp: (TestWebKitAPI::TEST(WTF_RobinHoodHashMap, Ref_Value)):
https://github.com/WebKit/WebKit/commit/ed879d3520c048a360bf7b520799f149a4283e66
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/0f483d300ff8a8ea6f2d44c03ec82eabf15f3352)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/782a3124ef0d1f222bb95aac333869fe875b500a)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/5dcf510245399668b3073187cf0876f77221b0c1)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/236733e207d854ad8e10905db3043e9126a180db)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/6e4402dbac84ac245de4d02bf49a3e13a6f586a5)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/5e2c20d4fb2c1c35d0bd16cee40d647ef7e66eb1)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/e2cddce6eab4853f4b0bff02f0a99f7d75518324)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/700f8880fd5b499d000a500cbbb398109ab26386)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/4016f29d2dd0698597f519a04b49babc1d33c4e1)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/d8bf18139245772b8eec71371ac186864c0862ca)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/9c6f5aa410ab2bbb63476f21f42211a052d40257)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/bb79839009495b2de6618ee6006767de5a06d225)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/70930ea2769891d6f7e8e556be74c52f1769a798)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/de47151dba6777b58b7fc3c2c676af9780c0d1ab)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/00ac235dbaadd32290949cc00a84c75cfe4bbe7c)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/e0a80eb8118fdcf3d7fba5bb441d78c2c0ae1a09)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/8b43343cad526c351c473b06035ea36e99490f5a)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/1d294daeb04c859054a5d1dc6977a16b808593e9)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/ed879d3520c048a360bf7b520799f149a4283e66)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/dfaf49ee98e985dffa385bb0ccc6d2a222fd6081)
EWS run on current version of this PR (hash https://github.com/WebKit/WebKit/commit/7db56ebbafd2673b6193b4cfdb7c5bf226464056)
Committed 280952@main (b945d56c49fa): https://commits.webkit.org/280952@main
Reviewed commits have been landed. Closing PR #29744 and removing active labels.
๐งช api-ios