-
Notifications
You must be signed in to change notification settings - Fork 54
Meta issue: support return/continue/?/break #15
Copy link
Copy link
Closed
Labels
P1Max priorityMax prioritybugSomething isn't workingSomething isn't workingengineIssue in the engineIssue in the engineenhancementNew feature or requestNew feature or requestmarked-unimplementedIssue refered by `Unimplemented {issue_id...}` in the engineIssue refered by `Unimplemented {issue_id...}` in the enginemeta
Milestone
Description
This issue is about any expression that can yield an early return: ?, return, continue, break.
The engine has a module side_effect_utils.ml that deals with any expression with side effects: its approach is to hoist every side effect within an expression.
After applying this side effect phase, expressions are trees with let, if, match, loop nodes, and the side-effects occur only on rhs of lets.
Note early return is one of the different possible side effects. Also, one cannot rewrite early returns without considering other side effects: for instance, early returns can interact badly with mutation.
From there:
CfIntoMonadslifts early return bottom up into various monads.- we also want a phase that attempts to restructure control flow, to push early returns to end positions.
Road map
- resugar questions marks (Rustc rewrite
?withreturns); - add a phase that transforms early returns into monadic constructions;
- test this monadic phase;
- fix bugs;
- add a phase that attempts at reformulating control flow to avoid early returns (i.e. we'd better do
if c {return e1} return e2->return (if c {e1} {e2})than a monadic transformation) (see Add aRewriteControlFlowphase (return/continue/break) #393 and Engine: strip automaticallyreturnwhen in end position #254); - wrap the monadic and reformulation phase into another phase that decides heuristically which looks best.
- support continue/return within loops:
return/break/continuewithin loops #196
Original issue
This is related to the question mark operator, since
e?actually expands to amatchwhose one branch is areturnstatement.TODOs:
- (x) add a phase that transforms early returns into monadic constructions;
- fix the current monadic encoding Fix monadic transform for
?s #399;- add a phase that attempts at reformulating control flow to avoid early returns (i.e. we'd better do
if c {return e1} return e2->return (if c {e1} {e2})than a monadic transformation) (see Add aRewriteControlFlowphase (return/continue/break) #393);- add a phase that tries both monadic and control-flow reformulation phases and decides heuristically which seems better;
- (x) figure out how to translate code containing the
?operator nicely (some resugaring?).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P1Max priorityMax prioritybugSomething isn't workingSomething isn't workingengineIssue in the engineIssue in the engineenhancementNew feature or requestNew feature or requestmarked-unimplementedIssue refered by `Unimplemented {issue_id...}` in the engineIssue refered by `Unimplemented {issue_id...}` in the enginemeta