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


  • Phobos is now compiled with -p... Walter Bright via Digitalmars-d-announce
    • Re: Phobos is now compile... Dukc via Digitalmars-d-announce
      • Re: Phobos is now com... Walter Bright via Digitalmars-d-announce
        • Re: Phobos is now... Dukc via Digitalmars-d-announce
          • Re: Phobos is... Walter Bright via Digitalmars-d-announce
            • Re: Phob... Meta via Digitalmars-d-announce
              • Re: ... Mike Franklin via Digitalmars-d-announce
                • ... Mike Franklin via Digitalmars-d-announce
                • ... Meta via Digitalmars-d-announce
                • ... Mike Franklin via Digitalmars-d-announce
                • ... Mike Franklin via Digitalmars-d-announce
                • ... Meta via Digitalmars-d-announce
                • ... Meta via Digitalmars-d-announce
                • ... Jonathan M Davis via Digitalmars-d-announce
              • Re: ... ag0aep6g via Digitalmars-d-announce
                • ... Meta via Digitalmars-d-announce
                • ... ag0aep6g via Digitalmars-d-announce
                • ... Meta via Digitalmars-d-announce
                • ... ag0aep6g via Digitalmars-d-announce
                • ... Jonathan M Davis via Digitalmars-d-announce

Reply via email to