[Issue 8845] Can't pass immediate or rvalue args to ref function parameters

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Nov 27 07:45:16 PST 2013


https://d.puremagic.com/issues/show_bug.cgi?id=8845



--- Comment #18 from Maxim Fomin <maxim at maxim-fomin.ru> 2013-11-27 07:45:10 PST ---
(In reply to comment #17)
>
> One allocates, the other is just a subversion of the type system. 

Actually each of them allocates. You either allocate on stack or in heap.
Advantage of heap is that you don't care about escaping references and
advantage of stack is efficiency. Second example is obviously not a subversion
of the type system. 

> It's
> basically the same (and less clear?) than just doing:
>   int temp = 0-0;
>   foo(temp);
> 

No, it is not the same. By the way, it was you who complained about writing
code without dummy variables. 

> Either way, it's equally unsafe, and the discussion regarding rvalue->ref
> parameters was mainly around safety concerns.
> 

No, first is safe, second is conditionally safe if reference does not escape.
By the way, you wrote that creating temporary and passing pointer is acceptable
(either you do this or language automatically does).

> If the function being called returns a ref, it would add an implicit function
> exit condition which would validate that the ref being returned is not within
> the function's stack (controlled by -noboundscheck for optimisation).
> This way, it would be safe to return a ref that was passed in to a function,
> but not a function local. This would cascade outwards.
> 

The idea has flaw, it does not take into account that there are ways for stack
pointer to escape other than through return. 

> Frankly, I just want a solution. I like the 'scope ref' concept, but it depends
> on escape analysis working well, and I'm not that precious about
> implementation, I just want something that works. It's a major inhibitor to
> maths intensive code, like image/geometry/physics/audio processing.
> Particularly where fairly 'primitive' objects like vectors, matrices,
> quaternions, colours, etc are concerned.

Frankly, there is excess of people wanting a solution and shortage of people
executing them.

I think you need to decide what exactly do you want: allocating temporary by
language (which is unlikely to happen), using workaround with the purpose not
to have dummy variables (seems to be no), writing DIP for the issue (which
having been written and discussed goes to archive), or somebody to fix scope
ref (which is unlikely to happen soon).

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list