Safe reference counting cannot be implemented as a library

Martin Nowak via Digitalmars-d digitalmars-d at
Sun Nov 1 12:47:58 PST 2015

On 10/27/2015 12:41 PM, Andrei Alexandrescu wrote:
> It follows that if we want safe reference counting, there must be
> language support for it. One possibility is to attach an attribute to
> the class definition:
> @safe @rc class Widget {
>   ...
> }

Let's think about this more clearly before we bake a monolithic feature
for a single problem into the language.

A few thoughts:

- @rc and @noescape are orthogonal

  while @rc requires @noescape the latter could
  be useful for other purposes

- If the compiler knows a reference has a limited lifetime
  it could check for @noescape making most of RC implementable
  in a library.

  struct RC
    Object get() return; // lifetime of Object is bound to RC, compiler
could check any function called on Object for @noescape

- I'm not a fan of adding yet another attribute but as inference support
  is currently limited it seems we'd need an explicit attribute for
  public APIs.

More information about the Digitalmars-d mailing list