rtoy / maxima

A Clone of Maxima's repo
Other
0 stars 0 forks source link

"local" doesn't work in translated code #3777

Closed rtoy closed 4 months ago

rtoy commented 4 months ago

Imported from SourceForge on 2024-07-08 15:03:48 Created by tomasriker on 2015-06-13 18:36:39 Original: https://sourceforge.net/p/maxima/bugs/2976


local doesn't work in compiled functions, as demonstrated by the following code:

(%i1) f() := block([arr], local(arr), arr[otherwise] := 42)$
(%i2) f()$
(%i3) arrayinfo(arr);
arrayinfo: arr is not an array.
 -- an error. To debug this try: debugmode(true);
(%i4) compile(f)$
(%i5) f()$
(%i6) arrayinfo(arr);
(%o6) [hashed,1]

arr's property of being a hashed array was leaked by the compiled function f, but not by the original non-compiled one.

rtoy commented 4 months ago

Imported from SourceForge on 2024-07-08 15:03:49 Created by kjak on 2020-08-01 23:17:20 Original: https://sourceforge.net/p/maxima/bugs/2976/#a4d5


rtoy commented 4 months ago

Imported from SourceForge on 2024-07-08 15:03:53 Created by kjak on 2020-08-01 23:17:20 Original: https://sourceforge.net/p/maxima/bugs/2976/#bcde


I have a fix for this and another bug I've found so far related to local in translated code.

I'm changing the title of this report because it's not really specific to functions. For example, the same sort of bug you reported also occurs in a translated file where local is used in a top-level block.

Here's that other bug I mentioned. It's caused by an internal flag not being correctly set/unset:

(%i1) foo () := local ()$ /* just something with local */
(%i2) bar () := local ()$ /* same here */

(%i3) translate (foo);
(%o3) [foo]

(%i4) translate (bar); /* translate(foo) also fails here */
error: there is already a 'local' in this block.
error: failed to translate bar
(%o4) []

While I'm here I'll point out that using the same (translated) foo as above we can actually make Maxima eventually run out of memory:

(%i5) do foo ();

It looks like this should just be an infinite loop because it doesn't seem like foo does much of anything, but we run out of memory because every call is affecting some internal state that doesn't get cleaned up. (This is really just the same bug you reported.)

Anyway, I'll commit fixes for these soon after I look around for other related bugs and after I write up some other tests.