dxforth <
dxf...@gmail.com> writes:
>On 6/06/2022 19:34, Anton Ertl wrote:
>> However, I believe that they have had reports from customers, have
>> considered it, and decided that inlining or tail-call optimization are
>> enabled by default, and they give the programmers ways to disable
>> these optimizations, so the programmers can get return-address
>> manipulations to work (at a cost in performance).
>
>I'm puzzled by the claim an optimizing compiler wouldn't know how to
>handle a colon definition with UNNEST or ABANDON in it.
I checked gforth, iForth, lxf, sf, vfxlin, and none of them has a word
called ABANDON. Only gforth-0.7.3 has a word called UNNEST; it's a
variable and probably not what you have in mind.
They are also not in fig-Forth, Forth-79, or Forth-83. Why should any
Forth system, optimizing or not, know how to handle UNNEST or ABANDON?
As for stuff like using R>, >R, etc. for return address manipulation,
Bernd Paysan has discussed how a sophisticated compiler might not just
notice this and disable inlining or tail-call optimization in that
case, but he also discussed how an even more sophisticated compiler
could optimize this by performing data-flow analysis of the return
address, and then inlining and rearranging the code. However, do we
really want to spend that much effort on this idiom?
In the meantime, even for unsophisticated compilers like gforth-itc,
return address manipulation interacts badly with locals.
: foo r> drop ;
: bar 1 {: a :} foo ;
: flip 2 {: b :} bar b . ;
flip
On current gforth-itc this results in:
flip 1
*the terminal*:4:5: error: Invalid memory address
flip>>><<<
On SwiftForth this seems to result in an endless loop, with a
Segmentation fault on Ctrl-C.
On vfxlin this results in a segmentation violation right away.
Even if I disable inlining and optimizations in VFX with
unoptimised
no inlining
-sin
I get the same result. BTW, in looking for these settings, I found a
section "return stack modifiers" in the VFX manual, which demonstrates
that return-address manipulation has been considered in VFX.
You may prefer return-address manipulation over locals, but these
systems implement locals, and return-address manipulation does not
work well with that, even without optimization.
>When I write a
>discrete definition I expect the compiler to respect that and optimize
>only when safe to do so. The presence of those words should signal
>don't inline this definition.
They certainly won't inline the definition, because the presence of
these words results in a compilation error.
In the example above, disabling the optimizations does not change
anything in VFX.
However, for the earlier example:
: foo r> drop ;
: bar foo ;
: flip bar ." end flip." ;
: flop flip ." end flop." ;
flop
Disabling optimizations in VFX as shown above results in the same
output as that produced by Gforth.
As for the idea that the optimizer should not change the behaviour, we
have three different goals:
same behaviour as without optimization
performance
compiler simplicity
Choose any two. In general I value the first goal higher, but in the
present case return-address manipulation is something that breaks in
the presence of locals even without optimization. So for a compiler
that implements locals, is the first goal really worth abandoning one
of the others for?
>>>> Given the lack of common practice these days, I expect that that ship
>>>> has sailed, but if you feel like it, you can try proposing support for
>>>> that feature.
>
>It's left out of ANS and there's an injunction to not remove from the
>return stack what the program didn't put there. If such practice isn't
>common today that's entirely on ANS and 200x.
You assign much more power to the standard than it has. E.g.,
Forth-94 specified that standard programs shall not rely on 1 chars =
1, nor on 2s-complement arithmetic, and yet these continued to be
common practice, and eventually were standardized.
If return-address manipulation had been similarly common practice
before Forth-94, we would not have seen F-PC, which broke the common
idioms for that; we would still have seen cmForth, which broke that;
and after Forth-94, systems implementors would not have dared to break
it, and we probably would have standardized it by now.
>>>Does the Pope ask Catholics to send him proposals?
>>
>> Why should that be relevant?
>
>Same top-down business model?
I don't know about the "business model" of the Catholic church, but
for Forth-200x the process is that anyone can make a proposal, and
that things that are not proposed by anyone are not standardized.
Things that are proposed may or may not be standardized. I have given
you my guess about the chances of a proposal for return-address
manipulation being accepted, but my guesses have been wrong before.