feat: add do +forward for effect forwarding#13931
Open
sgraf812 wants to merge 1 commit into
Open
Conversation
Contributor
Author
|
!bench |
|
Benchmark results for b98ea5d against f3e3c0c are in. There are significant results. @sgraf812
Small changes (2✅, 4🟥)
|
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.
b98ea5d to
6522129
Compare
Contributor
Author
|
!bench |
|
Benchmark results for 6522129 against 9987781 are in. No significant results found. @sgraf812
Small changes (2✅, 4🟥)
|
|
Mathlib CI status (docs):
|
Collaborator
|
Reference manual CI status:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces the
do +forward bodymarker that lets continuation-taking wrappers likewithReaderparticipate in the surroundingdoblock's control flow. Whendo +forward bodyappears as the last argument of an application inside adoblock, the body'sreturn,break,continue, andmut-variable reassignments are forwarded out through the wrapper to the enclosing block.Internally,
elabDoExprand theControlInfoinferer recognise the marker and route the body through the sameEffectForwarderframework that already powerstry/catch.dropParensmoves fromLean.Elab.TermtoLean.Parser.Termsince it is a generic term-syntax utility.