Skip to content

Doesn't compile on Nim devel due to shallowCopy being removed from the language. #73

@exelotl

Description

@exelotl

in Nim 2.0, shallowCopy will be removed. This means every occurrence of shallowCopy in the library must be replaced by something else.

See: nim-lang/Nim#20017

For simple situations, sink may be good enough:

e.g.

proc init*[T](b: var Buffer[T], d: T) =
  shallowCopy(b.data, d)
  b.offset = 0

becomes

proc init*[T](b: var Buffer[T], d: sink T) =
  b.data = d
  b.offset = 0

The compiler will then decide whether to move or copy the data depending on whether it can prove that buf.init(s) is the last usage of s or not.

However, there are some problems:

  1. If the compiler decides to copy, then there will be a performance hit. To keep good performance in this case, I believe some sort of buffer-via-pointer is needed, e.g. trick's View or collections' View or Nim's experimental view types.

  2. There are some uses of shallowCopy in the codebase that don't neatly fit the sink pattern, e.g.

    shallowCopy(png.apngPixels[0], png.pixels)
    frameConvert[T](png, modeIn, modeOut, png.width, png.height, 0, state)
    shallowCopy(png.pixels, png.apngPixels[0])

    (edit, maybe they can be solved like this?)

    png.apngPixels[0] = move(png.pixels)
    frameConvert[T](png, modeIn, modeOut, png.width, png.height, 0, state)
    png.pixels = move(png.apngPixels[0])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions