Skip to content

Commit

Permalink
new compilers in CI (#28)
Browse files Browse the repository at this point in the history
* add new compilers (clang 17, 18, 19), gcc-14
* add ubuntu 24
* workaround gcc bug (final awaiter is promise))
* workaround clang 17 + bug (cache equality thread local variables)
  • Loading branch information
kelbon authored Oct 5, 2024
1 parent 4cbe2a6 commit 23673c6
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 61 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ jobs:
build:
strategy:
matrix:
os: [ubuntu-22.04]
compiler: [g++-12, clang++-14]
os: [ubuntu-24.04]
compiler: [g++-12, g++-14, clang++-14, clang++-17]
cpp_standard: [20]
build_type: [Debug, Release]
runs-on: ${{matrix.os}}
Expand All @@ -18,10 +18,10 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install ninja-build lld gcc-12 clang-14
sudo apt-get install ninja-build lld gcc-12 gcc-14 clang-14 clang-17
sudo ln -sf /usr/local/bin/ld /usr/bin/lld
- name: Configure CMake
run: |
run: |
cmake . -DKELCORO_ENABLE_TESTING=ON \
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
-DCMAKE_CXX_COMPILER=${{matrix.compiler}} \
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/clang_new_version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: build_and_test

on: push

jobs:
build:
strategy:
matrix:
os: [ubuntu-24.04]
version: [18, 19]
cpp_standard: [20]
build_type: [Debug, Release]
runs-on: ${{matrix.os}}
name: clang-${{matrix.version}}-${{matrix.build_type}}
steps:
- uses: actions/checkout@v2

- name: Install dependencies
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh ${{matrix.version}}
sudo apt-get update
sudo apt-get install ninja-build lld
sudo ln -sf /usr/local/bin/ld /usr/bin/lld
- name: Configure CMake
run: |
cmake . -DKELCORO_ENABLE_TESTING=ON \
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
-DCMAKE_CXX_COMPILER=clang++-${{matrix.version}} \
-DCMAKE_CXX_STANDARD=${{matrix.cpp_standard}} \
-B build -G "Ninja"
- name: Build
run:
cmake --build build

- name: Test
run: |
cd build
ctest --output-on-failure -C ${{matrix.build_type}} -V
43 changes: 24 additions & 19 deletions include/kelcoro/channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include "noexport/generators_common.hpp"

#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wattributes"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wattributes"
#endif
namespace dd {

Expand Down Expand Up @@ -94,23 +94,28 @@ struct channel_promise : not_movable {
static constexpr std::suspend_always initial_suspend() noexcept {
return {};
}
// *this is an final awaiter for size optimization
static constexpr bool await_ready() noexcept {
return false;
}
static constexpr void await_resume() noexcept {
}
KELCORO_ASSUME_NOONE_SEES constexpr std::coroutine_handle<> await_suspend(
std::coroutine_handle<>) const noexcept {
if (root != this) {
skip_this_leaf();
return owner();

struct final_awaiter {
const channel_promise& p;

static constexpr bool await_ready() noexcept {
return false;
}
set_result(nullptr);
return consumer_handle();
}
const channel_promise& final_suspend() const noexcept {
return *this;
static constexpr void await_resume() noexcept {
}
KELCORO_ASSUME_NOONE_SEES constexpr std::coroutine_handle<> await_suspend(
std::coroutine_handle<>) const noexcept {
if (p.root != &p) {
p.skip_this_leaf();
return p.owner();
}
p.set_result(nullptr);
return p.consumer_handle();
}
};

final_awaiter final_suspend() const noexcept {
return final_awaiter{*this};
}
static constexpr void return_void() noexcept {
}
Expand Down Expand Up @@ -367,5 +372,5 @@ struct operation_hash<std::coroutine_handle<channel_promise<Y>>> {
} // namespace dd

#ifdef __GNUC__
#pragma GCC diagnostic pop
#pragma GCC diagnostic pop
#endif
35 changes: 19 additions & 16 deletions include/kelcoro/generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,26 @@ struct generator_promise : not_movable, yield_block<generator_promise<Yield>, Yi
return {};
}

// *this is an final awaiter for size optimization
static constexpr bool await_ready() noexcept {
return false;
}
static constexpr void await_resume() noexcept {
}
KELCORO_ASSUME_NOONE_SEES constexpr std::coroutine_handle<> await_suspend(
std::coroutine_handle<>) const noexcept {
if (root != this) {
skip_this_leaf();
return owner();
struct final_awaiter {
const generator_promise& p;
static constexpr bool await_ready() noexcept {
return false;
}
set_result(nullptr);
return std::noop_coroutine();
}
const generator_promise& final_suspend() const noexcept {
return *this;
static constexpr void await_resume() noexcept {
}
KELCORO_ASSUME_NOONE_SEES constexpr std::coroutine_handle<> await_suspend(
std::coroutine_handle<>) const noexcept {
if (p.root != &p) {
p.skip_this_leaf();
return p.owner();
}
p.set_result(nullptr);
return std::noop_coroutine();
}
};

final_awaiter final_suspend() const noexcept {
return final_awaiter{*this};
}
static constexpr void return_void() noexcept {
}
Expand Down
61 changes: 39 additions & 22 deletions tests/test_coroutines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,14 @@ TEST(gen_mm) {
return error_count;
}

[[gnu::noinline]] void nocache(auto&) {
}

TEST(job_mm) {
std::atomic<size_t> err_c = 0;
auto job_creator = [&](std::atomic<int32_t>& value) -> dd::job {
auto th_id = std::this_thread::get_id();
nocache(th_id);
(void)co_await dd::jump_on(TP);
if (th_id == std::this_thread::get_id())
++err_c;
Expand Down Expand Up @@ -793,31 +797,44 @@ TEST(when_any_different_ctxts) {
return error_count;
}

#define RUN(TEST_NAME) \
{ \
std::cout << "- " << #TEST_NAME << std::flush; \
size_t c = TEST##TEST_NAME(); \
if (c > 0) { \
std::cerr << " FAIL " << c << '\n'; \
ec += c; \
} else { \
std::cout << " +" << '\n'; \
} \
}

int main() {
srand(time(0));
size_t ec = 0;
ec += TESTgenerator();
ec += TESTzip_generator();
ec += TESTlogical_thread();
ec += TESTcoroutines_integral();
ec += TESTlogical_thread_mm();
ec += TESTgen_mm();
ec += TESTjob_mm();
ec += TESTasync_tasks();
ec += TESTvoid_async_task();
ec += TESTchannel();
ec += TESTallocations();
ec += TESTdetached_tasks();
ec += TESTtask_blocking_wait();
ec += TESTtask_with_exception();
ec += TESTtask_blocking_wait_noexcept();
ec += TESTtask_start_and_detach();
ec += TESTcontexted_task();
ec += TESTcomplex_ret();
ec += TESTwhen_all_same_ctx();
ec += TESTwhen_any();
ec += TESTwhen_all_dynamic();
ec += TESTwhen_any_different_ctxts();
RUN(generator);
RUN(generator);
RUN(zip_generator);
RUN(logical_thread);
RUN(coroutines_integral);
RUN(logical_thread_mm);
RUN(gen_mm);
RUN(job_mm);
RUN(async_tasks);
RUN(void_async_task);
RUN(channel);
RUN(allocations);
RUN(detached_tasks);
RUN(task_blocking_wait);
RUN(task_with_exception);
RUN(task_blocking_wait_noexcept);
RUN(task_start_and_detach);
RUN(contexted_task);
RUN(complex_ret);
RUN(when_all_same_ctx);
RUN(when_any);
RUN(when_all_dynamic);
RUN(when_any_different_ctxts);
return ec;
}
#else
Expand Down

0 comments on commit 23673c6

Please sign in to comment.