Skip to content

Commit 6f0cc6d

Browse files
snarkmasterfacebook-github-bot
authored andcommitted
Reduce usage of costly-to-compile std::invoke_result_t
Summary: ispeters points out that instantiating `std::invoke_result_t` can quite heavy due to its flexible implementation. yfeldblum authored a folly mimic, which strives to be cheaper. In some places, we can just get away with `decltype(...)` -- primarily to avoid adding another #include. Reviewed By: yfeldblum Differential Revision: D79298082 fbshipit-source-id: 18a5e641e8af40a88249a3993e5661ee34d115fb
1 parent 3cc15ab commit 6f0cc6d

File tree

8 files changed

+13
-17
lines changed

8 files changed

+13
-17
lines changed

third-party/folly/src/folly/channels/ChannelProcessor-inl.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ class ChannelProcessorImpl {
118118

119119
template <
120120
typename Function,
121-
typename ReturnType =
122-
typename std::invoke_result_t<Function>::StorageType>
121+
typename ReturnType = typename invoke_result_t<Function>::StorageType>
123122
static folly::coro::Task<ReturnType> catchNonCoroException(Function func) {
124123
auto result = folly::makeTryWith(std::move(func));
125124
if (result.hasException()) {

third-party/folly/src/folly/coro/GmockHelpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ auto makeCoAction(Fn&& fn) {
115115
std::is_copy_constructible_v<remove_cvref_t<Fn>>,
116116
"Fn should be copyable to allow calling mocked call multiple times.");
117117

118-
using Ret = std::invoke_result_t<remove_cvref_t<Fn>&&>;
118+
using Ret = invoke_result_t<remove_cvref_t<Fn>&&>;
119119
return ::testing::InvokeWithoutArgs(
120120
[fn = std::forward<Fn>(fn)]() mutable -> Ret { return co_invoke(fn); });
121121
}

third-party/folly/src/folly/coro/Synchronized.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,10 @@ class Synchronized : public NonCopyableNonMovable {
190190
}
191191

192192
template <typename FuncT>
193-
using rlock_result_t = std::invoke_result_t<FuncT, ReadLockedPtr>;
193+
using rlock_result_t = invoke_result_t<FuncT, ReadLockedPtr>;
194194

195195
template <typename FuncT>
196-
using wlock_result_t = std::invoke_result_t<FuncT, WriteLockedPtr>;
196+
using wlock_result_t = invoke_result_t<FuncT, WriteLockedPtr>;
197197

198198
template <typename FuncT, typename ReturnT = rlock_result_t<FuncT>>
199199
typename std::enable_if<!is_semi_awaitable_v<ReturnT>, Task<ReturnT>>::type

third-party/folly/src/folly/coro/safe/detail/AsyncClosure.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ auto async_closure_inner_coro_and_storage(auto&& make_inner_coro, BTup& b_tup) {
561561
if constexpr (OnlyGetInnerCoroType) { // Non-evaluated, see (1)
562562
return type_identity<detected_or_t<
563563
void*,
564-
std::invoke_result_t,
564+
invoke_result_t,
565565
decltype(make_inner_coro),
566566
decltype(async_closure_bind_inner_coro_arg<
567567
StorageIs,

third-party/folly/src/folly/coro/safe/test/NowTaskTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ CO_TEST(NowTaskTest, awaitTry) {
258258
#endif
259259
}
260260

261-
// `std::invoke_result_t` cannot pass prvalues -- it invokes a move ctor.
261+
// `invoke_result_t` cannot pass prvalues -- it invokes a move ctor.
262262
template <typename T>
263263
using blockingWait_result_t = decltype(blockingWait(FOLLY_DECLVAL(T)));
264264
template <typename T, typename Res>

third-party/folly/src/folly/lang/bind/Bind.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ template <typename... Args>
430430
constexpr auto in_place_with(
431431
auto make_fn, Args&&... args [[clang::lifetimebound]]) {
432432
return detail::in_place_fn_args<
433-
std::invoke_result_t<decltype(make_fn), Args&&...>,
433+
decltype(make_fn(FOLLY_DECLVAL(Args&&)...)),
434434
decltype(make_fn),
435435
Args...>{std::move(make_fn), static_cast<Args&&>(args)...};
436436
}

third-party/folly/src/folly/observer/detail/Core.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Core : public std::enable_shared_from_this<Core> {
6363
static CreatorContext create(const F& creator) {
6464
CreatorContext context;
6565
context.typeInfo = &typeid(F);
66-
context.invokeResultTypeInfo = &typeid(std::invoke_result_t<F>);
66+
context.invokeResultTypeInfo = &typeid(decltype(FOLLY_DECLVAL(F&&)()));
6767
if constexpr (Has_getNameT_v<F>) {
6868
context.name = creator.getName();
6969
}

third-party/folly/src/folly/result/result.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,10 @@ const non_value_result& dfatal_get_empty_result_error();
278278
const non_value_result& dfatal_get_bad_result_access_error();
279279

280280
template <typename T>
281-
using result_ref_wrap = std::conditional_t< // Reused by `result_generator`
281+
using result_ref_wrap = conditional_t< // Reused by `result_generator`
282282
std::is_rvalue_reference_v<T>,
283283
rvalue_reference_wrapper<std::remove_reference_t<T>>,
284-
std::conditional_t<
284+
conditional_t<
285285
std::is_lvalue_reference_v<T>,
286286
std::reference_wrapper<std::remove_reference_t<T>>,
287287
T>>;
@@ -921,15 +921,12 @@ auto /* implicit */ operator co_await(
921921
/// - `result<>` coroutines catch unhandled exceptions, but can throw due to
922922
/// argument copy/move ctors, or due to `bad_alloc`.
923923
/// - Like all functions, `result<>` non-coroutines let exceptions fly.
924-
template <typename F>
924+
template <typename F, typename RetF = decltype(FOLLY_DECLVAL(F&&)())>
925925
// Wrap the return type of `fn` with `result` unless it already is `result`.
926-
typename std::conditional_t<
927-
is_instantiation_of_v<result, std::invoke_result_t<F>>,
928-
std::invoke_result_t<F>,
929-
result<std::invoke_result_t<F>>>
926+
conditional_t<is_instantiation_of_v<result, RetF>, RetF, result<RetF>>
930927
result_catch_all(F&& fn) noexcept {
931928
try {
932-
if constexpr (std::is_void_v<std::invoke_result_t<F>>) {
929+
if constexpr (std::is_void_v<RetF>) {
933930
static_cast<F&&>(fn)();
934931
return {};
935932
} else {

0 commit comments

Comments
 (0)