Remove implicit return expression in favour of explicit return statements, if possible. #4189
Labels
compiler: frontend
Everything to do with type checking, control flow analysis, and everything between parsing and IRgen
language feature
Core language features visible to end users
Problem
At the moment there are a few special cases in the front-end regarding implicit returns vs explicit returns. I have an intuition what we could probably remove implicit return expressions entirely, which would simplify control flow and associated analyses.
Benefits
If we could assume that the only way to exit a function was via a return statement then DCA and control flow divergence would be simpler, as would IRgen.
Caveats
But it's only worthwhile if it's easy to do. Replacing an implicit return at the end of a function body (or just generating it instead of the implicit return) is trivial. Implicit returns are used for all code blocks though, and so an alternative would need to be found for control flow within functions (if/else, while loops, etc).
There may be some gotchas which may make a change like this infeasible or the ROI not worthwhile. Some more analysis is required before going ahead.
The text was updated successfully, but these errors were encountered: