Incorporating D

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Jan 28 09:40:48 PST 2013


On Mon, Jan 28, 2013 at 06:21:17PM +0100, Paulo Pinto wrote:
> Am 28.01.2013 17:30, schrieb deadalnix:
> >On Monday, 28 January 2013 at 16:26:29 UTC, Paulo Pinto wrote:
> >>This is not true for current native compilers and JVMs.
> >>
> >>If escape analysis can prove the object does not leave scope, new
> >>actually allocates on the stack.
> >>
> >
> >Modern can even speculate that an object will not leave scope,
> >allocate it on stack, and move it on heap if it escape !
> 
> That is how Go works if you return a pointer to something declared on
> the stack.

I think DMD needs something like this, to fix all of those ref-to-stack
bugs, like:

- Unsafe slicing of static arrays
- Slicing of variadic arguments
- Delegates that reference a returned struct (becomes invalid because
  caller moves the struct but doesn't update the delegate's context ptr)
- ref functions returning ref to local variables

And many others. All of these become non-problems if the compiler (or
code at runtime) detects the escaping reference and move the stuff onto
the heap.


T

-- 
Some ideas are so stupid that only intellectuals could believe them. -- George Orwell


More information about the Digitalmars-d mailing list