-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
warn about destructors with setLenUninit
in docs
#24345
base: devel
Are you sure you want to change the base?
Conversation
a compiler warning/error would be a lot more useful :/ |
I don't know if the compiler can easily track this, it's decided at runtime whether the memory is uninitialized or not. It's already unsafe to read from, it just might be hard to guess that it's unsafe to write to as well. The docs for |
Well, the way I see it, newSeqUninit should only be exposed for what in C++ is called a trivial type - it's similar to |
I'm tired of this |
constraining uninit by traits is the way to only expose the non-nukes (and still allowing efficient serialization frameworks etc). dfa won't get you all the way regardless. |
DFA is one thing and the other is better API design like |
what do you use to implement These facilities are not for "the general nim users" - they're primitives needed to build other safe abstractions. |
I think A) while there is a footgun docs should warn - so good PR & B) a It hasn't yet been observed in this converation that the old Very parenthetically, it would be good for very "audit bait" things like this to be spelled one way, esp since the sub-substring "init" is also used all over the place, conventionally). I don't really care if it's {.noinit.} (back to 2011) or "uninit", but just one way, pretty please. (It's not Earth shattering or anything, but seems like needless, life-complicating variety.) |
The compiler normally prevents destructor calls when assigning to
noinit
locations (sink, variable init). But withsetLenUninit
the compiler can't track that the location is uninitialized, and so destructor calls are still generated. This can cause crashes since destructors may assume that the assigned location is well-formed. To deal with this, grow, add, setLen all usenodestroy
to prevent any destructor calls from being generated. So the docs forsetLenUninit
now warn about this issue, and suggest usingnodestroy
.