1. 26 Oct, 2019 1 commit
  2. 25 Oct, 2019 2 commits
    • Yedidya Feldblum's avatar
      Change an ifdef to a constexpr ternary · 2cb34df8
      Yedidya Feldblum authored
      Summary: [Folly] Change an `#ifdef` to a constexpr ternary for `MemoryMapping`.
      
      Reviewed By: meyering
      
      Differential Revision: D18024494
      
      fbshipit-source-id: 7ee040891ecee9bccf46af1dc43e54946e676c70
      2cb34df8
    • Wez Furlong's avatar
      getdeps: memoize eden prefetched dirs · 60df0a6b
      Wez Furlong authored
      Summary:
      currently, the implementation of `eden prefetch` calls into
      a mercurial function that is overly eager in making network connections,
      which results in what should be a fast NOP second prefetch call taking
      more time than is desirable.
      
      This diff adds a little cache to avoid repeatedly calling prefetch
      for the same directory more than once for the life of the getdeps
      process.
      
      Given the usage pattern of getdeps it is OK that we don't provide
      a way to invalidate this cache.
      
      Reviewed By: fanzeyi
      
      Differential Revision: D18005408
      
      fbshipit-source-id: 0ec3f477da1043a5a715704b512c81fcfaa0acde
      60df0a6b
  3. 24 Oct, 2019 1 commit
    • Yedidya Feldblum's avatar
      Optimize Function::operator() codegen · 6e0a487c
      Yedidya Feldblum authored
      Summary:
      [Folly] Optimize `Function::operator()` codegen for size and speed.
      
      * Avoid translating between values and references for trivially-copyable values.
      * Avoid shifting all arguments to make room for the function object address.
      
      In the optimal case, the codegen for calling a `Function` with many arguments translates into just a `jmp`.
      
      See:
      * https://github.com/thecppzoo/zoo/commits/master/inc/zoo/AnyCallable.h
      * https://github.com/bloomberg/bde/blob/3.38.0.1/groups/bsl/bslstl/bslstl_function.h
      * https://github.com/bloomberg/bde/blob/3.38.0.1/groups/bsl/bslmf/bslmf_forwardingtype.h
      
      Given this example code:
      
      ```lang=c++,name=check.cpp
      extern "C" void check_0(folly::Function<void()>& f) { f(); }
      extern "C" void check_1(int i, folly::Function<void(int)>& f) { f(i); }
      extern "C" void check_2(int i, int j, folly::Function<void(int, int)>& f) { f(i, j); }
      extern "C" void check_3(int i, int j, int k, folly::Function<void(int, int, int)>& f) { f(i, j, k); }
      extern "C" void check_4(int i, int j, int k, int l, folly::Function<void(int, int, int, int)>& f) { f(i, j, k, l); }
      ```
      
      Before:
      
      ```name=check.o
      0000000000000000 <check_0>:
         0:   ff 67 30                jmp    QWORD PTR [rdi+0x30]
      0000000000000000 <check_1>:
         0:   55                      push   rbp
         1:   48 89 f0                mov    rax,rsi
         4:   48 89 e5                mov    rbp,rsp
         7:   48 83 ec 10             sub    rsp,0x10
         b:   89 7d fc                mov    DWORD PTR [rbp-0x4],edi
         e:   48 8d 75 fc             lea    rsi,[rbp-0x4]
        12:   48 89 c7                mov    rdi,rax
        15:   ff 50 30                call   QWORD PTR [rax+0x30]
        18:   c9                      leave
        19:   c3                      ret
      0000000000000000 <check_2>:
         0:   55                      push   rbp
         1:   48 89 d0                mov    rax,rdx
         4:   48 89 e5                mov    rbp,rsp
         7:   48 83 ec 10             sub    rsp,0x10
         b:   89 7d f8                mov    DWORD PTR [rbp-0x8],edi
         e:   89 75 fc                mov    DWORD PTR [rbp-0x4],esi
        11:   48 8d 55 fc             lea    rdx,[rbp-0x4]
        15:   48 8d 75 f8             lea    rsi,[rbp-0x8]
        19:   48 89 c7                mov    rdi,rax
        1c:   ff 50 30                call   QWORD PTR [rax+0x30]
        1f:   c9                      leave
        20:   c3                      ret
      0000000000000000 <check_3>:
         0:   55                      push   rbp
         1:   48 89 c8                mov    rax,rcx
         4:   48 89 e5                mov    rbp,rsp
         7:   48 83 ec 10             sub    rsp,0x10
         b:   89 7d f4                mov    DWORD PTR [rbp-0xc],edi
         e:   89 75 f8                mov    DWORD PTR [rbp-0x8],esi
        11:   89 55 fc                mov    DWORD PTR [rbp-0x4],edx
        14:   48 8d 4d fc             lea    rcx,[rbp-0x4]
        18:   48 8d 55 f8             lea    rdx,[rbp-0x8]
        1c:   48 8d 75 f4             lea    rsi,[rbp-0xc]
        20:   48 89 c7                mov    rdi,rax
        23:   ff 50 30                call   QWORD PTR [rax+0x30]
        26:   c9                      leave
        27:   c3                      ret
      0000000000000000 <check_4>:
         0:   55                      push   rbp
         1:   4c 89 c0                mov    rax,r8
         4:   48 89 e5                mov    rbp,rsp
         7:   48 83 ec 10             sub    rsp,0x10
         b:   89 7d f0                mov    DWORD PTR [rbp-0x10],edi
         e:   89 75 f4                mov    DWORD PTR [rbp-0xc],esi
        11:   89 55 f8                mov    DWORD PTR [rbp-0x8],edx
        14:   89 4d fc                mov    DWORD PTR [rbp-0x4],ecx
        17:   4c 8d 45 fc             lea    r8,[rbp-0x4]
        1b:   48 8d 4d f8             lea    rcx,[rbp-0x8]
        1f:   48 8d 55 f4             lea    rdx,[rbp-0xc]
        23:   48 8d 75 f0             lea    rsi,[rbp-0x10]
        27:   48 89 c7                mov    rdi,rax
        2a:   ff 50 30                call   QWORD PTR [rax+0x30]
        2d:   c9                      leave
        2e:   c3                      ret
      ```
      
      After:
      
      ```name=check.o
      0000000000000000 <check_0>:
         0:   ff 67 30                jmp    QWORD PTR [rdi+0x30]
      0000000000000000 <check_1>:
         0:   ff 66 30                jmp    QWORD PTR [rsi+0x30]
      0000000000000000 <check_2>:
         0:   ff 62 30                jmp    QWORD PTR [rdx+0x30]
      0000000000000000 <check_3>:
         0:   ff 61 30                jmp    QWORD PTR [rcx+0x30]
      0000000000000000 <check_4>:
         0:   41 ff 60 30             jmp    QWORD PTR [r8+0x30]
      ```
      
      Reviewed By: luciang
      
      Differential Revision: D17523239
      
      fbshipit-source-id: beed0bae827aad8290e807374e8596f71f98ce99
      6e0a487c
  4. 23 Oct, 2019 3 commits
    • Lewis Baker's avatar
      Add .startInlineUnsafe() method to folly::coro::Task · f01cb070
      Lewis Baker authored
      Summary: This allows the caller to guarantee that the coroutine starts executing on the current thread. This can be necessary for correctness in some situations, where having the coroutine enqueued to the executor, as `.start()` does, and potentially allowing other code to run in the meantime could invalidate some assumptions.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D18076197
      
      fbshipit-source-id: a6c5c226f2d7189f37e8f9713a30896767e9b8e9
      f01cb070
    • Kaz Ondo's avatar
      Initialize addrStorage on stack · 1b99423a
      Kaz Ondo authored
      Summary:
      MemorySanitizer was failing due to uninitialized memory in the stack.
      
      ```
      ==596112==WARNING: MemorySanitizer: use-of-uninitialized-value
      [testserver][INFO]: IOBuff received. Len = 128
          #0 0x9d4b21 in folly::SocketAddress::updateUnixAddressLength(unsigned int) xplat/folly/SocketAddress.cpp:710:7
          #1 0x9d4740 in folly::SocketAddress::setFromSockaddr(sockaddr_un const*, unsigned int) xplat/folly/SocketAddress.cpp:338:3
      
        Uninitialized value was created by an allocation of 'addrStorage' in the stack frame of function '_ZN5folly17AsyncServerSocket12handler
      ReadyEtNS_13NetworkSocketEt'
          #0 0x7de840 in folly::AsyncServerSocket::handlerReady(unsigned short, folly::NetworkSocket, unsigned short) xplat/folly/io/async/Asyn
      cServerSocket.cpp:835
      ```
      
      Differential Revision: D18086738
      
      fbshipit-source-id: f36013b157d7b34d3b29c08d4533f01be1a1a8c9
      1b99423a
    • Alexey Spiridonov's avatar
      Don't use private googletest API in TestUtils.h · d32d4344
      Alexey Spiridonov authored
      Summary:
      Until [very recently](https://github.com/google/googletest/pull/2517), `googletest` did not print the skip message in any shape or form, so nothing can possibly depend on us customizing the skip message here.
      
      The default is perfectly fine, let's keep it simple.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D18051635
      
      fbshipit-source-id: f7b889b0adf5e34a70c2579a34748bb159809b3c
      d32d4344
  5. 22 Oct, 2019 5 commits
  6. 21 Oct, 2019 5 commits
    • Yedidya Feldblum's avatar
      Guard the forward declaration of fibers::Baton · b440ee45
      Yedidya Feldblum authored
      Summary: [Folly] Guard the forward declaration of `fibers::Baton` by the same condition which determines whether `fibers::Baton` is ever used in futures.
      
      Reviewed By: lewissbaker
      
      Differential Revision: D17962552
      
      fbshipit-source-id: 2494026999cd170c36adec91108732254212abf1
      b440ee45
    • Yedidya Feldblum's avatar
      Prefer a C++ symbol over back-defining MAP_POPULATE · 54a20c00
      Yedidya Feldblum authored
      Summary: [Folly] Prefer a C++ symbol over back-defining `MAP_POPULATE`.
      
      Reviewed By: nbronson
      
      Differential Revision: D18024313
      
      fbshipit-source-id: 7f3b754a7911d6947e5a6f34860f9f0d3833aa51
      54a20c00
    • Yedidya Feldblum's avatar
      Add missing inline to co_current_executor · 979cdf43
      Yedidya Feldblum authored
      Summary: [Folly] Add missing `inline` to `co_current_executor`.
      
      Reviewed By: ericniebler
      
      Differential Revision: D18034078
      
      fbshipit-source-id: 8c212ef6278112cc8e90075494a3038d9111bb64
      979cdf43
    • Nathan Bronson's avatar
      switch to RDTSC spin loop timing · c9d712c3
      Nathan Bronson authored
      Summary:
      The PAUSE instruction's latency varies widely across x64
      architectures, resulting in too much spinning on Skylake in some
      scenarios.  This diff switches to using cycle counts to limit spinning
      on x64, so that the minimum and maximum spin durations are independent
      of asm_volatile_pause's latency.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D17961663
      
      fbshipit-source-id: 6170bfa48d007ca21b73b1a5c7e68da0043cda2c
      c9d712c3
    • Wez Furlong's avatar
      getdeps: don't use fbsource hash in the simple shipit fetcher · eddca91c
      Wez Furlong authored
      Summary:
      This avoids invalidating the entire build in response
      to just running `hg amend`, which is frustrating and slow.
      
      Reviewed By: chadaustin
      
      Differential Revision: D18005409
      
      fbshipit-source-id: ef93313859919298be78204046eb08bcadc5398e
      eddca91c
  7. 19 Oct, 2019 1 commit
    • Yedidya Feldblum's avatar
      Backport invocability variable templates · 88742563
      Yedidya Feldblum authored
      Summary: [Folly] Backport invocability variable templates: `is_invocable_v`, `is_invocable_r_v`, `is_nothrow_invocable_v`, `is_nothrow_invocable_r_v`. And for the member-invoke and free-invoke traits.
      
      Reviewed By: ericniebler
      
      Differential Revision: D17950331
      
      fbshipit-source-id: 5409d7a72116b0976573e1f64760c5ef9274966f
      88742563
  8. 18 Oct, 2019 4 commits
    • Mingtao Yang's avatar
      Make getSSLServerName() return SNI presented in CH, if available · d9b854ef
      Mingtao Yang authored
      Summary:
      If CH parsing is enabled, also parse out the ServerName extension. OpenSSL 1.1.1
      changes the behavior of `SSL_get_servername`: an SNI value is stored in
      the underlying SESSION if and only if both parties negotiated that SNI.
      
      There are some situations where one would wish to retrieve the original
      ServerName that the client sent.
      
      Reviewed By: knekritz
      
      Differential Revision: D17893443
      
      fbshipit-source-id: b29ee42e90629c869dd5e68c93c7cb2abc19745f
      d9b854ef
    • Lewis Baker's avatar
      Make folly::coro::collectAll() isolate RequestContext state of child tasks. · 615a44f0
      Lewis Baker authored
      Summary:
      No longer allow a child task's modifications to the RequestContext made before it's first suspension point to bleed into the next child task's context.
      
      Now always restore the parent task's RequestContext before starting subsequent tasks.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D17846070
      
      fbshipit-source-id: 44e206d4c833759fc36c7d1bd0f3545ca6bb9ab1
      615a44f0
    • Dan Melnic's avatar
      Relax DFATAL message · 368f00f0
      Dan Melnic authored
      Summary: Relax DFATAL message
      
      Reviewed By: yfeldblum
      
      Differential Revision: D18001089
      
      fbshipit-source-id: 2027d0257e1cba6905dc4eb1863b70a8fe6a7366
      368f00f0
    • Alexander Zinoviev's avatar
      trim, ltrim, rtrim functions with custom predicate · d0002eca
      Alexander Zinoviev authored
      Summary: trim, ltrim and rtrim are similar to ltrimWhitespace, rtrimWhitespace and trimWhitespace but you can specify what you want to remove
      
      Reviewed By: yfeldblum
      
      Differential Revision: D17946658
      
      fbshipit-source-id: 9bdc5e6eb810e628a8c16b5142c17a3313f884f2
      d0002eca
  9. 17 Oct, 2019 7 commits
    • Rodolfo Granata's avatar
      folly/executors: properly synchronize access to thread pool stats. · 8c7a26ad
      Rodolfo Granata authored
      Summary:
      ThreadPoolExecutor::getPoolStats depends on derived classes implementation.
      Calling `getPoolStats` is specially useful from `ThreadPoolExecutor::withAll`.
      
      This change moves registration of thread pool executor instances to derived classes
      to avoid `ThreadPoolExecutor::withAll` racing with thread pool destruction while calling `getPoolStats`.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D17965135
      
      fbshipit-source-id: 637de55ed78b085dc86fffa0e0f4a66cd4cfcede
      8c7a26ad
    • Dan Melnic's avatar
      keepAliveRelease code reorg · e4519f66
      Dan Melnic authored
      Summary: keepAliveRelease code reorg
      
      Reviewed By: kevin-vigor
      
      Differential Revision: D17835172
      
      fbshipit-source-id: 48c60b04324f0d9bd1ac628e2625d3d4d2654c99
      e4519f66
    • Dan Melnic's avatar
      Add missing switch case · f6ca07e8
      Dan Melnic authored
      Summary: Add missing switch case
      
      Reviewed By: yfeldblum
      
      Differential Revision: D17945170
      
      fbshipit-source-id: 8128c40e1c86b2a5ff8d1bad3c0e9fe197adc174
      f6ca07e8
    • Wez Furlong's avatar
      getdeps: regard IOError as transient when fetching URLs · a9e811bd
      Wez Furlong authored
      Summary:
      this should help avoid this particular error:
      
      ```
      IOError: [Errno socket error] [Errno 11001] getaddrinfo failed
      ```
      
      Reviewed By: chadaustin
      
      Differential Revision: D17886598
      
      fbshipit-source-id: bd9f5b84ebd7ca5c339be3afec3a975fa907d052
      a9e811bd
    • Wez Furlong's avatar
      watchman: pass version info down to watchman build via environment · 4a9c487d
      Wez Furlong authored
      Summary:
      This diff allows passing a watchman version number override
      via the environment as well as via the cmake `WATCHMAN_VERSION_OVERRIDE`
      option.
      
      To help invalidate the build I've added a new section to the manifest
      files that allows listing out additional env vars that the project
      hashes should be sensitive to.  The effect of this is that we'll
      re-run the cmake configure step if the listed env vars are changed.
      
      Reviewed By: Ben0mega
      
      Differential Revision: D17865896
      
      fbshipit-source-id: 8ea5572b0b9b7af95ec5c310e494cb17a139ced4
      4a9c487d
    • Wez Furlong's avatar
      getdeps: constrain testpilot to our number of jobs · e009093f
      Wez Furlong authored
      Summary: testpilot's defaults assume a bigger machine than some of our laptops
      
      Reviewed By: fanzeyi
      
      Differential Revision: D17878120
      
      fbshipit-source-id: e01f1f9c77a4f5f011051c9c642dbe934c66bc0b
      e009093f
    • Lucas Dobson-Defenbaugh's avatar
      Check for existence of thread during getEventBase · a5bffff6
      Lucas Dobson-Defenbaugh authored
      Summary: During shutdown there's a race condition in IOThreadPoolExecutor::getEventBase where a thread is created in ensureActiveThreads, and then destroyed before pickThread() is called. This adds the same guard that exists in add().
      
      Reviewed By: yfeldblum
      
      Differential Revision: D17955227
      
      fbshipit-source-id: 042cb5c42056a9da4578571fb10936bbc477c4ff
      a5bffff6
  10. 16 Oct, 2019 7 commits
    • Eric Niebler's avatar
      add Folly portability macros for C++17 inline variables · fc88fcbf
      Eric Niebler authored
      Summary: Add a portability macro for testing whether the compiler supports C++17's inline variables.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D17957184
      
      fbshipit-source-id: bff7d2bc15867e32f787860b4f8e5a0176ac1017
      fc88fcbf
    • Yedidya Feldblum's avatar
      Fix wrong definition of FOLLY_HAVE_GROUP_VARINT · bfdc0a57
      Yedidya Feldblum authored
      Summary: [Folly] Fix wrong definition of `FOLLY_HAVE_GROUP_VARINT` when group varint is unsupported.
      
      Reviewed By: Orvid
      
      Differential Revision: D17961015
      
      fbshipit-source-id: 3c82aaaf4b257180ab0956e4b181bfd619d7adda
      bfdc0a57
    • Matt Ma's avatar
      Fix folly Travis build caused by D17506766. · 91b375da
      Matt Ma authored
      Summary:
      /home/folly/folly/experimental/test/QuotientMultiSetTest.cpp:60:29: error:
      missing template arguments before 'reader'
           folly::QuotientMultiSet reader(data);
      
      Reviewed By: vitaut
      
      Differential Revision: D17959566
      
      fbshipit-source-id: 02fec44b3d644eea0213895aa4df70349ef7d062
      91b375da
    • Wei Liu's avatar
      Revert D17908896: Fix deadlock in Folly RCU · 58405477
      Wei Liu authored
      Differential Revision:
      D17908896
      
      Original commit changeset: 85847fc17f4a
      
      fbshipit-source-id: 9b2bd8c11881cad18cffea0e14349e25d743b150
      58405477
    • Rodolfo Granata's avatar
      ThreadPoolExecutor: throw in getPendingTaskCountImpl instead of pure virtual. · 560befd3
      Rodolfo Granata authored
      Summary:
      Calling `folly::ThreadPoolExecutor::withAll` is powerfull when combined with `folly::ThreadPoolExecutor::getPoolStats`.
      However getPendingTaskCountImpl being pure virtual can trigger `__cxa_pure_virtual ... std::terminate()` while object is partially destructed.
      
      This change signals implementors of derived clases to write a body for getPendingTaskCountImpl while allowing calling getPoolStats -> getPendingTaskCountImpl within a try/catch block.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D17915523
      
      fbshipit-source-id: 2ffad7076313407969d88c75c7e457fa4e7e2d6d
      560befd3
    • Joe Loser's avatar
      Check if type is instantiation of a template (#1184) · 626871c3
      Joe Loser authored
      Summary:
      - There is not an easy way to check if a given type is an instantiation
        of a class template.
      - The common solution is to write a custom trait each time and
        specialize it for the given instantiation so that the trait returns
        `std:true_type`.
      - Add `is_instantiation_of` to help with DRY in custom traits for
        checking if a type is an instance of a given class template. Note that
        this does not work when the class template has a mix of type and
        non-type template parameters. It only works with types.
      Pull Request resolved: https://github.com/facebook/folly/pull/1184
      
      Reviewed By: vitaut
      
      Differential Revision: D16161679
      
      Pulled By: yfeldblum
      
      fbshipit-source-id: c933fd3db7c56f61b6784fdcd199ff7963d61d8f
      626871c3
    • Liu Cao's avatar
      Fix deadlock in Folly RCU · 06a918b7
      Liu Cao authored
      Summary:
      The deadlock repro is described https://github.com/facebook/folly/issues/1211.
      Fix is to check the working epoch before retire() starts the sync work.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D17908896
      
      fbshipit-source-id: 85847fc17f4a75058d4a72c43dba0c570a2593d6
      06a918b7
  11. 15 Oct, 2019 4 commits
    • Felix Handte's avatar
      Expose Deleter in Context Pool · 6e0b5856
      Felix Handte authored
      Summary: As title.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D17937014
      
      fbshipit-source-id: a0ff5f5f9cbbb182794dc564610d7adb9c7c8d08
      6e0b5856
    • Yedidya Feldblum's avatar
      Fix Json.SortKeys test when F14NodeMap may randomize · 628af5dd
      Yedidya Feldblum authored
      Summary: [Folly] Fix `Json.SortKeys` test when `F14NodeMap` may randomize table iteration order.
      
      Reviewed By: shixiao
      
      Differential Revision: D17903465
      
      fbshipit-source-id: 00f1a8c441af3e11815a4312f6dc810ec9455a5e
      628af5dd
    • Chad Austin's avatar
      poll more efficiently in Subprocess::waitTimeout · 3b62632c
      Chad Austin authored
      Summary:
      Unconditionally sleeping for 100ms in the wait polling loop has high average latency. If a process exits just after the initial wait() call, it's better to poll again sooner.
      
      Start with a 2ms sleep and double it every sleep, capping out at 100ms.
      
      Reviewed By: yfeldblum, mzhaom
      
      Differential Revision: D17769851
      
      fbshipit-source-id: efec8fdb8c2199b8db29b46b8c43fdaac56f69a8
      3b62632c
    • Chad Austin's avatar
      add Subprocess::waitOrTerminateOrKill · 16d41c4b
      Chad Austin authored
      Summary: `waitOrTerminateOrKill` fills the gap between `wait()` and `terminateOrKill`. It allows giving the subprocess a chance to shut down cleanly (after closing its stdin pipe, for example), but avoids waiting forever or leaking a child process.
      
      Reviewed By: yfeldblum, mzhaom
      
      Differential Revision: D17769090
      
      fbshipit-source-id: 8940fd63f7eb9c09ef293c89a5e97f69805735ff
      16d41c4b