Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add async timer primitives based on libuv #6219

Merged
merged 55 commits into from
Jan 6, 2025

Conversation

algebraic-dev
Copy link
Contributor

This PR adds support for Timer and a event loop thread that gets requests from another threads and executes it.

@algebraic-dev algebraic-dev requested a review from TwoFX as a code owner November 26, 2024 00:38
@algebraic-dev algebraic-dev marked this pull request as draft November 26, 2024 00:39
@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Nov 26, 2024
@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented Nov 26, 2024

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 0eca3bd55de7f29320e90b83ef2f43e9dff7546b --onto 20acc72a29a8bb4d55223651caa0553ffa82ac88. (2024-11-26 01:04:03)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 0eca3bd55de7f29320e90b83ef2f43e9dff7546b --onto 6d495586a1836da3e12efb4fbf9946bd9088ac5f. (2024-11-29 23:10:28)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase b2f70dad52dfd72975ab08c8b24d5d46f79e9d7b --onto 3c5e612dc54733cd707becb929457d2f9d8ca6fd. (2024-12-03 04:50:45)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 00718c3959d93972b43ee30ac008e9d655d9f151 --onto cb600ed9b436e4290b819b0529f8454490bffeb6. (2024-12-03 17:50:20)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 00718c3959d93972b43ee30ac008e9d655d9f151 --onto 019f8e175f9650b829aca8ee501f41c0a5d9076d. (2024-12-05 16:45:12)
  • ✅ Mathlib branch lean-pr-testing-6219 has successfully built against this PR. (2025-01-02 18:10:02) View Log
  • ✅ Mathlib branch lean-pr-testing-6219 has successfully built against this PR. (2025-01-02 20:17:03) View Log
  • ✅ Mathlib branch lean-pr-testing-6219 has successfully built against this PR. (2025-01-03 11:13:15) View Log
  • ✅ Mathlib branch lean-pr-testing-6219 has successfully built against this PR. (2025-01-03 23:05:15) View Log
  • ✅ Mathlib branch lean-pr-testing-6219 has successfully built against this PR. (2025-01-04 21:13:18) View Log

src/Std/UV.lean Outdated Show resolved Hide resolved
src/Std/UV.lean Outdated Show resolved Hide resolved
src/Std/UV.lean Outdated Show resolved Hide resolved
src/Std/UV.lean Outdated Show resolved Hide resolved
src/runtime/libuv.cpp Outdated Show resolved Hide resolved
src/runtime/libuv.cpp Outdated Show resolved Hide resolved
src/runtime/libuv.cpp Outdated Show resolved Hide resolved
src/runtime/libuv.cpp Outdated Show resolved Hide resolved
src/runtime/libuv.cpp Outdated Show resolved Hide resolved
src/runtime/libuv.cpp Outdated Show resolved Hide resolved
src/runtime/libuv.cpp Outdated Show resolved Hide resolved
src/runtime/libuv.cpp Outdated Show resolved Hide resolved
src/runtime/uv_scheduler.h Outdated Show resolved Hide resolved
src/runtime/uv_scheduler.h Outdated Show resolved Hide resolved
src/runtime/libuv.cpp Outdated Show resolved Hide resolved
src/Std/Internal/UV.lean Outdated Show resolved Hide resolved
@TwoFX TwoFX added the release-ci Enable all CI checks for a PR, like is done for releases label Dec 3, 2024
src/Std/Internal/UV.lean Outdated Show resolved Hide resolved
src/Std/Internal/UV.lean Outdated Show resolved Hide resolved
src/runtime/event_loop.cpp Outdated Show resolved Hide resolved
src/runtime/event_loop.cpp Outdated Show resolved Hide resolved
src/runtime/libuv.h Outdated Show resolved Hide resolved
src/runtime/libuv.cpp Outdated Show resolved Hide resolved
src/runtime/libuv.cpp Outdated Show resolved Hide resolved
src/runtime/libuv.cpp Outdated Show resolved Hide resolved
src/runtime/libuv.cpp Outdated Show resolved Hide resolved
src/runtime/libuv.cpp Outdated Show resolved Hide resolved
@algebraic-dev algebraic-dev force-pushed the libuv branch 2 times, most recently from add268b to f7c1771 Compare December 3, 2024 13:40
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jan 2, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jan 2, 2025
src/Std/Internal/UV.lean Outdated Show resolved Hide resolved
src/Std/Internal/UV.lean Outdated Show resolved Hide resolved
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jan 3, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jan 3, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jan 3, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jan 3, 2025
@hargoniX hargoniX marked this pull request as ready for review January 4, 2025 19:19
@hargoniX hargoniX added the changelog-no Do not include this PR in the release changelog label Jan 4, 2025
Copy link
Contributor

@hargoniX hargoniX left a comment

Choose a reason for hiding this comment

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

(Just to remove my changes requested)

@hargoniX
Copy link
Contributor

hargoniX commented Jan 4, 2025

@algebraic-dev and I went over the code yesterday, adding some tracing into the allocator/deallocator and observing the behavior of programs allocating many timers in a loop, the memory management seems to work fine now. Unless someone speaks up I'll merge this into the ft-async branch on Monday evening European time.

@hargoniX hargoniX added the will-merge-soon …unless someone speaks up label Jan 4, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jan 4, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jan 4, 2025
@hargoniX hargoniX merged commit b6f02ac into leanprover:ft-async Jan 6, 2025
28 of 29 checks passed
hargoniX added a commit that referenced this pull request Jan 10, 2025
This PR adds support for `Timer` and a event loop thread that gets
requests from another threads and executes it.

---------

Co-authored-by: Markus Himmel <markus@himmel-villmar.de>
Co-authored-by: Henrik Böving <hargonix@gmail.com>
hargoniX added a commit that referenced this pull request Jan 10, 2025
This PR implements a basic asynchronous timer API on top of the libuv
work.

It purposely puts this into `Std.Internal` as we might still have to
change the API as we continue develop of the async library across
releases so I would only like to stabilize it once we are certain this
is a fine API.

A few additional notes:
- we currently do not implement a bind operator on `AsyncTask` on
purpose as `Task.bind` on `Task.pure` is a non trivial operation and
users should be aware of it. Furthermore there is the consideration that
as they will have to bind on both `IO` and `AsyncTask` we might want to
make potential task points explicit in the syntax (did somebody say
`await`?).
- the API generally takes inspiration from
https://docs.rs/tokio/latest/tokio/time/index.html, though it has to
adapt as Rust's and Lean's asynchronity concepts are sufficiently
different.

Stacked on top of #6219.
hargoniX added a commit that referenced this pull request Jan 13, 2025
This PR adds support for `Timer` and a event loop thread that gets
requests from another threads and executes it.

---------

Co-authored-by: Markus Himmel <markus@himmel-villmar.de>
Co-authored-by: Henrik Böving <hargonix@gmail.com>
hargoniX added a commit that referenced this pull request Jan 13, 2025
This PR implements a basic asynchronous timer API on top of the libuv
work.

It purposely puts this into `Std.Internal` as we might still have to
change the API as we continue develop of the async library across
releases so I would only like to stabilize it once we are certain this
is a fine API.

A few additional notes:
- we currently do not implement a bind operator on `AsyncTask` on
purpose as `Task.bind` on `Task.pure` is a non trivial operation and
users should be aware of it. Furthermore there is the consideration that
as they will have to bind on both `IO` and `AsyncTask` we might want to
make potential task points explicit in the syntax (did somebody say
`await`?).
- the API generally takes inspiration from
https://docs.rs/tokio/latest/tokio/time/index.html, though it has to
adapt as Rust's and Lean's asynchronity concepts are sufficiently
different.

Stacked on top of #6219.
hargoniX added a commit that referenced this pull request Jan 13, 2025
This PR adds support for `Timer` and a event loop thread that gets
requests from another threads and executes it.

---------

Co-authored-by: Markus Himmel <markus@himmel-villmar.de>
Co-authored-by: Henrik Böving <hargonix@gmail.com>
hargoniX added a commit that referenced this pull request Jan 13, 2025
This PR implements a basic asynchronous timer API on top of the libuv
work.

It purposely puts this into `Std.Internal` as we might still have to
change the API as we continue develop of the async library across
releases so I would only like to stabilize it once we are certain this
is a fine API.

A few additional notes:
- we currently do not implement a bind operator on `AsyncTask` on
purpose as `Task.bind` on `Task.pure` is a non trivial operation and
users should be aware of it. Furthermore there is the consideration that
as they will have to bind on both `IO` and `AsyncTask` we might want to
make potential task points explicit in the syntax (did somebody say
`await`?).
- the API generally takes inspiration from
https://docs.rs/tokio/latest/tokio/time/index.html, though it has to
adapt as Rust's and Lean's asynchronity concepts are sufficiently
different.

Stacked on top of #6219.
hargoniX added a commit that referenced this pull request Jan 13, 2025
This PR adds support for `Timer` and a event loop thread that gets
requests from another threads and executes it.

---------

Co-authored-by: Markus Himmel <markus@himmel-villmar.de>
Co-authored-by: Henrik Böving <hargonix@gmail.com>
hargoniX added a commit that referenced this pull request Jan 13, 2025
This PR implements a basic asynchronous timer API on top of the libuv
work.

It purposely puts this into `Std.Internal` as we might still have to
change the API as we continue develop of the async library across
releases so I would only like to stabilize it once we are certain this
is a fine API.

A few additional notes:
- we currently do not implement a bind operator on `AsyncTask` on
purpose as `Task.bind` on `Task.pure` is a non trivial operation and
users should be aware of it. Furthermore there is the consideration that
as they will have to bind on both `IO` and `AsyncTask` we might want to
make potential task points explicit in the syntax (did somebody say
`await`?).
- the API generally takes inspiration from
https://docs.rs/tokio/latest/tokio/time/index.html, though it has to
adapt as Rust's and Lean's asynchronity concepts are sufficiently
different.

Stacked on top of #6219.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
builds-mathlib CI has verified that Mathlib builds against this PR changelog-no Do not include this PR in the release changelog release-ci Enable all CI checks for a PR, like is done for releases toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN will-merge-soon …unless someone speaks up
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants