DIP 1014:Hooking D's struct move semantics--Community Review Round 1

kinke noone at nowhere.com
Thu May 17 11:33:30 UTC 2018


> 3. When deciding to move a struct instance, the compiler MUST 
> emit a call to the struct's __move_post_blt after blitting the 
> instance and before releasing the memory containing the old 
> instance. __move_post_blt MUST receive references to both the 
> pre- and post-move instances.

This implies that such structs must not be considered PODs, i.e., 
cannot be passed in registers and must be passed on the stack. It 
also means that the compiler will have to insert a 
__move_post_blt call right before the call (as the callee has no 
idea about the old address), after blitting the arg to the callee 
params stack; this may be tricky to implement for LDC, as that 
last blit is implicit in LLVM IR (LLVM byval attribute).

As a side note, when passing a postblit-struct lvalue arg by 
value, the compiler first copies the lvalue to a temporary on the 
caller's stack, incl. postblit call, and then moves that copy to 
the callee. So this requires either a postblit+postmove combo on 
the caller side before the actual call, or a single postblit call 
for the final address (callee's param).


More information about the Digitalmars-d mailing list