Commit 2ee091de authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Move folly/Assume.h

Summary: [Folly] Move `folly/Assume.h` to `folly/lang/`.

Reviewed By: luciang, ot

Differential Revision: D6181983

fbshipit-source-id: 25564bb07daa1a6765651cd919b4778efb931446
parent cbd3e7fb
......@@ -14,58 +14,4 @@
* limitations under the License.
*/
#pragma once
#include <cstdlib>
#include <folly/Portability.h>
namespace folly {
namespace detail {
extern void assume_check(bool cond);
} // namespace detail
/**
* Inform the compiler that the argument can be assumed true. It is
* undefined behavior if the argument is not actually true, so use
* with care.
*
* Implemented as a function instead of a macro because
* __builtin_assume does not evaluate its argument at runtime, so it
* cannot be used with expressions that have side-effects.
*/
FOLLY_ALWAYS_INLINE void assume(bool cond) {
if (kIsDebug) {
detail::assume_check(cond);
} else {
#if defined(__clang__) // Must go first because Clang also defines __GNUC__.
__builtin_assume(cond);
#elif defined(__GNUC__)
if (!cond) { __builtin_unreachable(); }
#elif defined(_MSC_VER)
__assume(cond);
#else
// Do nothing.
#endif
}
}
[[noreturn]] FOLLY_ALWAYS_INLINE void assume_unreachable() {
assume(false);
// Do a bit more to get the compiler to understand
// that this function really will never return.
#if defined(__GNUC__)
__builtin_unreachable();
#elif defined(_MSC_VER)
__assume(0);
#else
// Well, it's better than nothing.
std::abort();
#endif
}
} // namespace folly
#include <folly/lang/Assume.h> // @shim
......@@ -60,8 +60,8 @@
#include <limits>
#include <type_traits>
#include <folly/Assume.h>
#include <folly/Portability.h>
#include <folly/lang/Assume.h>
#include <folly/portability/Builtins.h>
namespace folly {
......
......@@ -29,7 +29,6 @@
#include <typeinfo>
#include <utility>
#include <folly/Assume.h>
#include <folly/CPortability.h>
#include <folly/Demangle.h>
#include <folly/ExceptionString.h>
......@@ -37,6 +36,7 @@
#include <folly/Portability.h>
#include <folly/Traits.h>
#include <folly/Utility.h>
#include <folly/lang/Assume.h>
#ifdef __GNUC__
#pragma GCC diagnostic push
......
......@@ -312,6 +312,7 @@ nobase_follyinclude_HEADERS = \
io/async/test/UndelayedDestruction.h \
io/async/test/Util.h \
json.h \
lang/Assume.h \
Launder.h \
Lazy.h \
LifoSem.h \
......@@ -486,7 +487,6 @@ libfollybase_la_SOURCES = \
Unicode.cpp
libfolly_la_SOURCES = \
Assume.cpp \
ClockGettimeWrappers.cpp \
compression/Compression.cpp \
compression/Zlib.cpp \
......@@ -560,6 +560,7 @@ libfolly_la_SOURCES = \
io/async/ssl/OpenSSLUtils.cpp \
io/async/ssl/SSLErrors.cpp \
json.cpp \
lang/Assume.cpp \
detail/MemoryIdler.cpp \
detail/SocketFastOpen.cpp \
MacAddress.cpp \
......
......@@ -34,12 +34,12 @@
#include <glog/logging.h>
#include <folly/Assume.h>
#include <folly/Conv.h>
#include <folly/Exception.h>
#include <folly/ScopeGuard.h>
#include <folly/String.h>
#include <folly/io/Cursor.h>
#include <folly/lang/Assume.h>
#include <folly/portability/Sockets.h>
#include <folly/portability/Stdlib.h>
#include <folly/portability/SysSyscall.h>
......
......@@ -16,9 +16,9 @@
#include <folly/dynamic.h>
#include <folly/Assume.h>
#include <folly/Format.h>
#include <folly/Hash.h>
#include <folly/lang/Assume.h>
#include <folly/portability/BitsFunctexcept.h>
namespace folly {
......
......@@ -28,7 +28,6 @@
#include <limits>
#include <type_traits>
#include <folly/Assume.h>
#include <folly/Bits.h>
#include <folly/Likely.h>
#include <folly/Portability.h>
......@@ -36,6 +35,7 @@
#include <folly/experimental/CodingDetail.h>
#include <folly/experimental/Instructions.h>
#include <folly/experimental/Select64.h>
#include <folly/lang/Assume.h>
#include <glog/logging.h>
#if !FOLLY_X64
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include <folly/Assume.h>
#include <folly/lang/Assume.h>
#include <glog/logging.h>
......
/*
* Copyright 2017 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <cstdlib>
#include <folly/Portability.h>
namespace folly {
namespace detail {
extern void assume_check(bool cond);
} // namespace detail
/**
* Inform the compiler that the argument can be assumed true. It is
* undefined behavior if the argument is not actually true, so use
* with care.
*
* Implemented as a function instead of a macro because
* __builtin_assume does not evaluate its argument at runtime, so it
* cannot be used with expressions that have side-effects.
*/
FOLLY_ALWAYS_INLINE void assume(bool cond) {
if (kIsDebug) {
detail::assume_check(cond);
} else {
#if defined(__clang__) // Must go first because Clang also defines __GNUC__.
__builtin_assume(cond);
#elif defined(__GNUC__)
if (!cond) { __builtin_unreachable(); }
#elif defined(_MSC_VER)
__assume(cond);
#else
// Do nothing.
#endif
}
}
[[noreturn]] FOLLY_ALWAYS_INLINE void assume_unreachable() {
assume(false);
// Do a bit more to get the compiler to understand
// that this function really will never return.
#if defined(__GNUC__)
__builtin_unreachable();
#elif defined(_MSC_VER)
__assume(0);
#else
// Well, it's better than nothing.
std::abort();
#endif
}
} // namespace folly
......@@ -45,12 +45,12 @@
#include <boost/operators.hpp>
#include <boost/type_traits.hpp>
#include <folly/Assume.h>
#include <folly/ConstexprMath.h>
#include <folly/FormatTraits.h>
#include <folly/Portability.h>
#include <folly/SmallLocks.h>
#include <folly/Traits.h>
#include <folly/lang/Assume.h>
#include <folly/memory/Malloc.h>
#include <folly/portability/BitsFunctexcept.h>
#include <folly/portability/Malloc.h>
......
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