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

not generate redundant final return for return voidExpr #6420

Closed
nadako opened this issue Jun 29, 2017 · 3 comments
Closed

not generate redundant final return for return voidExpr #6420

nadako opened this issue Jun 29, 2017 · 3 comments

Comments

@nadako
Copy link
Member

nadako commented Jun 29, 2017

class Main {
	static function f(fn:Void->Void) fn();

	static function voidFunc() trace("hi");

	static function main() {
		f(function() return voidFunc());
		f(() -> voidFunc());
	}
}

This generates:

Main.main = function() {
	Main.f(function() {
		Main.voidFunc();
		return;
	});
	Main.f(function() {
		Main.voidFunc();
		return;
	});
};

That happens because we rewrite return voidExpr to {voidExpr; return;}. However if that's a final expression there's no need to generate the final return.

While this is a minor issue that was pretty rare in real-world code, it occurs more often now with arrow functions that just call some void function (like in the example above), so we might want to get rid of that final return for the sake of nicer code generation.

I'm not sure if it's possible to check at the point when we rewrite return voidExpr, maybe it should be done in the analyzer CFG builder or some cleanup module...

@Simn Simn added this to the Backlog milestone Apr 17, 2018
@Simn Simn modified the milestones: Backlog, Design Jul 2, 2019
@Simn
Copy link
Member

Simn commented Jul 2, 2019

The question here is if we only want to avoid that return in the return void case or if we always want to remove redundant returns, even if written by users.

@nadako
Copy link
Member Author

nadako commented Jul 2, 2019

want to remove redundant returns

fwiw we remove some of them already due to CFG building and unreachable blocks

@Simn
Copy link
Member

Simn commented Jul 2, 2019

fwiw we remove some of them already due to CFG building and unreachable blocks

That's not specific to return though, it just prunes dead code (which is actually necessary for some targets).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants