From 1946acf3a4da9bbbab6e2e386bb9a4e792e7a896 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Thu, 3 Jan 2019 02:31:08 +0100 Subject: [PATCH] Proper fix for unwanted substitutions in function calls SymbolReplacedOrDeleted had an "emergency fix" that disabled several kinds of substitutions, because they generated code that didn't compile. The cause was actually elsewhere. The actual problem was the marking of function parameters as being written to by function calls. This is true in a sense, but there's a big scope change that totally destroys the possibility of substituting identifiers, for example. We were not removing the function parameters, anyway, therefore that code has just been disabled. Note that removal of function parameters may be impossible if one parameter has side effects. Consider this: f(string x, integer y, string z) { llOwnerSay(x + z); } integer n = 2; default{state_entry(){ f("a" + (string)n, n=llSetRegionPos(<100,100,100>), "c" + (string)n); }} Even worse if the expression for the x argument has side effects too and x and y need to be performed in the right order. Fortunately, such case is highly unlikely. But if we ever implement removal of function parameters, that's an additional difficulty to take care of. --- lslopt/lsldeadcode.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lslopt/lsldeadcode.py b/lslopt/lsldeadcode.py index 360a1d2..df82658 100644 --- a/lslopt/lsldeadcode.py +++ b/lslopt/lsldeadcode.py @@ -163,13 +163,16 @@ class deadcode(object): # Each element is a "write" on the callee's parameter. # E.g. f(integer a, integer b) { f(2,3); } means 2, 3 are # writes to a and b. + # This has been eliminated, as it causes more trouble than + # it fixes. self.MarkReferences(child[idx]) if fdef is not None: psym = self.symtab[fdef.pscope][fdef.pnames[idx]] - if 'W' in psym: - psym['W'] = False - else: - psym['W'] = child[idx] + #if 'W' in psym: + # psym['W'] = False + #else: + # psym['W'] = child[idx] + psym['W'] = False if 'Loc' in sym: if not hasattr(self.tree[sym['Loc']], 'X'): @@ -355,9 +358,7 @@ class deadcode(object): # Replacing j with i+1 in llOwnerSay will produce wrong code because # the name i is redefined after j is assigned. shrinknames prevents # that. - # FIXME: EMERGENCY FIX: shrinknames is not enough guarantee. See nposerlv.lsl. - #if not self.shrinknames or not node.SEF: - if True or not node.SEF: + if not self.shrinknames or not node.SEF: return False if nt not in ('VECTOR', 'ROTATION'):