News for hackers. Stuff that matters.
Re:Nim 1.4 by Boxxed on Friday October 16, 2020 @08:51AM (#24800296)
There are a lot of gotchas with the new GC that make me nervous about this release:

> As far as we know, ARC works with the complete standard library except for the current implementation of async...

That's not a great endorsement...

> If your code uses cyclic data structures, or if you’re not sure if your code produces cycles, you need to use --gc:orc and not --gc:arc.

Seems like this is a big onus to put on the user -- it's tough to prove a negative like this.

Re:Nim 1.4 by leorize on Friday October 16, 2020 @09:20AM (#24800521)
I believe the phrasing might not be clear to everyone, so here's a reduced version:

* Nim's current async implementation creates a lot of cycles in the graph, so ARC can't collect them.

* ORC is then developed as ARC + cycle collector to solve this issue, and it has been a success.

* This 1.4 release introduces ORC to everyone so that we can have mass testing for this new GC and eventually move torwards ORC as the default GC.

TL;DR: ORC works with everything† and will be the new default GC in the future. Your old Nim code will continue to work, and will just get faster‡.

† We are not sure that it's bug-free yet, which is why it's not the default for this release.

‡ Most of the time ORC speeds things up, but there are edge cases where it might slow things down. You're encouraged to test your code with --gc:orc against our default GC and report performance regressions.

Re:Nim 1.4 by treeform on Friday October 16, 2020 @01:25PM (#24802974)
Your explanation is very clear. Thanks.
Re:Nim 1.4 by djur on Friday October 16, 2020 @09:08AM (#24800436)
I think you missed this detail:

> ARC was first shipped with Nim 1.2... [ORC is] our main new feature for this release

Seems like they should phrase it like "use ORC unless you know you don't have cycles" rather than "use ORC if you're not sure you have cycles", but that's a reasonable responsibility to take on if you're choosing to use an alternative garbage collector.

Re:Nim 1.4 by mumblemumble on Friday October 16, 2020 @09:56AM (#24800837)
I'd prefer no phrasing at all. Just pick one that will work well in all cases, and don't give me any footguns.
Re:Nim 1.4 by judofyr on Friday October 16, 2020 @11:01AM (#24801469)
To clarify: By default Nim will still use the GC which doesn't have any "footguns". ARC and ORC are new features which have different trade-offs, and some limitations. You opt-in to using them if you're interested.
Re:Nim 1.4 by gameswithgo on Friday October 16, 2020 @11:01AM (#24801473)
A way of dealing with memory that works well in all cases! That would be great.
Re:Nim 1.4 by adamc on Friday October 16, 2020 @10:41AM (#24801246)
Yes. Or at least put them in the appendix.
Re:Nim 1.4 by nicoburns on Friday October 16, 2020 @08:53AM (#24800314)
Looks like it'a still an opt-in experimental option at this point rather than the default. Preaumably they'll fix these caveats before recommending it for general use.
Re:Nim 1.4 by ziotom78 on Friday October 16, 2020 @09:07AM (#24800427)
If I recall correctly, I read that the intention is to eventually make ORC the default, not ARC. (ORC is like ARC, but it avoids problems with cycles.)
Re:Nim 1.4 by Tiberium on Friday October 16, 2020 @09:09AM (#24800444)
Yes, you're totally right! That's the exact reason ORC should eventually become the new default GC.
Re:Nim 1.4 by Tiberium on Friday October 16, 2020 @08:59AM (#24800368)
Sorry if you got misled by the article - ORC is what you should use if your program has cycles. ORC deals with async just fine.
Re:Nim 1.4 by MaxBarraclough on Friday October 16, 2020 @10:48AM (#24801318)
Does ORC stand for something?
Re:Nim 1.4 by cb321 on Friday October 16, 2020 @10:53AM (#24801370)
I could be wrong, but I believe the acronyms are: ARC = Automatic Reference Counting (NOTE: not Atomic) ORC = Optimized Reference Counting

The loopy/circular character of the letter 'O' may be a secondary mnemonic since it collects cycles.

Re:Nim 1.4 by cb321 on Saturday October 17, 2020 @06:03AM (#24808907)
I meant "character" as in "nature" not as in the prog.lang "character type"..I just realized that in context this might be confusing. Lol.
Re:Nim 1.4 by mcintyre1994 on Friday October 16, 2020 @12:21PM (#24802297)
At an ELI5 level, does anyone know why Swift can have ARC and async but Nim's ARC doesn't work with async? Is it just implementation details of Nim's async specifically instead of anything more fundamental to ARC? Just asking out of curiosity.
Re:Nim 1.4 by treeform on Friday October 16, 2020 @01:24PM (#24802966)
Yes. There is nothing fundamental to nim's ARC working with nim's async. There are attempts on make nim's async cycle free.
Re:Nim 1.4 by dom96 on Friday October 16, 2020 @04:37PM (#24804789)
Note that what we're referring to as "async" for Nim is actually "async await". AFAIK Swift doesn't support that, does it?
Re:Nim 1.4 by darthrupert on Saturday October 17, 2020 @01:56AM (#24807737)
Swift doesn't claim hard realtime capabilities like Nim's ARC does.
Re:Nim 1.4 by karmakaze on Friday October 16, 2020 @11:04AM (#24801497)
I'm not familiar with Nim. Does it also support weak references?

A significant portion of the problems with cycles in ARC are parent references.

Re:Nim 1.4 by planetis on Friday October 16, 2020 @11:53AM (#24802027)
Weak references are possible with the .cursor pragma applied on local variables and object fields. This release introduces cursor inference too, enabled by default with --gc:arc|orc, but only for local variables.
Re:Nim 1.4 by wffurr on Friday October 16, 2020 @09:30AM (#24800627)
Is there an msan/asan equivalent that can detect leaks in your test suite?
Re:Nim 1.4 by leorize on Friday October 16, 2020 @10:17AM (#24801020)
Yes, we use valgrind for the compiler and stdlib test suite. The testament tool supports this, however it's not in widespread use outside of the compiler and stdlib, so documentation is rather sparse.

Since Nim uses the C compiler to generate executables, you should be able to use `--passC:-fsanitize=memory --passL:-fsanitize=memory` to enable msan. For maximum effectiveness the flags `-d:useMalloc --gc:orc` should also be used.

`-d:useMalloc` tells Nim to allocate memory using libc's malloc instead of our TSLF implementation. This should provide adequate compatibility for use with external inspection tools. We do

`--gc:orc` because this is one of the only GCs that support -d:useMalloc (the other being arc).

Re:Nim 1.4 by scns on Saturday October 17, 2020 @08:09AM (#24809379)
Please put this in the docs, if it is not there already