@safe D requires which DIP switches?

Bastiaan Veelo Bastiaan at Veelo.net
Tue Jan 4 19:56:25 UTC 2022


On Tuesday, 4 January 2022 at 11:57:41 UTC, Dennis wrote:
> This is the situation on dmd's master branch:
> ✅ = correct, considering the current language design
> 🆗 = correct, but is more strict than necessary
> 💀 = incorrect, allows memory corruption
>
> | Action                         | no dip1000 | dip1000         
>                                    |
> |--------------------------------|------------|----------------------------------------------------|
> | Take address of local variable | 🆗 Error   | ✅ Allowed using 
> `scope` when type has no pointers  |
> | Make slice of local variable   | 💀 Allowed | ✅ Allowed using 
> `scope` when type has no pointers  |
> | Take address of `ref` return   | 💀 Allowed | 🆗 Allowed using 
> `scope` when type has no pointers |
> | Make slice of `ref` return     | 💀 Allowed | 💀 Allowed even 
> when type has pointers             |
>
> I'm trying to turn dip1000's 💀 into an 🆗, but Walter wants to 
> go straight to a ✅:
> https://github.com/dlang/dmd/pull/13362#issuecomment-981181277
>
> On top of this, dip1000 currently has a few more 💀s because:
>
> - parameters of `pure` functions can be incorrectly inferred 
> `scope`, even when you can escape them with a thrown Exception. 
> The fix is easy, but it requires updating Phobos and excel-d to 
> pass the test suite, which is cumbersome.
> https://issues.dlang.org/show_bug.cgi?id=22221
>
> - `inout` on struct member functions currently gives the 
> permissions of `return` without the associated lifetime 
> restrictions.
> https://issues.dlang.org/show_bug.cgi?id=20149
>
> - Some checks are missing when using closures:
> https://issues.dlang.org/show_bug.cgi?id=22298

> dip25 prevents returning a `ref` parameter by `ref`, unless you 
> annotate it `return ref`. It's enabled by default, but only as 
> a deprecation. `-preview=dip25` turns the deprecation into an 
> error. `-preview=dip1000` implies `-preview=dip25`, so there's 
> no need to use both switches.

This is really helpful, thanks!

-- Bastiaan.


More information about the Digitalmars-d mailing list