Reference counted containers prototype

2011-12-26 Thread Andrei Alexandrescu
Hello, I've been playing with a new approach to reference counting, in particular for the containers library. A small prototype is at http://pastebin.com/WnSQY1Jw. The prototype features a simple doubly-linked list implementation DListImpl. That is not supposed to be manipulated directly (o

Re: Reference counted containers prototype

2011-12-26 Thread Michel Fortin
On 2011-12-26 17:25:10 +, Andrei Alexandrescu said: Hello, I've been playing with a new approach to reference counting, in particular for the containers library. A small prototype is at http://pastebin.com/WnSQY1Jw. The prototype features a simple doubly-linked list implementation DL

Re: Reference counted containers prototype

2011-12-26 Thread Andrei Alexandrescu
On 12/26/11 12:46 PM, Michel Fortin wrote: Although I am a little concerned by this small but important implementation detail: Your RefCounted destructor is racy. Just like other reference counted things in Phobos, if you somehow store a reference on the GC heap (as a class member for instance)

Re: Reference counted containers prototype

2011-12-26 Thread jdrewsen
On Monday, 26 December 2011 at 17:25:12 UTC, Andrei Alexandrescu wrote: Hello, I've been playing with a new approach to reference counting, in particular for the containers library. A small prototype is at http://pastebin.com/WnSQY1Jw. The prototype features a simple doubly-linked list impl

Re: Reference counted containers prototype

2011-12-26 Thread Peter Alexander
On 26/12/11 5:25 PM, Andrei Alexandrescu wrote: (a) All interaction with the held object is done via opDispatch. In fact opDispatch can be engineered to statically enforce no reference to the held object escapes. I have a separate, but very much related concern: If the held object has a method

Re: Reference counted containers prototype

2011-12-26 Thread Robert Jacques
On Mon, 26 Dec 2011 17:09:02 -0800, Peter Alexander wrote: On 26/12/11 5:25 PM, Andrei Alexandrescu wrote: (a) All interaction with the held object is done via opDispatch. In fact opDispatch can be engineered to statically enforce no reference to the held object escapes. I have a separate,

Re: Reference counted containers prototype

2011-12-26 Thread Peter Alexander
On 27/12/11 1:09 AM, Peter Alexander wrote: On 26/12/11 5:25 PM, Andrei Alexandrescu wrote: (a) All interaction with the held object is done via opDispatch. In fact opDispatch can be engineered to statically enforce no reference to the held object escapes. I have a separate, but very much rela

Re: Reference counted containers prototype

2011-12-26 Thread Peter Alexander
On 27/12/11 1:14 AM, Robert Jacques wrote: On Mon, 26 Dec 2011 17:09:02 -0800, Peter Alexander If the held object has a method with the same name as RefCounted (e.g. asConst) then how do you call the held object's method instead of RefCounted's method? You, can't. Looking at the source code as

Re: Reference counted containers prototype

2011-12-26 Thread Andrei Alexandrescu
On 12/26/11 7:09 PM, Peter Alexander wrote: On 26/12/11 5:25 PM, Andrei Alexandrescu wrote: (a) All interaction with the held object is done via opDispatch. In fact opDispatch can be engineered to statically enforce no reference to the held object escapes. I have a separate, but very much rela

Re: Reference counted containers prototype

2011-12-26 Thread Andrei Alexandrescu
On 12/26/11 7:14 PM, Robert Jacques wrote: There are several uses for opDispatch. For example, vector swizzling is an example of using opDispatch to replace a finite set of related functions. General forwarding, like alias this, requires a minimalistic design: the public interface should be as sm

Re: Reference counted containers prototype

2011-12-26 Thread Andrei Alexandrescu
On 12/26/11 7:25 PM, Peter Alexander wrote: Following up to this, how do I access non-function members of the held object? e.g. struct Foo { int x = 1; } void main() { RefCounted!Foo f; writeln(f.x); // Doesn't work } We can easily have opDispatch look at field names. But I think it's poor d

Re: Reference counted containers prototype

2011-12-26 Thread Andrej Mitrovic
On 12/27/11, Andrei Alexandrescu wrote: > We can easily have opDispatch look at field names. But I think it's poor > design to expose bald data anyway. opDispatch doesn't work with property functions, or opBinary, or opOpAssign. And what about the ctor? I can't call the ctor with your RefCounted.

Re: Reference counted containers prototype

2011-12-26 Thread Peter Alexander
On 27/12/11 1:29 AM, Andrei Alexandrescu wrote: We can easily have opDispatch look at field names. But I think it's poor design to expose bald data anyway. I disagree, especially with immutable structs. There's no point wrapping immutable data in functions or properties. Also, what about t

Re: Reference counted containers prototype

2011-12-26 Thread Andrei Alexandrescu
On 12/26/11 11:25 AM, Andrei Alexandrescu wrote: [snip] Destroy. Walter indeed just destroyed me over the phone: I conflated reference counting with copy-on-write. Essentially instead of defining a reference type that's garbage-collected, I defined a value type that has cow. Which is not ba

Re: Reference counted containers prototype

2011-12-26 Thread Andrei Alexandrescu
On 12/26/11 7:49 PM, Andrej Mitrovic wrote: On 12/27/11, Andrei Alexandrescu wrote: We can easily have opDispatch look at field names. But I think it's poor design to expose bald data anyway. opDispatch doesn't work with property functions, It actually does, as per the unittests. Even if it

Re: Reference counted containers prototype

2011-12-26 Thread Andrei Alexandrescu
On 12/26/11 8:23 PM, Peter Alexander wrote: On 27/12/11 1:29 AM, Andrei Alexandrescu wrote: We can easily have opDispatch look at field names. But I think it's poor design to expose bald data anyway. I disagree, especially with immutable structs. There's no point wrapping immutable data in fun

Re: Reference counted containers prototype

2011-12-26 Thread Michel Fortin
On 2011-12-27 02:47:50 +, Andrei Alexandrescu said: On 12/26/11 11:25 AM, Andrei Alexandrescu wrote: [snip] Destroy. Walter indeed just destroyed me over the phone: I conflated reference counting with copy-on-write. Essentially instead of defining a reference type that's garbage-colle

Re: Reference counted containers prototype

2011-12-26 Thread Andrej Mitrovic
On 12/27/11, Andrei Alexandrescu wrote: > It actually does, as per the unittests. Even if it currently does by > @property being too lax, it should continue to work. It actually doesn't: struct FooImpl { int _x; @property int x() { return _x; } @property void x(int val) { _x = val; }

Re: Reference counted containers prototype

2011-12-26 Thread Robert Jacques
On Mon, 26 Dec 2011 17:30:54 -0800, Peter Alexander wrote: On 27/12/11 1:14 AM, Robert Jacques wrote: On Mon, 26 Dec 2011 17:09:02 -0800, Peter Alexander If the held object has a method with the same name as RefCounted (e.g. asConst) then how do you call the held object's method instead of R

Re: Reference counted containers prototype

2011-12-26 Thread Robert Jacques
On Mon, 26 Dec 2011 19:00:57 -0800, Andrei Alexandrescu wrote: On 12/26/11 7:49 PM, Andrej Mitrovic wrote: On 12/27/11, Andrei Alexandrescu wrote: We can easily have opDispatch look at field names. But I think it's poor design to expose bald data anyway. opDispatch doesn't work with prope

Re: Reference counted containers prototype

2011-12-26 Thread Martin Nowak
On Tue, 27 Dec 2011 03:47:50 +0100, Andrei Alexandrescu wrote: On 12/26/11 11:25 AM, Andrei Alexandrescu wrote: [snip] Destroy. Walter indeed just destroyed me over the phone: I conflated reference counting with copy-on-write. Essentially instead of defining a reference type that's gar

Re: Reference counted containers prototype

2011-12-26 Thread Martin Nowak
On Mon, 26 Dec 2011 18:25:10 +0100, Andrei Alexandrescu wrote: Hello, I've been playing with a new approach to reference counting, in particular for the containers library. A small prototype is at http://pastebin.com/WnSQY1Jw. The prototype features a simple doubly-linked list impleme

Re: Reference counted containers prototype

2011-12-27 Thread Froglegs
When I go to that link it just says Unknown Paste ID! Don't see any code anywhere.. hum What is wrong with value containers? They work great in C++, a container is such a basic thing that ref counting and whatnot is rarely if ever needed, and in the unlikely event you need to share a co

Re: Reference counted containers prototype

2011-12-27 Thread Andrei Alexandrescu
On 12/27/11 5:43 AM, deadalnix wrote: BTW, the plan is to have the same thread that constructed objects to call their destructors; each thread would have a worklist of garbage objects to destroy. The list can be reduced during calls to allocation functions within each thread, and of course when t

Re: Reference counted containers prototype

2011-12-27 Thread Andrei Alexandrescu
On 12/27/11 12:08 AM, Andrej Mitrovic wrote: On 12/27/11, Andrei Alexandrescu wrote: It actually does, as per the unittests. Even if it currently does by @property being too lax, it should continue to work. It actually doesn't: struct FooImpl { int _x; @property int x() { return _x

Re: Reference counted containers prototype

2011-12-27 Thread deadalnix
Le 26/12/2011 18:25, Andrei Alexandrescu a écrit : Hello, I've been playing with a new approach to reference counting, in particular for the containers library. A small prototype is at http://pastebin.com/WnSQY1Jw. The prototype features a simple doubly-linked list implementation DListImpl. Th

Re: Reference counted containers prototype

2011-12-27 Thread Andrei Alexandrescu
On 12/27/11 6:15 AM, Froglegs wrote: When I go to that link it just says Unknown Paste ID! Don't see any code anywhere.. hum What is wrong with value containers? They work great in C++, a container is such a basic thing that ref counting and whatnot is rarely if ever needed, and in the unli

Re: Reference counted containers prototype

2011-12-27 Thread Andrei Alexandrescu
On 12/27/11 8:21 AM, Michel Fortin wrote: On 2011-12-27 02:47:50 +, Andrei Alexandrescu 1. "Basic" containers - reference semantics, using classic garbage collection 2. Reference counted containers - still reference semantics, using reference counting 3. COW containers - value semantics, u

Re: Reference counted containers prototype

2011-12-27 Thread Jonathan M Davis
On Tuesday, December 27, 2011 12:32:01 deadalnix wrote: > The first thing that I see looking at the source code is how many null > check you'll find in RefCounted . As the RefCounted struct is useless > without a payload, we should ensure that the payload exists, in all > cases, and not null check

Re: Reference counted containers prototype

2011-12-27 Thread Andrei Alexandrescu
On 12/27/11 2:24 AM, Jonathan M Davis wrote: On Monday, December 26, 2011 20:47:50 Andrei Alexandrescu wrote: 1. "Basic" containers - reference semantics, using classic garbage collection 2. Reference counted containers - still reference semantics, using reference counting 3. COW containers -

Re: Reference counted containers prototype

2011-12-27 Thread Andrei Alexandrescu
On 12/27/11 5:27 AM, kenji hara wrote: I've already posted a dmd patch to fix all of opDispatch problems: https://github.com/D-Programming-Language/dmd/pull/280 As far a I understand you pass the whole template as a string inside opDispatch? For example, say obj defines opDispatch: obj.foo!

Re: Reference counted containers prototype

2011-12-27 Thread Andrei Alexandrescu
On 12/27/11 5:32 AM, deadalnix wrote: The first thing that I see looking at the source code is how many null check you'll find in RefCounted . As the RefCounted struct is useless without a payload, we should ensure that the payload exists, in all cases, and not null check at every operation. D'

Re: Reference counted containers prototype

2011-12-27 Thread deadalnix
Le 26/12/2011 20:49, Andrei Alexandrescu a écrit : On 12/26/11 12:46 PM, Michel Fortin wrote: Although I am a little concerned by this small but important implementation detail: Your RefCounted destructor is racy. Just like other reference counted things in Phobos, if you somehow store a refer

Re: Reference counted containers prototype

2011-12-27 Thread Andrei Alexandrescu
On 12/27/11 9:27 AM, Michel Fortin wrote: On 2011-12-27 14:57:18 +, Andrei Alexandrescu said: I talked a lot about this with Walter and we concluded that the story with const and immutable goes like this: in a RefCounted!T object, the T is constant, not the RefCounted. So it would be RefCou

Re: Reference counted containers prototype

2011-12-27 Thread Andrei Alexandrescu
On 12/27/11 4:32 AM, Peter Alexander wrote: On 27/12/11 3:05 AM, Andrei Alexandrescu wrote: On 12/26/11 8:23 PM, Peter Alexander wrote: I am not convinced that it can be used seamlessly without some relatively large changes to the language. I repeat that opDispatch and auto ref were invented

Re: Reference counted containers prototype

2011-12-27 Thread deadalnix
Le 27/12/2011 16:09, Andrei Alexandrescu a écrit : On 12/27/11 5:27 AM, kenji hara wrote: I've already posted a dmd patch to fix all of opDispatch problems: https://github.com/D-Programming-Language/dmd/pull/280 As far a I understand you pass the whole template as a string inside opDispatch?

Re: Reference counted containers prototype

2011-12-27 Thread deadalnix
Le 27/12/2011 16:06, Andrei Alexandrescu a écrit : On 12/27/11 5:43 AM, deadalnix wrote: BTW, the plan is to have the same thread that constructed objects to call their destructors; each thread would have a worklist of garbage objects to destroy. The list can be reduced during calls to allocatio

Re: Reference counted containers prototype

2011-12-27 Thread deadalnix
Le 27/12/2011 16:04, Andrei Alexandrescu a écrit : On 12/27/11 5:32 AM, deadalnix wrote: The first thing that I see looking at the source code is how many null check you'll find in RefCounted . As the RefCounted struct is useless without a payload, we should ensure that the payload exists, in al

Re: Reference counted containers prototype

2011-12-27 Thread Peter Alexander
On 27/12/11 4:32 PM, deadalnix wrote: Le 27/12/2011 16:09, Andrei Alexandrescu a écrit : On 12/27/11 5:27 AM, kenji hara wrote: I've already posted a dmd patch to fix all of opDispatch problems: https://github.com/D-Programming-Language/dmd/pull/280 As far a I understand you pass the whole t

Re: Reference counted containers prototype

2011-12-27 Thread kenji hara
ProxyOf rewrites the expression > obj.foo!(bar, baz)(a, b); to obj.opDispatch!("foo").opDispatch!(bar, baz)(a, b) // opDispatch!("foo").opDispatch generates a temporary member template for forwarding. // And it is actually processed as 'eponymous template'. Thanks. Kenji Hara 2011/12/28 Andrei

Re: Reference counted containers prototype

2011-12-27 Thread Andrei Alexandrescu
On 12/27/11 9:34 AM, Peter Alexander wrote: I don't believe this will work in general when the template parameter passed in requires name look-up in the local scope. struct Foo { int bar(alias f)() { return f(); } } void main() { static int fun() { return 1; } RefCounted!Foo foo; writeln(foo.

Re: Reference counted containers prototype

2011-12-27 Thread Michel Fortin
On 2011-12-27 14:57:18 +, Andrei Alexandrescu said: On 12/27/11 8:21 AM, Michel Fortin wrote: On 2011-12-27 02:47:50 +, Andrei Alexandrescu 1. "Basic" containers - reference semantics, using classic garbage collection 2. Reference counted containers - still reference semantics, usin

Re: Reference counted containers prototype

2011-12-27 Thread deadalnix
Le 27/12/2011 08:00, Robert Jacques a écrit : On Mon, 26 Dec 2011 17:30:54 -0800, Peter Alexander wrote: On 27/12/11 1:14 AM, Robert Jacques wrote: On Mon, 26 Dec 2011 17:09:02 -0800, Peter Alexander If the held object has a method with the same name as RefCounted (e.g. asConst) then how do

Re: Reference counted containers prototype

2011-12-27 Thread Peter Alexander
On 27/12/11 3:05 AM, Andrei Alexandrescu wrote: On 12/26/11 8:23 PM, Peter Alexander wrote: I am not convinced that it can be used seamlessly without some relatively large changes to the language. I repeat that opDispatch and auto ref were invented for this, so anything that doesn't work now i

Re: Reference counted containers prototype

2011-12-27 Thread Jonathan M Davis
On Monday, December 26, 2011 20:47:50 Andrei Alexandrescu wrote: > On 12/26/11 11:25 AM, Andrei Alexandrescu wrote: > [snip] > > > Destroy. > > Walter indeed just destroyed me over the phone: I conflated reference > counting with copy-on-write. Essentially instead of defining a reference > type t

Re: Reference counted containers prototype

2011-12-27 Thread SHOO
When I tried implementation of Unique which was not usable at all though it was listed in a document, I faced a similar problem. The patch of Kenji is intended to just solve this. Even if these patch applied, some problems are left. (e.g. Automatic definitions of the opEquals function for Object

Re: Reference counted containers prototype

2011-12-27 Thread Peter Alexander
On 27/12/11 3:10 PM, Andrei Alexandrescu wrote: On 12/27/11 4:32 AM, Peter Alexander wrote: On 27/12/11 3:05 AM, Andrei Alexandrescu wrote: On 12/26/11 8:23 PM, Peter Alexander wrote: I am not convinced that it can be used seamlessly without some relatively large changes to the language. I r

Re: Reference counted containers prototype

2011-12-27 Thread Peter Alexander
On 27/12/11 12:15 PM, Froglegs wrote: What is wrong with value containers? They work great in C++, a container is such a basic thing that ref counting and whatnot is rarely if ever needed, and in the unlikely event you need to share a container, wrapping it with a smart pointer of some sort is ea

Re: Reference counted containers prototype

2011-12-27 Thread Joshua Reusch
Am 27.12.2011 02:14, schrieb Robert Jacques: On Mon, 26 Dec 2011 17:09:02 -0800, Peter Alexander wrote: On 26/12/11 5:25 PM, Andrei Alexandrescu wrote: (a) All interaction with the held object is done via opDispatch. In fact opDispatch can be engineered to statically enforce no reference to t

Re: Reference counted containers prototype

2011-12-27 Thread kenji hara
I've already posted a dmd patch to fix all of opDispatch problems: https://github.com/D-Programming-Language/dmd/pull/280 With it, I've posted a useful library utility to implement 'super-type' like D1 typedef: https://github.com/D-Programming-Language/phobos/pull/300 I'm naming it 'ProxyOf', a

Re: Reference counted containers prototype

2011-12-27 Thread Michel Fortin
On 2011-12-27 02:47:50 +, Andrei Alexandrescu said: The perspectives here are extremely exciting. The question remains how to best package this awesome array of options to maximize coherence. So we have: 1. "Basic" containers - reference semantics, using classic garbage collection 2. R

Re: Reference counted containers prototype

2011-12-27 Thread deadalnix
Le 27/12/2011 18:03, Peter Alexander a écrit : On 27/12/11 4:32 PM, deadalnix wrote: Le 27/12/2011 16:09, Andrei Alexandrescu a écrit : On 12/27/11 5:27 AM, kenji hara wrote: I've already posted a dmd patch to fix all of opDispatch problems: https://github.com/D-Programming-Language/dmd/pull/

Re: Reference counted containers prototype

2011-12-27 Thread Jacob Carlborg
On 2011-12-27 02:09, Peter Alexander wrote: On 26/12/11 5:25 PM, Andrei Alexandrescu wrote: (a) All interaction with the held object is done via opDispatch. In fact opDispatch can be engineered to statically enforce no reference to the held object escapes. I have a separate, but very much rela

Re: Reference counted containers prototype

2011-12-27 Thread Jacob Carlborg
On 2011-12-27 02:30, Peter Alexander wrote: On 27/12/11 1:14 AM, Robert Jacques wrote: On Mon, 26 Dec 2011 17:09:02 -0800, Peter Alexander If the held object has a method with the same name as RefCounted (e.g. asConst) then how do you call the held object's method instead of RefCounted's method

Re: Reference counted containers prototype

2011-12-27 Thread Michel Fortin
On 2011-12-27 15:48:56 +, Andrei Alexandrescu said: On 12/27/11 9:27 AM, Michel Fortin wrote: It can't be a library feature because it requires the compiler to implicitly add a "ref" to functions parameters when they are of a "ref struct" type. That's pretty much all it does: add a flag

Re: Reference counted containers prototype

2011-12-27 Thread Robert Jacques
On Tue, 27 Dec 2011 07:10:14 -0800, Andrei Alexandrescu wrote: On 12/27/11 4:32 AM, Peter Alexander wrote: On 27/12/11 3:05 AM, Andrei Alexandrescu wrote: On 12/26/11 8:23 PM, Peter Alexander wrote: I am not convinced that it can be used seamlessly without some relatively large changes to t

Re: Reference counted containers prototype

2011-12-27 Thread Andrei Alexandrescu
On 12/28/11 12:59 AM, Robert Jacques wrote: I would have thought that the template parameters would be passed to opDispatch i.e. obj.opDispatch!("foo",bar,baz)(a,b); although I don't know how opDispatch would be written to handle such a call in a generic manner, i.e. I would want to define it a

Re: Reference counted containers prototype

2011-12-28 Thread Daniel Murphy
"Peter Alexander" wrote in message news:jdct6a$2230$1...@digitalmars.com... > How would that work? opDispatch already has variadic templates for the > normal function parameters. Make opDispatch a template inside a template? I suppose that's what this is for. http://d.puremagic.com/issues/show_

Re: Reference counted containers prototype

2012-03-13 Thread Tove
Is work ongoing on this container prototype? Sounds quite interesting...