Skip to content

Meta issue: support return/continue/?/break  #15

@W95Psp

Description

@W95Psp

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:

  • CfIntoMonads lifts 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

Original issue

This is related to the question mark operator, since e? actually expands to a match whose one branch is a return statement.

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 a RewriteControlFlow phase (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?).

Metadata

Metadata

Assignees

Labels

P1Max prioritybugSomething isn't workingengineIssue in the engineenhancementNew feature or requestmarked-unimplementedIssue refered by `Unimplemented {issue_id...}` in the enginemeta

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions