Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove implicit return expression in favour of explicit return statements, if possible. #4189

Open
otrho opened this issue Feb 27, 2023 · 0 comments
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

Comments

@otrho
Copy link
Contributor

otrho commented Feb 27, 2023

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.

@anton-trunov anton-trunov added 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 labels Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

2 participants