www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Non movable structs

reply deadalnix <deadalnix gmail.com> writes:
Well all is in the title. Is there a way to achieve this ? If 
not, would this be possible to make this happen ?

Background: I'm working on synchronization primitives for SDC's 
runtime. All the cool kids synchronization primitives rely on the 
mutex's address to do various things.

Making the mutex a class is out of the question, especially since 
They'll be used in the GC, so that would create a dependency loop 
I don't want to get into. System mutexes are good as a fallback, 
but they aren't lightweight - also, they require 32/64 bits 
instead of being able to be flags -, so you'd want to hit them 
only in the slow path.

Long story short, I need structs that do not move. I'm sure there 
are many other use cases.
Jun 18 2016
next sibling parent ketmar <ketmar ketmar.no-ip.org> writes:
On Sunday, 19 June 2016 at 02:06:59 UTC, deadalnix wrote:
 Long story short, I need structs that do not move. I'm sure 
 there are many other use cases.
there definitely are. Eyal from Weka, for example, desperately wants 'em to implement intrusive lists, and even created a bug report[1] for the somewhat similar thing. [1] https://issues.dlang.org/show_bug.cgi?id=16131
Jun 18 2016
prev sibling next sibling parent reply Adrian Matoga <dlang.spam matoga.info> writes:
On Sunday, 19 June 2016 at 02:06:59 UTC, deadalnix wrote:
 Long story short, I need structs that do not move. I'm sure 
 there are many other use cases.
I needed that for a struct member function to be passed as delegate for a fiber. The easiest way I found was to malloc the struct.
Jun 19 2016
parent Mathias Lang via Digitalmars-d <digitalmars-d puremagic.com> writes:
Normally, you would need to disable both identity opAssign and postblit and
it should work. At the moment, it works for the struct itself, however it
breaks when the struct is nested in another one.
There are a couple of issues I am currently looking into fixing (after an
IRC discussion with Eyal).

The gist of it is https://github.com/dlang/dmd/pull/5854 . However with the
current state of the specs / implementation that would make the language
more inconsistent, which is why I put it on hold.
First we need to make `opAssign` properly transitive. You expect that the
compiler-generated `opAssign` call its members `opAssign` if they have any.
This currently happens, but only if the struct has neither dtor nor
postblit.

There are probably a couple of other low-hanging fruits to harvest in the
process (one of them is that the compiler-generated `opAssign` takes its
argument by value, which result in the `struct` being copied and
postblited...)

2016-06-19 11:37 GMT+02:00 Adrian Matoga via Digitalmars-d <
digitalmars-d puremagic.com>:

 On Sunday, 19 June 2016 at 02:06:59 UTC, deadalnix wrote:

 Long story short, I need structs that do not move. I'm sure there are
 many other use cases.
I needed that for a struct member function to be passed as delegate for a fiber. The easiest way I found was to malloc the struct.
Jun 19 2016
prev sibling parent Nick Treleaven <ntrel-pub mybtinternet.com> writes:
On Sunday, 19 June 2016 at 02:06:59 UTC, deadalnix wrote:
 
 Long story short, I need structs that do not move. I'm sure 
 there are many other use cases.
This would be useful for std.typecons.scoped - class instances can be moved otherwise (which is illegal). I think if structs can disable moving, we can make a non-escaping slice wrapper. Very useful for enforcing safe, e.g. for slicing static arrays.
Jun 24 2016