folly.git
7 years agofix strange recursive std::is_constructible instantiation involving the Function...
Eric Niebler [Mon, 18 Sep 2017 22:21:34 +0000 (15:21 -0700)]
fix strange recursive std::is_constructible instantiation involving the Function converting constructor

Summary: In rare and obscure cases, the fact that `folly::Function`'s perfectly-forwarding, implicit converting constructor was SFINAE-ing on the argument's constructibility was causing a recursive template instantiation of std::is_constructible. Switch to passing the argument by value to avoid the need to test for constructibility.

Reviewed By: yfeldblum

Differential Revision: D5847034

fbshipit-source-id: ce2ad1d2490206c6cae84c17544bd9fcd6ff47bb

7 years agoFix coroutine feature test macro on MSVC v2017.09.18.00
Eric Niebler [Fri, 15 Sep 2017 21:21:45 +0000 (14:21 -0700)]
Fix coroutine feature test macro on MSVC

Summary: Coroutines are only available on MSVC when the /await compiler switch was passed, in which case the `_RESUMABLE_FUNCTIONS_SUPPORTED` macro is defined.

Reviewed By: Orvid

Differential Revision: D5837303

fbshipit-source-id: af3349646e8875e3eac1bc3bbf47203f41f0bbde

7 years agoAllow awaiting on a folly::Optional that returns a move-only type
Dylan Yudaken [Fri, 15 Sep 2017 17:13:16 +0000 (10:13 -0700)]
Allow awaiting on a folly::Optional that returns a move-only type

Summary:
await_resume is only called once, so this allows it to move the value out.
At the same time remove a redundant clear (but keep the existing requirement that the promise type is an OptionalPromise), and clean up the tests.
Also add a test to make sure the coroutine is cleaned up

Reviewed By: ericniebler

Differential Revision: D5834861

fbshipit-source-id: 7ad487e818969cdf6fe27c9e82931aa247daf4e4

7 years agoAllow getAutoUncompressionCodec() to have 1 terminal decoder
Stella Lau [Fri, 15 Sep 2017 17:13:08 +0000 (10:13 -0700)]
Allow getAutoUncompressionCodec() to have 1 terminal decoder

Summary: getAutoUncompressionCodec() currently only allows unambiguous headers. Allow a single "terminal codec" to be called if all other codecs can't uncompress or throw.

Reviewed By: terrelln

Differential Revision: D5804833

fbshipit-source-id: 057cb6e13a48fea20508d5c028234afddf7435f6

7 years agofix usingJEMalloc() with LTO
Pádraig Brady [Fri, 15 Sep 2017 07:56:25 +0000 (00:56 -0700)]
fix usingJEMalloc() with LTO

Summary:
LTO has better optimization which results in the malloc() being optimized away in this function.

Note we don't use folly::dontOptimizeAway() because
that introduces a circular dependency between the
malloc and benchmark targets.

Reviewed By: marksantaniello, meyering, interwq

Differential Revision: D5840883

fbshipit-source-id: 5dd9b152f70b7a49f125b6d79b4dfa40f4cdac59

7 years agoNoHeap small_vector's no longer require a move constructor.
Martin Martin [Thu, 14 Sep 2017 20:04:20 +0000 (13:04 -0700)]
NoHeap small_vector's no longer require a move constructor.

Summary:
NoHeap small_vector's no longer require a move constructor.

Also changes const -> constexpr in a bunch of places.

Reviewed By: nbronson

Differential Revision: D5804361

fbshipit-source-id: 0f00fee6d318fa9296612409805d4ffcfbadb974

7 years agoWindow, mainly for futures
Tom Jackson [Thu, 14 Sep 2017 02:01:02 +0000 (19:01 -0700)]
Window, mainly for futures

Summary: Just a circular buffer in the middle of a pipeline.

Reviewed By: yfeldblum

Differential Revision: D5791551

fbshipit-source-id: 2808a53df9b8cd2a402da0678a6b4ed0e6ca6e00

7 years agoWorkaround a bug in template instation in MSVC 2017.3 with /permissive-
Christopher Dykes [Thu, 14 Sep 2017 01:59:20 +0000 (18:59 -0700)]
Workaround a bug in template instation in MSVC 2017.3 with /permissive-

Summary:
As described in the comment in `folly/stats/Histogram.h`, MSVC 2017.3 has issues with `/permissive-`.
The bug has been fixed upstream, it's just waiting for release.

These explicit template instantiations are never forward-declared anywhere, so, as long as `Histogram-defs.h` has been included, it's perfectly safe to just not do them.

https://developercommunity.visualstudio.com/content/problem/81223/incorrect-error-c5037-with-permissive.html

Reviewed By: yfeldblum

Differential Revision: D5828891

fbshipit-source-id: 4db8407c9d35aa5bb3f7b81aa24f611b5787fb6e

7 years agoFix build without zlib compression enabled
Christopher Dykes [Wed, 13 Sep 2017 21:41:27 +0000 (14:41 -0700)]
Fix build without zlib compression enabled

Summary: The namespace alias was trying to alias a namespace that doesn't exist unless Folly is being compiled with zlib support.

Reviewed By: terrelln

Differential Revision: D5810929

fbshipit-source-id: c659d8f775fc9b99e57cc95f5914418507e546fb

7 years agofixing namespacing issue for the dummy non sse crc32c_hw
Stephen Chen [Wed, 13 Sep 2017 21:19:14 +0000 (14:19 -0700)]
fixing namespacing issue for the dummy non sse crc32c_hw

Summary:
Because the way the #if was written, the dummy crc32c_hw function accidentally
ended in folly namespace instead of folly::details as expected. Fix this.

Reviewed By: yfeldblum

Differential Revision: D5826187

fbshipit-source-id: ba0f2207a00bc21eda7a727f3f1025e1106d55f9

7 years agoFix UB from signed integer overflow in RWSpinLock
Marcus Holland-Moritz [Wed, 13 Sep 2017 08:39:44 +0000 (01:39 -0700)]
Fix UB from signed integer overflow in RWSpinLock

Summary:
The signed counters used in a couple of places can in theory (and practice)
overflow, yielding UB. Use unsigned counters instead.

Reviewed By: luciang, philippv

Differential Revision: D5818606

fbshipit-source-id: c5928b779e76b309b00b7f6308a220e2bf6cbf79

7 years agoBacked out changeset ea9041ce2280
Jon Maltiel Swenson [Wed, 13 Sep 2017 04:30:08 +0000 (21:30 -0700)]
Backed out changeset ea9041ce2280

Summary: Revert D5787837. Breaks `onSet()`/`onUnset()` behavior.

Reviewed By: palmtenor

Differential Revision: D5817063

fbshipit-source-id: c7dea636fa60eb616d4ebe0a9d418bc96b3018ae

7 years agoInclude glog/logging.h in SmallLocksTest for DCHECK
Michael Lee [Tue, 12 Sep 2017 23:05:54 +0000 (16:05 -0700)]
Include glog/logging.h in SmallLocksTest for DCHECK

Summary: The test uses DCHECK, but does not include glog/logging.h.

Reviewed By: yfeldblum

Differential Revision: D5818647

fbshipit-source-id: fcb2630ac2b12acd1a7b84e228349b2887e976cd

7 years agoUpdate String.h
Alberto Schiabel [Tue, 12 Sep 2017 21:47:03 +0000 (14:47 -0700)]
Update String.h

Summary:
Fixed typo in doc comment related to `void toLowerAscii(char* str, size_t length)`.
This fixes the annoying xCode's warning `Parameter 'len' not found in the function declaration`.
Closes https://github.com/facebook/folly/pull/670

Reviewed By: yfeldblum

Differential Revision: D5815034

Pulled By: Orvid

fbshipit-source-id: 9580cd0bbd4924d4ed461a5435f525316e5c285a

7 years agoDon't use std::void_t
Christopher Dykes [Tue, 12 Sep 2017 20:54:49 +0000 (13:54 -0700)]
Don't use std::void_t

Summary: I was wrong, MSVC's implementation has the same bug as everything else.

Reviewed By: yfeldblum

Differential Revision: D5810646

fbshipit-source-id: 9caabbbc2115f57b7e836bb85c9b108588c94ad9

7 years agoconst -> constexpr in folly::small_vector
Martin Martin [Tue, 12 Sep 2017 18:51:07 +0000 (11:51 -0700)]
const -> constexpr in folly::small_vector

Summary: const -> constexpr in folly::small_vector

Reviewed By: yfeldblum

Differential Revision: D5814264

fbshipit-source-id: 4631bb7f3f04906636e5a188d4aa0d33ad796a3c

7 years agoRemove unneeded parts of build script
Philip Jameson [Tue, 12 Sep 2017 18:49:14 +0000 (11:49 -0700)]
Remove unneeded parts of build script

Summary: Remove an unneeded autoconf flag, as it causes the build to fail on missing boost-context

Reviewed By: yfeldblum

Differential Revision: D5815646

fbshipit-source-id: cb6544593de9fbf8248506b09c56412b4635b30c

7 years agoclang-format folly::small_vector. No functional change.
Martin Martin [Tue, 12 Sep 2017 18:34:55 +0000 (11:34 -0700)]
clang-format folly::small_vector. No functional change.

Summary: clang-format folly::small_vector.  No functional change.

Reviewed By: Orvid

Differential Revision: D5808357

fbshipit-source-id: d2ee831e25c60778c699214b875635c22854832d

7 years agoMake RequestContext provider overridable in order to save cost of setContext() on...
Jon Maltiel Swenson [Tue, 12 Sep 2017 16:09:42 +0000 (09:09 -0700)]
Make RequestContext provider overridable in order to save cost of setContext() on each fiber context switch

Summary:
Each fiber context switch currently involves the cost of saving/restoring `RequestContext`.  Certain
fibers-based applications such as mcrouter don't use `RequestContext` at all, so updating the current
thread-global `RequestContext` on each fiber context switch is unnecessary overhead.  Avoid this cost
by allowing `FiberManager` to override the `RequestContext` provider at the start and end of each fiber drain
loop.

Reviewed By: andriigrynenko

Differential Revision: D5787837

fbshipit-source-id: ea9041ce228063c8701165366fd1e34132868d22

7 years agoFix CMake build
Christopher Dykes [Tue, 12 Sep 2017 02:15:15 +0000 (19:15 -0700)]
Fix CMake build

Summary: Spookyhash got moved a long time ago, and a duplicate test name was added with the migration of executors from wangle to folly.

Reviewed By: yfeldblum

Differential Revision: D5811321

fbshipit-source-id: 789b4d3187a2e1e21c6cf8297f733bb4dffdbd60

7 years agoDead shift in ConcurrentHashMapSegment
Phil Willoughby [Mon, 11 Sep 2017 19:20:45 +0000 (12:20 -0700)]
Dead shift in ConcurrentHashMapSegment

Summary: Original problem detected by compiling with `-Werror,-Wunused-value`. On further inspection the only place which uses this detail class ensures that the `max_size` parameter is a power of two already, so we can discard the logic to manipulate `max_size` and put a `CHECK` clause in its place to guard against future changes to the caller that break this assumption.

Reviewed By: yfeldblum

Differential Revision: D5799110

fbshipit-source-id: d21ed9ff196d54ef91e38254df8b1b88bbf29275

7 years agoMove SSL_CTX sessionContext initialization into main SSL_CTX initialization path
Anirudh Ramachandran [Mon, 11 Sep 2017 11:54:57 +0000 (04:54 -0700)]
Move SSL_CTX sessionContext initialization into main SSL_CTX initialization path

Summary: This field was only previously set if setupSessionCache was called on the wangle::ServerSSLContext

Reviewed By: yfeldblum

Differential Revision: D5776057

fbshipit-source-id: ecdbe83816fee2ecbe7ea1b26a67b682a571309a

7 years agoAdd convenience std::string overload for toLowerAscii v2017.09.11.00
Giuseppe Ottaviano [Sun, 10 Sep 2017 16:59:56 +0000 (09:59 -0700)]
Add convenience std::string overload for toLowerAscii

Summary:
`toLowerAscii` is surprisingly hard to use with `std::string` because (until C++17) `data()` returns a `const char*`. In addition, it is not widely known that `s[0]` is legal even if the string is empty. This can lead to a variety of suboptimal code, from explicitly checking emptiness, to casting away the `const` (which causes UB).

Let's just have a simple overload for it.

Reviewed By: pixelb, philippv, yfeldblum

Differential Revision: D5801970

fbshipit-source-id: 407e2e9e66147a0662a5e09c75921255adff0702

7 years agoFix typo in async/README.md
Giuseppe Ottaviano [Sun, 10 Sep 2017 06:59:18 +0000 (23:59 -0700)]
Fix typo in async/README.md

Reviewed By: yfeldblum

Differential Revision: D5802013

fbshipit-source-id: 472b09da2be7234157a7886018004e2f4ed4f279

7 years agoOptional.h - make == operators constexprs
Benjamin Jaeger [Fri, 8 Sep 2017 20:59:20 +0000 (13:59 -0700)]
Optional.h - make == operators constexprs

Summary: This more closely matches std optional and allows folly Optional to be a drop in replacement.

Reviewed By: aary, yfeldblum

Differential Revision: D5775541

fbshipit-source-id: f754c006429fa3c5a866b6b5ffdfd8883ec2dd4f

7 years agosupport using co_await with folly::Optional when it is available
Eric Niebler [Fri, 8 Sep 2017 19:36:10 +0000 (12:36 -0700)]
support using co_await with folly::Optional when it is available

Summary:
Coroutines can be used to simulate the monadic "do" notion of Haskell. Use coroutines to enable monadic composition with folly::Optional.

```
Optional<int> f() {
  return 7;
}
Optional<int> g(int) {
  return folly::none;
}

void MonadicOptional() {
  Optional<int> r = []() -> Optional<int> {
    int x = co_await f();
    assert(x == 7);
    int y = co_await g(x);
    assert(false); // not executed
    co_return y;
  }();
  assert(!r.hasValue());
}
```

Reviewed By: yfeldblum

Differential Revision: D5763371

fbshipit-source-id: 9babc682244f38da7006d0b3a8444fd4efec1747

7 years agoGrammar fix: s/it's/its/
Michael Bolin [Fri, 8 Sep 2017 18:42:01 +0000 (11:42 -0700)]
Grammar fix: s/it's/its/

Summary:
I noticed this while reading the docs.

(Note: this ignores all push blocking failures!)

Reviewed By: lbrandy

Differential Revision: D5795548

fbshipit-source-id: 9ec5aa13a8913f217b3118e72714d02dc4a9407f

7 years agoFix data race in folly/executors/Codel.cpp exposed by TSAN
Kenny Yu [Thu, 7 Sep 2017 17:46:48 +0000 (10:46 -0700)]
Fix data race in folly/executors/Codel.cpp exposed by TSAN

Summary:
I found a data race with TSAN while attempting to run a sanitizer version of my service:

```
WARNING: ThreadSanitizer: data race (pid=266)
  Read of size 8 at 0x7b58000c0c08 by thread T370:
    @ folly::Codel::overloaded(std::chrono::duration<long, std::ratio<1l, 1000000000l> >) at ./folly/executors/Codel.cpp:44
    @ apache::thrift::concurrency::ThreadManager::ImplT<folly::LifoSemImpl<std::atomic, folly::Baton<std::atomic, true, true> > >::Worker<folly::LifoSemImpl<std::atomic, folly::Baton<std::atomic, true, true> > >::run() at ./thrift/lib/cpp/concurrency/ThreadManager.tcc:119
    @ apache::thrift::concurrency::PthreadThread::threadMain(void*) at ./thrift/lib/cpp/concurrency/PosixThreadFactory.cpp:200
    @ __tsan_thread_start_func at crtstuff.c:?

  Previous write of size 8 at 0x7b58000c0c08 by thread T371:
    @ folly::Codel::overloaded(std::chrono::duration<long, std::ratio<1l, 1000000000l> >) at ./folly/executors/Codel.cpp:62
    @ apache::thrift::concurrency::ThreadManager::ImplT<folly::LifoSemImpl<std::atomic, folly::Baton<std::atomic, true, true> > >::Worker<folly::LifoSemImpl<std::atomic, folly::Baton<std::atomic, true, true> > >::run() at ./thrift/lib/cpp/concurrency/ThreadManager.tcc:119
    @ apache::thrift::concurrency::PthreadThread::threadMain(void*) at ./thrift/lib/cpp/concurrency/PosixThreadFactory.cpp:200
    @ __tsan_thread_start_func at crtstuff.c:?

  Location is heap block of size 744 at 0x7b58000c0c00 allocated by thread T314:
    @ operator new(unsigned long) at ??:?
    @ PriorityImplT at ./thrift/lib/cpp/concurrency/ThreadManager.tcc:826
    @ void __gnu_cxx::new_allocator<apache::thrift::concurrency::PriorityThreadManager::PriorityImplT<folly::LifoSemImpl<std::atomic, folly::Baton<std::atomic, true, true> > > >::construct<apache::thrift::concurrency::PriorityThreadManager::PriorityImplT<folly::LifoSemImpl<std::atomic, folly::Baton<std::atomic, true, true> > >, std::array<std::pair<std::shared_ptr<apache::thrift::concurrency::ThreadFactory>, unsigned long>, 5ul>&, bool&, unsigned long&>(apache::thrift::concurrency::PriorityThreadManager::PriorityImplT<folly::LifoSemImpl<std::atomic, folly::Baton<std::atomic, true, true> > >*, std::array<std::pair<std::shared_ptr<apache::thrift::concurrency::ThreadFactory>, unsigned long>, 5ul>&, bool&, unsigned long&)
    @ std::shared_ptr<apache::thrift::concurrency::PriorityThreadManager> apache::thrift::concurrency::PriorityThreadManager::newPriorityThreadManager<folly::LifoSemImpl<std::atomic, folly::Baton<std::atomic, true, true> > >(std::array<unsigned long, 5ul> const&, bool, unsigned long) at ./thrift/lib/cpp/concurrency/ThreadManager.tcc:1090
    @ std::shared_ptr<apache::thrift::concurrency::PriorityThreadManager> apache::thrift::concurrency::PriorityThreadManager::newPriorityThreadManager<folly::LifoSemImpl<std::atomic, folly::Baton<std::atomic, true, true> > >(unsigned long, bool, unsigned long) at ./thrift/lib/cpp/concurrency/ThreadManager.tcc:1100
    @ apache::thrift::ThriftServer::serve() at ./thrift/lib/cpp2/server/ThriftServer.cpp:475
    @ apache::thrift::server::TServer::run() at ./thrift/lib/cpp/server/TServer.h:186
    @ apache::thrift::concurrency::PthreadThread::threadMain(void*) at ./thrift/lib/cpp/concurrency/PosixThreadFactory.cpp:200
    @ __tsan_thread_start_func at crtstuff.c:?

  Thread T370 (tid=638, running) created by thread T314 at:
    @ pthread_create at ??:?
    @ apache::thrift::concurrency::PthreadThread::start() at ./thrift/lib/cpp/concurrency/PosixThreadFactory.cpp:108
    @ apache::thrift::concurrency::ThreadManager::ImplT<folly::LifoSemImpl<std::atomic, folly::Baton<std::atomic, true, true> > >::addWorker(unsigned long) at ./thrift/lib/cpp/concurrency/ThreadManager.tcc:185
    @ apache::thrift::concurrency::PriorityThreadManager::PriorityImplT<folly::LifoSemImpl<std::atomic, folly::Baton<std::atomic, true, true> > >::start() at ./thrift/lib/cpp/concurrency/ThreadManager.tcc:840
    @ apache::thrift::ThriftServer::setup() at ./thrift/lib/cpp2/server/ThriftServer.cpp:347
    @ apache::thrift::ThriftServer::serve() at ./thrift/lib/cpp2/server/ThriftServer.cpp:475
    @ apache::thrift::server::TServer::run() at ./thrift/lib/cpp/server/TServer.h:186
    @ apache::thrift::concurrency::PthreadThread::threadMain(void*) at ./thrift/lib/cpp/concurrency/PosixThreadFactory.cpp:200
    @ __tsan_thread_start_func at crtstuff.c:?

  Thread T371 (tid=639, running) created by thread T314 at:
    @ pthread_create at ??:?
    @ apache::thrift::concurrency::PthreadThread::start() at ./thrift/lib/cpp/concurrency/PosixThreadFactory.cpp:108
    @ apache::thrift::concurrency::ThreadManager::ImplT<folly::LifoSemImpl<std::atomic, folly::Baton<std::atomic, true, true> > >::addWorker(unsigned long) at ./thrift/lib/cpp/concurrency/ThreadManager.tcc:185
    @ apache::thrift::concurrency::PriorityThreadManager::PriorityImplT<folly::LifoSemImpl<std::atomic, folly::Baton<std::atomic, true, true> > >::start() at ./thrift/lib/cpp/concurrency/ThreadManager.tcc:840
    @ apache::thrift::ThriftServer::setup() at ./thrift/lib/cpp2/server/ThriftServer.cpp:347
    @ apache::thrift::ThriftServer::serve() at ./thrift/lib/cpp2/server/ThriftServer.cpp:475
    @ apache::thrift::server::TServer::run() at ./thrift/lib/cpp/server/TServer.h:186
    @ apache::thrift::concurrency::PthreadThread::threadMain(void*) at ./thrift/lib/cpp/concurrency/PosixThreadFactory.cpp:200
    @ __tsan_thread_start_func at crtstuff.c:?

  Thread T314 (tid=582, running) created by main thread at:
    @ pthread_create at ??:?
    @ apache::thrift::concurrency::PthreadThread::start() at ./thrift/lib/cpp/concurrency/PosixThreadFactory.cpp:108
    ...
```

Looks like there is a data race in how `codelMinDelay_` is used. I couldn't get `std::atomic` to compile with `std::chrono::nanoseconds`,
so I used `std::atomic<uint64_t>` and converted between `uint64_t` and time types appropriately.

Reviewed By: yfeldblum

Differential Revision: D5759588

fbshipit-source-id: 8213f3789808265ddfe5ab122f0f86490d0ea6ea

7 years agomove wangle/concurrent to folly/executors
James Sedgwick [Wed, 6 Sep 2017 06:09:06 +0000 (23:09 -0700)]
move wangle/concurrent to folly/executors

Summary:
For the initial cutover, just pull the copies in folly into the wangle namespace
The main problem with that approach is that forward declarations of wangle components no longer work, so I fixed those manually

ALSO, IMPORTANT: This is a great, once in a lifetime opportunity to rename/restructure these components. I have a few ideas that I'll noodle and share eventually, e.g. changing LifoSemMPMCQueue so it's just descriptive and not an enumeration of implementation details. Please chip in with yr ideas!

Reviewed By: yfeldblum

Differential Revision: D5694213

fbshipit-source-id: 4fc0ea9359d1216191676fc9729fb53a3f06339f

7 years agoCompress empty strings with underlying compressor
Stella Lau [Tue, 5 Sep 2017 22:15:13 +0000 (15:15 -0700)]
Compress empty strings with underlying compressor

Summary:
- Current behavior compresses empty strings to empty strings. This is undesirable as decompression using underlying decompressor (side-stepping the codec) will fail. This change passes empty strings to the underlying compressor
- Decompressing empty string -> empty string was kept for backwards compatibility
- Fix `getUncompressedLength` for zlib

Reviewed By: terrelln, yfeldblum

Differential Revision: D5740034

fbshipit-source-id: 5a747ea4963dad872103209aa4410197f6c605db

7 years agoFix constexpr_min after D5739715 v2017.09.04.00
Yedidya Feldblum [Sat, 2 Sep 2017 09:11:34 +0000 (02:11 -0700)]
Fix constexpr_min after D5739715

Summary:
[Folly] Fix `constexpr_min` after {D5739715} (facebook/folly@6d7c6d55f0f4b7b75607608ef9037db58083368f).

Add new unit-tests for `constexpr_min` and `constexpr_max` to avoid silly mistakes like this in the future.

It was defined recursively in terms of `constexpr_max` rather than, as intended, in terns of `constexpr_min`. HT Mandar12.

Reviewed By: Orvid

Differential Revision: D5761831

fbshipit-source-id: 2dad5833e05679232b3c529d33325a0205c2e4e4

7 years agoincrease stack size when TSAN is enabled
Igor Sugak [Fri, 1 Sep 2017 20:23:11 +0000 (13:23 -0700)]
increase stack size when TSAN is enabled

Reviewed By: meyering

Differential Revision: D5757469

fbshipit-source-id: ad70c47251993c79a502d30f312534e28c9241d4

7 years agoDeflake some AsyncSSLSocket tests.
Kyle Nekritz [Fri, 1 Sep 2017 16:13:58 +0000 (09:13 -0700)]
Deflake some AsyncSSLSocket tests.

Summary: Fulfilling starts destroying the evb in another thread which races with the socket closing on the evb.

Reviewed By: siyengar, ngoyal

Differential Revision: D5755271

fbshipit-source-id: ace37eee63e684c97ca0fe503293eee83514e0ac

7 years agoAdd a comment on File.h
Aravind Anbudurai [Thu, 31 Aug 2017 23:20:43 +0000 (16:20 -0700)]
Add a comment on File.h

Summary: title

Reviewed By: yfeldblum

Differential Revision: D5751299

fbshipit-source-id: d3967c2499da9a2c98c2862b9bdc9994c12edc76

7 years agoExtract non-portability constexpr math functions to new header
Yedidya Feldblum [Thu, 31 Aug 2017 02:26:32 +0000 (19:26 -0700)]
Extract non-portability constexpr math functions to new header

Summary:
[Folly] Extract non-portability `constexpr` math functions to new header.

This new header, `folly/ConstexprMath.h`, is specifically for compile-time-computable math functions. We start with `min`, `max`, `abs`, and `log2`.

Included substantive changes:
* Add new tests for `constexpr_strlen`, which remains in the portability header.
* Make `constexpr_min` and `constexpr_max` variadic.
* Make `constexpr_log2` tail-recursive, remove `const_log2` in `FixedString.h`, and move the related comment.

Reviewed By: Orvid

Differential Revision: D5739715

fbshipit-source-id: 29d3cc846ce98bb4bdddcc8b0fa80e4d32075fe0

7 years agoDon't use symbolizer on OSX
Philip Jameson [Thu, 31 Aug 2017 01:00:36 +0000 (18:00 -0700)]
Don't use symbolizer on OSX

Summary:
When trying to build with targets files on OSX, I couldn't use the symbolizer because it needs StackTrace, which requires libunwind and elf. This makes it so that we only build on linux for now. This also makes it so that we set FOLLY_USE_SYMBOLIZER in autoconf, since that wasn't set before.

Does a few things surrounding usage of the symbolizer library:
- Introduce FOLLY_USE_SYMBOLIZER in folly-config.h and USE_SYMBOLIZER as an AM definition
-- Filter some code out of init and some other random libs that optionally need the symbolizer
- Fix libdwarf detection. Previously on a fresh ubuntu container, we didn't find libdwarf/dwarf.h, so we stopped trying before looking at dwarf.h

Reviewed By: yfeldblum

Differential Revision: D5644352

fbshipit-source-id: f0a3580c41122e5e8fdfd17a9fdbb0921be21401

7 years agoInclude `<array>` for test
Michael Lee [Wed, 30 Aug 2017 23:16:27 +0000 (16:16 -0700)]
Include `<array>` for test

Summary: <array> is sometimes necessary for using `std::array`. Fix up

Reviewed By: aary

Differential Revision: D5740866

fbshipit-source-id: 13bafadd26fdd0f2eff3513115b43811682e7cda

7 years agoConditionally compiled for_each with constexpr
Aaryaman Sagar [Wed, 30 Aug 2017 21:36:25 +0000 (14:36 -0700)]
Conditionally compiled for_each with constexpr

Summary:
Code was breaking in versions of C++ where constexpr functions are
required to have one line bodies

Reviewed By: yfeldblum, mzlee

Differential Revision: D5739062

fbshipit-source-id: 6c509f1daf77751d33ce9c173a0d7f1d3bd2a006

7 years agoDynamic MPMCQueue: Eliminate cases of enqueue indefinite blocking and failure in...
Maged Michael [Wed, 30 Aug 2017 19:53:16 +0000 (12:53 -0700)]
Dynamic MPMCQueue: Eliminate cases of enqueue indefinite blocking and failure in the extensible version that impossible under the default pre-allocated version

Summary:
Currently under the extensible version (Dynamic == true), some enqueue operations may block indefinitely or fail (return false) even though such outcomes are impossible under the default (Dynamic == false) pre-allocated version.

This diff eliminates such cases by changing the algorithms for the extensible version. Some of the high-level changes:
- The offset formula for an expansion guarantees that no enqueue operation left behind in a closed array does not have an existing dequeue operation that unblocks it. The old formula was 1 + max(head, tail). The new formula is max(head, current offset) + current capacity.
- Conditional operations validate state after the success of CAS.

Reviewed By: djwatson

Differential Revision: D5701013

fbshipit-source-id: 4917c5b35b7e2a2fddfd2e11fb5aeb478502137c

7 years agoconstexpr_log2
Yedidya Feldblum [Wed, 30 Aug 2017 18:39:43 +0000 (11:39 -0700)]
constexpr_log2

Summary:
[Folly] `constexpr_log2`.

Useful for anything that needs to compute log2 at compile time.

Reviewed By: eduardo-elizondo

Differential Revision: D5734727

fbshipit-source-id: 8eab7991eea2104570eecd8e84ede6160bb0b549

7 years agoShrink MicroSpinLock.h transitive includes and inline methods
Yedidya Feldblum [Wed, 30 Aug 2017 03:28:59 +0000 (20:28 -0700)]
Shrink MicroSpinLock.h transitive includes and inline methods

Summary: [Folly] Shrink `MicroSpinLock.h` transitive includes and inline methods.

Reviewed By: meyering

Differential Revision: D5732693

fbshipit-source-id: 386816f0d97c145ff8a4180d41c8a682694aa6cb

7 years agorm old comment on HHWheelTimer::UniquePtr
Xiao Shi [Wed, 30 Aug 2017 03:05:38 +0000 (20:05 -0700)]
rm old comment on HHWheelTimer::UniquePtr

Summary: This comment is outdated.

Reviewed By: yfeldblum

Differential Revision: D5730049

fbshipit-source-id: f6088c4354210fafb019656cdf8246abf90fbc06

7 years agoUse weak_ptr to hold future context in timekeeper to allow clean up when future complete
Richard Meng [Tue, 29 Aug 2017 17:18:29 +0000 (10:18 -0700)]
Use weak_ptr to hold future context in timekeeper to allow clean up when future complete

Summary:
Before this change, future context will not be cleaned up until timekeeper times out. These objects has been occupying memory when more shorter future tasks are registered.
Switch to use weak ptr to hold context, so that context objects are deallocated as soon as the future completes (or times out)

Reviewed By: yfeldblum

Differential Revision: D5692040

fbshipit-source-id: b3b74a29b2ccafef6c4a06011699b069feb3a847

7 years agoAllow forcing value for FOLLY_FUTURE_USING_FIBER in folly-config.h
Andrew Krieger [Tue, 29 Aug 2017 05:36:16 +0000 (22:36 -0700)]
Allow forcing value for FOLLY_FUTURE_USING_FIBER in folly-config.h

Summary:
Let clients choose whether to use fibers or not, but default
to the same autodetected setting as prior logic.

Reviewed By: yfeldblum

Differential Revision: D5585605

fbshipit-source-id: 9a4bf9f9bc23b4e15601f30c40602f21798c9685

7 years agoFix potentially uninitialized struct used on MSVC
Andrew Krieger [Tue, 29 Aug 2017 05:34:42 +0000 (22:34 -0700)]
Fix potentially uninitialized struct used on MSVC

Summary:
MSVC warns this might be used but uninitialized. Force
the struct to be zero initialized.

Reviewed By: yfeldblum

Differential Revision: D5585320

fbshipit-source-id: 9454a2a4a66c7689f42b1eb211dc57f5d3b88fea

7 years agoFix portability opendir() behavior on paths without trailing slashes
Andrew Krieger [Tue, 29 Aug 2017 05:33:44 +0000 (22:33 -0700)]
Fix portability opendir() behavior on paths without trailing slashes

Summary:
Off-by-one error in DIR::open() would result in paths not
ending in a trailing separator to fail to open. Fix the arithmetic.

Reviewed By: Orvid

Differential Revision: D5579657

fbshipit-source-id: 79507bc398549033eb26b2ffa788d66241deb623

7 years agoImplement folly::launder for MSVC
Andrew Krieger [Tue, 29 Aug 2017 05:30:39 +0000 (22:30 -0700)]
Implement folly::launder for MSVC

Summary:
This implementation should suffice for MSVC. _ReadWriteBarrier()
generates no instructions but instructs the compiler not to reorder accesses
around it, and we have to rely on MSVC not currently having any other
optimizations for const members to worry about.

Reviewed By: yfeldblum

Differential Revision: D5723782

fbshipit-source-id: a68caa4673a5c410b326c1d2e3c0752bd945f4a6

7 years agoApply clang-format to folly/experimental/exception_tracer/
Yedidya Feldblum [Tue, 29 Aug 2017 02:59:43 +0000 (19:59 -0700)]
Apply clang-format to folly/experimental/exception_tracer/

Summary: [Folly] Apply `clang-format` to `folly/experimental/exception_tracer/`.

Reviewed By: Orvid

Differential Revision: D5722994

fbshipit-source-id: 2e52c920119ba58d123aaffd59491d7561c37c17

7 years agoRevert D5714883: [Folly] Shrink MicroSpinLock.h transitive includes and inline methods
Christopher Dykes [Tue, 29 Aug 2017 01:06:22 +0000 (18:06 -0700)]
Revert D5714883: [Folly] Shrink MicroSpinLock.h transitive includes and inline methods

Summary:
This reverts commit 1744685ff9fa8d3620aef2545c8fe3ebc481df06

bypass-lint

Differential Revision: D5714883

fbshipit-source-id: 0cdb5f2cac095a9202cb1310ff8e75e75b4afd74

7 years agoEnable auto-deps in all of Folly
Christopher Dykes [Mon, 28 Aug 2017 22:13:58 +0000 (15:13 -0700)]
Enable auto-deps in all of Folly

Summary: This enables the last of the magic internally.

Reviewed By: yfeldblum

Differential Revision: D5719795

fbshipit-source-id: fb59a0d7873e9a9f3b73f556b42b647091ca7e67

7 years agoShrink MicroSpinLock.h transitive includes and inline methods
Yedidya Feldblum [Mon, 28 Aug 2017 08:29:16 +0000 (01:29 -0700)]
Shrink MicroSpinLock.h transitive includes and inline methods

Summary: [Folly] Shrink `MicroSpinLock.h` transitive includes and inline methods.

Reviewed By: Orvid

Differential Revision: D5714883

fbshipit-source-id: 1744685ff9fa8d3620aef2545c8fe3ebc481df06

7 years agoMake cancelling and rescheduling of functions O(1) v2017.08.28.00
Patryk Zaryjewski [Mon, 28 Aug 2017 06:35:38 +0000 (23:35 -0700)]
Make cancelling and rescheduling of functions O(1)

Summary: Currently FunctionScheduler calls that cancel/restart timer for a function of particular id are O(n). By introducing hashmap that translate id to pointer of particular RepeatFunc, we make it O(1).

Reviewed By: simpkins

Differential Revision: D5668557

fbshipit-source-id: e5e8bf9bd75b6d5d42f0bfa398d476703e5801fa

7 years agogcc 6.2 was not accepting the current definition of void_t
Aaryaman Sagar [Fri, 25 Aug 2017 23:08:18 +0000 (16:08 -0700)]
gcc 6.2 was not accepting the current definition of void_t

Summary:
The current definition of void_t was leading to errors because unused
template parameters are ignored and SFINAE SFIAEs

Reviewed By: yfeldblum

Differential Revision: D5700825

fbshipit-source-id: d23336070c217e8594980d6db710cb417b014236

7 years agoAdded a flag FOLLY_FORCE_EXCEPTION_COUNT_USE_STD
Marko Novakovic [Fri, 25 Aug 2017 22:23:42 +0000 (15:23 -0700)]
Added a flag FOLLY_FORCE_EXCEPTION_COUNT_USE_STD

Summary:
The flag FOLLY_FORCE_EXCEPTION_COUNT_USE_STD forces
the usage of std:uncaught_exceptions() for folly's
implementation of uncaught_exceptions()

Reviewed By: yfeldblum

Differential Revision: D5542302

fbshipit-source-id: 2c2f507ab9dde916a160a9c370a267cdcfd7203a

7 years agoEnforce forward progress with StreamCodec
Stella Lau [Fri, 25 Aug 2017 16:23:46 +0000 (09:23 -0700)]
Enforce forward progress with StreamCodec

Summary:
- Throw exception if no forward progress was made with `StreamCodec.compress()` and `StreamCodec.uncompress()`
- Prevents infinite looping behavior when no forward progress was made
- Update tests

Reviewed By: terrelln

Differential Revision: D5685690

fbshipit-source-id: 969393896b74f51250f0e0ce3af0cd4fedcab49a

7 years agoFix typo in Function.h
Qinfan Wu [Fri, 25 Aug 2017 10:05:04 +0000 (03:05 -0700)]
Fix typo in Function.h

Summary: [Folly] Fix typo in `Function.h`.

Reviewed By: yfeldblum

Differential Revision: D5703550

fbshipit-source-id: 9dc09697fd09db6c65b1a4f2d8bdf44451b4aab2

7 years agoadd public kSlotSize to IndexedMemPool
Greg Nisbet [Fri, 25 Aug 2017 00:53:08 +0000 (17:53 -0700)]
add public kSlotSize to IndexedMemPool

Summary:
add public kSlotSize to IndexedMemPool,
needed to support getting the approximate memory footprint of the pool
(since a Slot has two atomic uint32_t's more than a bare Elem)

Reviewed By: yfeldblum

Differential Revision: D5690225

fbshipit-source-id: 667da6b67b339038b92b0e5acde17219fe1c85c5

7 years agoAdded rvalue and const rvalue overloads to Try
Aaryaman Sagar [Thu, 24 Aug 2017 21:46:17 +0000 (14:46 -0700)]
Added rvalue and const rvalue overloads to Try

Summary:
Try was missing some important-ish overloads that help it behave well
in rvalue contexts

Reviewed By: yfeldblum

Differential Revision: D5692021

fbshipit-source-id: c34627b56eb52dceaeb1f00ae930ee3bc6e00306

7 years agounwrapTryTuple only accepted rvalue tuple types
Aaryaman Sagar [Thu, 24 Aug 2017 21:42:53 +0000 (14:42 -0700)]
unwrapTryTuple only accepted rvalue tuple types

Summary:
unwrapTryTuple only accepted rvalue tuple types, this diff fixes that
to work with forwarding reference tuple types.

Also reduces the number of template instantiations

Reviewed By: yfeldblum

Differential Revision: D5682996

fbshipit-source-id: ee6dd2c20d8dfca33e769a98a6ca56fa96c73b72

7 years agoCreate generic method to extract mac address from EUI-64 constructed addresses
Andrii Kryzhyk [Thu, 24 Aug 2017 19:08:18 +0000 (12:08 -0700)]
Create generic method to extract mac address from EUI-64 constructed addresses

Summary: Link local is not the only type of address that is based on mac address, therefore create generic function to extract mac address from EUI-64 autoconfigured addresses using the same logic as for getMacAddressFromLinkLocal

Reviewed By: pallotron

Differential Revision: D5697781

fbshipit-source-id: 4d69085a1d8f08e06496b8a9b638ac7ff31c6c3a

7 years agoImprove formatting of scripts and test files
Peter DeLong [Thu, 24 Aug 2017 17:16:37 +0000 (10:16 -0700)]
Improve formatting of scripts and test files

Summary: Reformatted the scripts and test files to look better and also to avoid lint warnings in the future

Reviewed By: andriigrynenko

Differential Revision: D5673856

fbshipit-source-id: 5818625ec14d18ef3b9b804df53949afefc3b98f

7 years agoAdd LZMA streaming interface
Stella Lau [Thu, 24 Aug 2017 16:26:59 +0000 (09:26 -0700)]
Add LZMA streaming interface

Summary:
- Replace LZMA2Codec with LZMA2StreamCodec
- Update tests to reflect LZMA2_VARINT_SIZE requiring data length

Reviewed By: terrelln

Differential Revision: D5625388

fbshipit-source-id: 3303c6dda5d41f40615c87504a46923815b0b716

7 years agoTry::exception overload for Try&&
Yedidya Feldblum [Thu, 24 Aug 2017 07:42:16 +0000 (00:42 -0700)]
Try::exception overload for Try&&

Summary:
[Folly] `Try::exception` overload for `Try&&`.

For consistency with `Try::value`.

Reviewed By: WillerZ

Differential Revision: D5691758

fbshipit-source-id: 9904b2a5c90f4575a3c09dc012658d359d11fdd9

7 years agoRename FOLLY_A64 to FOLLY_AARCH64
Christopher Dykes [Thu, 24 Aug 2017 05:51:43 +0000 (22:51 -0700)]
Rename FOLLY_A64 to FOLLY_AARCH64

Summary:
`FOLLY_AARCH64` is more descriptive.
(searching for A64 tells you nothing, searching for aarch64 tells you a lot)

Reviewed By: yfeldblum, andrewjcg

Differential Revision: D5663075

fbshipit-source-id: 8f31fde4aa394f5452305929541af6d38e4d8a37

7 years agoupdate README for ubuntu 16.04 LTS + custom boost installation details
shane [Thu, 24 Aug 2017 00:40:02 +0000 (17:40 -0700)]
update README for ubuntu 16.04 LTS + custom boost installation details

Summary:
the README didn't have explicit instructions for ubuntu 16.04 LTS...  now it does.

i also added a section for how to handle building folly w/a custom boost installation.
Closes https://github.com/facebook/folly/pull/664

Reviewed By: eduardo-elizondo

Differential Revision: D5694143

Pulled By: yfeldblum

fbshipit-source-id: e2786d045c3459cac49c8b052d90ca24d10f7922

7 years agomacro to enable scoped trace section functionality
Alison Tsai [Wed, 23 Aug 2017 23:50:28 +0000 (16:50 -0700)]
macro to enable scoped trace section functionality

Summary: Add a macro to enable optional scoped trace section functionality (user-defined). This macro will have no effect unless configured to do so. This change means that if proxygen is being upgraded, folly must also be updated.

Reviewed By: mzlee

Differential Revision: D5635123

fbshipit-source-id: 7db17f6ae8c0d1484cf9fad043eb42717279bd0a

7 years agoUse simple exception_wrapper ctor in the Promise::setException test
Yedidya Feldblum [Tue, 22 Aug 2017 22:51:49 +0000 (15:51 -0700)]
Use simple exception_wrapper ctor in the Promise::setException test

Summary:
[Folly] Use simple `exception_wrapper` ctor in the `Promise::setException` test.

And add a new case testing with `exception_ptr`.

Reviewed By: andrewjcg

Differential Revision: D5683035

fbshipit-source-id: e8276166dacbe09a9a745271d636db44c593058c

7 years agoAdded a for_each function to iterate through ranges
Aaryaman Sagar [Tue, 22 Aug 2017 17:54:11 +0000 (10:54 -0700)]
Added a for_each function to iterate through ranges

Summary:
Adding a for_each function that allows generalized indexed and breakable iteration through ranges, these can either be runtime ranges (i.e. entities for which std::begin and std::end work) or compile time ranges (as deemed by the presence of a std::tuple_length<>, get<> (ADL resolved) functions)

The function is made to provide a convenient library based solution to the proposal p0589r0, which aims to generalize the range based for loop even further to work with compile time ranges

A drawback of using range based for loops is that sometimes you do not have access to the index within the range.  This provides easy access to that, even with compile time ranges.

Further this also provides a good way to break out of a loop without any overhead when that is not used.

A simple use case would be when using futures, if the user was doing calls to n servers then they would accept the callback with the futures like this

   auto vec = std::vector<std::future<int>>{request_one(), ...};
   when_all(vec.begin(), vec.end()).then([](auto futures) {
     folly::for_each(futures, [](auto& fut) { ... });
   });

Now when this code switches to use tuples instead of the runtime std::vector, then the loop does not need to change, the code will still work just fine

   when_all(future_one, future_two, future_three).then([](auto futures) {
     folly::for_each(futures, [](auto& fut) { ... });
   });

Reviewed By: yfeldblum

Differential Revision: D5557336

fbshipit-source-id: 79fcbafa7e1671f8856f0dcb7bf7996435dadeaa

7 years agoExplicitly initialize AsyncSocket in MockAsyncSSLSocket
Mingtao Yang [Tue, 22 Aug 2017 17:36:32 +0000 (10:36 -0700)]
Explicitly initialize AsyncSocket in MockAsyncSSLSocket

Summary:
Even though MockAsyncSSLSocket's initializes AsyncSSLSocket, which should
initialize AsyncSocket, this does not actually happen because AsyncSSLSocket
virtually inherits from AsyncSocket.

Because of this, prior to this diff, the MockAsyncSSLSocket was not properly
setting its EventBase.

Reviewed By: knekritz

Differential Revision: D5676596

fbshipit-source-id: 5f3c0e848179cb5eb4d2dc4921a11e7c04d7c0e0

7 years agoUse exception_wrapper::from_exception_ptr in Try and Promise
Yedidya Feldblum [Tue, 22 Aug 2017 04:10:34 +0000 (21:10 -0700)]
Use exception_wrapper::from_exception_ptr in Try and Promise

Summary:
[Folly] Use `exception_wrapper::from_exception_ptr` in `Try` and `Promise`.

It does just what we need; DRY.

Reviewed By: andrewjcg

Differential Revision: D5674663

fbshipit-source-id: 73e46df62c06736c4eaf013d05dfea819cbec515

7 years agoAdd zlib-specific codec initialization
Stella Lau [Tue, 22 Aug 2017 01:15:27 +0000 (18:15 -0700)]
Add zlib-specific codec initialization

Summary:
- Create interface to initialize zlib codec using specific parameters
- This enables the raw inflate/deflate and auto inflate options
- Add tests for option initialization

Reviewed By: terrelln, yfeldblum

Differential Revision: D5649980

fbshipit-source-id: fd36e8edc0e8c528cd6c9d8f39e8ef839b6acfef

7 years agoexception_wrapper::from_exception_ptr
Yedidya Feldblum [Mon, 21 Aug 2017 18:38:39 +0000 (11:38 -0700)]
exception_wrapper::from_exception_ptr

Summary:
[Folly] `exception_wrapper::from_exception_ptr`.

A handry helper for converting from `std::exception_ptr` to `folly::exception_wrapper`.

Reviewed By: ericniebler

Differential Revision: D5668179

fbshipit-source-id: a81a60cb22a2a697714268e027af62dd8825d2c3

7 years agoSynchronizedPtr
Phil Willoughby [Mon, 21 Aug 2017 12:07:57 +0000 (05:07 -0700)]
SynchronizedPtr

Summary: Fairly minimal API to start with. Refer to the comments for the rationale/usage.

Reviewed By: yfeldblum

Differential Revision: D5554854

fbshipit-source-id: 173bf7c40e70b55bf6afb8c4bc9e83d48f90b6ee

7 years agoRecommended cipher list for server side. v2017.08.21.00
Xiangyu Bu [Fri, 18 Aug 2017 23:59:18 +0000 (16:59 -0700)]
Recommended cipher list for server side.

Summary: A SSLOptions recommended for cipher use.

Reviewed By: yfeldblum

Differential Revision: D5614280

fbshipit-source-id: a6b1adfa8d168f35c7bc7d4088c4073c3f4084a5

7 years agoLet SSLContext::setCipherList accept generic container type.
Xiangyu Bu [Fri, 18 Aug 2017 23:35:27 +0000 (16:35 -0700)]
Let SSLContext::setCipherList accept generic container type.

Summary:
Make SSLContext::setCipherList() and SSLContext::setSignatureAlgorithms()
accept std::array besides std::vector so that cipher lists in SSLOptions
can be initialized POD.

Reviewed By: yfeldblum

Differential Revision: D5578758

fbshipit-source-id: 7e5c2e9a75600e93c89e7b13a9042434a4189384

7 years agoDrop jemalloc specific smartRealloc integration
Dave Watson [Fri, 18 Aug 2017 15:45:44 +0000 (08:45 -0700)]
Drop jemalloc specific smartRealloc integration

Summary:
This was added several jemalloc versions ago, and is no longer a win.

From microbenches in folly/test, this codepath is successful less than .5% of the time.

There are a handful of other places directly using this (fbvector, IOBuf, ThreadLocal),
but should probably change them individually.

Reviewed By: interwq

Differential Revision: D5596678

fbshipit-source-id: 354d7204f61df0eace4d98d930d0f6e06a90ffde

7 years agoRemove outdated comments referencing removed TAsyncSSLServerSocket
David Lam [Fri, 18 Aug 2017 05:59:58 +0000 (22:59 -0700)]
Remove outdated comments referencing removed TAsyncSSLServerSocket

Summary:
TAsyncSSLServerSocket was deleted in D1806807, so we should remove
these comments.

Reviewed By: yfeldblum

Differential Revision: D5657431

fbshipit-source-id: ca875293737ad8ba0a8c028c9bfa5651f4a6065f

7 years agoFix incorrect format in Overview markdown
darrenl [Fri, 18 Aug 2017 05:41:29 +0000 (22:41 -0700)]
Fix incorrect format in Overview markdown

Summary:
The format is incorrect in [Overview.md](https://github.com/facebook/folly/blob/master/folly/docs/Overview.md)
Closes https://github.com/facebook/folly/pull/661

Reviewed By: eduardo-elizondo

Differential Revision: D5657083

Pulled By: yfeldblum

fbshipit-source-id: a9cedb413cbb3d455f4c1e5f785d05a33f8182c8

7 years agoFix undefined behavior when decoding varint
Stella Lau [Thu, 17 Aug 2017 23:34:56 +0000 (16:34 -0700)]
Fix undefined behavior when decoding varint

Summary: Left shifting `0x7f` by `63` is undefined behavior (i.e. when decoding `0xFFFF...`)

Reviewed By: yfeldblum, terrelln

Differential Revision: D5653353

fbshipit-source-id: c74c9f43a9bc82d15a2223df853dc533cea1478b

7 years agoAdd getSSLContext() to AsyncSSLSocket
Mingtao Yang [Thu, 17 Aug 2017 20:54:11 +0000 (13:54 -0700)]
Add getSSLContext() to AsyncSSLSocket

Reviewed By: knekritz

Differential Revision: D5632201

fbshipit-source-id: 5db380379ab6cb608922c77dd716bfc4410b2cd8

7 years agoChange AsyncSSLSocket getSecurityProtocol to handle unencrypted mode
Neel Goyal [Thu, 17 Aug 2017 17:59:06 +0000 (10:59 -0700)]
Change AsyncSSLSocket getSecurityProtocol to handle unencrypted mode

Summary: Return empty string for `getSecurityProtocol` if the socket is good and the handshake failed, otherwise "TLS"

Reviewed By: knekritz

Differential Revision: D5647637

fbshipit-source-id: b95cbf39e4bb7f89b1ebcbc0238c2becba7ad42a

7 years agoRemove a use of SFINAE in the Range constructor.
Phil Willoughby [Thu, 17 Aug 2017 08:27:07 +0000 (01:27 -0700)]
Remove a use of SFINAE in the Range constructor.

Summary:
Specifically, the constructor `implicit Range(Iter)` is now declared and defined for all `Range` specializations. It is an error to use it, and we `static_assert`, unless `Iter` is `char const *` or `char *`.

Performance effect
 ---
Measuring compilation-time on a file that just make ~40k StringPieces, compiled with -O3. All compilers produced identical code before/after this change.

* clang-trunk: 4% improvement
* gcc-5: no change
* gcc-4.9: 11% improvement
* gcc-7.1: 5% improvement

Could this possibly break any existing code?
 ---
Yes. If you have a function that's overloaded for both `Range<char const*>` and `Range<X>` and your input object is not `char const*` and is implicitly convertible to both `char const*` and `X`: that is now ambiguous whereas before it would unambiguously pick the `Range<char const*>` overload. I don't consider this scenario likely.

Why should this work?
 ---
Using SFINAE is more expensive at compile time (with some compilation environments) than not using it. It's necessary to use SFINAE when there is an alternative function which will be used in preference when the substitution fails, but when that is not the case it is on average cheaper to make the function always exist and use static_assert to disallow the bad uses of it. A bonus is that the caller gets a more comprehensible error message.

Reviewed By: nbronson

Differential Revision: D5639502

fbshipit-source-id: 13469f2995a487398734f86108087fdc8e32ad71

7 years agoOptionally run autoconf
Philip Jameson [Thu, 17 Aug 2017 00:46:52 +0000 (17:46 -0700)]
Optionally run autoconf

Summary:
This makes it so that the //folly:config rule can run autoconf to create folly-config

- Uses cxx_genrule get compiler settings and paths to dependent libraries
- Goes around a couple of oddities in the way that buck exports some of its macros
- While it uses buck_cxx_library, that's okay to use outside of facebook's internal repos.

Reviewed By: meyering

Differential Revision: D5620729

fbshipit-source-id: 0d2d8e3bda92182dcdcd3e80cb12a3756b3816ac

7 years agoAdd prepareSkipTo() method to EliasFanoReader
Rushy Panchal [Thu, 17 Aug 2017 00:19:03 +0000 (17:19 -0700)]
Add prepareSkipTo() method to EliasFanoReader

Summary:
`prepareSkipTo(x`) allows the client of EliasFanoReader to "hint" that
`skipTo(x)` will be called in the near future. The primary benefit of doing so
is that memory which is needed for `skipTo(x)` can be prefetched to minimize
cache misses incurred when calling `skipTo(x)`.

Reviewed By: ot, philippv

Differential Revision: D5508995

fbshipit-source-id: 4876b566256849f76193db3dc0404768aeeeb30d

7 years agoAdd ConcurrentHashMap installable
Shu Zhang [Wed, 16 Aug 2017 20:17:13 +0000 (13:17 -0700)]
Add ConcurrentHashMap installable

Summary:
ConcurrentHashMap is a newly added feature and we wanted to test it in our enviornment, making it installable.

Built & Installed on ubuntu 14 env.
Closes https://github.com/facebook/folly/pull/659

Reviewed By: djwatson

Differential Revision: D5629159

Pulled By: yfeldblum

fbshipit-source-id: 8a40e768f3db7918a3b284059f2efa0b7ecb9aca

7 years agofolly::ElfFile - add support to iterate over program headers
Mirek Klimos [Wed, 16 Aug 2017 04:04:27 +0000 (21:04 -0700)]
folly::ElfFile - add support to iterate over program headers

Summary: Adding iterateProgramHeaders, similar to iterateSections, just iterates over program headers instead of section headers. I want this to get the size of the first PT_LOAD header.

Differential Revision: D5602575

fbshipit-source-id: f73989cade20214f884571c1099761ecaa4841f7

7 years agoFix destruction order
Maged Michael [Wed, 16 Aug 2017 01:01:19 +0000 (18:01 -0700)]
Fix destruction order

Summary:
- Added `hazptr.cpp` and `memory_resource.cpp`. Moved singleton code to source.
  - Changed the singleton for the default `hazptr_domain` to a global.
  - Changed hazptr_stats singleton to a global.
  - Moved the thread caching calls from the hazptr_domain functions to the constructor/destructor of hazptr_holder.
  - Changed the TLS singletons to TLS globals.
  - Changed some inlining directives.
  - Leak the hazptr_rec-s in the default domain

Reviewed By: davidtgoldblatt, djwatson

Differential Revision: D5553753

fbshipit-source-id: da69eecec55c0f78fb8ef5591f9aeffee99ff3fa

7 years agotry to fix folly, wangle, etc open-source build
Alexey Spiridonov [Tue, 15 Aug 2017 17:52:45 +0000 (10:52 -0700)]
try to fix folly, wangle, etc open-source build

Summary: add missing source files to Makefile

Reviewed By: andriigrynenko

Differential Revision: D5630758

fbshipit-source-id: 0f04c11b65fd3a6f4f33e34ae57c0fcba8671e97

7 years agoAdd hooks to track which threads belong to which thread pools
Peter DeLong [Mon, 14 Aug 2017 23:40:47 +0000 (16:40 -0700)]
Add hooks to track which threads belong to which thread pools

Summary:
Keep track of which threads belong to which thread pools for use when debugging.
This will be paired with a gdb script that associates threads with their thread pools

Reviewed By: andriigrynenko

Differential Revision: D5514729

fbshipit-source-id: 57ada4dd1aaaec5d7026e4eee05b0ec4e7434c77

7 years agoallow comparing Optional<T> with none
Nick Wolchko [Mon, 14 Aug 2017 19:49:06 +0000 (12:49 -0700)]
allow comparing Optional<T> with none

Summary:
`std::optional` supports comparing with `std::nullopt`, so
`folly::Optional` should do the same with `folly::none`.
This also involves marking hasValue() noexcept to be the same as `std::optional`.

Reviewed By: yfeldblum, WillerZ

Differential Revision: D5617825

fbshipit-source-id: a4b863dd61c3a86223fb21a5b7759e7c295fd272

7 years agoAsyncSSLSocket::get/setClientCertValidationResult API.
Xiangyu Bu [Mon, 14 Aug 2017 17:13:58 +0000 (10:13 -0700)]
AsyncSSLSocket::get/setClientCertValidationResult API.

Summary:
The added API will be used for storing and retrieving validation result of client cert.

At some point we may change "client" to "peer" to make it generic.

Reviewed By: anirudhvr

Differential Revision: D5610404

fbshipit-source-id: 2feb03abc0594af4c68db33d8885ea214867148a

7 years agosmall_vector default constructor shouldn't be explicit v2017.08.14.00
Nathan Bronson [Thu, 10 Aug 2017 19:35:20 +0000 (12:35 -0700)]
small_vector default constructor shouldn't be explicit

Summary:
Containers should not tag their default constructor explicit,
because it means that you can't return an empty one with "return {};".
This diff removes the explicit tag from small_vector's default
constructor.

Reviewed By: meyering

Differential Revision: D5602749

fbshipit-source-id: 2a4a356134c69d01e3b040719dc6ffca0fe97e75

7 years agofix sorted_vector_{set,map} bulk_insert deduplication
Nick Jiang [Wed, 9 Aug 2017 22:23:24 +0000 (15:23 -0700)]
fix sorted_vector_{set,map} bulk_insert deduplication

Summary: this fixes the case where bulk inserting a range where the smallest element is equal to the largest element of the current set/map fails to deduplicate that element.

Reviewed By: mlogan, yfeldblum

Differential Revision: D5593284

fbshipit-source-id: 487500ee7a5e33f27c24321ad4a3c07a669fc26c

7 years agoExplicitly handle gcc in FOLLY_MAYBE_UNUSED
Yedidya Feldblum [Wed, 9 Aug 2017 21:55:17 +0000 (14:55 -0700)]
Explicitly handle gcc in FOLLY_MAYBE_UNUSED

Summary:
[Folly] Explicitly handle gcc in `FOLLY_MAYBE_UNUSED`.

Fixes build break from {D5562220}.

Reviewed By: Orvid

Differential Revision: D5594288

fbshipit-source-id: 5aa2dcb6133d53a0eb20d34b67c8e4407dd2b7ca

7 years agoCut unnecessary parens in IPAddress.h
Yedidya Feldblum [Wed, 9 Aug 2017 18:21:38 +0000 (11:21 -0700)]
Cut unnecessary parens in IPAddress.h

Summary: [Folly] Cut unnecessary parens in `IPAddress.h`.

Reviewed By: meyering

Differential Revision: D5589756

fbshipit-source-id: 6499e0db2aeb232356e2808fc59a35869b5dad0a

7 years agoLet IPAddressV4::bitCount and IPAddressV6::bitCount be constexpr
Yedidya Feldblum [Wed, 9 Aug 2017 03:27:39 +0000 (20:27 -0700)]
Let IPAddressV4::bitCount and IPAddressV6::bitCount be constexpr

Summary: [Folly] Let `IPAddressV4::bitCount` and `IPAddressV6::bitCount` be `constexpr`.

Reviewed By: meyering

Differential Revision: D5589954

fbshipit-source-id: f4208efd62e71f47a7c87bdc8ddd421f93413c29

7 years agoApply clang-format to folly/**/*Address*.*
Yedidya Feldblum [Tue, 8 Aug 2017 21:40:04 +0000 (14:40 -0700)]
Apply clang-format to folly/**/*Address*.*

Summary: [Folly] Apply `clang-format` to `folly/**/*Address*.*`.

Reviewed By: Orvid

Differential Revision: D5581523

fbshipit-source-id: 97b5270e43e279e7deb9606524d5fee844a50649

7 years agoAdd a UDL suffix to define a StringPiece
Phil Willoughby [Tue, 8 Aug 2017 10:19:16 +0000 (03:19 -0700)]
Add a UDL suffix to define a StringPiece

Summary:
Use it like this:
```
using namespace folly::string_piece_literals;
StringPiece p = "A literal string"_sp;
```

In some compilation environments it can be more efficient than the implicit
conversion from `char const *` to `StringPiece`.

Reviewed By: yfeldblum

Differential Revision: D5562782

fbshipit-source-id: ce715edc65b1510761e127bf89a6936370253a68

7 years agoDon't allow Future::onError([](exception_wrapper&){}) to compile
Sargun Vohra [Mon, 7 Aug 2017 20:29:40 +0000 (13:29 -0700)]
Don't allow Future::onError([](exception_wrapper&){}) to compile

Summary: `Future::onError` does not work with a function that takes `exception_wrapper&`, so it should not compile. `exception_wrapper`, `const exception_wrapper&`, and `exception_wrapper&&` are unaffected.

Reviewed By: yfeldblum

Differential Revision: D5556083

fbshipit-source-id: 45d096d9fee00322eeec6b9b9b1dcbef55cced03

7 years agoConsistent use of sformat in address-related files v2017.08.07.00
Yedidya Feldblum [Sun, 6 Aug 2017 05:09:13 +0000 (22:09 -0700)]
Consistent use of sformat in address-related files

Summary:
[Folly] Consistent use of `sformat` in address-related files.

V.s. `format(/*...*/).str()` and v.s. `to<std::string>`.

Reviewed By: meyering

Differential Revision: D5570334

fbshipit-source-id: 83aedf9a694721fb209e62e94f1a5c5ecd355e81