Discussion Thread: DIP 1035-- at system Variables--Final Review
Paul Backus
snarwin at gmail.com
Mon Feb 21 21:50:31 UTC 2022
On Monday, 21 February 2022 at 20:30:07 UTC, Dennis wrote:
> On Monday, 21 February 2022 at 19:49:58 UTC, Paul Backus wrote:
>> If there is no benefit to memory-safety from applying `scope`
>> checking to data without indirections, then there is no
>> justification for enabling such checks in all `@safe` code,
>> even if they may occasionally be "desirable" for other,
>> non-memory-safety-related reasons.
>
> It is memory-safety related, it allows you to create custom
> pointer types. A pointer is just an integer under the hood, the
> idea of indirections and lifetimes is just a compile time idea
> around a `size_t` which indexes into memory. Why can't we do
> the same with a `ushort` which indexes into an array?
If the goal is being able to define custom pointer types, then
the DIP should use that as an example instead of talking about
file descriptors, and it should explain *exactly* which part of
the example depends on this feature for memory safety (as the
other examples do).
I still don't think it's a compelling use-case, though.
[`TailUnqual`][1] does something very similar, using the `union`
workaround, and it would not benefit from having access to
`scope`-checked integers because (a) it stores a `size_t`, so
eliminating the `union` wouldn't save any space; and (b) it needs
the `union` for correct GC scanning regardless.
[1]:
https://gist.github.com/pbackus/1638523a5b6ea3ce2c0a73358cff4dc6
More information about the Digitalmars-d
mailing list