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. This is how those sort of semantics are preserved where OSR is not implemented. Regarding rebinding (+): A few people have expressed opinions about scheme becoming less fluid, and I think most would probably agree that even if certain bindings are assumed constant or types are declared in module APIs and specialised code generated, the most-general code still wants to be available, and ideally from within the .so . -- William Leslie