Re:Zero-cost futures in Rust
by gpderetta on Saturday August 13, 2016 @02:57PM
(#12282608)
I never understood this argument, it feels to me a post hoc rationalisation. Yes, with toplevel only yield you know all suspension points, but doesn't really buy you anything, as calling an unknown function can potentially mutate any object possibly by invoking user callbacks or other generators. If the function behaviour is well documented, then whether it is a suspension point would be as well.
[ Parent
| on HN ]
The difference is that when you call a function, you can easily know what will happen: the function will execute. You can use your knowledge about the function you are calling (and the functions it calls, etc.) to ensure it does not violate any invariants you set up.
Whereas, if you have an implicit yield point that goes back to the event loop, the event loop can run arbitrary other tasks---not ones you can locally reason about or predict, but simply those that are ready to be executed.
But if you know what a function does and call you would also know whether it is an implicit yield point or not, right?
Also, I don't know about JS, but many event loops can be reentered recursively, so even with top level only yield all bets are off.