Skip to content

refactor: make CancelToken Promise-based#13303

Draft
nomeata wants to merge 3 commits intomasterfrom
joachim/cancellation-promise
Draft

refactor: make CancelToken Promise-based#13303
nomeata wants to merge 3 commits intomasterfrom
joachim/cancellation-promise

Conversation

@nomeata
Copy link
Copy Markdown
Collaborator

@nomeata nomeata commented Apr 7, 2026

This PR moves CancelToken from Init.System.IO to its own file Init.System.CancelToken, backed by IO.Promise Unit instead of IO.Ref Bool. This adds a CancelToken.task method returning a Task Unit that completes when cancelled, enabling non-polling cancellation propagation via IO.mapTask.

(An experiment so far.)

Move CancelToken from Init.System.IO to its own file Init.System.CancelToken,
backed by IO.Promise Unit instead of IO.Ref Bool. This adds a CancelToken.task
method returning a Task Unit that completes when cancelled, enabling
non-polling cancellation propagation via IO.mapTask.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@nomeata nomeata added the merge-ci Enable merge queue CI checks for PR. In particular, produce artifacts for all major platforms. label Apr 7, 2026
@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 Apr 7, 2026
@mathlib-lean-pr-testing
Copy link
Copy Markdown

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase d48863fc2bb15ffbb9b393fba4b5b0bd767fe391 --onto 4f6bcc5adac8d6234a9e3def3675402cb89823c6. You can force Mathlib CI using the force-mathlib-ci label. (2026-04-07 13:41:37)

@leanprover-bot
Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase d48863fc2bb15ffbb9b393fba4b5b0bd767fe391 --onto 861bc19e0c1c45b5766cc5c9ef0488568368b236. You can force reference manual CI using the force-manual-ci label. (2026-04-07 13:41:39)

nomeata and others added 2 commits April 7, 2026 16:04
This PR updates `check_interrupted()` in the C++ runtime to check the
Promise-based `CancelToken` directly via `lean_io_get_task_state_core`,
rather than calling the Lean-exported `lean_io_cancel_token_is_set`.
The old approach failed during stage2 build because the stage0-compiled
export assumed the IORef-based representation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Update `delabConst.lean` and `printStructure.lean` to reflect that
`IO.CancelToken` now wraps `IO.Promise Unit` instead of `IO.Ref Bool`.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-ci Enable merge queue CI checks for PR. In particular, produce artifacts for all major platforms. toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants