Re:What I Learned Making My Own JIT Language
by dan-robertson on Wednesday June 27, 2018 @10:43PM
(#17413673)
This seems nice but it is hard. Imagine the following scenario in a JavaScript where one has lisp like singly linked lists:
function map(f, list) {
if (list==null)
return null;
return cons(f(head(list)), map(f, tail(list)));
}
Now as there is a call to map, a JIT compiled version will put in a redefinition check and if the check passes then it can call an optimised map which eg knows it has two arguments and f is a function. If the check fails then a slow path which does a full call is followed.
In your scenario there is no redefinition check and instead when one tries to redefine map, any optimised calls must be downgraded to the slow path.
But now imagine calling map with a function that redefines map after say the third recursive call. Then the redefinition downgrading magic needs to somehow modify one version of map halfway through a call so that when f returns it will call the new map, but the calls further up the stack frame don’t need to be modified as they won’t call map again.
In your scenario there is no redefinition check and instead when one tries to redefine map, any optimised calls must be downgraded to the slow path.
But now imagine calling map with a function that redefines map after say the third recursive call. Then the redefinition downgrading magic needs to somehow modify one version of map halfway through a call so that when f returns it will call the new map, but the calls further up the stack frame don’t need to be modified as they won’t call map again.