[Issue 17676] New: [REG 2.075] bad inlining of functions with multiple return values

2017-07-23 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17676 Issue ID: 17676 Summary: [REG 2.075] bad inlining of functions with multiple return values Product: D Version: D2 Hardware: x86_64 OS: Windows Status

Return type based overloading and multiple return values via templates

2016-08-04 Thread Steve Biedermann via Digitalmars-d
Every few weeks D amazes me, with how flexible this language is. Today, I'm amazed that I could implement multiple return values and return type based function overloading on a library level: https://github.com/hardliner66/D_ReturnLowering Probably not the best code. Also not as comfortable

Re: Optional extra return value? Multiple return values with auto?

2012-08-15 Thread ReneSac
On Wednesday, 15 August 2012 at 01:22:41 UTC, Era Scarecrow wrote: On Wednesday, 15 August 2012 at 00:37:32 UTC, ReneSac wrote: And my last question of my first post: I can't use auto for the out values right? An enhancement proposal like this would be compatible with D? I would say No.

Re: Optional extra return value? Multiple return values with auto?

2012-08-14 Thread ReneSac
Thanks, this indeed works. One obvious (when your program starts to behave weirdly...) down side of this solution: it needs a different dummy for each optional out value of a function, or else multiple variables will be modifying the same dummy. And, of course, a different dummy for each type

Re: Optional extra return value? Multiple return values with auto?

2012-08-14 Thread Era Scarecrow
On Wednesday, 15 August 2012 at 00:37:32 UTC, ReneSac wrote: And my last question of my first post: I can't use auto for the out values right? An enhancement proposal like this would be compatible with D? I would say No. Maybe if it was a union, but I don't think so;.It still needs to

Re: Optional extra return value? Multiple return values with auto?

2012-08-14 Thread Ali Çehreli
On 08/14/2012 06:22 PM, Era Scarecrow wrote: On Wednesday, 15 August 2012 at 00:37:32 UTC, ReneSac wrote: And my last question of my first post: I can't use auto for the out values right? An enhancement proposal like this would be compatible with D? I would say No. Maybe if it was a

Re: Optional extra return value? Multiple return values with auto?

2012-08-14 Thread Era Scarecrow
On Wednesday, 15 August 2012 at 01:42:11 UTC, Ali Çehreli wrote: Agreed. The function code must be compiled to use certain amount of data from the program stack for that particular parameter. That size of that parameter must be known at compile time. The compiler could in theory examine the

Re: Optional extra return value? Multiple return values with auto?

2012-08-11 Thread ReneSac
On Tuesday, 24 July 2012 at 05:30:49 UTC, Ali Çehreli wrote: The options that I can think of: - Return a struct (or a class) where one of the members is not filled-in - Similarly, return a tuple This is awkward, and doesn't look good for performance. - Use an out parameter, which can

Re: Optional extra return value? Multiple return values with auto?

2012-08-11 Thread Ali Çehreli
On 08/11/2012 03:48 PM, ReneSac wrote: On Tuesday, 24 July 2012 at 05:30:49 UTC, Ali Çehreli wrote: - Use an out parameter, which can have a default lvalue: int g_default_param; void foo(ref int i = g_default_param) { if (i == g_param) { // The caller is not interested in 'i' } else {

Re: Optional extra return value? Multiple return values with auto?

2012-08-11 Thread Timon Gehr
There is no compiler bug. You cannot pass immutable/rvalue by reference to mutable.

Re: Optional extra return value? Multiple return values with auto?

2012-07-24 Thread Chris NS
On Tuesday, 24 July 2012 at 03:25:55 UTC, ReneSac wrote: Do I really have to duplicate the function, in order to achieve this? In a nutshell, yes. Or else resort to bizarre sorcery such as may rot the very heart from one's chest (or template ninjitsu, whatever). But is it really so

Re: Optional extra return value? Multiple return values with auto?

2012-07-24 Thread David
Am 24.07.2012 05:25, schrieb ReneSac: I whish there was: auto foo() { return Tuple!(foo, bar, 1, new Custum()); } void main() { auto (s1, s2, i, c) = foo(); }

Re: Optional extra return value? Multiple return values with auto?

2012-07-24 Thread bearophile
On Tuesday, 24 July 2012 at 03:25:55 UTC, ReneSac wrote: How I can return multiple values in D, but one of them being optional? One of the ways to to it is to return a tuple with your arguments, where the last item of the tuple is a Nullable of the optional element: import std.stdio,

Re: Optional extra return value? Multiple return values with auto?

2012-07-24 Thread Chris NS
On Tuesday, 24 July 2012 at 08:56:21 UTC, David wrote: Am 24.07.2012 05:25, schrieb ReneSac: I whish there was: auto foo() { return Tuple!(foo, bar, 1, new Custum()); } void main() { auto (s1, s2, i, c) = foo(); } I think the main blocker to something like that right now is the

Re: Optional extra return value? Multiple return values with auto?

2012-07-24 Thread bearophile
It seems forum.dlang.org hides my first answer, I don't know why: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learnarticle_id=37708 Bye, bearophile

Optional extra return value? Multiple return values with auto?

2012-07-23 Thread ReneSac
How I can return multiple values in D, but one of them being optional? I tried the 'out' hack to achieve multiple return values, but it didn't accepted a default argument: it needed a lvalue in the calling function. In Lua, for example, one can do: function foo(input) -- calculations

Re: Optional extra return value? Multiple return values with auto?

2012-07-23 Thread Ali Çehreli
On 07/23/2012 08:25 PM, ReneSac wrote: How I can return multiple values in D, but one of them being optional? I tried the 'out' hack to achieve multiple return values, but it didn't accepted a default argument: it needed a lvalue in the calling function. Like in C and C++, functions in D can

Re: Multiple return values...

2012-03-16 Thread Iain Buclaw
On 16 March 2012 02:26, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: On 3/15/12 5:44 PM, foobar wrote: On Thursday, 15 March 2012 at 18:23:57 UTC, Andrei Alexandrescu wrote: I understand how the draw of reaching for new syntax is extremely alluring. I used to fall for it much

Re: Multiple return values...

2012-03-16 Thread Iain Buclaw
On 15 March 2012 17:51, Manu turkey...@gmail.com wrote: On 15 March 2012 19:05, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: On 3/15/12 11:30 AM, Manu wrote: On 15 March 2012 17:32, Andrei Alexandrescu seewebsiteforem...@erdani.org mailto:seewebsiteforem...@erdani.org wrote:  

Re: Multiple return values...

2012-03-16 Thread Artur Skawina
On 03/16/12 01:03, H. S. Teoh wrote: On Fri, Mar 16, 2012 at 12:11:44AM +0100, Simen Kjærås wrote: On Thu, 15 Mar 2012 23:44:09 +0100, foobar f...@bar.com wrote: Is swap usually inlined by the compiler? This is the body of swap for simple types: auto tmp = lhs; lhs = rhs; rhs =

Re: Multiple return values...

2012-03-16 Thread Manu
On 16 March 2012 04:26, Andrei Alexandrescu seewebsiteforem...@erdani.orgwrote: A good design should strive to provide general features instead of special cases (E.g. swap is limited to the 2-tuple case). Also, why force an overhead of a function call on such a basic feature as assignment?

Re: Multiple return values...

2012-03-16 Thread Andrei Alexandrescu
On 3/16/12 6:29 AM, Manu wrote: On 16 March 2012 04:26, Andrei Alexandrescu seewebsiteforem...@erdani.org mailto:seewebsiteforem...@erdani.org wrote: A good design should strive to provide general features instead of special cases (E.g. swap is limited to the 2-tuple case).

Re: Multiple return values...

2012-03-16 Thread Iain Buclaw
On 16 March 2012 16:37, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: On 3/16/12 6:29 AM, Manu wrote: On 16 March 2012 04:26, Andrei Alexandrescu seewebsiteforem...@erdani.org mailto:seewebsiteforem...@erdani.org wrote:        A good design should strive to provide general

Re: Multiple return values...

2012-03-16 Thread Andrei Alexandrescu
On 3/16/12 3:48 AM, Iain Buclaw wrote: This could also be done for arrays too. (int a, b) = arr[]; - static assert(arr.length == 2); int a = arr[0]; int b = arr[1]; Yah, the rewrite is purely syntactic, not tuple-specific. That's a major thing I like about it. Or possibly a use in

Re: Multiple return values...

2012-03-16 Thread Andrei Alexandrescu
On 3/16/12 11:50 AM, Iain Buclaw wrote: If you were to forget all about MRV for a brief moment, the change request being proposed here is to return *all* structures (including delegates, complex types and vectors) in registers if at all possible even if the underlying ABI default is to return it

Re: Multiple return values...

2012-03-16 Thread Iain Buclaw
On 16 March 2012 16:53, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: On 3/16/12 11:50 AM, Iain Buclaw wrote: If you were to forget all about MRV for a brief moment, the change request being proposed here is to return *all* structures (including delegates, complex types and

Re: Multiple return values...

2012-03-16 Thread Manu
On 16 March 2012 18:37, Andrei Alexandrescu seewebsiteforem...@erdani.orgwrote: Actually, as has been mentioned, swizzling can be done very nicely inside the language. How? The only example I saw in this thread was your from()/to() approach, which Timon said didn't actually work...? On

Re: Multiple return values...

2012-03-16 Thread Manu
On 16 March 2012 18:53, Andrei Alexandrescu seewebsiteforem...@erdani.orgwrote: On 3/16/12 11:50 AM, Iain Buclaw wrote: If you were to forget all about MRV for a brief moment, the change request being proposed here is to return *all* structures (including delegates, complex types and

Re: Multiple return values...

2012-03-16 Thread Manu
On 16 March 2012 19:13, Iain Buclaw ibuc...@ubuntu.com wrote: On 16 March 2012 16:53, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: On 3/16/12 11:50 AM, Iain Buclaw wrote: If you were to forget all about MRV for a brief moment, the change request being proposed here is to

Re: Multiple return values...

2012-03-16 Thread Timon Gehr
On 03/16/2012 06:33 PM, Manu wrote: On 16 March 2012 18:37, Andrei Alexandrescu seewebsiteforem...@erdani.org mailto:seewebsiteforem...@erdani.org wrote: Actually, as has been mentioned, swizzling can be done very nicely inside the language. How? Use opDispatch. a = a.yxwz; The

Re: Multiple return values...

2012-03-16 Thread Manu
On 16 March 2012 19:53, Timon Gehr timon.g...@gmx.ch wrote: On 03/16/2012 06:33 PM, Manu wrote: On 16 March 2012 18:37, Andrei Alexandrescu seewebsiteforem...@erdani.org mailto:SeeWebsiteForEmail@**erdani.orgseewebsiteforem...@erdani.org wrote: Actually, as has been mentioned,

Re: Multiple return values...

2012-03-16 Thread Simen Kjærås
On Fri, 16 Mar 2012 03:26:55 +0100, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: I think this is a reasonable request: (auto a, b) = fun(); --- static assert(fun().length == 2); auto __t = fun(); auto a = __t[0]; auto b = __t[1]; That would be nice. As was mentioned in a

Re: Multiple return values...

2012-03-16 Thread bearophile
Simen K.: Now, a pattern that our productive friend bearophile posted earlier was this: int[] foo(); (auto a, b) = foo(); --- auto __t = foo(); assert( __t.length 0 ); auto a = __t[0]; auto b = __t[1..$]; Is this something we might also want? That's not a good idea,

Re: Multiple return values...

2012-03-15 Thread Iain Buclaw
On 14 March 2012 22:06, Derek Parnell ddparn...@bigpond.com wrote: On Thu, 15 Mar 2012 08:52:26 +1100, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: On 3/14/12 3:00 PM, Simen Kjærås wrote: template to(T...) { alias T to; } auto from(T...)(T t) { struct Result { T t; alias t

Re: Multiple return values...

2012-03-15 Thread Timon Gehr
On 03/14/2012 11:06 PM, Derek Parnell wrote: On Thu, 15 Mar 2012 08:52:26 +1100, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: On 3/14/12 3:00 PM, Simen Kjærås wrote: template to(T...) { alias T to; } auto from(T...)(T t) { struct Result { T t; alias t this; } return Result( t );

Re: Multiple return values...

2012-03-15 Thread Derek
On Thu, 15 Mar 2012 19:23:57 +1100, Timon Gehr timon.g...@gmx.ch wrote: I'd like to break the nexus between science and magic here. // this is used to access language built-in tuples template to(T...) { alias T to; } // this builds a struct akin to std.typecons.tuple // it contains the

Re: Multiple return values...

2012-03-15 Thread Iain Buclaw
On 15 March 2012 09:52, Derek ddparn...@bigpond.com wrote: On Thu, 15 Mar 2012 19:23:57 +1100, Timon Gehr timon.g...@gmx.ch wrote: I'd like to break the nexus between science and magic here. // this is used to access language built-in tuples template to(T...) {     alias T to; } // this

Re: Multiple return values...

2012-03-15 Thread Andrei Alexandrescu
On 3/15/12 5:14 AM, Iain Buclaw wrote: On 15 March 2012 09:52, Derekddparn...@bigpond.com wrote: Are you saying that the generated code is something like ... struct __tmpS { int Fa, int Fb }; __tempS __tmp; __tmp.Fa = a; __tmp.Fb = b; a = __tmp.Fb; b = __tmp.Fa; In

Re: Multiple return values...

2012-03-15 Thread Manu
On 15 March 2012 17:32, Andrei Alexandrescu seewebsiteforem...@erdani.orgwrote: On 3/15/12 5:14 AM, Iain Buclaw wrote: On 15 March 2012 09:52, Derekddparn...@bigpond.com wrote: Are you saying that the generated code is something like ... struct __tmpS { int Fa, int Fb }; __tempS

Re: Multiple return values...

2012-03-15 Thread Andrei Alexandrescu
On 3/15/12 11:30 AM, Manu wrote: On 15 March 2012 17:32, Andrei Alexandrescu seewebsiteforem...@erdani.org mailto:seewebsiteforem...@erdani.org wrote: One note - the code is really ingenious, but I still prefer swap() in this case. It's more concise and does less work in the general

Re: Multiple return values...

2012-03-15 Thread Timon Gehr
On 03/15/2012 04:32 PM, Andrei Alexandrescu wrote: One note - the code is really ingenious, but I still prefer swap() in this case. It's more concise and does less work in the general case. swap(a[i + k], a[j + j]); only computes the indexing once (in source, too). In the general case,

Re: Multiple return values...

2012-03-15 Thread Manu
On 15 March 2012 19:05, Andrei Alexandrescu seewebsiteforem...@erdani.orgwrote: On 3/15/12 11:30 AM, Manu wrote: On 15 March 2012 17:32, Andrei Alexandrescu seewebsiteforem...@erdani.org mailto:SeeWebsiteForEmail@**erdani.orgseewebsiteforem...@erdani.org wrote: One note - the code

Re: Multiple return values...

2012-03-15 Thread Andrei Alexandrescu
On 3/15/12 12:51 PM, Manu wrote: On 15 March 2012 19:05, Andrei Alexandrescu It's a function call. Why is a function call a ugly hack? Because now we're involving libraries to perform a trivial assignment. It's not a trivial assignment, it's swapping two pieces of data. This matter has

Re: Multiple return values...

2012-03-15 Thread foobar
On Thursday, 15 March 2012 at 17:05:00 UTC, Andrei Alexandrescu wrote: On 3/15/12 11:30 AM, Manu wrote: On 15 March 2012 17:32, Andrei Alexandrescu seewebsiteforem...@erdani.org mailto:seewebsiteforem...@erdani.org wrote: One note - the code is really ingenious, but I still prefer swap()

Re: Multiple return values...

2012-03-15 Thread foobar
On Thursday, 15 March 2012 at 18:23:57 UTC, Andrei Alexandrescu wrote: I understand how the draw of reaching for new syntax is extremely alluring. I used to fall for it much more often, but over years I have hardened myself to resist it, and I think that made me a better language designer.

Re: Multiple return values...

2012-03-15 Thread bearophile
return values). They are not necessary, so if you don't want to add the syntax sugar we'll do with the libray Tuple we have. But so far I have not seen ways to replace that syntax sugar with with something else. Bye, bearophile

Re: Multiple return values...

2012-03-15 Thread Simen Kjærås
On Thu, 15 Mar 2012 23:44:09 +0100, foobar f...@bar.com wrote: Is swap usually inlined by the compiler? This is the body of swap for simple types: auto tmp = lhs; lhs = rhs; rhs = tmp; For more complex types: ubyte[T.sizeof] t = void; auto a = (cast(ubyte*) lhs)[0 .. T.sizeof];

Re: Multiple return values...

2012-03-15 Thread H. S. Teoh
On Fri, Mar 16, 2012 at 12:11:44AM +0100, Simen Kjærås wrote: On Thu, 15 Mar 2012 23:44:09 +0100, foobar f...@bar.com wrote: Is swap usually inlined by the compiler? This is the body of swap for simple types: auto tmp = lhs; lhs = rhs; rhs = tmp; For more complex types:

Re: Multiple return values...

2012-03-15 Thread Andrei Alexandrescu
On 3/15/12 5:44 PM, foobar wrote: On Thursday, 15 March 2012 at 18:23:57 UTC, Andrei Alexandrescu wrote: I understand how the draw of reaching for new syntax is extremely alluring. I used to fall for it much more often, but over years I have hardened myself to resist it, and I think that made

Re: Multiple return values...

2012-03-15 Thread James Miller
2. When was the last time you needed to swap arbitrary numbers of elements, and so badly and frequently, you needed a new language feature for that? Andrei I would like to point out Boscop's vector swizzling tutorial that he made recently as evidence that not only do you not need it that

Re: Multiple return values...

2012-03-15 Thread H. S. Teoh
On Fri, Mar 16, 2012 at 04:46:52PM +1300, James Miller wrote: 2. When was the last time you needed to swap arbitrary numbers of elements, and so badly and frequently, you needed a new language feature for that? Andrei I would like to point out Boscop's vector swizzling tutorial that

Re: Tuple unpacking syntax [Was: Re: Multiple return values...]

2012-03-14 Thread Manu
I'm encouraged to see that every person in this thread so far seems to feel the same way as me regarding the syntax. On 14 March 2012 05:25, Derek Parnell ddparn...@bigpond.com wrote: On Wed, 14 Mar 2012 13:33:18 +1100, Kevin Cox kevincox...@gmail.com wrote: (int i,,float f) =

Re: Tuple unpacking syntax [Was: Re: Multiple return values...]

2012-03-14 Thread RivenTheMage
On Wednesday, 14 March 2012 at 02:33:29 UTC, Kevin Cox wrote: Kind of unrelated but I think that it is important to have a way to ignore values also. Leaving them bank would sufice. (int i,,float f) = intBoringFloat(); or (int i, null, float f) = intBoringFloat(); or (int i, void, float

Re: Tuple unpacking syntax [Was: Re: Multiple return values...]

2012-03-14 Thread Robert Jacques
On Wed, 14 Mar 2012 03:52:55 -0500, Manu turkey...@gmail.com wrote: I'm encouraged to see that every person in this thread so far seems to feel the same way as me regarding the syntax. On 14 March 2012 05:25, Derek Parnell ddparn...@bigpond.com wrote: On Wed, 14 Mar 2012 13:33:18 +1100,

Re: Multiple return values...

2012-03-14 Thread Ary Manzana
On 3/13/12 6:12 PM, Andrei Alexandrescu wrote: On 3/13/12 2:57 PM, Manu wrote: And you think that's more readable and intuitive than: (v1, v2, v3) = fun(); ? Yes (e.g. when I see the commas my mind starts running in all directions because that's valid code nowadays that ignores v1 and v2 and

Re: Multiple return values...

2012-03-14 Thread Andrei Alexandrescu
On 3/14/12 2:02 PM, Ary Manzana wrote: On 3/13/12 6:12 PM, Andrei Alexandrescu wrote: On 3/13/12 2:57 PM, Manu wrote: And you think that's more readable and intuitive than: (v1, v2, v3) = fun(); ? Yes (e.g. when I see the commas my mind starts running in all directions because that's valid

Re: Multiple return values...

2012-03-14 Thread Simen Kjærås
On Wed, 14 Mar 2012 20:02:50 +0100, Ary Manzana a...@esperanto.org.ar wrote: Here's what you can do in Ruby: a = 1 b = 2 # Swap the contents a, b = b, a Can you do something like that with templates in D, with a nice syntax? template to(T...) { alias T to; } auto from(T...)(T t) {

Re: Multiple return values...

2012-03-14 Thread Ary Manzana
On 3/14/12 5:00 PM, Simen Kjærås wrote: On Wed, 14 Mar 2012 20:02:50 +0100, Ary Manzana a...@esperanto.org.ar wrote: Here's what you can do in Ruby: a = 1 b = 2 # Swap the contents a, b = b, a Can you do something like that with templates in D, with a nice syntax? template to(T...) {

Re: Multiple return values...

2012-03-14 Thread Manu
On 14 March 2012 22:10, Ary Manzana a...@esperanto.org.ar wrote: On 3/14/12 5:00 PM, Simen Kjærås wrote: On Wed, 14 Mar 2012 20:02:50 +0100, Ary Manzana a...@esperanto.org.ar wrote: Here's what you can do in Ruby: a = 1 b = 2 # Swap the contents a, b = b, a Can you do something

Re: Tuple unpacking syntax [Was: Re: Multiple return values...]

2012-03-14 Thread Manu
On 14 March 2012 15:17, Robert Jacques sandf...@jhu.edu wrote: But there's a reason we use /// instead of ⫻; we shouldn't require custom keyboard mappings in order to program efficiently in D. Hold that thought, I think you're missing a major franchising opportunity right there... D branded

Re: Multiple return values...

2012-03-14 Thread Andrei Alexandrescu
On 3/14/12 3:00 PM, Simen Kjærås wrote: template to(T...) { alias T to; } auto from(T...)(T t) { struct Result { T t; alias t this; } return Result( t ); } void main( ) { int a = 3; int b = 4; to!(a, b) = from(b, a); assert( a == 4 ); assert( b == 3 ); } I got reborn inside a little when

Re: Multiple return values...

2012-03-14 Thread Derek Parnell
On Thu, 15 Mar 2012 08:52:26 +1100, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: On 3/14/12 3:00 PM, Simen Kjærås wrote: template to(T...) { alias T to; } auto from(T...)(T t) { struct Result { T t; alias t this; } return Result( t ); } void main( ) { int a = 3; int b = 4;

Re: Multiple return values...

2012-03-14 Thread Simen Kjærås
On Wed, 14 Mar 2012 22:52:26 +0100, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: On 3/14/12 3:00 PM, Simen Kjærås wrote: template to(T...) { alias T to; } auto from(T...)(T t) { struct Result { T t; alias t this; } return Result( t ); } void main( ) { int a = 3; int b = 4;

Re: Tuple unpacking syntax [Was: Re: Multiple return values...]

2012-03-14 Thread foobar
On Wednesday, 14 March 2012 at 13:17:47 UTC, Robert Jacques wrote: snip But there's a reason we use /// instead of ⫻; we shouldn't require custom keyboard mappings in order to program efficiently in D. Aren't we supposed to be moving towards more natural interfaces in computing? I'm sure

Re: Multiple return values...

2012-03-13 Thread Manu
On 13 March 2012 06:45, Andrei Alexandrescu seewebsiteforem...@erdani.orgwrote: You see, at this point I have no idea what to believe anymore. You argued very strongly from the position of one whose life depends on efficiency. Here and there you'd mix some remark about syntax, and I'd like

Re: Multiple return values...

2012-03-13 Thread Iain Buclaw
On 13 March 2012 09:12, Manu turkey...@gmail.com wrote: On 13 March 2012 06:45, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: You see, at this point I have no idea what to believe anymore. You argued very strongly from the position of one whose life depends on efficiency. Here and

Re: Multiple return values...

2012-03-13 Thread Manu
On 13 March 2012 13:27, Iain Buclaw ibuc...@ubuntu.com wrote: What about alternative optimisations for MRV, rather than stating that it should always be returned in registers where possible (and breaking ABI on all target platforms). What about, for example, using named return value

Re: Multiple return values...

2012-03-13 Thread Andrei Alexandrescu
On 3/13/12 4:12 AM, Manu wrote: I think I feel a sense of urgency towards the ABI aspect because it is a breaking change, and I suspect the longer anything like that is left, the less likely/more risky it becomes. If it gets delayed for 6-12 months, are you honestly more or less likely to say

Re: Multiple return values...

2012-03-13 Thread Manu
On 13 March 2012 16:44, Andrei Alexandrescu seewebsiteforem...@erdani.orgwrote: I thought more about it and we should be fine with two functions (untested): enum Skip {}; @property ref Skip skip() { static __gshared Skip result; return result; } void scatter(T, U...)(auto ref T

Re: Multiple return values...

2012-03-13 Thread Andrei Alexandrescu
On 3/13/12 10:48 AM, Manu wrote: float t; ... (myStruct.pos, t, _, int err) = intersectThings(); I actually find the scatter syntax better than this. Anyway, I hope you'll agree there's not much difference pragmatically. Andrei

Re: Multiple return values...

2012-03-13 Thread Manu
On 13 March 2012 18:07, Andrei Alexandrescu seewebsiteforem...@erdani.orgwrote: On 3/13/12 10:48 AM, Manu wrote: float t; ... (myStruct.pos, t, _, int err) = intersectThings(); I actually find the scatter syntax better than this. Anyway, I hope you'll agree there's not much difference

Re: Multiple return values...

2012-03-13 Thread Andrei Alexandrescu
On 3/13/12 12:02 PM, Manu wrote: There's a few finicky differences. I'm still of the understanding (and I may be wrong, still mystified by some of D's more complicated template syntax) that once you give the returned tuple a name, it is structurally bound to the stack. At that point, passing any

Re: Multiple return values...

2012-03-13 Thread Manu
On 13 March 2012 19:25, Andrei Alexandrescu seewebsiteforem...@erdani.orgwrote: On 3/13/12 12:02 PM, Manu wrote: There's a few finicky differences. I'm still of the understanding (and I may be wrong, still mystified by some of D's more complicated template syntax) that once you give the

Re: Multiple return values...

2012-03-13 Thread Jose Armando Garcia
On Tue, Mar 13, 2012 at 9:07 AM, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: On 3/13/12 10:48 AM, Manu wrote: float t; ... (myStruct.pos, t, _, int err) = intersectThings(); This can be checked at compile time. The D compiler can check that the number of arguments and the types

Re: Multiple return values...

2012-03-13 Thread Andrei Alexandrescu
On 3/13/12 2:07 PM, Jose Armando Garcia wrote: On Tue, Mar 13, 2012 at 9:07 AM, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: On 3/13/12 10:48 AM, Manu wrote: float t; ... (myStruct.pos, t, _, int err) = intersectThings(); This can be checked at compile time. The D compiler

Re: Multiple return values...

2012-03-13 Thread Andrei Alexandrescu
On 3/13/12 1:20 PM, Manu wrote: What value does it add over Kenji's change? Is this because Kenji's change is unable to perform direct to existing variables? Yes. My understanding from early in the thread was that Kenji's change hides the returned tuple, and performs a convenient unpack. How

Re: Multiple return values...

2012-03-13 Thread Manu
On 13 March 2012 21:40, Andrei Alexandrescu seewebsiteforem...@erdani.orgwrote: On 3/13/12 1:20 PM, Manu wrote: What value does it add over Kenji's change? Is this because Kenji's change is unable to perform direct to existing variables? Yes. My understanding from early in the thread

Re: Multiple return values...

2012-03-13 Thread Andrei Alexandrescu
On 3/13/12 2:57 PM, Manu wrote: And you think that's more readable and intuitive than: (v1, v2, v3) = fun(); ? Yes (e.g. when I see the commas my mind starts running in all directions because that's valid code nowadays that ignores v1 and v2 and keeps v3 as an lvalue). Let me put it

Tuple unpacking syntax [Was: Re: Multiple return values...]

2012-03-13 Thread bearophile
Andrei Alexandrescu: Let me put it another way: I don't see one syntax over another a deal maker or deal breaker. At all. I am usually able to follow threads, but this time I am a bit lost (this discussion has mixed very different topics like ABIs, implementation efficiency of tuples and

Re: Tuple unpacking syntax [Was: Re: Multiple return values...]

2012-03-13 Thread Michael
Maybe [x, y] = func(); ?

Re: Tuple unpacking syntax [Was: Re: Multiple return values...]

2012-03-13 Thread foobar
On Tuesday, 13 March 2012 at 22:26:14 UTC, bearophile wrote: Andrei Alexandrescu: Let me put it another way: I don't see one syntax over another a deal maker or deal breaker. At all. I am usually able to follow threads, but this time I am a bit lost (this discussion has mixed very different

Re: Multiple return values...

2012-03-13 Thread Martin Nowak
Shall we discuss the shortcomings of his implementation? Can someone demonstrate the details of his implementation? From the little examples up in the thread, it looked like you could only declare new variables inline, but not assign out to existing ones. I'd say this needs to be added too, and

Re: Tuple unpacking syntax [Was: Re: Multiple return values...]

2012-03-13 Thread Derek Parnell
On Wed, 14 Mar 2012 13:33:18 +1100, Kevin Cox kevincox...@gmail.com wrote: Kind of unrelated but I think that it is important to have a way to ignore values also. Leaving them bank would sufice. (int i,,float f) = intBoringFloat(); For what its worth, the Euphoria Programming Language

Re: Multiple return values...

2012-03-12 Thread Timon Gehr
On 03/12/2012 05:01 AM, Robert Jacques wrote: On Sun, 11 Mar 2012 21:49:52 -0500, Mantis mail.mantis...@gmail.com wrote: 12.03.2012 4:00, Robert Jacques пишет: On Sun, 11 Mar 2012 18:15:31 -0500, Timon Gehr timon.g...@gmx.ch wrote: On 03/11/2012 11:58 PM, Robert Jacques wrote: Manu was

Re: Multiple return values...

2012-03-12 Thread Manu
On 12 March 2012 04:44, Andrei Alexandrescu seewebsiteforem...@erdani.orgwrote: On 3/11/12 6:30 PM, Manu wrote: D should define an MRV ABI which is precisely the ABI for passing multiple args TO a function, but in reverse, for any given architecture. This also has the lovely side effect of

Re: Multiple return values...

2012-03-12 Thread Manu
On 12 March 2012 04:00, Robert Jacques sandf...@jhu.edu wrote: On Sun, 11 Mar 2012 18:15:31 -0500, Timon Gehr timon.g...@gmx.ch wrote: On 03/11/2012 11:58 PM, Robert Jacques wrote: Manu was arguing that MRV were somehow special and had mystical optimization potential. That's simply not

Re: Multiple return values...

2012-03-12 Thread Mantis
12.03.2012 6:01, Robert Jacques пишет: On Sun, 11 Mar 2012 21:49:52 -0500, Mantis mail.mantis...@gmail.com wrote: [...] That's the point of discussion. Fields of structure may not be optimized away, because they are not independent variables. In D you have unchecked pointer-to-pointer casts,

Re: Multiple return values...

2012-03-12 Thread RivenTheMage
So, function with MRV is basically the function that returns Tuple where one can specify return convention? --- auto fun() { return(Windows) tuple(1, 2.0f); } (int x, float y) = fun(); ---

Re: Multiple return values...

2012-03-12 Thread Iain Buclaw
On 12 March 2012 01:37, Andrew Wiley wiley.andre...@gmail.com wrote: On Sun, Mar 11, 2012 at 7:44 PM, Manu turkey...@gmail.com wrote: On 12 March 2012 00:58, Robert Jacques sandf...@jhu.edu wrote: That's an argument for using the right register for the job. And we can / will be doing this on

Re: Multiple return values...

2012-03-12 Thread Iain Buclaw
On 12 March 2012 00:44, Manu turkey...@gmail.com wrote: On 12 March 2012 00:58, Robert Jacques sandf...@jhu.edu wrote: That's an argument for using the right register for the job. And we can / will be doing this on x86-64, as other compilers have already done. Manu was arguing that MRV were

Re: Multiple return values...

2012-03-12 Thread Manu
On 12 March 2012 19:03, Iain Buclaw ibuc...@ubuntu.com wrote: On 12 March 2012 00:44, Manu turkey...@gmail.com wrote: On 12 March 2012 00:58, Robert Jacques sandf...@jhu.edu wrote: That's an argument for using the right register for the job. And we can / will be doing this on x86-64, as

Re: Multiple return values...

2012-03-12 Thread Iain Buclaw
On 12 March 2012 17:22, Manu turkey...@gmail.com wrote: On 12 March 2012 19:03, Iain Buclaw ibuc...@ubuntu.com wrote: On 12 March 2012 00:44, Manu turkey...@gmail.com wrote: On 12 March 2012 00:58, Robert Jacques sandf...@jhu.edu wrote: That's an argument for using the right register for

Re: Multiple return values...

2012-03-12 Thread Iain Buclaw
On 12 March 2012 17:49, Iain Buclaw ibuc...@ubuntu.com wrote: On 12 March 2012 17:22, Manu turkey...@gmail.com wrote: On 12 March 2012 19:03, Iain Buclaw ibuc...@ubuntu.com wrote: On 12 March 2012 00:44, Manu turkey...@gmail.com wrote: On 12 March 2012 00:58, Robert Jacques sandf...@jhu.edu

Re: Multiple return values...

2012-03-12 Thread Manu
On 12 March 2012 19:49, Iain Buclaw ibuc...@ubuntu.com wrote: OK, -msse2 is not an ARM target option. :~) Oh sorry, I thought you were asking about the x86 codegen ;) I used -S -O2 -float-abi=hard Looking around, the Procedure Call Standard for the ARM Architecture specifically says

Re: Multiple return values...

2012-03-12 Thread Iain Buclaw
On 12 March 2012 17:59, Manu turkey...@gmail.com wrote: On 12 March 2012 19:49, Iain Buclaw ibuc...@ubuntu.com wrote: OK, -msse2 is not an ARM target option. :~) Oh sorry, I thought you were asking about the x86 codegen ;) I used -S -O2 -float-abi=hard Looking around, the Procedure Call

Re: Multiple return values...

2012-03-12 Thread Robert Jacques
On Mon, 12 Mar 2012 02:15:55 -0500, Timon Gehr timon.g...@gmx.ch wrote: On 03/12/2012 05:01 AM, Robert Jacques wrote: On Sun, 11 Mar 2012 21:49:52 -0500, Mantis mail.mantis...@gmail.com wrote: 12.03.2012 4:00, Robert Jacques пишет: On Sun, 11 Mar 2012 18:15:31 -0500, Timon Gehr

Re: Multiple return values...

2012-03-12 Thread Robert Jacques
On Mon, 12 Mar 2012 04:46:45 -0500, Mantis mail.mantis...@gmail.com wrote: 12.03.2012 6:01, Robert Jacques пишет: On Sun, 11 Mar 2012 21:49:52 -0500, Mantis mail.mantis...@gmail.com wrote: [...] That's the point of discussion. Fields of structure may not be optimized away, because they are not

Re: Multiple return values...

2012-03-12 Thread Robert Jacques
On Mon, 12 Mar 2012 04:25:54 -0500, Manu turkey...@gmail.com wrote: On 12 March 2012 04:00, Robert Jacques sandf...@jhu.edu wrote: On Sun, 11 Mar 2012 18:15:31 -0500, Timon Gehr timon.g...@gmx.ch wrote: On 03/11/2012 11:58 PM, Robert Jacques wrote: Manu was arguing that MRV were somehow

Re: Multiple return values...

2012-03-12 Thread Martin Nowak
Is this basically like saying it'll never happen? There is already a pending pull request implementing the syntax, that addresses half of the feature straight up.. codegen can come later, I agreed earlier that it is of lesser importance. You don't see the immediate value in a convenient MRV

Re: Multiple return values...

2012-03-12 Thread Andrei Alexandrescu
On 3/12/12 3:37 AM, Manu wrote: On 12 March 2012 04:44, Andrei Alexandrescu seewebsiteforem...@erdani.org mailto:seewebsiteforem...@erdani.org wrote: On 3/11/12 6:30 PM, Manu wrote: D should define an MRV ABI which is precisely the ABI for passing multiple args

  1   2   3   >