Unique as a transitive type?

Jason House jason.james.house at gmail.com
Mon Jun 1 16:16:55 PDT 2009


Andrei has stated previously that unique was left out of the type system because it added little value to the const system. Now that shared and multithreading are here, unique has more value.

I have two basic questions:

1. What would make unique difficult to add?

2. What benefits do you forsee?


Here are my thoughts:
1) Escape analysis - construction of unique objects must be careful with how they manipulate their members. This would require scope parameters (AKA lent in Bartosz's blog/literature). After construction, it may also be necessary to update the manipulate the unique object while preserving its uniqueness. Personally, I like the idea of scope by default, but I'm probably in the minority.

2) Plugs a gaping hole in the type system. Even with shared added, I had a moderate multi-threaded code base compile and run without use of shared or casting. That boiled down to an inability to start threads without (silently) subverting the type system. 
It's also possible to optimize operations on unique data in ways that one can't do when a rogue write reference might exist somewhere.  That's not the same as invariant, but it's similar. Unique can be implicitly cast to scope invariant. 



More information about the Digitalmars-d mailing list