[Issue 3713] New: Tail call optimization not enabled with the ?: operator
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Jan 16 20:40:57 PST 2010
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 at puremagic.com
ReportedBy: andrei at metalanguage.com
--- Comment #0 from Andrei Alexandrescu <andrei at metalanguage.com> 2010-01-16 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: -------
More information about the Digitalmars-d-bugs
mailing list