Bug 24453 – [REG2.108] idup fails for inout(T)[] slices

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-03-26T15:18:37Z
Last change time
2024-04-01T22:28:44Z
Keywords
pull
Assigned to
No Owner
Creator
kinke

Comments

Comment #0 by kinke — 2024-03-26T15:18:37Z
This regressed with v2.108 (tested with rc1): ``` inout(char)[] foo(ref scope return inout(char)[] s) { auto bla = s.idup; return s; } ``` Output: ``` core/internal/array/construction.d(342): Error: `inout` on `return` means `inout` must be on a parameter as well for `pure nothrow @trusted inout(char)[](size_t length, bool isShared = false)` core/internal/array/duplication.d(24): Error: template instance `core.internal.array.construction._d_newarrayUPureNothrow!(inout(char))` error instantiating object.d(3876): instantiated from here: `_dup!(inout(char), immutable(char))` reg2108.d(3): instantiated from here: `idup!(inout(char))` ``` Not sure if it's a compiler or druntime regression.
Comment #1 by schveiguy — 2024-03-26T16:26:48Z
druntime regression, though really we should just fix the `inout` restriction. The `_d_newarrayUPureNothrow` is building an array of `inout(char)`, which is wrong at this point. It should always return mutable data, and then properly cast at the right place. Ideally, only one cast should ever be present. The prior version of druntime avoids all the casts by just using `extern(C)` functions with `TypeInfo` and void arrays. Change is here: https://github.com/dlang/dmd/pull/16097
Comment #2 by kinke — 2024-03-26T19:54:57Z
Thanks Steven for checking & linking. > The `_d_newarrayUPureNothrow` is building an array of `inout(char)`, which > is wrong at this point. It should always return mutable data, and then > properly cast at the right place. I think this used to be valid in general, but copy ctors made this all more complex - the element type might define a different copy ctor overload when constructing an immutable instance. In such a case of different copy ctor overloads, the template should probably fail to instantiate indeed; but obviously not for trivial types like char.
Comment #3 by kinke — 2024-03-26T20:00:23Z
Oh wait, `_d_newarrayUPureNothrow` is just allocating, not initializing. No problem with copy ctors then.
Comment #4 by dlang-bot — 2024-03-26T20:12:16Z
@kinke created dlang/dmd pull request #16337 "[stable] Fix Bugzilla Issue 24453 - idup fails for inout(T)[] slices" fixing this issue: - Fix Bugzilla Issue 24453 - idup fails for inout(T)[] slices https://github.com/dlang/dmd/pull/16337
Comment #5 by dlang-bot — 2024-03-27T09:38:13Z
dlang/dmd pull request #16337 "[stable] Fix Bugzilla Issue 24453 - idup fails for inout(T)[] slices" was merged into stable: - 2e8a37324c2586e0385c21d3874b99231329f3dc by Martin Kinkelin: Fix Bugzilla Issue 24453 - idup fails for inout(T)[] slices https://github.com/dlang/dmd/pull/16337
Comment #6 by dlang-bot — 2024-04-01T22:28:44Z
dlang/dmd pull request #16355 "merge stable" was merged into master: - 2c1deeced9df3cd8434d576e6e8733fc9d74f79f by Martin Kinkelin: Fix Bugzilla Issue 24453 - idup fails for inout(T)[] slices https://github.com/dlang/dmd/pull/16355