"Tootsie Pop" model #21
Description
The Tootsie Pop model leverages unsafe declarations to simultaneously permit aggressive optimization in safe code while being very accepting of unsafe code patterns. The high-level summary is roughly:
- identify lexically scoped unsafe abstractions;
- within an unsafe abstraction, disable optimizations and stick to a very simple model.
This has the advantage of being very permissive -- if we pick a suitable scope for the unsafe abstraction, I suspect that most any unsafe code that is out there in the wild which is sort of "remotely correct" will work out fine. But its achilles heel is that it can inhibit quite a lot of optimization. Somewhat annoyingly, it seems to interact poorly with both simple and complex cases of unsafe code:
- The "unchecked get" use case is a good example where this can strike very innocent code (optimizing around unchecked-get #20).
- But of course one can also imagine that sophisticated unsafe authors will want to supply detailed hints about performance -- for example, it would definitely make sense to ensure that we can wring detailed aliasing information out of the code in libstd.
Where the Tootsie Pop model does really well is the "middle" cases -- unsafe code that manipulates pointers and so forth, but where the author is not familiar with the unsafe code guidelines in depth. (The appeal of the Tootsie Pop model is thus dependent, to some extent, on how complex it is to understand and use the more advanced models.)
It's worth noting that even if we adopted the Tootsie Pop model, we'd likely still want to hammer out a more advanced model to cover the more advanced use cases.