-
Notifications
You must be signed in to change notification settings - Fork 39
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
disallow sink openArray[T]
types
#544
base: devel
Are you sure you want to change the base?
Conversation
## Summary No specification for how `sink openArray[T]` should work exists, and the current implementation only works without issues in the simple case where the argument is a literal array-constructor expression that is not constant. For most other cases, either the `seq` or `string` used as the argument are not cleaned up or, for constant expression, a segmentation fault occurs at run-time when trying to mutate the `openArray`. Passing an immutable `openArray` to a `sink openArray`, while in theory supported, also results in a run-time error. ## Details - remove the "cannot create implicit openArray` report; it's unused now - disable the test that made use of `sink openArray`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bors r+
(•_•)
sink openArray
( •_•)>⌐■-■
You've been sunk for the last time
(⌐■_■)
544: disallow `sink openArray[T]` types r=saem a=zerbina ## Summary No specification for how `sink openArray[T]` should work exists, and the current implementation only works without issues in the simple case where the argument is a literal array-constructor expression that is not constant. For most other cases, either the `seq` or `string` used as the argument are not cleaned up or, for constant expression, a segmentation fault occurs at run-time when trying to mutate the `openArray`. Passing an immutable `openArray` to a `sink openArray`, while in theory supported, also results in a run-time error. ## Details - remove the "cannot create implicit openArray` report; it's unused now - disable the test that made use of `sink openArray` Co-authored-by: zerbina <[email protected]>
Build failed: |
I had not considered generics (i.e. A possible solutionIf the argument to the In other words: if the Thoughts? |
Given current definitions:
I think I think the issue is that If we need a decision in the interim because this blocks other things, let's keep the behaviour as it is in your PR, I believe it's actually correct, and adapt any stdlib bits if required. |
I think so too. But I'm not so sure whether it's a good idea to also report an error for Adapting the parts in the that are causing the issues is possible: proc add*[T: not openArray](x: var seq[T], item: sink T) {.magic: "AppendSeqElem".}
proc add*[T: openArray](x: var seq[T], item: T) {.magic: "AppendSeqElem".} but when using first-class The PR is not blocking anything else right now, so I'm turning it into draft until we got the details figured out. |
In my code I've seen it always as a language supported pointer+length pair. Something that I've done in C with pointer + length as two distinct parameters I can now do In one. Nice. I've also writter C code wrappers that expose a pointer+length pair as an In C a pointer+length parameter can very much move the ownership of the data. But that doesn't apply to Nim. Here an |
Summary
No specification for how
sink openArray[T]
should work exists, and the current implementation only works without issues in the simple case where the argument is a literal array-constructor expression that is not constant.For most other cases, either the
seq
orstring
used as the argument are not cleaned up or, for constant expression, a segmentation fault occurs at run-time when trying to mutate theopenArray
.Passing an immutable
openArray
to asink openArray
, while in theory supported, also results in a run-time error.Details
sink openArray