Move folly/Assume.h
authorYedidya Feldblum <yfeldblum@fb.com>
Sun, 29 Oct 2017 04:19:52 +0000 (21:19 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Sun, 29 Oct 2017 04:36:21 +0000 (21:36 -0700)
Summary: [Folly] Move `folly/Assume.h` to `folly/lang/`.

Reviewed By: luciang, ot

Differential Revision: D6181983

fbshipit-source-id: 25564bb07daa1a6765651cd919b4778efb931446

folly/Assume.cpp [deleted file]
folly/Assume.h
folly/Bits.h
folly/ExceptionWrapper.h
folly/Makefile.am
folly/Subprocess.cpp
folly/dynamic.cpp
folly/experimental/EliasFanoCoding.h
folly/lang/Assume.cpp [new file with mode: 0644]
folly/lang/Assume.h [new file with mode: 0644]
folly/small_vector.h

diff --git a/folly/Assume.cpp b/folly/Assume.cpp
deleted file mode 100644 (file)
index bf148df..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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.
- */
-
-#include <folly/Assume.h>
-
-#include <glog/logging.h>
-
-namespace folly {
-
-namespace detail {
-
-void assume_check(bool cond) {
-  CHECK(cond) << "compiler-hint assumption fails at runtime";
-}
-
-} // namespace detail
-
-} // namespace folly
index 36470fba1574cf05045dc76238d68cd89571e012..73b66a500b8b5ed2f47d1fa99bdb0dff2d232a04 100644 (file)
  * 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
index 942de4dc95633e358ee1f386daa86787c1b22194..529073b2823124bb591519a90fce81bf7d8a3e5c 100644 (file)
@@ -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 {
index eb493fc68c10429428515a8f6459429e24d01162..0d028714231fa5ad6fde57055c41b6734b13356f 100644 (file)
@@ -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
index f2b89b7e7de4dc6fc12536beb7dfaaea3b8c0033..dafdd730431ec21d6abd08dd6d17d7c6941b0612 100644 (file)
@@ -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 \
index 7770621385483a965427ec728513157bbb4ca39e..7fb038b2dd198f4f1a197d9385b1dda704291168 100644 (file)
 
 #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>
index aee3e87dd02d1d4c15672b99395bc9af965d1de4..f2be8f27324177208ed03f3fb16274ef69a8e10f 100644 (file)
@@ -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 {
index 628b813da46fbebca605cb2338b5f6b486f12a92..04a0f15881a850216f2f7167ff24a53c9cb0bffb 100644 (file)
@@ -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
diff --git a/folly/lang/Assume.cpp b/folly/lang/Assume.cpp
new file mode 100644 (file)
index 0000000..52d62a4
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ */
+
+#include <folly/lang/Assume.h>
+
+#include <glog/logging.h>
+
+namespace folly {
+
+namespace detail {
+
+void assume_check(bool cond) {
+  CHECK(cond) << "compiler-hint assumption fails at runtime";
+}
+
+} // namespace detail
+
+} // namespace folly
diff --git a/folly/lang/Assume.h b/folly/lang/Assume.h
new file mode 100644 (file)
index 0000000..36470fb
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * 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
index d8911a077b2dd9fb561ceb52ca8c9f1c75ad44c4..7287585ac0ea92284f95d0c4ca9c174b9d9c00f0 100644 (file)
 #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>