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

Better inlining in Printing.wurst #108

Closed
wants to merge 2 commits into from

Conversation

ElusiveMori
Copy link
Contributor

@ElusiveMori ElusiveMori commented Aug 18, 2018

init
    Log.trace("TRACE")
    Log.debug("DEBUG")
    Log.info("INFO")
    Log.warn("WARN")
    Log.error("ERROR")

Produces this code:

function Loglevel_getTag takes integer this returns string
	if this == 0 then
		return "|cffADADADtrace|r"
	elseif this == 1 then
		return "|cff2685DCdebug|r"
	elseif this == 2 then
		return "|cffFFCC00info|r"
	elseif this == 3 then
		return "|cffF47E3Ewarning|r"
	elseif this == 4 then
		return "|cffFB2700error|r"
	endif
	return "?"
endfunction

function printLog takes player showTo, integer loglvl, string msg returns nothing
	if 2 <= loglvl then
		call DisplayTimedTextToPlayer(showTo, 0., 0., 45., Loglevel_getTag(loglvl) + " - " + msg)
	endif
endfunction

function init_Hello takes nothing returns boolean
	call printLog(Player_localPlayer, 0, "TRACE")
	call printLog(Player_localPlayer, 1, "DEBUG")
	call printLog(Player_localPlayer, 2, "INFO")
	call printLog(Player_localPlayer, 3, "WARN")
	call printLog(Player_localPlayer, 4, "ERROR")
	return true
endfunction

Even though the log level is a constant by default, Wurst doesn't know whether to remove the TRACE and DEBUG calls or not, even though the condition inside printLog will never pass.

It also doesn't inline them, which it potentially could.

This PR does some reshuffling so that these printing calls get properly removed when logLevel is constant, and also makes them inline better.

The result of this that the above code now gets compiled into this:

function init_Hello takes nothing returns boolean
	call DisplayTimedTextToPlayer(Player_localPlayer, 0., 0., 45., "|cffFFCC00info|r - INFO")
	call DisplayTimedTextToPlayer(Player_localPlayer, 0., 0., 45., "|cffF47E3Ewarning|r - WARN")
	call DisplayTimedTextToPlayer(Player_localPlayer, 0., 0., 45., "|cffFB2700error|r - ERROR")
	return true
endfunction

@Frotty
Copy link
Member

Frotty commented Aug 18, 2018

Maybe add to description what the current problem is.
The correct solution might also be just to add/improve optimizations

@Frotty
Copy link
Member

Frotty commented Sep 7, 2018

Okay, the inlining rules have been improved. The example you posted now gets inlined.
Can you re-check on your project?

@Frotty
Copy link
Member

Frotty commented Sep 10, 2018

Can reopen if this still persists.

@Frotty Frotty closed this Sep 10, 2018
@ElusiveMori ElusiveMori deleted the printing branch January 6, 2019 20:50
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.

None yet

2 participants