ARC: cycle detector (#12823)
* first implementation of the =trace and =dispose hooks for the cycle collector * a cycle collector for ARC: progress * manual: the .acyclic pragma is a thing once again * gcbench: adaptations for --gc:arc * enable valgrind tests for the strutils tests * testament: better valgrind support * ARC refactoring: growable jumpstacks * ARC cycle detector: non-recursive algorithm * moved and renamed core/ files back to system/ * refactoring: --gc:arc vs --gc:orc since 'orc' is even more experimental and we want to ship --gc:arc soonish
This commit is contained in:
parent
5848f0042c
commit
83a736a34a
45 changed files with 939 additions and 229 deletions
|
|
@ -6017,8 +6017,32 @@ The ``noreturn`` pragma is used to mark a proc that never returns.
|
|||
|
||||
acyclic pragma
|
||||
--------------
|
||||
The ``acyclic`` pragma applies to type declarations. It is deprecated and
|
||||
ignored.
|
||||
The ``acyclic`` pragma can be used for object types to mark them as acyclic
|
||||
even though they seem to be cyclic. This is an **optimization** for the garbage
|
||||
collector to not consider objects of this type as part of a cycle:
|
||||
|
||||
.. code-block:: nim
|
||||
type
|
||||
Node = ref NodeObj
|
||||
NodeObj {.acyclic.} = object
|
||||
left, right: Node
|
||||
data: string
|
||||
|
||||
Or if we directly use a ref object:
|
||||
|
||||
.. code-block:: nim
|
||||
type
|
||||
Node {.acyclic.} = ref object
|
||||
left, right: Node
|
||||
data: string
|
||||
|
||||
In the example a tree structure is declared with the ``Node`` type. Note that
|
||||
the type definition is recursive and the GC has to assume that objects of
|
||||
this type may form a cyclic graph. The ``acyclic`` pragma passes the
|
||||
information that this cannot happen to the GC. If the programmer uses the
|
||||
``acyclic`` pragma for data types that are in reality cyclic, the memory leaks
|
||||
can be the result, but memory safety is preserved.
|
||||
|
||||
|
||||
|
||||
final pragma
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue