Skip to content

feat: add do +forward for effect forwarding#13931

Open
sgraf812 wants to merge 1 commit into
masterfrom
worktree-control-lifting-tactic
Open

feat: add do +forward for effect forwarding#13931
sgraf812 wants to merge 1 commit into
masterfrom
worktree-control-lifting-tactic

Conversation

@sgraf812
Copy link
Copy Markdown
Contributor

@sgraf812 sgraf812 commented Jun 2, 2026

This PR introduces the do +forward body marker that lets continuation-taking wrappers like withReader participate in the surrounding do block's control flow. When do +forward body appears as the last argument of an application inside a do block, the body's return, break, continue, and mut-variable reassignments are forwarded out through the wrapper to the enclosing block.

Internally, elabDoExpr and the ControlInfo inferer recognise the marker and route the body through the same EffectForwarder framework that already powers try/catch. dropParens moves from Lean.Elab.Term to Lean.Parser.Term since it is a generic term-syntax utility.

@sgraf812 sgraf812 added the changelog-language Language features and metaprograms label Jun 2, 2026
@sgraf812
Copy link
Copy Markdown
Contributor Author

sgraf812 commented Jun 2, 2026

!bench

@leanprover-radar
Copy link
Copy Markdown

leanprover-radar commented Jun 2, 2026

Benchmark results for b98ea5d against f3e3c0c are in. There are significant results. @sgraf812

  • 🟥 build//instructions: +5.6G (+0.05%)
  • 🟥 other exited with code 1

Small changes (2✅, 4🟥)

  • 🟥 build/module/Lean.Elab.BuiltinDo.Misc//instructions: +31.0M (+1.67%)
  • build/module/Lean.Elab.Do.Control//instructions: -32.9M (-0.88%)
  • 🟥 build/module/Lean.Elab.Do.InferControlInfo//instructions: +113.1M (+0.92%) (reduced significance based on *//lines)
  • build/module/Lean.Elab.Term.TermElabM//instructions: -66.0M (-0.26%)
  • 🟥 build/module/Lean.Parser.Do//instructions: +95.6M (+1.65%)
  • 🟥 build/module/Lean.Parser.Term//instructions: +71.2M (+0.45%)

This PR introduces the `do +forward body` marker that lets continuation-taking wrappers like `withReader` or `withFinalizer` participate in the surrounding `do` block's control flow. When `do +forward body` appears as the last argument of an application inside a `do` block, the body's `return`, `break`, `continue`, and `mut`-variable reassignments are forwarded out through the wrapper to the enclosing block. Unknown `do +<flag>` markers are rejected with a dedicated error.

Internally, `elabDoExpr` and the `ControlInfo` inferer recognise the marker and route the body through the same `EffectForwarder` framework that already powers `try`/`catch`. `EffectForwarder` lets callers decide whether the surrounding continuation is dead (try/catch uses `info.noFallthrough`; forward always treats it as live), with a new `DoElemCont.withDeadCodeFromInfo` helper for the shared pattern. `dropParens` moves from `Lean.Elab.Term` to `Lean.Parser.Term` since it is a generic term-syntax utility.
@sgraf812 sgraf812 force-pushed the worktree-control-lifting-tactic branch from b98ea5d to 6522129 Compare June 2, 2026 16:33
@sgraf812
Copy link
Copy Markdown
Contributor Author

sgraf812 commented Jun 2, 2026

!bench

@leanprover-radar
Copy link
Copy Markdown

leanprover-radar commented Jun 2, 2026

Benchmark results for 6522129 against 9987781 are in. No significant results found. @sgraf812

  • 🟥 build//instructions: +3.9G (+0.03%)

Small changes (2✅, 4🟥)

  • 🟥 build/module/Lean.Elab.BuiltinDo.Misc//instructions: +31.2M (+1.70%)
  • build/module/Lean.Elab.Do.Control//instructions: -37.6M (-1.01%)
  • 🟥 build/module/Lean.Elab.Do.InferControlInfo//instructions: +111.8M (+0.91%) (reduced significance based on *//lines)
  • build/module/Lean.Elab.Term.TermElabM//instructions: -64.5M (-0.26%)
  • 🟥 build/module/Lean.Parser.Do//instructions: +88.9M (+1.52%)
  • 🟥 compiled/parser//instructions: +9.8M (+0.03%)

@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 Jun 2, 2026
@mathlib-lean-pr-testing
Copy link
Copy Markdown

mathlib-lean-pr-testing Bot commented Jun 2, 2026

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase f3e3c0c7c2f4e20b85071f981197ad8c53910fb3 --onto c47a0c7cf035381a2bcdd4cdf2442782eb4a5214. You can force Mathlib CI using the force-mathlib-ci label. (2026-06-02 16:50:06)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 9987781e0f7aad29ccc1216e8532dd9df83dced2 --onto c47a0c7cf035381a2bcdd4cdf2442782eb4a5214. You can force Mathlib CI using the force-mathlib-ci label. (2026-06-02 17:36:19)

@leanprover-bot
Copy link
Copy Markdown
Collaborator

leanprover-bot commented Jun 2, 2026

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase f3e3c0c7c2f4e20b85071f981197ad8c53910fb3 --onto 803553a556fd82fa1060efb0c43eda542130cb16. You can force reference manual CI using the force-manual-ci label. (2026-06-02 16:50:07)
  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase 9987781e0f7aad29ccc1216e8532dd9df83dced2 --onto 803553a556fd82fa1060efb0c43eda542130cb16. You can force reference manual CI using the force-manual-ci label. (2026-06-02 17:36:21)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-language Language features and metaprograms 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.

3 participants