William ML Leslie <william.leslie....@gmail.com> writes:

> On 20 February 2013 03:21, Mark H Weaver <m...@netris.org> wrote:
>> (define (func x)
>>   (let ((r (my-special-function x)))
>>     (+ x 2 r)))
>>
>> Here, (my-special-function x) must be evaluated before evaluating '+'.
>> Evaluating '+' means to fetch the value stored in the location denoted
>> by '+'.  Therefore, if '+' is rebound during the call to
>> 'my-special-function', then the new binding for '+' must be used.
>>
>> This is a case where on-stack-replacement is needed to implement the
>> correct semantics.
>>
>> To summarize, when you rebind a function 'foo', it is not the existing
>> activation records for 'foo' that you need to worry about.  Instead, you
>> need to worry about existing activation records for all compiled
>> procedures 'bar' that incorporated assumptions about 'foo'.
>
> Recompiling every procedure that uses + when somebody binds it means
> compiling a lot of code that probably isn't going to be used.  More
> likely, if + has been inlined here, the compiler will have to emit a
> guard that checks inlining assumptions as the start of the let body.
I'm afraid this isn't good enough.  Even if one ignores the possibility
of multiple threads, checks would have to be added not just at the start
of each let body, but also upon return from every procedure that might
rebind '+' or capture its continuation.  This includes all procedures
accessed through toplevel/module bindings.

Therefore, I repeat my initial assertion that this is a can of worms.
I'd like to see it implemented in Guile some day, but it's a big job.

     Regards,
       Mark

Reply via email to