Prototype of Ownership/Borrowing System for D

mipri mipri at
Wed Nov 20 06:57:55 UTC 2019

On Wednesday, 20 November 2019 at 04:59:37 UTC, Walter Bright 
> It's entirely opt-in by adding the `@live` attribute on a 
> function, and the implementation is pretty much contained in 
> one module, so it doesn't disrupt the rest of the compiler.

dmd and phobos sure do compile fast! For anyone else:

as a bash script:

   mkdir ~/dtest
   cd ~/dtest
   git clone
   cd dmd
   git checkout ob
   make -f posix.mak -j8 AUTO_BOOTSTRAP=1
   cd ..
   git clone
   cd phobos
   make -f posix.mak -j8

and now you can compile with

The longest part of this process is the 'git clone' so why not?

No need to -preview= anything.

@live:  // doesn't add @live to following functions.

I tried writing some bad code and got some nice errors
that made sense. This is the first error that surprises
me (someone who's never learned Rust or dealt with a
borrow checker):

   import std;
   import core.stdc.stdlib: malloc;

   struct Person {
       uint age;
       uint karma;
       char[0] name;

   @live void birthday(Person* p) {
   } // Error: variable x4.omg.p is left dangling at return

   void main() {
       auto p = cast(Person*)malloc(Person.sizeof + 10);
       birthday(p);[0] = 'B';

With linear types in ATS there's a special syntax to
suggest that birthday is giving ownership back to caller
on return. But without that... this of course works:

   @live Person* birthday(Person* p) {
       return p;
       p = birthday(p);

More information about the Digitalmars-d mailing list