[dmd-internals] Type-checked arrays?

Don Clugston dclugston at googlemail.com
Tue Jun 14 01:27:31 PDT 2011


On 14 June 2011 04:23, Michel Fortin <michel.fortin at michelf.com> wrote:
> I've been looking at how to implement named arguments and one approach that comes to mind is to replace the array of expressions which holds arguments with an array of Argument (a new type) which would contain the expression as well as the name of the argument, and possibly later the
>
> But here comes the problem. Everywhere in DMD, the Array struct holds raw pointers which then get casted to whatever you need in a given context. Having to cast every time you extract an element from an array prevents the compiler from doing proper type checking. This in turn makes it extremely perilous to refractor code in a way that changes the type contained in the array.
>
> The standard C++ way to deal with that is to use a template parametrized on the type of content. I can understand that Walter likes that the compiler can compile even on the oldest C++ compiler, but at the same time I feel the lack of type-checking is holding us back.

There have been a huge number of bugs(mostly ICE, but a couple of
wrong-code bugs)  because of the lack of type checking. For example,
there's still one in there, related to tuples.

BTW named arguments for functions has very much in common with named
arguments for struct initializers, which was finally implemented in
the last release. That uses two Arrays, one with the argument and the
other with the name.

>
> I'd like to ask this: would it make sense to transform Array into a template and getting rid of all these casts? And if templates are still out bounds, couldn't we do the same using macros? What do you think?
>
> --
> Michel Fortin
> michel.fortin at michelf.com
> http://michelf.com/
>
>
>
> _______________________________________________
> dmd-internals mailing list
> dmd-internals at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/dmd-internals
>


More information about the dmd-internals mailing list