Want reasonable reference counting? Disable automatic sharing of immutable
Ola Fosheim Grøstad
ola.fosheim.grostad at gmail.com
Mon Nov 15 14:59:48 UTC 2021
On Monday, 15 November 2021 at 12:58:46 UTC, Imperatorn wrote:
> On Monday, 15 November 2021 at 09:42:03 UTC, Ola Fosheim
> Grøstad wrote:
>> So, I would think that could be covered by having a mechanism
>> for inferring "full immutability"?
>
> Would a new keyword be required or would it be enough to
> specify it so that optimizations could be done etc? (So that we
> don't loose the "benefits" we have today). Sorry, I'm writing
> this the fly so haven't thought this through.
>
> For me the right solution though seems to be keeping it
> "external".
>
> Why? Don't touch the object, the usage of it is not of it's
> concern.
I am primarily thinking about potential use cases in
metaprogramming. For instance: a hashtable that wants to treat
keys as binary data and requires the key to be "fully immutable"
(you don't want to hash a refcount). The hashtable does not care
what the type is, it just want a definitive answer about the
key's ability to change. You need more information than this, of
course, you also need to know if they key is in a canonical form.
I'm starting to think that the C-style typing isn't really
powerful or flexible enough to support meta-programming well. I
guess such querying also could be done as a library feature, I
think C++ was onto something in their library when they added
some information about buffers being contiguous in memory that
could be queried. Typing in languages are often on a higher
abstract level, but in system level programming one often want
machine level knowledge about the concrete representation.
However, doing it on the library level often requires the
programmer who build types to take these needs into account,
maybe there are opportunities to create robust language level
inference that is better? Clearly some things cannot easily be
inferred (such as whether the key is in canonical form), but
maybe some things can be inferred and that would be interesting
to think about.
> Hence, it makes more sense to keep track of it in a separately,
> maybe even in another universe (depending on interpretation).
Yes, you could say that too. Then you are thinking about it in
abstract terms.
> Now I'm late for lunch and it's your fault! *raises fist*
\*offers you a cup of tea\*
More information about the Digitalmars-d
mailing list