November 27

Hi,

Last week I started to convert _d_arrayliteralTX to a template. The hook is somewhat similar to _d_newarrayT in that it's used to allocate array literals like so [1, 2, 3]. Note that unlike _d_newarrayT, which also initialises the newly created array, _d_arrayliteralTX just allocates memory for it. The reason for this choice is to limit the number of arguments passed to the hook. If it were to also initialise the array, it would have to receive its contents as an extra variadic argument. I am going to stick to this decision because now with the template hook, an extra variadic template argument would mean a lot more instances for something that is already handled just as fine and with less code by the compiler.

One annoying fact about array literals is that they suffer lots of optimisations after semantic analysis (so after the introduction of the hook). In short, they are either eliminated altogether, or coalesced with concatenations into larger literals. For example, [1, 2, 3] ~ 4 is optimised by the compiler to [1, 2, 3, 4]. This becomes a nuisance because the hook receives the length of the array as an argument and this length changes in the previous example. Since the lowering is introduced during semantic analysis and this optimisation (which is not the only one that may happen) takes place during optimize.d, so after semantic analysis, I'd have to make changes to ArrayLiteralExps in multiple places, which does not scale and will introduce bugs if another change to ArrayLiteralExp is introduced without taking the hook into account.

A cleaner solution which I'm going to try this week is to inspect the call to the hook once more during IR generation and update the array length argument according to the new size of the array.

Thanks,
Teodor