[Pharo-project] RB AST Rewriter to eliminate/consoliate temporary variables?
Hi all, Hi Lukas: Do you know if anyone ever implemented a rewriter for the RB AST that reduces the amount of temporary variables if possible? I have a naive rewriting step that creates too many temps, but some of them are not strictly necessary. However, currently, I run into 'Cannot compile -- stack including temps is too deep' which is, well, ehm, not so nice. In case anyone has something in that direction, I would be interested. Thanks Stefan -- Stefan Marr Software Languages Lab Vrije Universiteit Brussel Pleinlaan 2 / B-1050 Brussels / Belgium http://soft.vub.ac.be/~smarr Phone: +32 2 629 2974 Fax: +32 2 629 3525
Hi Stefan, I think there is a lint rule that does that: TempNotRead ... I don't have an image at hand, but I can check tonight if you haven't found it until then. Lukas On 9 December 2011 16:29, Stefan Marr <pharo@stefan-marr.de> wrote:
Hi all, Hi Lukas:
Do you know if anyone ever implemented a rewriter for the RB AST that reduces the amount of temporary variables if possible?
I have a naive rewriting step that creates too many temps, but some of them are not strictly necessary.
However, currently, I run into 'Cannot compile -- stack including temps is too deep' which is, well, ehm, not so nice.
In case anyone has something in that direction, I would be interested.
Thanks Stefan
-- Stefan Marr Software Languages Lab Vrije Universiteit Brussel Pleinlaan 2 / B-1050 Brussels / Belgium http://soft.vub.ac.be/~smarr Phone: +32 2 629 2974 Fax: Â +32 2 629 3525
-- Lukas Renggli www.lukas-renggli.ch
Hi Lukas: On 09 Dec 2011, at 16:54, Lukas Renggli wrote:
Hi Stefan,
I think there is a lint rule that does that: TempNotRead ... I don't have an image at hand, but I can check tonight if you haven't found it until then.
Thanks, I checked the lint rules, but well, while there are some rules which provide related analysis, what I was looking for is slightly more complex. I basically want to be able to automatically reduce the number of temps for the following example to one: | t1 t2 | t1 := o1 foo. o2 bar: t1. o3 bar: t1. t2 := o1 foo. o2 bar: t2. o3 bar: t2. Of course it is slightly more complex than that, because the usage of the temps is not just in a sequence, but can be also in blocks, or nested expressions. But in this simple example, I could remove t2 and use t1 instead. Well, for the moment, I just removed the offending test from the system, but since my benchmarks do not run yet, I fear that I might run into the problem with real code, too. Best regards Stefan
Lukas
On 9 December 2011 16:29, Stefan Marr <pharo@stefan-marr.de> wrote:
Hi all, Hi Lukas:
Do you know if anyone ever implemented a rewriter for the RB AST that reduces the amount of temporary variables if possible?
I have a naive rewriting step that creates too many temps, but some of them are not strictly necessary.
However, currently, I run into 'Cannot compile -- stack including temps is too deep' which is, well, ehm, not so nice.
In case anyone has something in that direction, I would be interested.
Thanks Stefan
-- Stefan Marr Software Languages Lab Vrije Universiteit Brussel Pleinlaan 2 / B-1050 Brussels / Belgium http://soft.vub.ac.be/~smarr Phone: +32 2 629 2974 Fax: +32 2 629 3525
-- Lukas Renggli www.lukas-renggli.ch
-- Stefan Marr Software Languages Lab Vrije Universiteit Brussel Pleinlaan 2 / B-1050 Brussels / Belgium http://soft.vub.ac.be/~smarr Phone: +32 2 629 2974 Fax: +32 2 629 3525
I basically want to be able to automatically reduce the number of temps for the following example to one:
| t1 t2 | t1 := o1 foo. o2 bar: t1. o3 bar: t1.
t2 := o1 foo. o2 bar: t2. o3 bar: t2.
Of course it is slightly more complex than that, because the usage of the temps is not just in a sequence, but can be also in blocks, or nested expressions.
But in this simple example, I could remove t2 and use t1 instead.
No, "o1 foo", "o2 bar: t1", "o3 bar: t1" could have side-effects that influence what "o1 foo" returns. No tool on the world (without additional knowledge) can safely replace "t2" with "t1". Lukas -- Lukas Renggli www.lukas-renggli.ch
Hi: On 09 Dec 2011, at 18:10, Lukas Renggli wrote:
I basically want to be able to automatically reduce the number of temps for the following example to one:
| t1 t2 | t1 := o1 foo. o2 bar: t1. o3 bar: t1.
t2 := o1 foo. o2 bar: t2. o3 bar: t2.
Of course it is slightly more complex than that, because the usage of the temps is not just in a sequence, but can be also in blocks, or nested expressions.
But in this simple example, I could remove t2 and use t1 instead.
No, "o1 foo", "o2 bar: t1", "o3 bar: t1" could have side-effects that influence what "o1 foo" returns. No tool on the world (without additional knowledge) can safely replace "t2" with "t1".
It is about the slot, not about the value. This is a perfectly legal transformation: | t1 | t1 := o1 foo. o2 bar: t1. o3 bar: t1. t1 := o1 foo. o2 bar: t1. o3 bar: t1. That is the same what register allocators do. t1, as a slot, is not going to be read anymore, thus, the slot can be used to hold another temporary value. Well, anyway, I just hope that I can work around the frame size limitations when I encounter them in real code. Thanks Stefan
Lukas
-- Lukas Renggli www.lukas-renggli.ch
-- Stefan Marr Software Languages Lab Vrije Universiteit Brussel Pleinlaan 2 / B-1050 Brussels / Belgium http://soft.vub.ac.be/~smarr Phone: +32 2 629 2974 Fax: +32 2 629 3525
But in this simple example, I could remove t2 and use t1 instead.
No, "o1 foo", "o2 bar: t1", "o3 bar: t1" could have side-effects that influence what "o1 foo" returns. No tool on the world (without additional knowledge) can safely replace "t2" with "t1".
It is about the slot, not about the value. This is a perfectly legal transformation:
| t1 | t1 := o1 foo. o2 bar: t1. o3 bar: t1.
t1 := o1 foo. o2 bar: t1. o3 bar: t1.
That is the same what register allocators do. t1, as a slot, is not going to be read anymore, thus, the slot can be used to hold another temporary value.
Luckily Smalltalk is not a register machine. Even if your example looks perfectly linear, the order in which the statements are executed is pretty much unpredictable (think of exceptions, continuations, reflection, ...).
Well, anyway, I just hope that I can work around the frame size limitations when I encounter them in real code.
The NewCompiler had a visitor that would overflow excess literals into arrays. You could theoretically do the same for excess temps. Lukas -- Lukas Renggli www.lukas-renggli.ch
participants (2)
-
Lukas Renggli -
Stefan Marr