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

newSeqOfCap is not working in newruntime #11098

Closed
cooldome opened this issue Apr 23, 2019 · 3 comments

Comments

@cooldome
Copy link
Member

commented Apr 23, 2019

The following example doesn't compile with --newruntime:

var s = newSeqOfCap[int](10)
echo s.len

I have tried to implement it myself, but realised that newSeqPayload from `seqs.nim`` will not for this case.

Possible ways forward:

  1. Add to system.nim proc newSeqOfCap*[T](s: var seq[T], cap: Natural) and make it a magic instead of proc newSeqOfCap*[T](cap: Natural): seq[T] just like it is done for newSeq. Will allow a sequences to be created in a unified way.
  2. Add new proc to seqs.nim just to implement newSeqOfCap.

Araq,
do you have a preference?

@Araq

This comment has been minimized.

Copy link
Member

commented Apr 24, 2019

can't we have a magic proc newSeq[T](len, cap: Natural): seq[T] instead and clean up this mess?

@mratsim

This comment has been minimized.

Copy link
Collaborator

commented Apr 24, 2019

Note that I'm heavily relying on newSeqOfCap not zero-ing memory for trivial types (typetraits.supportsCopyMem) so if we have this overload proc newSeq[T](len, cap: Natural): seq[T], I hope it doesn't zero memory between [len, cap], i.e. if len = 0, we get the raw seq.

@Araq

This comment has been minimized.

Copy link
Member

commented Apr 24, 2019

I hope it doesn't zero memory between [len, cap], i.e. if len = 0, we get the raw seq.

Uh oh, emplace_back here we come...

@Araq Araq closed this in e083a15 Jun 26, 2019

narimiran added a commit that referenced this issue Jun 27, 2019

fixes #11098
(cherry picked from commit e083a15)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.