$
works for ref|ptr|pointer for all targets (c,cpp,js,vm) + other bugfixes
#14043
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
nim js
bugs that should be fixedcast
in VM which was causing a crash$
now works for ref|ptr|pointer for all targets (c,cpp,js,vm),showing the address, which is useful, eg for determining whether 2 pointers/ref objects are the same (eg inside a log)$ for ref|ptr|pointer
for
nim js
it returns a unique object id, eg@123
for all other targets it returns hex address, eg
0x10d766608
the addresses should furthermore be deterministic across re-runs if you disable ASLR, eg by passing
--passl:-Wl,-no_pie
(see example 2)see tests in tests/system/tostring.nim
example 1
instead of what's printed before this PR:
which doesn't tell you anything useful about reference semantics (eg which pointers are the same)
example 2
note
before PR
$
doesn't compile for ref,ptr,pointer which is not a very useful behavior, in particular for debugging (or, inside an object/tuple, would show as...
which isn't particularly useful). The current behavior gives you no easy way to check which ref/ptr objects are identical. Showing the addresses allows exactly that, is safe, and also gives a hint as to whether an address is on the stack, heap, or data segment based on its range.refactoring and yak shaving. #13687 attempted to make
$
recurse inside ref objects however I've explained here Every value should be printable with echo RFCs#203 (comment) why this is a bad idea as a default behaviora more sophisticated and customizable pretty-printing (
std/prettyprint
as I suggested in Every value should be printable with echo RFCs#203 (comment)) doesn't remove the need for$
to work on pointer-like types, since importingstd/prettyprint
won't work for some modules due to cyclic imports