shallow pragma

The shallow pragma affects the semantics of a type: The compiler is allowed to make a shallow copy. This can cause serious semantic issues and break memory safety! However, it can speed up assignments considerably, because the semantics of Nim require deep copying of sequences and strings. This can be expensive, especially if sequences are used to build a tree structure:

  1. type
  2. NodeKind = enum nkLeaf, nkInner
  3. Node {.shallow.} = object
  4. case kind: NodeKind
  5. of nkLeaf:
  6. strVal: string
  7. of nkInner:
  8. children: seq[Node]