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

local static in inlined function gets optimized away with analyzer #11725

Closed
Antriel opened this issue Jul 18, 2024 · 5 comments
Closed

local static in inlined function gets optimized away with analyzer #11725

Antriel opened this issue Jul 18, 2024 · 5 comments
Assignees

Comments

@Antriel
Copy link
Contributor

Antriel commented Jul 18, 2024

With analyzer turned on, and inline the variable won't exist. Removing inline or disabling analyzer makes it work. Reproducible on all Haxe versions it seems.

function main() foo();

inline function foo() {
	static var count = 5;
	trace(--count);
}

Compiles down to:

function Test_main() {
	console.log("Test.hx:5:",4);
}
@Simn Simn self-assigned this Jul 18, 2024
@Simn
Copy link
Member

Simn commented Jul 18, 2024

The optimization is a symptom, the real problem here must be the inliner. Without thinking about it too much, static vars should probably not be duplicated like normal vars when inlining.

@Simn
Copy link
Member

Simn commented Jul 18, 2024

Actually I'm not entirely sure if static local variables should even be allowed in inline functions, but I'm basing that mostly on the fact that thinking about it makes my head hurt.

@kLabz
Copy link
Contributor

kLabz commented Jul 18, 2024

Yeah it seems to be that the fix would be to disallow that.. but then what about call site inlining? Would still fail, right?

@kLabz kLabz added this to the 4.3 Hotfix candidates milestone Jul 18, 2024
@Simn
Copy link
Member

Simn commented Jul 18, 2024

For cases like here we can detect it at definition-level, for call-site inlining we have to detect it during inlining.

@Simn Simn closed this as completed in dd4eb9f Jul 18, 2024
@Simn
Copy link
Member

Simn commented Jul 18, 2024

I've made it error when inlining because that covers both cases and we do this for some other things like super and non-final return as well.

kLabz pushed a commit that referenced this issue Jul 18, 2024
kLabz pushed a commit that referenced this issue Jul 18, 2024
@kLabz kLabz mentioned this issue Jul 18, 2024
kLabz pushed a commit that referenced this issue Jul 18, 2024
@kLabz kLabz removed this from the 4.3 Hotfix candidates milestone Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants