-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add a way to prevent pakettic from reordering certain expressions (was: Lua issue with table access expression reordering) #15
Comments
As an update, if it helps any, |
-aanneal is probably just lucky and does not produce invalid code. I agree, this is super weird. I'll investigate. Meanwhile, can you send the whole offending code? This might have something to do with the specific tables you have. You can DM me on discord if you want more real-time debugging session. Oh, are you on 1.3.1? |
Regarding |
I look to be, based on my env's site packages. I only installed it a couple days ago. As to aanneal, I think so too since I also got it to bug once. Just lucky it decided that wasn't a better optimization.
I did actually have a I did later determine the the I was able to work around this problem by a suggestion of just looping through and precaulating the added values before the sort so it's only ever run once per sort. I'll sort out sending you a copy since I still hold out a little hope I can figure out how to get my code ≤ 1kb for something upcoming. 🙂 |
a+b+c != a+c+b in general. For example: a and b can be both so small that when added to a big number c, it rounds back to c. But when a & b are first added together, it becomes just big enough number to notch c up by tiny amount. Therefore, if ax, ay, az are calculated using one set of equations and bx, by and bz calculated using another set of equations, the sorting result might depend on which element is a and which element is b. And thus, LUA correctly complains that the sorting function is invalid, because it is :) The sorting function should not depend which element is which. One ugly idea: make one function to return ax, ay, az that is called for a and b separately. This guarantees that the values are calculated identically. True sizecoding way: just sort by the zs of the first vertices and be done with it :D |
Well, this is the first example where pakettic reordering broke the code. Granted, we were able to find ways around it, but I'll change this into a feature request: add a way to prevent pakettic from reordering certain expressions. More magic comments are needed; I'll spend some time to think what's actually the good notation for it. |
I have some code that, at least in my original TIC-80 program works perfectly but after minification (with default settings) it fails with
invalid order function for sorting
.tl;dr: The problem isn't the minification per se, it's that certain table accesses if not done in one of a few specific orders results in different behavior/output.
Original code (works):
b0
is a table that contains triangles ({{x=1.0,y=1.0,z=1.0}}
) that have doubles as property values.Minified code (fails):
This has been reformatted for clarity and the variables renamed to match original, but I've tested to ensure the error still occurs. I also verified the comparison "flip" is not the cause either since it maintains the original meaning.
The Fix
This reorders the table access for line 6 of the sort function to match the two above it. Then it doesn't fail.
Buuuut I still don't have any d-mn idea why that fixes it because if go grab my original code and pair it with the minified code:
It now fails!
But this works!
I am so confused.
This issue isn't really the minifiers fault, since I can trigger it in unminified code, but there's two-three issues that may be:
--{!
and--}
around entiretable.sort
block, and reorders stuff inside anyway.-- Starchaser
The text was updated successfully, but these errors were encountered: