Associative Arrays in the data segment

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Fri Apr 10 08:31:17 PDT 2015


On Fri, Apr 10, 2015 at 05:54:47PM +1000, Daniel Murphy via Digitalmars-d wrote:
> One long-standing issue with AAs has been that you can't generate
> constant ones at compile time and access them at run-time.
> Workarounds are available, like initializing them in static this or
> using horribly inefficient enum AAs.

Didn't somebody submit some PRs for factoring out AA literal
initializations? Whatever happened with that? In theory, that should
have been the first step in allowing compile-time initialized AAs.


[...]
> It only works with integral types of at most 32-bits at the moment,
> but most built-in types are fairly easy to support.  The downside is
> requires re-implementing druntime's AA and hashing algorithms in the
> compiler, and keeping them in sync when either changes.

I think this is unacceptable. We're trying to decouple AA's from
compiler innards, and this is going backwards and adding a huge
dependency between them again, not to mention being a maintenance
nightmare because bugs are bound to happen when the two code bases go
out of sync. It's the very problem we've been trying to fix for years.

While I am very much in favor of compile-time initialized AA's (been
wanting that for years now), I think this is not the right approach.  In
my mind, the correct approach is to factor out the AA implementation
into a library solution, and use CTFE on that library code to generate
the compile-time initialized literal.


T

-- 
"A one-question geek test. If you get the joke, you're a geek: Seen on a California license plate on a VW Beetle: 'FEATURE'..." -- Joshua D. Wachs - Natural Intelligence, Inc.


More information about the Digitalmars-d mailing list