-
-
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
repr missing pointer when applied to seq/string with arc #16052
Comments
@pietroppeter please send a PR if you can, it shouldn't be complicated. see tests I had added in tests/stdlib/trepr.nim (https://github.com/nim-lang/Nim/pull/16034/files) noticing this, and that should be edited when this issue is fixed. the following can be done in followup work:for repr in vm:
|
mmh, I would be happy to be able to submit a PR but I might need some hand holding, since I never touched the compiler (not even run koch or testament for which this could be a good opportunity to try). If you or someone wants to help me, here is my analysis of the issue:
Now I ask myself: how could c_sprintf have different behaviour when |
Also, for context: I ran into this while I was working on a fix for a bigints issue. The minimal example I had there (playground): import sugar
var
a = @[0]
proc op(a: var seq[int], b: seq[int]) =
dump a.repr
dump b.repr
a.setLen(2)
dump a.repr
dump b.repr
op(a, a) outputs:
apart the fact that I am not sure if this is a bug or expected behaviour (the fact that b is empty), when running that example with
which, apart for missing pointer in representation, is actually worse than the above (b having an arbitrary value inside). |
once I finish cleaning up #15827 you'll be able to use: when true:
import std/exectraces
proc main()=
var a = [10,11]
var b = a[0].addr
enableRuntimeTracing(true)
let s = repr(b)
enableRuntimeTracing(false)
main() nim r --exectrace:on --gc:arc main.nim
=> for gc:arc it's in lib/system/repr_v2.nim:127 will answer other questions later |
thanks, that --exectrace:on looks awesome! and of course my first assumption was wrong! 😄 looking at repr_v2 it is know much clearer where the difference is. the repr proc for seq container clearly is missing the pointer as prefix. I was then curious on how does the repr of pointer looks like and I would say that for arc is also bad, so probably this should be fixed contextually: let s = @[1]
echo s.repr
echo unsafeAddr(s[0]).repr
# default gc:
# 000000000091F050@[1]
#
# ptr 000000000091F060 --> 1
# arc:
# @[1]
# ptr 1 I guess for this the guilty part is this: https://github.com/nim-lang/Nim/blob/version-1-4/lib/system/repr_v2.nim#L127 Now the unclear part for me is how to produce the correct representation of the pointer. Should I use something as reprPointer in repr.nim (or exactly that? and why then there are two versions repr and repr_v2?). |
but beyond that some parts should be factorizable to avoid code duplication. |
thanks again. yes, I will definitely follow the advice of targeting minimal change (you could very well say that this is my actual 1st PR to code in nim codebase, the other one was mostly to understand git workflow and was basically my first PR ever in github). And actually, given the explanation on why the two version and giving a better look my impression is that repr_v2 looks like a better version of repr (modern proc signatures without the type in the name...) that I guess it might be able to supplant it at some point. Also I noticed that there is in fact already a All considered I think that, thanks to your support, I do not see at the moment other obstacles on my side for making the PR. Of course more questions might come up when actually writing it. I plan to have it ready at some point during the weekend. |
feel free to send early draft (mark it as draft) for early feedback |
This behaviour is intended (not printing the pointer), but maybe it should be changed.
The reason for this is not related to repr, it's because arc is missing error messages for illegal aliasing/not introducing a copy to prevent it. |
I took the liberty and re-implemented |
The new repr is better than the old one, at least you can write unit tests when the address is left out. |
system.repr
(docs) when applied to a sequence and compiled withgc:arc
does not output the pointer (it does with default gc).Example
example.nim
:Current Output
nim r example
:nim r --gc:arc example
:Expected Output
I would expect the same output when compiled with both gc options
Additional Information
The text was updated successfully, but these errors were encountered: