On 2013-12-07 00:56, Walter Bright wrote:
2. D knows when functions are pure. C has to make worst case
assumptions.
Does the compiler currently take advantage of this?
dmd does.
Compiling the following code:
pure int foo (immutable int a, immutable int b)
{
return a + b;
}
void main ()
{
auto a = foo(1, 2);
auto b = foo(1, 2);
auto c = a + b;
}
With DMD 2.064.2 produce the exact same assembly code for "foo" and
"main" with our without "pure". I compiled with "dmd -O -release foo.d",
am I doing something wrong?
This is about inherent language opportunities, not whether current
implementations fall short or not.
I think most people will care about what's working right now. Not what
could possibly work sometime in the future.
--
/Jacob Carlborg