Bug 23726 – Array append in CTFE no longer works without _d_arrayappendT
Status
RESOLVED
Resolution
INVALID
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-02-18T07:47:31Z
Last change time
2023-02-19T00:23:03Z
Keywords
bare-metal, betterC
Assigned to
No Owner
Creator
zach-dmd
Comments
Comment #0 by zach-dmd — 2023-02-18T07:47:31Z
Here is my test.d file:
```
alias foo = () {
string x = "1";
x ~= "2";
return x;
};
enum string bar = foo();
```
and minimal object.d file:
```
module object;
alias string = immutable(char)[];
```
Compiling with DMD v2.102.0 causes
```
$ dmd -c -betterC test.d
test.d(3): Error: `object._d_arrayappendT` not found. The current runtime does not support appending array to arrays, or the runtime is corrupt.
```
But compiling with D frontend v2.100.1 works fine (I have been testing with LDC 1.30, based on D frontend v2.100.1).
It seems likely this was introduced between v2.101 and v2.102 but I haven't looked in detail.
I'm not sure if this use-case is supposed to be supported, but it does break code that previously worked and did not need an implementation of `_d_arrayappendT`.
Comment #1 by dkorpel — 2023-02-18T10:33:37Z
This is a consequence of druntime hooks being translated to templates in the front end: https://github.com/dlang/projects/issues/25
> I'm not sure if this use-case is supposed to be supported
dmd and druntime are tied together. You can't expect stability if you upgrade dmd without upgrading your (custom) druntime with it.
Comment #2 by zach-dmd — 2023-02-18T19:35:47Z
I see, thanks for the explanation. I guess this is not a bug then. However, lack of stability between DMD and D-runtime makes it difficult to make a case for bare-metal D (with a custom runtime), since we will have to maintain the custom D-runtime in unison with compiler updates, and the application will probably only be usable with the most recent version of D (unless we start maintaining the custom D-runtime for all compiler versions since the start of the project). I suppose if we keep the number of language features used to a minimum (e.g., disallow `~=`, even in CTFE), then hopefully there won't be much/any breakage across D versions, but there is no guarantee.
Comment #3 by maxhaton — 2023-02-18T23:01:38Z
It's pretty common for embedded toolchains to provide or insist upon a compiler version, you should do that too. When you are ready to support fix your custom runtime then bump the compiler version (and so on)
Comment #4 by zach-dmd — 2023-02-18T23:08:22Z
Fair enough. I've also noticed that if I include just the declaration (for string, but could be templated) in object.d:
```
ref string _d_arrayappendT(return ref scope string x, scope string y) @trusted;
```
Then it is usable and works in CTFE, but nicely causes a link error if it is used in runtime code (this is what I want).
Comment #5 by maxhaton — 2023-02-19T00:23:03Z
Do get in touch if you need any help with anything along those lines.