Discussion Thread: DIP 1035-- at system Variables--Final Review

Dukc ajieskola at gmail.com
Fri Mar 4 13:06:35 UTC 2022


On Friday, 4 March 2022 at 09:39:53 UTC, Dennis wrote at the 
feedback theard:
> On Friday, 25 February 2022 at 21:46:25 UTC, Dukc wrote:
>> Wouldn't putting the handle in union with `void[1]` work?
>
> No, `void[1]` is not a type with unsafe values.

I was just checking what the language spec says about this, and 
found an alternative we have all been overlooking.

A type can be declared unsafe in the present language by giving 
it an invariant.

Yes I meant that contract programming invariant! The spec says 
that void-initializing a type with an invariant, or using an 
union that has a member with an invariant is `@system`-only. Thus 
the invariant effectively declares the type unsafe. It also means 
that `void[1]` is an unsafe type, because it can contain a struct 
with an invariant.

This DIP still has the advantage that `@safe` functions in the 
same module with the invariant type do not need any special care. 
But still, that sounds a pretty trivial gain to me - in the 
`IntSlice` example you can make the members read-only with a bit 
union trickery if you want to, or define a string mixin that does 
the same automatically.

I'm starting to think it's probably not worth it overall. Still 
I'm only slightly against because the rules proposed blend such 
nicely with the existing language, and it sure is sometimes 
convenient to have an alternative.




More information about the Digitalmars-d mailing list