Some thoughts on what isn't yet clear about the speci 2:
1, I believe that it is the intention that all ref's must be first be created
as owned ref's but it doesn't seem to be specified. It is clear that once they
exist, owned ref's can then only be destroyed or moved so how else will they
come about?
2\. Then, it isn't specified how one gets a unowned ref from an owned ref. It
seems to me that would mean assignment of a owned ref to an ordinary ref as a
=copy override to take as input an owned ref and to output an ordinary ref. So,
for this purpose, there would be a converter which can just be an expanded
=copy for unowned ref as follows:
proc `=copy`[T](dst: ref T; src: ref T | unowned ref T) = # note the source
can be either
# no need to check if they are equal...
if dst != nil: dst.refcnt.dec
if src != nil: src.refcnt.inc
bitwiseCopy dst, src # raw pointer copy
Run
This is just like the =copy for unowned ref's but can also take a owned ref as
a source. Have I got it right?
As to multi-threading, I see how owned ref's could be passed into them by move
semantics or if they are not to be consumed by the thread then can be passed in
by means of an unowned normal ref for the case where there is a persistent
outer scope that owns the "dangling" ref that was passed in as long as one can
guarantee the threads are done with use of the "dangling" ref before the
controlling outer owner goes out of scope and tries to destroy the owned ref.
It gets a little more complicated than for GC, but it looks to be workable. To
test it, I'm going to re-work an application so as to not depend on having GC
but rather on the principles that are used here; then when this specification
is implemented, I can further test it with the real thing quite quickly. The
application uses functional techniques such as lazy lists and also
multi-threading so it should be a fairly good test bed.