exercism / exercism/configlet

refactor: consider using `acyclic` pragma

Open
#368 0 comments 0 reactions 0 assignees View on GitHub
kind: refactor
Dominant language
Nim
Stars
23
Forks
17
Avg merge
13h 57m
Merged PRs (30d)
1

Description

This is useful if we ever use `--gc:orc`, which might become the default in the next major Nim release.

From [the manual](https://nim-lang.github.io/Nim/manual.html#pragmas-acyclic-pragma):

> ### acyclic pragma
>
> 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:
>
> ```Nim
> type
> Node = ref NodeObj
> NodeObj {.acyclic.} = object
> left, right: Node
> data: string
> ```
>
> Or if we directly use a ref object:
>
> ```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, this may result
> in memory leaks, but memory safety is preserved.

See also https://github.com/exercism/configlet/issues/190

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.