Phobos is now compiled with -preview=dip1000

Mike Franklin slavo5150 at yahoo.com
Fri May 17 20:59:43 UTC 2019


On Friday, 17 May 2019 at 17:03:51 UTC, Meta wrote:

> If you look at `main` above, `rawData` has the same lifetime as 
> the `dataRange` struct returned from `makeDataRange` and the 
> queue returned from `copyToQueue`. True, there is some 
> traditionally unsafe stuff happening in between; however, I 
> thought that the point of adding all these annotations is to 
> tell the compiler how the lifetimes of these objects propagate 
> up and down the call stack, so that it can check that there 
> will be no memory corruption. I'm not doing anything here that 
> will result in a pointer to an expired stack frame, or 
> otherwise cause memory corruption or use after free, or 
> anything like that (*unless* I allow either `dataRange` or 
> `result` to escape from the main function - which dip1000 
> correctly disallows).

I don't think it does because `Queue!(T).store` has infinite 
lifetime beyond that of even `main`, at least as far as the 
compiler is concerned.  The compiler doesn't have enough 
information to know that `store` is tied to the lifetime of 
`Queue!(T)` (a.k.a `rawData`) and maybe that's a missing language 
feature.  Maybe we should be allowed to declare aggregate fields 
as `scope` to convey that, but the compiler currently disallows 
it.

loosely related:  
https://issues.dlang.org/show_bug.cgi?id=18788#c7

Mike




More information about the Digitalmars-d-announce mailing list