Skip to content

Commit

Permalink
Merge branch 'MikePopoloski:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Sustrak committed Jun 25, 2023
2 parents 0d15296 + f94723c commit b97591f
Show file tree
Hide file tree
Showing 7 changed files with 1,314 additions and 24 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_compile_options(/utf-8 /bigobj /permissive-)
endif()

# mimalloc is incompatible with Python bindings on MacOS
if(CMAKE_SYSTEM_NAME MATCHES "Darwin" AND SLANG_INCLUDE_PYLIB)
# mimalloc is incompatible with Python bindings
if(SLANG_INCLUDE_PYLIB)
set(SLANG_USE_MIMALLOC OFF)
endif()

Expand Down
11 changes: 4 additions & 7 deletions docs/building.dox
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@ git clone https://github.com/MikePopoloski/slang.git
slang requires the following tools in order to build:
- [python 3](https://www.python.org/)
- [CMake](https://cmake.org/) (3.15 or later)
- C++20 compatible compiler
- GCC 10 is the minimum supported version
- clang 10 is the minimum supported version
- C++20 compatible compiler. Minimum supported compiler versions:
- GCC 10
- clang 16
- XCode 14.3
- MSVC support is tested only against the most recent update of VS 2022
- Other compilers (including earlier versions of the ones listed above) may or may not work.
Note that AppleClang has its own versioning scheme -- you generally need a newer AppleClang
to get full C++20 support, and Apple ties Xcode updates to OS versions so you may be forced
to update your OS.

@section building-start Quick Start

Expand Down
2 changes: 1 addition & 1 deletion include/slang/util/Enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ inline constexpr bitmask_detail::underlying_type_t<T> get_enum_mask(const T&) no
/// of bitwise-combined flags. Built-in strongly-typed C++ enums are not otherwise
/// combinable via operators like | and &.
template<typename T>
class SLANG_EXPORT bitmask {
class bitmask {
public:
using underlying_type = bitmask_detail::underlying_type_t<T>;

Expand Down
39 changes: 26 additions & 13 deletions include/slang/util/SmallVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class SmallVectorBase {
}

/// Appends a range of elements to the end of the array.
template<typename TIter, typename = std::enable_if_t<is_iterator_v<TIter>>>
template<std::input_or_output_iterator TIter>
void append(TIter first, TIter last) {
auto numElems = static_cast<size_type>(std::ranges::distance(first, last));
auto newSize = len + numElems;
Expand Down Expand Up @@ -231,6 +231,12 @@ class SmallVectorBase {
append(first, last);
}

/// Resets the contents of the array to be the contents of the given range.
template<typename TContainer>
void assign(const TContainer& container) {
assign(std::ranges::begin(container), std::ranges::end(container));
}

/// Constructs a new element at the specified position in the array.
template<typename... Args>
iterator emplace(const_iterator pos, Args&&... args) {
Expand Down Expand Up @@ -280,33 +286,32 @@ class SmallVectorBase {
reserve(newSize);

// Reset the iterator since reserve() may have invalidated it.
pos = begin() + offset;
auto result = begin() + offset;

// If there are more existing elements between the insertion point and
// the end of the range than there are being inserted we can use a
// simpler approach for insertion.
auto existingOverlap = static_cast<size_type>(end() - pos);
auto existingOverlap = static_cast<size_type>(end() - result);
if (existingOverlap >= numElems) {
auto oldEnd = end();
append(std::move_iterator<iterator>(end() - numElems),
std::move_iterator<iterator>(end()));

std::ranges::move_backward(pos, oldEnd - numElems, oldEnd);
std::ranges::copy(first, last, pos);
return pos;
std::ranges::move_backward(result, oldEnd - numElems, oldEnd);
std::ranges::copy(first, last, result);
return result;
}

// Move over elements we're about to overwrite.
std::uninitialized_move(pos, end(), begin() + newSize - existingOverlap);
std::uninitialized_move(result, end(), begin() + newSize - existingOverlap);

// Copy in the new elements.
std::ranges::copy_n(first, existingOverlap, pos);
first += existingOverlap;
first = std::ranges::copy_n(first, existingOverlap, result).in;

// Insert the non-overwritten middle part.
std::ranges::uninitialized_copy(first, last, end());
// Insert the non-overwritten end part.
std::ranges::uninitialized_copy(first, last, end(), end() + numElems - existingOverlap);
len = newSize;
return pos;
return result;
}

/// Inserts @a count copies of @a value at the specified position in the array.
Expand Down Expand Up @@ -490,7 +495,9 @@ class SmallVectorBase {

if (newSize > len) {
if (newSize > cap) {
resizeRealloc(newSize, val);
// Copy the value in case it's inside our existing array.
TVal temp(val);
resizeRealloc(newSize, temp);
return;
}

Expand Down Expand Up @@ -573,6 +580,12 @@ class SmallVector : public SmallVectorBase<T> {
this->append(first, last);
}

/// Constructs the SmallVector from the given range.
template<typename TRange>
explicit SmallVector(TRange range) {
this->append(range);
}

/// Copy constructs from another vector.
SmallVector(const SmallVector& other) : SmallVector(static_cast<const Base&>(other)) {}

Expand Down
2 changes: 1 addition & 1 deletion include/slang/util/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class SLANG_EXPORT AssertionException : public std::logic_error {
/// The real value of this type is in documenting in the API the intentions of the pointer,
/// so that consumers don't need to add explicit null checks.
template<typename T>
class SLANG_EXPORT not_null {
class not_null {
public:
static_assert(std::is_assignable<T&, std::nullptr_t>::value, "T cannot be assigned nullptr.");

Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ add_executable(
unittests/PortTests.cpp
unittests/PreprocessorTests.cpp
unittests/PrimitiveTests.cpp
unittests/SmallVectorTests.cpp
unittests/StatementParsingTests.cpp
unittests/StatementTests.cpp
unittests/SubroutineTests.cpp
Expand Down
Loading

0 comments on commit b97591f

Please sign in to comment.