Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions runtime-light/coroutine/detail/when-any.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "runtime-light/coroutine/concepts.h"
#include "runtime-light/coroutine/type-traits.h"
#include "runtime-light/coroutine/void-value.h"
#include "runtime-light/metaprogramming/type-functions.h"
#include "runtime-light/stdlib/diagnostics/logs.h"

namespace kphp::coro::detail::when_any {
Expand Down Expand Up @@ -120,7 +121,10 @@ class when_any_ready_awaitable<std::tuple<task_types...>> {

const auto task_result_processor{[&result = m_awaitable.m_result](auto&& task) noexcept {
if (auto task_result{std::forward<decltype(task)>(task).result()}; !result.has_value() && task_result.has_value()) {
result = std::move(task_result);
using result_variant_type = std::remove_cvref<decltype(result)>::type::value_type;
using task_result_type = decltype(task_result)::value_type;
result =
result_variant_type{std::in_place_index<kphp::type_functions::variant_index<result_variant_type, task_result_type>()>, *std::move(task_result)};
}
}};
std::apply([&task_result_processor](auto&&... tasks) noexcept { (std::invoke(task_result_processor, std::forward<decltype(tasks)>(tasks)), ...); },
Expand Down Expand Up @@ -290,8 +294,11 @@ class when_any_task {

template<kphp::coro::concepts::awaitable awaitable_type>
auto make_when_any_task(awaitable_type awaitable) noexcept -> when_any_task<typename kphp::coro::awaitable_traits<awaitable_type>::awaiter_return_type> {
co_yield co_await std::move(awaitable);
co_return;
if constexpr (std::is_void_v<typename kphp::coro::awaitable_traits<awaitable_type>::awaiter_return_type>) {
co_await std::move(awaitable);
} else {
co_yield co_await std::move(awaitable);
}
}

} // namespace kphp::coro::detail::when_any
16 changes: 14 additions & 2 deletions runtime-light/coroutine/io-scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <memory>
#include <optional>
#include <ranges>
#include <type_traits>
#include <utility>
#include <variant>

Expand Down Expand Up @@ -463,13 +464,24 @@ auto io_scheduler::schedule(coroutine_type coroutine, std::chrono::duration<rep_
using expected_return_type = typename kphp::coro::coroutine_traits<coroutine_type>::return_type;

if (timeout <= std::chrono::duration<rep_type, period_type>{0}) [[unlikely]] {
co_return std::expected<expected_return_type, timeout_status>{co_await schedule(std::move(coroutine))};
if constexpr (std::is_void_v<expected_return_type>) {
co_await schedule(std::move(coroutine));
co_return std::expected<expected_return_type, timeout_status>{};
} else {
co_return std::expected<expected_return_type, timeout_status>{co_await schedule(std::move(coroutine))};
}
}

auto result{co_await kphp::coro::when_any(std::move(coroutine), make_timeout_task(timeout))};
if (std::holds_alternative<timeout_status>(result)) [[unlikely]] {
co_return std::unexpected{std::move(std::get<1>(result))};
}
co_return std::expected<expected_return_type, timeout_status>{std::move(std::get<0>(result))};

if constexpr (std::is_void_v<expected_return_type>) {
co_return std::expected<expected_return_type, timeout_status>{};
} else {
co_return std::expected<expected_return_type, timeout_status>{std::move(std::get<0>(result))};
}
}

template<typename rep_type, typename period_type>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <cstddef>
#include <functional>

namespace kphp::concepts {

template<typename T>
concept standard_layout = std::is_standard_layout_v<T>;

Expand All @@ -18,3 +20,5 @@ concept hashable = requires(T t) {

template<typename type, typename... types>
concept in_types = (std::same_as<type, types> || ...);

} // namespace kphp::concepts
23 changes: 23 additions & 0 deletions runtime-light/metaprogramming/type-functions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Compiler for PHP (aka KPHP)
// Copyright (c) 2025 LLC «V Kontakte»
// Distributed under the GPL v3 License, see LICENSE.notice.txt

#pragma once

#include <cstddef>
#include <type_traits>
#include <variant>

namespace kphp::type_functions {

template<typename variant_type, typename T, size_t index = 0>
requires(index < std::variant_size_v<variant_type>)
consteval size_t variant_index() noexcept {
if constexpr (std::is_same_v<std::variant_alternative_t<index, variant_type>, T>) {
return index;
} else {
return variant_index<variant_type, T, index + 1>();
}
}

} // namespace kphp::type_functions
1 change: 0 additions & 1 deletion runtime-light/runtime-light.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ include(${RUNTIME_LIGHT_DIR}/coroutine/coroutine.cmake)
include(${RUNTIME_LIGHT_DIR}/server/server.cmake)
include(${RUNTIME_LIGHT_DIR}/stdlib/stdlib.cmake)
include(${RUNTIME_LIGHT_DIR}/tl/tl.cmake)
include(${RUNTIME_LIGHT_DIR}/utils/utils.cmake)
include(${RUNTIME_LIGHT_DIR}/state/state.cmake)
include(${RUNTIME_LIGHT_DIR}/memory-resource-impl/memory-resource-impl.cmake)

Expand Down
1 change: 1 addition & 0 deletions runtime-light/stdlib/stdlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ prepend(
diagnostics/backtrace.cpp
diagnostics/contextual-logger.cpp
diagnostics/error-handling-state.cpp
diagnostics/php-assert.cpp
file/resource.cpp
fork/fork-state.cpp
fork/wait-queue-state.cpp
Expand Down
4 changes: 2 additions & 2 deletions runtime-light/stdlib/string/regex-state.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
#include "common/mixin/not_copyable.h"
#include "runtime-common/core/allocator/script-allocator.h"
#include "runtime-common/core/std/containers.h"
#include "runtime-light/metaprogramming/concepts.h"
#include "runtime-light/stdlib/string/regex-include.h"
#include "runtime-light/utils/concepts.h"

struct RegexInstanceState final : private vk::not_copyable {
template<hashable Key, typename Value>
template<kphp::concepts::hashable Key, typename Value>
using unordered_map = kphp::stl::unordered_map<Key, Value, kphp::memory::script_allocator>;

static constexpr size_t MAX_SUBPATTERNS_COUNT = 512;
Expand Down
6 changes: 3 additions & 3 deletions runtime-light/tl/tl-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include "common/algorithms/find.h"
#include "runtime-common/core/allocator/script-allocator.h"
#include "runtime-common/core/std/containers.h"
#include "runtime-light/metaprogramming/concepts.h"
#include "runtime-light/stdlib/diagnostics/logs.h"
#include "runtime-light/utils/concepts.h"

namespace tl {

Expand Down Expand Up @@ -66,7 +66,7 @@ class storer {
m_buffer.append_range(bytes);
}

template<standard_layout T, standard_layout U>
template<kphp::concepts::standard_layout T, kphp::concepts::standard_layout U>
requires std::convertible_to<U, T>
void store_trivial(const U& t) noexcept {
store_bytes({reinterpret_cast<const std::byte*>(std::addressof(t)), sizeof(T)});
Expand Down Expand Up @@ -136,7 +136,7 @@ class fetcher {
return bytes;
}

template<standard_layout T>
template<kphp::concepts::standard_layout T>
std::optional<T> fetch_trivial() noexcept {
if (m_remaining < sizeof(T)) {
return std::nullopt;
Expand Down
1 change: 0 additions & 1 deletion runtime-light/utils/utils.cmake

This file was deleted.

Loading