Proposal 2: Exceptions and @nogc

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Sun Apr 9 14:17:35 PDT 2017


On Sunday, 9 April 2017 at 20:14:24 UTC, Walter Bright wrote:
> For another, a general mechanism for safe refcounting of 
> classes has eluded us.

The only thing you need to get backed into the language is to 
make sure things do not escape in uncontrolled manner. Everything 
else is library.

You wouldn't have this problem if you had listened to myself and 
Marc when defining DIP1000, because that's exactly what you've 
been warned about at the time.

Quoting from the timeline ML from Nov 2014:

[...]

Every expression has now has a lifetime associated with it, and 
can be marked as "scope". it is only possible to assign b to a if 
b has a lifetime equal or greater than a's.

An infinite lifetime is a lifetime greater or equal than any 
other lifetime. Expression of infinite lifetime are:
  - literals
  - GC heap allocated objects
  - statics and enums.
  - rvalues of type that do not contain indirections.
  - non scope rvalues.

Dereference share the lifetime of the dereferenced expression (ie 
infinite lifetime unless the expression is scope). Address of 
expression shared the lifetime of the base expression, and in 
addition gain the scope flag.

Comment: Using these rule, we basically define any indirection 
being of infinite lifetime by default, and we propagate the 
lifetime when scope. The addition of the scope flag for address 
of is necessary to disallow taking address->dereference to yield 
an infinite lifetime.

Variables delcarations (including parameters) have the lifetime 
of the block they are declared in (2 pitfalls here, I don't have 
good solution, and the original spec do not as well : #1 
destructor, finally, scope statement and #2 closures). Use of 
these variables shared the lifetime of the variable, unless they 
qualify for infinite lifetime. Parameter's lifetime are 
unordered, meaning smaller than infinite, greater than the 
function's scope, but not equal to each other nor greater/smaller 
than each others.

[...]



More information about the Digitalmars-d mailing list