Commit 50b82b1a authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Fix a DistributedMutex build failure under MSVC

Summary:
[Folly] Fix a `DistributedMutex` build failure under MSVC, which does not have great support for whatever is happening here, which in this case is a case of variable templates with SFINAE.

Not much information to go on, so this is a best guess:
```
folly/synchronization/DistributedMutex-inl.h(563): fatal error C1001: An internal error has occurred in the compiler.
```

Reviewed By: aary

Differential Revision: D15837884

fbshipit-source-id: 8da993cc27373f86728963d2112812c15a4f34ea
parent 81798e75
...@@ -547,20 +547,25 @@ class TaskWithBigReturnValue { ...@@ -547,20 +547,25 @@ class TaskWithBigReturnValue {
static_assert(sizeof(Waiter::storage_) < sizeof(ReturnType), ""); static_assert(sizeof(Waiter::storage_) < sizeof(ReturnType), "");
}; };
template <typename T, bool>
struct Sizeof_;
template <typename T>
struct Sizeof_<T, false> : index_constant<sizeof(T)> {};
template <typename T>
struct Sizeof_<T, true> : index_constant<0> {};
template <typename T>
struct Sizeof : Sizeof_<T, std::is_void<T>::value> {};
// we need to use std::integral_constant::value here as opposed to // we need to use std::integral_constant::value here as opposed to
// std::integral_constant::operator T() because MSVC errors out with the // std::integral_constant::operator T() because MSVC errors out with the
// implicit conversion // implicit conversion
template <typename T, typename = std::enable_if_t<true>>
constexpr const auto Sizeof = sizeof(T);
template <typename T>
constexpr const auto Sizeof<T, std::enable_if_t<std::is_void<T>::value>> = 0;
template <typename Func, typename Waiter> template <typename Func, typename Waiter>
using CoalescedTask = std::conditional_t< using CoalescedTask = std::conditional_t<
std::is_void<folly::invoke_result_t<const Func&>>::value, std::is_void<folly::invoke_result_t<const Func&>>::value,
TaskWithoutCoalesce<Func, Waiter>, TaskWithoutCoalesce<Func, Waiter>,
std::conditional_t< std::conditional_t<
Sizeof<folly::invoke_result_t<const Func&>> <= sizeof(Waiter::storage_), Sizeof<folly::invoke_result_t<const Func&>>::value <=
sizeof(Waiter::storage_),
TaskWithCoalesce<Func, Waiter>, TaskWithCoalesce<Func, Waiter>,
TaskWithBigReturnValue<Func, Waiter>>>; TaskWithBigReturnValue<Func, Waiter>>>;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment