Updated Destructors (rest)
This commit is contained in:
parent
833304ebcf
commit
5ddd47c46b
|
@ -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:
|
For a ``sink`` parameter called ``sp`` a **consume** looks like:
|
||||||
|
|
||||||
.. code-block:: nim
|
.. code-block:: nim
|
||||||
|
|
||||||
proc consume(c: var Container; sp: sink T) =
|
proc consume(c: var Container; sp: sink T) =
|
||||||
locationDerivedFrom(c) = sp
|
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":
|
A consume can also be forwarded, "pass sp to a different proc as a sink parameter":
|
||||||
|
|
||||||
.. code-block:: nim
|
.. code-block:: nim
|
||||||
|
|
||||||
proc consume(c: var Container; sp: sink T) =
|
proc consume(c: var Container; sp: sink T) =
|
||||||
c.takeAsSink(sp)
|
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:
|
local variables this is quite easy to prove:
|
||||||
|
|
||||||
.. code-block:: nim
|
.. code-block:: nim
|
||||||
|
|
||||||
proc consume(c: var Container; element: sink T) =
|
proc consume(c: var Container; element: sink T) =
|
||||||
c[i] = element
|
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:
|
``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
|
.. code-block:: nim
|
||||||
|
|
||||||
proc add(c: var Container; x: T) # version A
|
proc add(c: var Container; x: T) # version A
|
||||||
proc add(c: var Container; x: sink T) # version B
|
proc add(c: var Container; x: sink T) # version B
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue