digitalmars.D.bugs - [Issue 3713] New: Tail call optimization not enabled with the ?: operator
- d-bugmail puremagic.com (57/57) Jan 16 2010 http://d.puremagic.com/issues/show_bug.cgi?id=3713
- d-bugmail puremagic.com (11/11) Feb 20 2012 http://d.puremagic.com/issues/show_bug.cgi?id=3713
- d-bugmail puremagic.com (10/10) Oct 04 2013 http://d.puremagic.com/issues/show_bug.cgi?id=3713
- d-bugmail puremagic.com (12/12) Oct 04 2013 http://d.puremagic.com/issues/show_bug.cgi?id=3713
http://d.puremagic.com/issues/show_bug.cgi?id=3713 Summary: Tail call optimization not enabled with the ?: operator Product: D Version: unspecified Platform: Other OS/Version: Linux Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: andrei metalanguage.com 20:40:56 PST --- Consider: bool b1search(int[] a, int x) { if (!a.length) return 0; auto mid = a.length / 2; auto e = a[mid]; return x == e ? true : x < e ? b1search(a[0 .. mid], x) : b1search(a[mid + 1 .. $], x); } bool b2search(int[] a, int x) { if (!a.length) return 0; auto mid = a.length / 2; auto e = a[mid]; if (x == e) return true; return x < e ? b2search(a[0 .. mid], x) : b2search(a[mid + 1 .. $], x); } bool b3search(int[] a, int x) { if (!a.length) return 0; auto mid = a.length / 2; auto e = a[mid]; if (x == e) return true; if (x < e) return b3search(a[0 .. mid], x); return b3search(a[mid + 1 .. $], x); } bool b4search(int[] a, int x) { if (!a.length) return 0; auto mid = a.length / 2; auto e = a[mid]; if (x == e) return true; return b4search(x < e ? a[0 .. mid] : a[mid + 1 .. $], x); } void main() { } After compiling with: dmd -O -release test and looking at the generated object file, only b3search and b4search are tail-call optimized, but not b1search and b2search. Tail-call optimization doesn't seem to work when a ternary expression is used with return. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 16 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3713 yebblies <yebblies gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords|performance |pull, wrong-code AssignedTo|nobody puremagic.com |yebblies gmail.com https://github.com/D-Programming-Language/dmd/pull/745 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 20 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3713 20:01:14 PDT --- Created an attachment (id=1257) Partial solution I took a stab at this one. I've gotten b2search to compile to the same assembly code as b3search. I did not handle nested ternary operators following a return statement. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 04 2013
http://d.puremagic.com/issues/show_bug.cgi?id=3713 safety0ff.bugz <safety0ff.bugz gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- is obsolete| | 20:11:47 PDT --- Created an attachment (id=1258) Partial solution -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 04 2013