Skip to content

[V4] Fork infrastructure#56

Merged
ConorWilliams merged 45 commits intomodulesfrom
v4-fork-call
Feb 4, 2026
Merged

[V4] Fork infrastructure#56
ConorWilliams merged 45 commits intomodulesfrom
v4-fork-call

Conversation

@ConorWilliams
Copy link
Owner

@ConorWilliams ConorWilliams commented Feb 1, 2026

Summary by CodeRabbit

  • New Features

    • Added context management framework for work scheduling with polymorphic and thread-local variants.
    • Introduced fork and call operation helpers for asynchronous execution.
    • Added TLS-based and global bump allocators for memory management options.
  • Improvements

    • Enabled colored build diagnostics output.
    • Extended frame tracking with merge, steal, and exception metadata.
  • Refactoring

    • Reorganized core module exports and internal macros.
  • Tests

    • Enhanced tuple accessor test coverage across reference qualifications.

@coderabbitai
Copy link

coderabbitai bot commented Feb 1, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch v4-fork-call

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@benchmark/src/libfork_benchmark/fib/fib.hpp`:
- Around line 86-90: The pop() method currently calls work.back() and
work.pop_back() unconditionally which is undefined if the member vector work is
empty; update lf::work_handle pop() noexcept to defensively check work.empty()
(or assert) before accessing: either add an assertion (e.g.,
assert(!work.empty())) and keep behavior, or return a defined sentinel
lf::work_handle (or std::nullopt-equivalent) when empty; ensure the chosen
approach adjusts the noexcept/specifier and callers of pop() to handle the
sentinel or rely on the assert.

In `@benchmark/src/libfork_benchmark/fib/lf_parts.cpp`:
- Around line 125-127: The leak check currently only compares tls_bump_ptr
against buf.get(), so benchmarks that use the global allocator (e.g.,
no_await<global_bump>, await<global_bump>) that manipulate bump_ptr can leak
undetected; update the check in lf_parts.cpp to verify both tls_bump_ptr and
bump_ptr equal buf.get(), and call LF_TERMINATE("Stack leak detected") (or a
similar error) if either pointer != buf.get() so both thread-local and global
bump allocators are validated.
🧹 Nitpick comments (1)
src/core/context.cxx (1)

17-21: Consider constraining push return type for consistency.

The context concept constrains pop() to return work_handle, but push has no return type constraint. If push should always return void, consider making that explicit for stricter concept checking.

♻️ Optional: Add explicit return type constraint
 template <typename T>
 concept context = requires (T &ctx, work_handle h) {
-  { ctx.push(h) };
+  { ctx.push(h) } -> std::same_as<void>;
   { ctx.pop() } noexcept -> std::same_as<work_handle>;
 };

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces foundational “fork” infrastructure for libfork v4 by adding new core module partitions (ops/context), expanding frame metadata, and updating promise final-suspend logic and benchmarks/tests to exercise the new behavior.

Changes:

  • Add libfork.core:ops (call/fork packaging) and libfork.core:context (work handles + TLS context) and wire them into libfork.core/promise.
  • Extend coroutine frame metadata (category, cancellation, merge/steal bookkeeping) and update tuple accessor implementation.
  • Update benchmarks and tests to use the new root/fork mechanics and new allocators/contexts.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
test/src/tuple.cpp Adds forced instantiation of tuple accessors; introduces an any helper and extra get<0>() calls.
src/core/utility.cxx Adds safe_cast, not_null, and a defer scope guard utility.
src/core/tuple.cxx Adjusts tuple::get implementation to use an explicit cast for cvref propagation.
src/core/promise.cxx Major update: introduces fork/call awaitables, context integration, and new final_suspend logic.
src/core/ops.cxx New partition defining exported call()/fork() helpers and internal packages.
src/core/frame.cxx Adds category enum and expands frame_type with fork-related bookkeeping fields.
src/core/core.cxx Reorders/tiers module exports and exports new partitions (ops, context).
src/core/context.cxx New partition defining work_handle, context concept, polymorphic context, and TLS thread_context.
src/core/concepts.cxx Updates task forward declaration to include a Context parameter.
include/libfork/__impl/assume.hpp Renames LF_ASSERT to LF_ENSURE and adjusts LF_ASSUME debug behavior.
benchmark/src/libfork_benchmark/fib/lf_parts.cpp Updates fib benchmarks to mark tasks as root, adds fork/call benchmark variants, and wires TLS context pointers.
benchmark/src/libfork_benchmark/fib/fib.hpp Replaces old bump allocator with TLS/global bump allocators and adds a vector-backed context implementation.
benchmark/src/libfork_benchmark/fib/baremetal.cpp Updates baremetal coroutine benchmark to use the new TLS bump allocator pointer.
CMakeUserPresets.json Enables CMAKE_COLOR_DIAGNOSTICS for dev/bench presets.
CMakeLists.txt Adds new module sources (ops.cxx, context.cxx) to the build.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ConorWilliams ConorWilliams merged commit 6e127a8 into modules Feb 4, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant