Speculating that a debugger is not attached and modifying local variables, is one example.
> in the common case it should (at least) be something you could do just by walking the AST
Yes that’s why it’s speculation - handle the common cases and speculate away the uncommon cases.
A debugger can do anything. You can't outthink a debugger and shouldn't try.
> Yes that’s why it’s speculation - handle the common cases and speculate away the uncommon cases.
Speculation is when you guess and need to have a guard in case the guess is wrong. They're describing a situation where it can't be wrong and you wouldn't need to speculate.
Yes that's what we're saying. So you deoptimise when someone starts debugging.
> and shouldn't try
You'd get extremely slow code with this approach!
> Speculation is when you guess and need to have a guard in case the guess is wrong.
Yes, you're guessing that nobody will attach a debugger and you're guarding that no debugger has been attached. That guard is usually implicit.
> They're describing a situation where it can't be wrong and you wouldn't need to speculate.
It can be wrong... if someone's using a debugger. So you need to speculate that they aren't using a debugger.
I wrote a PhD about using speculation and deoptimisation to solve the problem of people debugging optimised code.
You must be interpreting that differently than I meant it. The approach I'm suggesting is "pretend debuggers don't exist when optimizing". It gives you the fast code.
A debugger can break any assumption you make. Even unoptimized code could crash if a debugger messes with it. The fear of a debugger should never make you decide not to do an optimization.
How would you use a guard if you want to deoptimize because a debugger attached? You'd have to have a guard between each instruction, and even then it might not be enough.
> Yes, you're guessing that nobody will attach a debugger and you're guarding that no debugger has been attached. That guard is usually implicit.
> So you deoptimise when someone starts debugging.
If an "implicit" guard means "we'll have a function the debugger calls, telling us to redo the compilation", then that's not something you need to do dynamic analysis for, and it doesn't make your compilation more complicated. You don't "speculate away" that case unless you're using the word "speculate" to include "completely ignore for now, without even a guard", which I didn't think fell under that umbrella. Does it?
> It can be wrong... if someone's using a debugger.
It's not wrong. A debugger can make 2+2 be 5. Debuggers don't follow any rules, but that doesn't mean your compiler should try (and inevitably fail) to make code that works in a world where no rules exist.