Hi all!<br>
<br>
This method is currently decompiled incorrectly. In particular, this makes it impossible to debug it without a changes file:<br>
<br>
    <b>test1</b><br>
    <font color="#000000">    </font><font color="#808080">|</font><font color="#000000"> </font><font color="#6B6B6B">x</font><font color="#000000"> </font><font color="#808080">|</font><font color="#000000"><br>
        </font><font color="#000000">(</font><font color="#6B6B6B">x</font><font color="#000000"> </font><b>:=</b><font color="#000000"> </font><font color="#800000">self</font><font color="#000000"> </font><font color="#000080">foo</font><font color="#000000">)</font><font color="#000000"> </font><font color="#000080">ifNotNil:</font><font color="#000000"> </font><font color="#000000">[</font><font color="#800000">self</font><font color="#000000"> </font><font color="#000080">bar</font><font color="#000000">]</font><font color="#000000">.</font><font color="#000000"><br>
        </font><font color="#800000">^</font><font color="#000000"> </font><font color="#6B6B6B">x</font><br>
<br>
The decompiler returns:<br>
<br>
    <b>test1</b><br>
        <font color="#800000">self</font><font color="#000000"> </font><font color="#000080">foo</font><font color="#000000"><br>
            </font><font color="#000080">ifNotNil:</font><font color="#000000"> </font><font color="#000000">[</font><font color="#000000">:</font><font color="#000080">x</font><font color="#000000"> </font><font color="#808080">|</font><font color="#000000"> </font><font color="#800000">self</font><font color="#000000"> </font><font color="#000080">bar</font><font color="#000000">]</font><font color="#000000">.</font><font color="#000000"><br>
        </font><font color="#800000">^</font><font color="#000000"> </font><font color="#FF0000">x</font><br>
<br>
Here is another example:<br>
<br>
    <b>test2</b><br>
        <font color="#808080">|</font><font color="#000000"> </font><font color="#6B6B6B">x</font><font color="#000000"> </font><font color="#808080">|</font><font color="#000000"><br>
        </font><font color="#6B6B6B">x</font><font color="#000000"> </font><b>:=</b><font color="#000000"> </font><font color="#800000">1</font><font color="#000000">.</font><font color="#000000"><br>
        </font><font color="#000000">[</font><font color="#6B6B6B">x</font><font color="#000000"> </font><font color="#000080"><=</font><font color="#000000"> </font><font color="#800000">5</font><font color="#000000">]</font><font color="#000000"> </font><font color="#000080">whileTrue:</font><font color="#000000"> </font><font color="#000000">[</font><font color="#000000"><br>
            </font><font color="#000000">Transcript</font><font color="#000000"> </font><font color="#000080">showln:</font><font color="#000000"> </font><font color="#6B6B6B">x</font><font color="#000000">.</font><font color="#000000"><br>
            </font><font color="#6B6B6B">x</font><font color="#000000"> </font><b>:=</b><font color="#000000"> </font><font color="#6B6B6B">x</font><font color="#000000"> </font><font color="#000080">+</font><font color="#000000"> </font><font color="#800000">1</font><font color="#000000">]</font><font color="#000000">.</font><font color="#000000"><br>
        </font><font color="#800000">^</font><font color="#000000"> </font><font color="#6B6B6B">x</font><br>
<br>
The decompiler returns:<br>
<br>
    <b>test2</b><br>
        <font color="#800000">1</font><font color="#000000"><br>
            </font><font color="#000080">to:</font><font color="#000000"> </font><font color="#800000">5</font><font color="#000000"><br>
            </font><font color="#000080">do:</font><font color="#000000"> </font><font color="#000000">[</font><font color="#000000">:</font><font color="#000080">x</font><font color="#000000"> </font><font color="#808080">|</font><font color="#000000"> </font><font color="#000000">Transcript</font><font color="#000000"> </font><font color="#000080">showln:</font><font color="#000000"> </font><font color="#000080">x</font><font color="#000000">]</font><font color="#000000">.</font><font color="#000000"><br>
        </font><font color="#800000">^</font><font color="#000000"> </font><font color="#FF0000">x</font><br>
<br>
In both examples, the decoding of the inlined message is invalid because the temporary is also accessed outside of the block scope.<br>
In DecompilerConstructor>>decodeIfNilWithReceiver:selector:arguments:tempReadCounts:, we already check "that there is no remote vector pointing to it", but the tempReadCounts arguments cannot see into the future, unfortunately.<br>
What would be the right way to fix this? I saw that we already have <font color="#000080">#markTemp:asOutOfScope:</font> but we do not send this from <font color="#000080">#jump:in:</font> and it is also unclear to me where the scope is really checked during the decompilation. If we do not want to perform a second run over all byte codes, I could only imagine that if a variable out of scope is pushed onto the stack (<font color="#000080">#pushTemporaryVariable:</font>), we could revert the previous decoding. But first of all, I do not see any possibility to get the current scope of a running decompiler and second, implementing this revert sounds like a not so small design change.<br>
<br>
Do you see a simple way to fix this limitation, or do we indeed need to rework the decompiler design to handle this edge case properly? If yes, which one would you prefer - 1) run the decompiler twice so that tempReadCounts is already filled correctly, or 2) try to identify the scope of every "pushTemp" instruction and if the scope is invalid, revert the inline decoding from there?<br>
<br>
Best,<br>
Christoph<br>
<br>
<font color="#808080">---<br>
</font><font color="#808080"><i>Sent from </i></font><font color="#808080"><i><a href="https://github.com/hpi-swa-lab/squeak-inbox-talk"><u><font color="#808080">Squeak Inbox Talk</font></u></a></i></font>