Bug 16982 – std.experimental.allocator.make!T must either call GC.addRange or be marked @system

Status
NEW
Severity
normal
Priority
P3
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-12-18T18:19:08Z
Last change time
2024-12-01T16:28:22Z
Keywords
safe
Assigned to
Andrei Alexandrescu
Creator
Sönke Ludwig
Moved to GitHub: phobos#9696 →

Comments

Comment #0 by sludwig — 2016-12-18T18:19:08Z
When creating objects that contain references, make() doesn't currently call GC.addRange(), which may lead to dangling references in case the GC frees such an unseen reference. To fix this, make() must either be marked as @system as soon as an object with references is created, or preferably, it should call GC.addRange(). A vanilla version ("makeNoGC"?) could be added to be able to opt-out of this, but it should be very clear from its name that it is unsafe in a GC scenario, because this is a pitfall that is very easy to hit. The same reasoning applies to makeArray().
Comment #1 by b2.temp — 2016-12-18T18:58:40Z
We could instead imagine a system based on introspection (discover data that should trigger addRange()) and annotations (trust data for for which addRange() should be called but wont). Depending on the result of the introspection, GC.addRange() would be called automatically. See also: - https://forum.dlang.org/thread/[email protected] - https://forum.dlang.org/thread/[email protected] - https://forum.dlang.org/post/[email protected]
Comment #2 by sludwig — 2016-12-18T19:55:16Z
Yeah, I used to simply `static if (std.traits.hasIndirections!T) GC.addRange(...);` in vibe.d's allocator module. Using annotations instead of controlling this at the call site is an interesting idea, although I can see applications for both approaches. Using @nogc sounds good, too, although if that approach is taken, I'd propose to define @nogc as a UDA in object.d instead of adding a new special trait for detecting its presence.
Comment #3 by greeenify — 2016-12-27T11:36:10Z
*** Issue 15790 has been marked as a duplicate of this issue. ***
Comment #4 by greeenify — 2016-12-27T11:37:46Z
(I just closed https://issues.dlang.org/show_bug.cgi?id=15790 as a duplicate, but it contains a good example that illustrates this issue)
Comment #5 by robert.schadek — 2024-12-01T16:28:22Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/9696 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB