The node containing the separator was not being copied; if it was modified by a later optimization step, the modification propagated to all previous nodes that contained it, causing incorrect results.
Many thanks to @KrsityKu for reporting and providing a repro.
Fixes#23.
llGetEnv() is not computable now, so remove it from the computable functions unit test.
The test generated lists inside a list, and after the llGetEnv() change, that caused a weird side effect that hasn't been investigated (see test result of previous commit). To be on the safe side, take all list-generating results out of the list, into their own llSetPrimitiveParams call.
In Python 2, function type names from buiiltins.txt were entered into the tables as Unicode, causing the output module to promote strings to Unicode, and causing trouble further down the line.
Entering them as str fixes the issue.
Thanks a lot to @PeterStindberg for reporting the issue and providing a script that reproduces it.
Fixes#21
This enables an option that was being done unconditionally: to swap the `if` and `else` branches if the condition is shorter when negated.
Enabled by default.
Fixes#19. Thanks to SaladDais for the report and test case.
With constant folding inactive, the dead code removal optimization was removing globals and their symbols when they were e.g. integer constants, without substituting them in other globals. This produced a crash when the output module tried to access said symbols.
For example, in this code:
```
integer A = 1;
integer B = A;
default{timer(){llBreakLink(B);}}
```
the line `integer A = 1` was being removed, as well as the `A` global symbol, but the line `integer B = A` was retained with the missing symbol, and the output module crashed when trying to look up the `A` symbol.
Apparently, it wasn't an issue when constant folding was active (which is why it went unnoticed for so long) because the constant folding code sets 'orig' in the symbol table to the original value the variable was being set to, which let the output module know what to output.
The fix is to replace the references to deleted symbols with their values in global definitions. In normal code that was already happening.
As of Second Life Server 2022-09-09.574921, STATUS_DIE_AT_EDGE and STATUS_DIE_AT_NO_ENTRY return their corresponding settings rather than always FALSE.
Regression/coverage tests are clearly lacking in this area, as the change didn't trigger any test breakage, therefore add some unit tests.
This annoyance and discrepancy with LSO was finally fixed by Linden Lab. The change has prompted some modifications to the test suite to accommodate for the new results. A further improvement has been to make these tests more friendly to be run in SL, making it easier to verify the results.
Fixes#17.
Reported by SaladDais@users.noreply.github.com - thanks!
1. When the last statement of a function is a RETURN statement which is syntactically required, it could still be deleted.
2. The child of a RETURN statement could be removed if the statement was not executed.
This commit fixes both issues.
Bug report and test case provided by @Tonaie. Fixes#14.
E.g. llSubStringIndex(...) > -1 was converted into !~llSubStringIndex(...) which is incorrect. We even had a test case for it... with a wrong expected response file.
Bug report and test case by Sinha Hynes (thanks!)
The algorithm for adding parentheses around unary operators was not working properly. It converted a * (-b) * c into a * -b * c, which LSL handles as a * -(b * c).
Fix and add test cases for that. One of the test cases shows an example where the difference matters: 0 * (-1e20) * 1e20 should result in 0.0, but if wrongly parenthesized, it gives NaN, because 1e20*1e20 gives infinity due to float overflow, and minus infinity times 0 is indeterminate.
The addition of parentheses has been improved, but it still does not eliminate every redundant parenthesis.
Also fix the horrendous typo of using "operands" where it should be "operators".
In the same places as state changes are allowed, i.e. in places where a parent of the AST node is a WHILE/DO/FOR or an IF without ELSE, it's allowed to use return statements with expressions that return void, e.g. llDie(), provided the function itself is declared as returning void.
The construction, when found, is rewritten to '{<void expression>; return;}' because the optimizer is not designed to deal with these monsters.
We've renamed the variable SuspiciousStSw to PruneBug, because it's used for both purposes now, though a better name might have been PruneBugPendingChecks, because these are only errors if the IF has an ELSE. We've also added the exception to raise as part of the data stored in the list.
Per report by Tonaie Resident.
This test suite has been in use for a long time now, in place of the obsolete and unmanageable testparser.py and testfuncs.py. It verifies the complete optimizer output to stdout and stderr, to ensure that the output matches the expectations.
See unit_tests/README.txt for more info.