Discussion Thread: DIP 1040--Copying, Moving, and Forwarding--Community Review Round 1
Walter Bright
newshound2 at digitalmars.com
Sat Mar 20 09:20:06 UTC 2021
One problem unaddressed is, for moveable structs, what if there *are* interior
pointers, and they wind up pointing to a defunct object? The current compiler
never moves structs, so this problem never occurs.
Some off the top of my head possibilities:
1. never move structs in @safe code (or at least disable moving structs that
contain pointers). Unfortunately, ref counted objects must have a payload
pointer in them.
2. add a runtime check on field pointer assignments
3. add an invariant() runtime check on field pointer values
4. insist that field pointers be marked with @system (there's another DIP for
marking variables as @system)
P.S. the original reason for not allowing interior pointers is so a compacting
garbage collector could be used.
More information about the Digitalmars-d
mailing list