Bug 19092 – __delete doesn't work with immutable

Status
RESOLVED
Resolution
FIXED
Severity
blocker
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-07-18T09:45:06Z
Last change time
2018-08-07T15:34:00Z
Assigned to
No Owner
Creator
Radu Racariu

Comments

Comment #0 by radu.racariu — 2018-07-18T09:45:06Z
The following program --- void main() { import core.memory : __delete; immutable(int)[] x; __delete(x); } --- Fails to compile --- /dlang/dmd/linux/bin64/../../src/druntime/import/core/memory.d(1022): Error: function core.memory.GC.free(void* p) is not callable using argument types (immutable(int)*) /dlang/dmd/linux/bin64/../../src/druntime/import/core/memory.d(1022): cannot pass argument cast(immutable(int)*)x of type immutable(int)* to parameter void* p onlineapp.d(7): Error: template instance `core.memory.__delete!(immutable(int)[])` error instantiating --- If `__delete` is suppose to be an alternative to `delete` then it has to support all use cases. As this compiles (with the deprecation warning) --- void main() { immutable(int)[] x; delete x; } ---
Comment #1 by slavo5150 — 2018-07-18T10:41:04Z
In principle, yes, `__delete` should be a drop-in replacement for `delete`, but using `__delete` should be avoided unless all other options have failed. In fact, when `delete` was deprecated there was some resistance to creating `__delete`. In my opinion, all it does is encourage anti-patterns and technical debt, and I wish `__delete` was never created. What is the actual use case and why is `destroy` in combination with `free`ing functions not possible?
Comment #2 by radu.racariu — 2018-07-18T11:04:03Z
The problem here is not if `delete` or `__delete` are correct or not. The issue is that the compiler deprecated `delete` and offers `__delete`as an alternative (with destroy/free as optional) and it doesn't work as advertised! This is a very bad in terms of the overall perceived quality, I don't wanna go into the reasoning of why `__delete` was added (or kept), but we have it and it should work with all language constructs! As a side note, this is not the first time I report issues related to const/immutable not being properly tested for druntime functions (__equals caused a regression for immutable AA), I think making sure cost/immutable/shared are covered for generic code should be a top priority when reviewing code.
Comment #3 by greeenify — 2018-07-18T11:15:15Z
An attempt at fixing __delete - https://github.com/dlang/druntime/pull/2253 @JinShil: I agree but unfortunately for a seamless deprecation of delete, __delete must be a full drop-in replacement.
Comment #4 by greeenify — 2018-07-18T11:29:15Z
> As a side note, this is not the first time I report issues related to const/immutable not being properly tested for druntime functions (__equals caused a regression for immutable AA), I think making sure cost/immutable/shared are covered for generic code should be a top priority when reviewing code. Aware of it, but sadly our review manpower isn't optimal at the moment and sometimes things slip through. However, any issue reported is certainly appreciated and (like here) we try to fix it ASAP.
Comment #5 by slavo5150 — 2018-07-18T11:50:43Z
> The issue is that the compiler deprecated `delete` and offers `__delete`as an alternative (with destroy/free as optional) and it doesn't work as advertised! `delete` was deprecated in favor of `destroy` and `free`ing functions. `__delete` was offered only as a last resort in case `destroy` was not possible. If you're reaching for `__delete` first, you are not using D as it was intended to be used and you are only going to create problems for yourself and for the maintainers of D. Please avoid it, if possible.
Comment #6 by github-bugzilla — 2018-08-07T15:34:00Z
Commits pushed to master at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/a9c5df1fe7b253e67c20662d37545cfd02460cea Fix Issue 19092 - __delete doesn't work with immutable https://github.com/dlang/druntime/commit/df22381b0935ddae1322710fede499275f7b968b Merge pull request #2253 from wilzbach/fix-19092 Fix Issue 19092 - __delete doesn't work with immutable