Skip to content

Commit

Permalink
[proxy](2/n) provide proxy layers for type traits (#717)
Browse files Browse the repository at this point in the history
* [proxy](2/n) provide proxy layers for type traits

* fix after rebasing
  • Loading branch information
SchrodingerZhu authored Jan 6, 2025
1 parent 7db1f24 commit 2cc74ea
Show file tree
Hide file tree
Showing 39 changed files with 557 additions and 122 deletions.
18 changes: 10 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -495,21 +495,23 @@ jobs:
run: ${{github.workspace}}/build/fuzzing/snmalloc-fuzzer

self-vendored:
name: Self Vendored STL Functionality
strategy:
fail-fast: false
matrix:
include:
- os: windows-2022
cxx: clang-cl
cc: clang-cl
- os: ubuntu-latest
cxx: clang++
cc: clang
- os: ubuntu-latest
cxx: g++
cc: gcc
- os: ubuntu-24.04
cxx: clang++-18
cc: clang-18
- os: ubuntu-24.04
cxx: g++-14
cc: gcc-14
- os: macos-latest
cxx: clang++
cc: clang
cc: clang
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand All @@ -524,7 +526,7 @@ jobs:
- name: Prepare Ubuntu
if: runner.os == 'Linux'
run: |
sudo apt install ninja-build
sudo apt-get install -y ninja-build
- name: Configure CMake
run: >
cmake
Expand Down
6 changes: 3 additions & 3 deletions src/snmalloc/aal/aal.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ namespace snmalloc
* must explicitly give their address_t.
*
* This somewhat obtuse way of spelling the defaulting is necessary so
* that all arguments to std::conditional_t are valid, even if they
* that all arguments to stl::conditional_t are valid, even if they
* wouldn't be valid in context. One might rather wish to say
*
* std::conditional_t<..., uintptr_t, Arch::address_t>
* stl::conditional_t<..., uintptr_t, Arch::address_t>
*
* but that requires that Arch::address_t always be given, precisely
* the thing we're trying to avoid with the conditional.
Expand All @@ -83,7 +83,7 @@ namespace snmalloc
using address_t = uintptr_t;
};

using address_t = typename std::conditional_t<
using address_t = typename stl::conditional_t<
(Arch::aal_features & IntegerPointers) != 0,
default_address_t,
Arch>::address_t;
Expand Down
11 changes: 5 additions & 6 deletions src/snmalloc/aal/aal_concept.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
# include "../ds_core/ds_core.h"
# include "aal_consts.h"

# include <cstdint>
# include <utility>
# include <stdint.h>

namespace snmalloc
{
Expand All @@ -16,10 +15,10 @@ namespace snmalloc
template<typename AAL>
concept IsAAL_static_members =
requires() {
typename std::integral_constant<uint64_t, AAL::aal_features>;
typename std::integral_constant<int, AAL::aal_name>;
typename std::integral_constant<std::size_t, AAL::bits>;
typename std::integral_constant<std::size_t, AAL::address_bits>;
typename stl::integral_constant<uint64_t, AAL::aal_features>;
typename stl::integral_constant<int, AAL::aal_name>;
typename stl::integral_constant<size_t, AAL::bits>;
typename stl::integral_constant<size_t, AAL::address_bits>;
};

/**
Expand Down
3 changes: 2 additions & 1 deletion src/snmalloc/backend/fixedglobalconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ namespace snmalloc
static_assert(B::wildness == capptr::dimension::Wildness::Wild);

static const size_t sz = sizeof(
std::conditional<std::is_same_v<std::remove_cv<T>, void>, void*, T>);
stl::
conditional_t<stl::is_same_v<stl::remove_cv_t<T>, void>, void*, T>);

UNUSED(ls);
auto address = address_cast(p);
Expand Down
2 changes: 1 addition & 1 deletion src/snmalloc/backend/globalconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace snmalloc
/**
* Use one of the default range configurations
*/
using LocalState = std::conditional_t<
using LocalState = stl::conditional_t<
mitigations(metadata_protection),
MetaProtectedRangeLocalState<Pal, Pagemap, Base>,
StandardLocalState<Pal, Pagemap, Base>>;
Expand Down
2 changes: 1 addition & 1 deletion src/snmalloc/backend/meta_protected_range.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace snmalloc
CommitRange<PAL>,
// In case of huge pages, we don't want to give each thread its own huge
// page, so commit in the global range.
std::conditional_t<
stl::conditional_t<
(max_page_chunk_size_bits > MIN_CHUNK_BITS),
LargeBuddyRange<
max_page_chunk_size_bits,
Expand Down
4 changes: 2 additions & 2 deletions src/snmalloc/backend_helpers/authmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace snmalloc
struct BasicAuthmap
{
static_assert(
std::is_same_v<capptr::Arena<void>, typename ConcreteMap::EntryType>,
stl::is_same_v<capptr::Arena<void>, typename ConcreteMap::EntryType>,
"BasicAuthmap's ConcreteMap must have capptr::Arena<void> element type!");

private:
Expand Down Expand Up @@ -70,7 +70,7 @@ namespace snmalloc
* Pick between the two above implementations based on StrictProvenance
*/
template<typename CA>
using DefaultAuthmap = std::conditional_t<
using DefaultAuthmap = stl::conditional_t<
aal_supports<StrictProvenance>,
BasicAuthmap<CA>,
DummyAuthmap>;
Expand Down
4 changes: 2 additions & 2 deletions src/snmalloc/backend_helpers/largebuddyrange.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ namespace snmalloc
* covers the whole range. Uses template insanity to make this work.
*/
template<bool exists = MAX_SIZE_BITS != (bits::BITS - 1)>
std::enable_if_t<exists>
stl::enable_if_t<exists>
parent_dealloc_range(capptr::Arena<void> base, size_t size)
{
static_assert(
Expand Down Expand Up @@ -343,7 +343,7 @@ namespace snmalloc
/* The large buddy allocator always deals in Arena-bounded pointers. */
using ChunkBounds = capptr::bounds::Arena;
static_assert(
std::is_same_v<typename ParentRange::ChunkBounds, ChunkBounds>);
stl::is_same_v<typename ParentRange::ChunkBounds, ChunkBounds>);

constexpr Type() = default;

Expand Down
6 changes: 3 additions & 3 deletions src/snmalloc/backend_helpers/pagemap.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ namespace snmalloc
using Entry = PagemapEntry;

static_assert(
std::is_same_v<PagemapEntry, typename ConcreteMap::EntryType>,
stl::is_same_v<PagemapEntry, typename ConcreteMap::EntryType>,
"BasicPagemap's PagemapEntry and ConcreteMap disagree!");

static_assert(
std::is_base_of_v<MetaEntryBase, PagemapEntry>,
stl::is_base_of_v<MetaEntryBase, PagemapEntry>,
"BasicPagemap's PagemapEntry type is not a MetaEntryBase");

/**
Expand Down Expand Up @@ -115,7 +115,7 @@ namespace snmalloc
*/
template<bool fixed_range_ = fixed_range>
static SNMALLOC_FAST_PATH
std::enable_if_t<fixed_range_, std::pair<address_t, address_t>>
stl::enable_if_t<fixed_range_, std::pair<address_t, address_t>>
get_bounds()
{
static_assert(fixed_range_ == fixed_range, "Don't set SFINAE parameter!");
Expand Down
6 changes: 3 additions & 3 deletions src/snmalloc/backend_helpers/range_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace snmalloc
template<typename Anc>
Anc* ancestor()
{
if constexpr (std::is_same_v<Anc, Parent>)
if constexpr (stl::is_same_v<Anc, Parent>)
{
return &parent;
}
Expand Down Expand Up @@ -119,7 +119,7 @@ namespace snmalloc
template<typename Anc>
Anc* ancestor()
{
if constexpr (std::is_same_v<Anc, Parent>)
if constexpr (stl::is_same_v<Anc, Parent>)
{
return &parent;
}
Expand Down Expand Up @@ -150,7 +150,7 @@ namespace snmalloc
template<typename Anc>
Anc* ancestor()
{
if constexpr (std::is_same_v<Anc, Parent>)
if constexpr (stl::is_same_v<Anc, Parent>)
{
return parent;
}
Expand Down
2 changes: 1 addition & 1 deletion src/snmalloc/backend_helpers/staticconditionalrange.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace snmalloc
using ChunkBounds = typename ActualParentRange::ChunkBounds;

static_assert(
std::is_same_v<ChunkBounds, typename ParentRange::ChunkBounds>,
stl::is_same_v<ChunkBounds, typename ParentRange::ChunkBounds>,
"Grandparent and optional parent range chunk bounds must be equal");

constexpr Type() = default;
Expand Down
4 changes: 2 additions & 2 deletions src/snmalloc/ds/entropy.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
namespace snmalloc
{
template<typename PAL>
std::enable_if_t<pal_supports<Entropy, PAL>, uint64_t> get_entropy64()
stl::enable_if_t<pal_supports<Entropy, PAL>, uint64_t> get_entropy64()
{
return PAL::get_entropy64();
}

template<typename PAL>
std::enable_if_t<!pal_supports<Entropy, PAL>, uint64_t> get_entropy64()
stl::enable_if_t<!pal_supports<Entropy, PAL>, uint64_t> get_entropy64()
{
#ifdef SNMALLOC_PLATFORM_HAS_GETENTROPY
return DefaultPal::get_entropy64();
Expand Down
2 changes: 1 addition & 1 deletion src/snmalloc/ds/mpmcstack.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace snmalloc
void push(T* item)
{
static_assert(
std::is_same<decltype(T::next), stl::Atomic<T*>>::value,
stl::is_same_v<decltype(T::next), stl::Atomic<T*>>,
"T->next must be an stl::Atomic<T*>");

return push(item, item);
Expand Down
10 changes: 5 additions & 5 deletions src/snmalloc/ds/pagemap.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ namespace snmalloc
* fixed-range pagemaps, whose size depends on dynamic configuration.
*/
template<bool has_bounds_ = has_bounds>
static constexpr std::enable_if_t<!has_bounds_, size_t> required_size()
static constexpr stl::enable_if_t<!has_bounds_, size_t> required_size()
{
static_assert(
has_bounds_ == has_bounds, "Don't set SFINAE template parameter!");
Expand All @@ -99,7 +99,7 @@ namespace snmalloc
* `required_size` is enabled for the has-bounds case.
*/
template<bool has_bounds_ = has_bounds>
std::enable_if_t<!has_bounds_> init(T* address)
stl::enable_if_t<!has_bounds_> init(T* address)
{
SNMALLOC_ASSERT(!is_initialised());

Expand All @@ -115,7 +115,7 @@ namespace snmalloc
* Returns usable range after pagemap has been allocated
*/
template<bool has_bounds_ = has_bounds>
std::enable_if_t<has_bounds_, std::pair<void*, size_t>>
stl::enable_if_t<has_bounds_, std::pair<void*, size_t>>
init(void* b, size_t s)
{
SNMALLOC_ASSERT(!is_initialised());
Expand Down Expand Up @@ -174,7 +174,7 @@ namespace snmalloc
* Initialise the pagemap without bounds.
*/
template<bool randomize_position, bool has_bounds_ = has_bounds>
std::enable_if_t<!has_bounds_> init()
stl::enable_if_t<!has_bounds_> init()
{
SNMALLOC_ASSERT(!is_initialised());

Expand Down Expand Up @@ -250,7 +250,7 @@ namespace snmalloc
}

template<bool has_bounds_ = has_bounds>
std::enable_if_t<has_bounds_, std::pair<address_t, size_t>> get_bounds()
stl::enable_if_t<has_bounds_, std::pair<address_t, size_t>> get_bounds()
{
SNMALLOC_ASSERT(is_initialised());

Expand Down
3 changes: 1 addition & 2 deletions src/snmalloc/ds/singleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#include "../ds_core/ds_core.h"
#include "flaglock.h"
#include "snmalloc/stl/atomic.h"

#include <type_traits>
#include "snmalloc/stl/type_traits.h"

namespace snmalloc
{
Expand Down
16 changes: 8 additions & 8 deletions src/snmalloc/ds_core/bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

#include "defines.h"
#include "snmalloc/stl/atomic.h"
#include "snmalloc/stl/type_traits.h"

#include <climits>
#include <cstdint>
#include <type_traits>
#if defined(_MSC_VER)
# include <intsafe.h>
#endif
Expand Down Expand Up @@ -55,7 +55,7 @@ namespace snmalloc
template<typename T = size_t, typename S>
constexpr T one_at_bit(S shift)
{
static_assert(std::is_integral_v<T>, "Type must be integral");
static_assert(stl::is_integral_v<T>, "Type must be integral");
SNMALLOC_ASSERT(sizeof(T) * 8 > static_cast<size_t>(shift));
return (static_cast<T>(1)) << shift;
}
Expand Down Expand Up @@ -95,15 +95,15 @@ namespace snmalloc
return BITS - index - 1;
# endif
#else
if constexpr (std::is_same_v<unsigned long, std::size_t>)
if constexpr (stl::is_same_v<unsigned long, std::size_t>)
{
return static_cast<size_t>(__builtin_clzl(x));
}
else if constexpr (std::is_same_v<unsigned long long, std::size_t>)
else if constexpr (stl::is_same_v<unsigned long long, std::size_t>)
{
return static_cast<size_t>(__builtin_clzll(x));
}
else if constexpr (std::is_same_v<unsigned int, std::size_t>)
else if constexpr (stl::is_same_v<unsigned int, std::size_t>)
{
return static_cast<size_t>(__builtin_clz(x));
}
Expand Down Expand Up @@ -182,15 +182,15 @@ namespace snmalloc
return _tzcnt_u32(static_cast<unsigned int>(x));
# endif
#else
if constexpr (std::is_same_v<unsigned long, std::size_t>)
if constexpr (stl::is_same_v<unsigned long, std::size_t>)
{
return static_cast<size_t>(__builtin_ctzl(x));
}
else if constexpr (std::is_same_v<unsigned long long, std::size_t>)
else if constexpr (stl::is_same_v<unsigned long long, std::size_t>)
{
return static_cast<size_t>(__builtin_ctzll(x));
}
else if constexpr (std::is_same_v<unsigned int, std::size_t>)
else if constexpr (stl::is_same_v<unsigned int, std::size_t>)
{
return static_cast<size_t>(__builtin_ctz(x));
}
Expand Down
Loading

0 comments on commit 2cc74ea

Please sign in to comment.