tail const
Michel Fortin
michel.fortin at michelf.com
Wed Dec 1 06:37:08 PST 2010
On 2010-12-01 06:17:24 -0500, Jonathan M Davis <jmdavisProg at gmx.com> said:
>> I proposed the following a while ago. First allow the class reference
>>
>> to (optionally) be made explicit:
>> C a; // mutable reference to mutable class
>> C ref b; // mutable reference to mutable class
>>
>> And now you can apply tail-const to it:
>> const(C)ref c; // mutable reference to const class
>> const(C ref) d; // const reference to const class
>> const(C) e; // const reference to const class
>
> The real issue is not syntax but getting it into the compiler.
> Apparently, there
> are difficulties in implementing tail const in the compiler which made
> Walter give
> up on it in the past. It should be doable, but Walter is totally sick of the
> issue and doesn't want to put the time in to do it - he has plenty on his plate
> as it is. So, if it's going to be done, someone else has to step up to
> the plate
> and do it. And with the general lack of dmd developers, that hasn't
> happened. No
> one thus far has had both the inclination and the time.
Well... I just took a quick look at the problem from inside the
compiler. The issue is this: the compiler has a type hierarchy, and
TypeClass is one type in it. There is no separate type for a class
reference, it just uses TypeClass do designate a class reference, which
means that if your TypeClass has the const or immutable modifier, so
does your reference. So either we create a TypeClassRef to designate
the reference, or we add additional flags to TypeClass for the
reference's modifier; in either case many parts of the semantic
analysis has to be revised to take this into account.
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list