RFC: reference counted Throwable
via Digitalmars-d
digitalmars-d at puremagic.com
Sat Sep 20 05:50:12 PDT 2014
On Saturday, 20 September 2014 at 08:42:51 UTC, Uranuz wrote:
> I'm quite a noobie in memory models but from position of user
> of D language I have some ideas about syntax of switching
> between memory models. I think that having everywhere
> declarations using wrapper structs (like RefCounted) is not
> very user-friendly. But still we need some way to say to
> compiler how we want to do memory management. I have read
> tutorial about Rust language. It looks not very clear for me,
> but I like the idea that type of memory management is included
> in variable declaration.
>
> Intead of wrapper struct like scoped!A or RefCounted!A we could
> declare variables with annotations (attributes in D) to say
> what memory model we want to use. Compiler should understand
> this annotation and create some code for memory management. I
> thing it's possible to declare some interface (maybe struct
> with compile-time duck typing) to support some user-defined
> memory models or modifications of basic (implemented in a
> language) memory models.
>
> Why I am saying about annotations? Because we can annotate some
> function, class or just block at the module scope that should
> use some sort of memory management and compiler will create
> corresponding code. In that case we don't need to put wrapper
> struct around all variables that use ref counting. We just
> annotate some function or class declaration as ref-counted and
> that's it!
>
> It's just a concept of what I like to see in the language
> design of D in future)) Of course there are a lot of problems
> in a practice.
>
> Also I think that we shouldn't impose some way of memory model
> to programmer and let him choose his approach but syntax should
> be simple and clear as much as it could be. Also some defaults
> should be for most common cases and for *novice* users of D.
>
> Waiting for critic or thoughts!!!))
You are right that there is an intricate relationship between the
various types of memory (better: ownership) management,
allocators, ref-counting, uniqueness, moving etc, as you write in
your other post. They interact in very specific ways. For this
reason I don't think it is feasible or desirable to set the type
of memory management "from the outside", the types in question
need to know how their innards work. In the same vein, if your
code uses a specific memory management strategy, it has to be
written in a way conforming to it. Walter has already stated
that: you cannot simply slap an attribute onto your code saying
"please do reference counting", and expect it to work, especially
not efficiently.
I think we can get a lot further if we work out said
relationships, and create good general purpose wrapper types that
implement the different strategies accordingly. I believe,
borrowing is crucial to this, which is why I made a proposal
about it [1], which also deals with the other related topics.
You do have a point about a simple, accessible syntax being
important. Still, I don't see a big difference between
@annotations and RC!T wrappers in this regard (except that the
former could apply to entire sections of code, which is not a
good idea IMO). And I think with auto/scope/const type deduction,
code is quite pleasant to read.
[1] http://wiki.dlang.org/User:Schuetzm/scope
More information about the Digitalmars-d
mailing list