[all-commits] [llvm/llvm-project] 07e984: [libc++] Support int8_t and uint8_t in integer dis...

Louis Dionne via All-commits all-commits at lists.llvm.org
Fri Jul 22 05:34:01 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 07e984bc52014a8565033be10f7e80982e974b99
      https://github.com/llvm/llvm-project/commit/07e984bc52014a8565033be10f7e80982e974b99
  Author: Louis Dionne <ldionne.2 at gmail.com>
  Date:   2022-07-22 (Fri, 22 Jul 2022)

  Changed paths:
    M libcxx/docs/ReleaseNotes.rst
    M libcxx/docs/UsingLibcxx.rst
    M libcxx/include/__random/binomial_distribution.h
    M libcxx/include/__random/discrete_distribution.h
    M libcxx/include/__random/geometric_distribution.h
    M libcxx/include/__random/is_valid.h
    M libcxx/include/__random/negative_binomial_distribution.h
    M libcxx/include/__random/poisson_distribution.h
    M libcxx/include/__random/uniform_int_distribution.h
    M libcxx/test/libcxx/numerics/rand/rand.req.urng/valid_int_type.verify.cpp
    M libcxx/test/std/numerics/rand/rand.dist/rand.dist.bern/rand.dist.bern.bin/eval.pass.cpp
    M libcxx/test/std/numerics/rand/rand.dist/rand.dist.bern/rand.dist.bern.geo/eval.pass.cpp
    M libcxx/test/std/numerics/rand/rand.dist/rand.dist.bern/rand.dist.bern.negbin/eval.pass.cpp
    M libcxx/test/std/numerics/rand/rand.dist/rand.dist.pois/rand.dist.pois.poisson/eval.pass.cpp
    M libcxx/test/std/numerics/rand/rand.dist/rand.dist.samp/rand.dist.samp.discrete/eval.pass.cpp
    M libcxx/test/std/numerics/rand/rand.dist/rand.dist.uni/rand.dist.uni.int/eval.pass.cpp

  Log Message:
  -----------
  [libc++] Support int8_t and uint8_t in integer distributions as an extension

In D125283, we ensured that integer distributions would not compile when
used with arbitrary unsupported types. This effectively enforced what
the Standard mentions here: http://eel.is/c++draft/rand#req.genl-1.5.

However, this also had the effect of breaking some users that were
using integer distributions with unsupported types like int8_t. Since we
already support using __int128_t in those distributions, it is reasonable
to also support smaller types like int8_t and its unsigned variant. This
commit implements that, adds tests and documents the extension. Note that
we voluntarily don't add support for instantiating these distributions
with bool and char, since those are not integer types. However, it is
trivial to replace uses of these random distributions on char using int8_t.

It is also interesting to note that in the process of adding tests
for smaller types, I discovered that our distributions sometimes don't
provide as faithful a distribution when instantiated with smaller types,
so I had to relax a couple of tests. In particular, we do a really bad
job at implementing the negative binomial, geometric and poisson distributions
for small types. I think this all boils down to the algorithm we use in
std::poisson_distribution, however I am running out of time to investigate
that and changing the algorithm would be an ABI break (which might be
reasonable).

As part of this patch, I also added a mitigation for a very likely
integer overflow bug we were hitting in our tests in negative_binomial_distribution.
I also filed http://llvm.org/PR56656 to track fixing the problematic
distributions with int8_t and uint8_t.

Supersedes D125283.

Differential Revision: https://reviews.llvm.org/D126823


  Commit: deb3b5552f04656dee27067b2cc68c906012cfe4
      https://github.com/llvm/llvm-project/commit/deb3b5552f04656dee27067b2cc68c906012cfe4
  Author: Louis Dionne <ldionne.2 at gmail.com>
  Date:   2022-07-22 (Fri, 22 Jul 2022)

  Changed paths:
    M libcxx/docs/DesignDocs/ExperimentalFeatures.rst
    M libcxx/docs/ReleaseNotes.rst
    M libcxx/docs/Status/Cxx20.rst
    M libcxx/docs/UsingLibcxx.rst
    M libcxx/include/__config
    A libcxx/test/libcxx/experimental/fexperimental-library.compile.pass.cpp
    M libcxx/utils/libcxx/test/params.py

  Log Message:
  -----------
  [libc++] Take advantage of -fexperimental-library in libc++

When -fexperimental-library is passed, libc++ will now pick up the
appropriate __has_feature flag defined by Clang to enable the
experimental library features.

As a fly-by, also update the documentation for the various TSes.

Differential Revision: https://reviews.llvm.org/D130176


Compare: https://github.com/llvm/llvm-project/compare/908054df4f15...deb3b5552f04


More information about the All-commits mailing list