Updated Destructors (rest)
This commit is contained in:
parent
c3e851e3ae
commit
a78cbea72b
|
@ -146,6 +146,21 @@ Rule Pattern Transformed into
|
||||||
======== ==================== ===========================================================
|
======== ==================== ===========================================================
|
||||||
|
|
||||||
|
|
||||||
|
Flaw 1
|
||||||
|
======
|
||||||
|
|
||||||
|
A ``sink`` parameter cannot be passed to its destructor since the destructor takes a ``var T`` parameter and ``sink`` itself cannot be passed as ``var``.
|
||||||
|
|
||||||
|
**Solution**: The destructor call is done on a temporary location that was bitcopied from the ``sink`` parameter or conceptually via ``unsafeAddr``. **Proof** that this is safe: After the destruction the ``sink`` parameter won't be used again. At the callsite either a copy was passed to the ``sink`` parameter which can't be used again either or an explicit ``move`` was performed which resets the memory and ensures that the it won't be used afterwards too. (Maybe this indicates that the destructor should also be a ``sink`` parameter and the ``reset`` step usually done in the destructor can be done by the compiler if required.)
|
||||||
|
|
||||||
|
Flaw 2
|
||||||
|
======
|
||||||
|
|
||||||
|
An analysis like "every code path provable leads to the parameters consumption" is hard to pull off, especially in a language like Nim with exceptions.
|
||||||
|
|
||||||
|
**Solution**: The analysis can introduce a fallback path with hidden bool flags like ``if not flag: =destroy(sinkParam)``. Furthermore the compiler should probably get even smarter in its inference of ``raises: []``.
|
||||||
|
|
||||||
|
|
||||||
Interactions with the GC
|
Interactions with the GC
|
||||||
========================
|
========================
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue