Updated Destructors (rest)

This commit is contained in:
Andreas Rumpf 2018-01-04 13:28:01 +01:00
parent 833304ebcf
commit 5ddd47c46b
1 changed files with 4 additions and 0 deletions

View File

@ -33,6 +33,7 @@ proc's body. The compiler will use a dataflow analysis to prove this fact.
For a ``sink`` parameter called ``sp`` a **consume** looks like:
.. code-block:: nim
proc consume(c: var Container; sp: sink T) =
locationDerivedFrom(c) = sp
@ -41,6 +42,7 @@ This assignment is mapped to the ``=sink`` operator.
A consume can also be forwarded, "pass sp to a different proc as a sink parameter":
.. code-block:: nim
proc consume(c: var Container; sp: sink T) =
c.takeAsSink(sp)
@ -53,6 +55,7 @@ and the compiler tries to prove that it is not used again afterwards. For
local variables this is quite easy to prove:
.. code-block:: nim
proc consume(c: var Container; element: sink T) =
c[i] = element
@ -153,6 +156,7 @@ Rule Pattern Transformed into
``sink T`` also affects overloading resolution rules; by the time type checking is performed we have no control flow graph yet so the property ``lastReadOf z`` is not available. However, passing a call expression ``f()`` to a ``g`` taking a sink parameter is a syntactic property and so is available for overloading resolution. Thus I propose the following rule:
.. code-block:: nim
proc add(c: var Container; x: T) # version A
proc add(c: var Container; x: sink T) # version B