Add docs on how to think through inline directives
This is my attempt at explaining the what, why, and how of inline directives, so I am better equipped to fix #6 in a future PR (e.g. #21).
🤔... I'm not sure how to replace the examples I provided with correct ones that still illustrate the idea I'm trying to convey.
🤔... I'm not sure how to replace the examples I provided with correct ones that still illustrate the idea I'm trying to convey.
I think in general, you should start from smaller examples and build up. I think you jump into let bindings and compound expressions too quickly. For example:
1 + 42
Can be reduced to 43, since the optimizer knows how to evaluate primitive addition (You can also mention examples of other primitive operations it knows how to evaluate). However:
a + 42
where a is a free variable, cannot be reduced because we don't know what a is yet.
{ foo: 42 }.foo
Can be reduced to 42, because we know what expression (42) is at the record property foo. However:
a.foo
where a is a free variable, cannot be reduced because we don't know what a is yet.
case Right 42 of
Right a -> a + 1
Left b -> b
Can be reduced to 42 + 1, because we known which constructor is being caseed on. And that can subsequently be reduced to 43 based on the previous examples.
a = { foo: 42 }
b = a.foo + 1
Cannot be reduced yet because in the expression a.foo, a is still free. However, if we inline our a binding, such that our expression is now:
b = { foo: 42 }.foo + 1
We can follow the same steps to reduce b to 42 + 1, and then 43. The basis for the optimizer is determining when and how things like a should be inlined to expose opportunities to further evaluate and reduce our code, which is done through a set of conservative heuristics.
Then inlining directives are a way for authors to tell the optimizer when a top-level binding should be inlined apart from it's own heuristics if we know that doing so is advantageous.
Ok, I rewrote the document with your feedback in mind.
This PR seems to have been open for a very long time, though it seams to have all issues resolved. How can I help it to be merged?