Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
exelotl opened this issue Oct 5, 2022 · 0 comments

Comments

@exelotl
Copy link

exelotl commented Oct 5, 2022

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])
@jangko jangko closed this as completed in 2dccf3e Oct 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant