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

Reconstruct do-loops #7979

Merged
merged 9 commits into from
Mar 26, 2023
Merged

Conversation

Simn
Copy link
Member

@Simn Simn commented Mar 13, 2019

Currently, the analyzer does not reconstruct do-loops so the generators never really see them. This PR changes this and surfaced some problems:

  • C++

This somehow generates a label after closing the loop, which throws off native compilation: while((cur_match < 10)) _hx_goto_1:;

  • Lua

Fails with /home/travis/build/Simn/haxe/std/lua/_std/EReg.hx:142: characters 5-10 : This expression cannot be compiled to Lua

  • HL

Just hangs.


I'm assigning the related target maintainers. I don't want to merge this for 4.0 anyway, but we should look into supporting this properly again.

@Simn Simn added this to the Release 4.1 milestone Mar 13, 2019
@skial skial mentioned this pull request Mar 14, 2019
1 task
@hughsando
Copy link
Member

Are you thinking about reconstructing for loops? IIRC, I had a few optimizations in there, which may have got a bit rusty.

@hughsando
Copy link
Member

I put a fix in for hxcpp:
c025565
There is also a fix in the hxcpp repo for cppia jit case.

@Simn Simn mentioned this pull request Jun 19, 2019
@Simn Simn assigned Simn and unassigned hughsando Feb 17, 2020
@Simn
Copy link
Member Author

Simn commented Feb 17, 2020

I have added support for do-while loops to the JVM target. It's not perfect but good enough for now.

@jdonaldson Lua still fails: std/lua/_std/EReg.hx:156: characters 5-10 : This expression cannot be compiled to Lua

@ncannasse HL still hangs

@jdonaldson
Copy link
Member

I'll check into this, sorry for the delay.

@jdonaldson jdonaldson added the platform-lua Everything related to Lua label Mar 4, 2020
# Conflicts:
#	src/generators/genjvm.ml
@Simn
Copy link
Member Author

Simn commented Mar 10, 2020

Updated the branch and added a checkbox for Justin. :)

@jdonaldson
Copy link
Member

image

@jdonaldson
Copy link
Member

/// CHECKBOX CLICKING INTENSIFIES ///

@jdonaldson jdonaldson removed their assignment Mar 13, 2020
@jdonaldson jdonaldson removed the platform-lua Everything related to Lua label Mar 13, 2020
@Simn Simn modified the milestones: Release 4.1, Release 4.2 Apr 27, 2020
@RealyUniqueName RealyUniqueName modified the milestones: Release 4.2, Backlog Dec 16, 2020
@Simn Simn modified the milestones: Backlog, Release 4.3 Mar 24, 2023
@Simn
Copy link
Member Author

Simn commented Mar 25, 2023

I want to check this for 4.3 and see where we're at. Maybe I'm even brave enough to fix HL.

@Simn
Copy link
Member Author

Simn commented Mar 25, 2023

Shockingly, the HL debugger worked and pointed me to EReg.map. The problem can be reproduced with that:

function main() {
	var a = ~/a+/g.map("aaabacx", function(r) return "[" + r.matched(0).substr(1) + "]");
	trace(a);
}

According to the debugger, offset is 0 on every iteration, which means there's never any break.

@Simn
Copy link
Member Author

Simn commented Mar 25, 2023

final global = true;

function main() {
	var offset = 0;
	do {
		trace(offset);
		if (offset >= 3)
			break;
		offset = 3;
	} while (global);
}

This infinitely prints 0. Dump looks fine, so I think it's the codegen.

@Simn
Copy link
Member Author

Simn commented Mar 26, 2023

Version without trace:

final global = true;

@:pure(false)
function dontTrace(d:Int) {}

function getOffset() {
	return 0;
}

function main() {
	var offset = getOffset();
	do {
		dontTrace(offset);
		if (offset >= 3)
			break;
		offset = 3;
	} while (global);
}

This is some problem with hlopt. Diff with/without -D hl_no_opt:

Merge_S9p39Xwddc

The original compares via registers 11 -> 1 -> 8, the optimized version stores in register 4 but never does anything with it. At the very least this would require a mov 0,4 before jumping back.

This might be a bit above my paygrade because it likely goes into the register liveness analysis. I'll probably just disable do-reconstruction for HL, but at some point this should definitely be looked into.

@Simn Simn merged commit 1b7d374 into HaxeFoundation:development Mar 26, 2023
@Simn Simn deleted the analyzer_do_reconstruction branch March 26, 2023 10:40
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

Successfully merging this pull request may close these issues.

5 participants