Re: Major Bug in Interpreter [Attn: Robert Craig]

new topic     » goto parent     » topic index » view thread      » older message » newer message

On Wed, 16 Feb 2005 07:59:27 -0800, Robert Craig
<guest at rapideuphoria.com> wrote:
> I could give a warning, but I think the false-alarm ratio would
> be too high for it to be useful. There would often be
> dozens or maybe hundreds of variables that might potentially
> be overwritten as a result of a function call. It's theoretically
> impossible to always know at compile-time whether a given variable
> will actually be overwritten at run-time. In many cases the
> potential will seem to be there, but in reality it will not happen.

Maybe hundreds? I don't mean a warning when a global variable might be
modified in a function, I mean a warning where in LHS = RHS(), the LHS
contains global variables that might be modified inside the RHS()
function. I think you can agree that this is the case being discussed,
and it's a problem that cannot be simply resolved by the programmer.

Some examples:
integer i
function do_i()
    i = 20
    return i + 1
end function
i = 10
i = do_i()
}}}
<eucode>
In this case, it's no big deal, i will be rewritten by the function
return anyway - no warning: i = 21

}}}
<eucode>
sequence arr
arr = {1,2,3,4,5}
function rem(integer i)
      arr = arr[1..i-1]&arr[i+1..$]
      return arr
end function
arr = rem(3)

Again, not a problem, as arr is rewritten by the function return - no
warning: arr = {1,2,4,5}


sequence arr
arr = {1,2,3,4,5}
function rem(integer i)
      arr = arr[1..i-1]&arr[i+1..$]
      return i*i
end function
arr[3] = rem(3)

This is a problem, as the LHS has to be resolved... does it refer to
arr before rem() is called, or after? WARNING. If after, arr =
{1,2,9,5}. If before, who knows? Maybe i*i is assigned to an element
that is deleted immediately after...

sequence arr
integer ind
arr = {1,2,3,4,5}
ind = 3
function stuff()
      ind = 2
      return 100
end function
arr[ind] = stuff()

This is a problem, as the subscripting variable is changed by the
function... WARNING
If it's resolved before, arr = {1,2,100,4,5}. If after, arr = {1,100,3,4,5}

sequence arr
integer ind
arr = {1,2,3,4,5}
ind = 3
function stuff()
      arr = {5,4,3,2,1}
      ind = 2
      return 100
end function
arr = arr[1..2] & stuff() & arr[ind]

Hmm, can the RHS ever be ambiguous? Maybe a problem, Rob? WARNING?
Assuming that all the elements are resolved before the function: arr =
{1,2, 100, 3}
Assuming that elements are resolved after the function: arr = {5,4, 100, 4}
Assuming that elements are resolved in their order: arr = {1,2, 100, 4}
Very strange stuff, but it could quite easily happen. A similar
example could occur where the LHS is an atom, with mathematical ops on
the RHS rather than concats.
Another example may occur where in a slice operation: arr[var..func()]
, var is modified by func().



Seems to me, that warnings should occur if:
* The left-hand-side is a sequence AND
* The left-hand-side is subscripted by a variable AND
* That variable is modified by the RHS function

Or
* The left-hand-side is a sequence AND
* The left-hand-side is subscripted by a variable or a literal AND
* The array is modified by the RHS function

Or
* An expression consists of both a variable and a function call
(connected together with concat or mathop, etc) AND
* That function call modifies the variable


I don't think there would be many false positives here... Rob, what
'hundreds' are you talking about?

-- 
MrTrick

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu