Bug 24018 – array concatenation doesn't work with disabled default construction

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2023-06-27T08:46:39Z
Last change time
2023-06-27T12:51:14Z
Keywords
pull
Assigned to
No Owner
Creator
FeepingCreature

Comments

Comment #0 by default_357-line — 2023-06-27T08:46:39Z
``` struct S { @disable this(); } void main() { S[] s; s = s ~ s; } ``` Results in ``` generated/linux/release/64/../../../../druntime/import/core/internal/array/concatenation.d(41): Error: struct `test.S` default construction is disabled test.d(10): Error: template instance `core.internal.array.concatenation._d_arraycatnTX!(S[], S[], S[])` error instantiating ```
Comment #1 by default_357-line — 2023-06-27T08:50:01Z
I think the underlying problem is maybe actually that `.length =` does default construction. There is no way to change length at once without "constructing" the target memory, but that's what `_d_arraycatnTX` requires.
Comment #2 by teodor.dutu — 2023-06-27T09:25:19Z
The old hook was using `__arrayAlloc()` and `__setArrayAllocLength()` to allocate the resulting array. I am trying to move them to core.lifetime.d as templates now as part of https://github.com/dlang/dmd/pull/15299. After this, I'll update `_d_arraycatnTX()` to use them instead of `.length = ...`. I can't just import them from rt.lifetime.d to core.lifetime.d because the build system doesn't allow this dependency. And core.lifetime.d is never compiled, so it can only contain templates. I gave more details about this issue in this post: https://github.com/dlang/dmd/pull/15299
Comment #3 by dlang-bot — 2023-06-27T09:25:31Z
@FeepingCreature created dlang/dmd pull request #15352 "CHANGE: Make `array.length = n` `@system` if default construction is disabled on the array type (fixes 24018)" fixing this issue: - Fix issue 24018: make `array.length = n` `@system` if default construction is disabled on the array type. This is needed as there is otherwise no good way to resize an array of non-constructable elements in user code at all. https://github.com/dlang/dmd/pull/15352
Comment #4 by dlang-bot — 2023-06-27T10:20:35Z
@FeepingCreature created dlang/dmd pull request #15354 "Fix issue 24018: set length manually via runtime function." fixing this issue: - Fix issue 24018: make `array.length = n` `@system` if default construction is disabled on the array type. This is needed as there is otherwise no good way to resize an array of non-constructable elements in user code at all. - Fix issue 24018: instead of calling `array.length =`, call the runtime function that implements `array.length =` instead. This skips the check for the element type being constructable, which is correct because concatenation doesn't expose unconstructed memory anyway. https://github.com/dlang/dmd/pull/15354
Comment #5 by dlang-bot — 2023-06-27T12:51:14Z
dlang/dmd pull request #15354 "Fix issue 24018: set length manually via runtime function." was merged into master: - f17d270cacabbb192c9f01a2aecd10e1389fcf8e by Mathis Beer: Fix issue 24018: make `array.length = n` `@system` if default construction is disabled on the array type. This is needed as there is otherwise no good way to resize an array of non-constructable elements in user code at all. - e37e3f18844494166ac3b68f2b5b6bf450867712 by Mathis Beer: Fix issue 24018: instead of calling `array.length =`, call the runtime function that implements `array.length =` instead. This skips the check for the element type being constructable, which is correct because concatenation doesn't expose unconstructed memory anyway. https://github.com/dlang/dmd/pull/15354