[OT] Re: DIP 1027---String Interpolation---Format Assessment

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Feb 27 19:38:12 UTC 2020


On Thu, Feb 27, 2020 at 02:20:14PM -0500, Steven Schveighoffer via Digitalmars-d-announce wrote:
> On 2/27/20 1:42 PM, H. S. Teoh wrote:
> > Making CTFE AAs usable at runtime is somewhat of a different beast,
> > though.  The main problem is that you need to be able to instantiate the
> > binary representation of a runtime AA (the main hash table, and each
> > of the buckets) at compile-time, and do so in a way that the
> > compiler can turn into data in the data segment of the executable.
> > Regardless of what the CTFE representation is, it needs an explicit
> > transformation step to turn it into something the runtime code can
> > decipher.
> 
> I think this is not too difficult. This works, and it's not much
> different:
> 
> static immutable rbt = new RedBlackTree!int(1,2, 3, 4);
> 
> In other words, I have pretty much faith that if the AA becomes a
> template, then whatever call is made for ["hello": 1, "world": 2] can
> be callable at compile time, and generate a compatible runtime AA.
> 
> The CTFE AA can be whatever CTFE likes, just when it moves to runtime
> land, it gets translated to an AA literal.
[...]

Interesting. So it looks like the problem is "merely" that the AA
implementation is opaque to the compiler (the current implementation is
PIMPL), so it doesn't know how to turn it into static data.  What if we
explicitly cast it into the implementation type, or into a parallel
declaration of the implementation type(s), then forcibly cast it back to
V[K]? Something like this:

	struct AANode { /* implementation here */ }

	static immutable AANode* aaImpl = /* CTFE AA here */;
	static immutable aa = cast(V[K]) aaImpl;

Not 100% sure about that last line, you probably have to force it into
void* or something at some point, I dunno.


T

-- 
MASM = Mana Ada Sistem, Man!


More information about the Digitalmars-d-announce mailing list