Workaround for nasty ternary closure codegen for min/max on Lua target #18
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is pretty gross to do, so I don't know if you'll want to merge it, but the codegen for ternaries on Lua target is truly terrible and I thought I'd bring it up. I think this is also the only set of functions where switching it to a Lua builtin would be relevant, everything else would just need a plain
if
instead of ternary.This also affects every other usage of ternaries such as in
sign
,step
,normalize
,faceforward
andreflect
, I just picked onmin
/max
first because there's a standard function for it. I don't think other targets have this codegen problem, but spitting out this many closures constantly does have gc/perf consequences on Lua.Before:
After:
Alternatively without the special casing:
outputs:
(all results from haxe 4.2.5 using
-D lua-vanilla -D analyzer-optimize -dce full