Thread overview
pure is as pure does with LLVM compiler
Jan 13, 2014
Ben Cumming
Jan 13, 2014
Dicebot
Jan 13, 2014
Ben Cumming
Jan 13, 2014
Dicebot
Jan 13, 2014
Ben Cumming
Jan 13, 2014
David Nadlinger
January 13, 2014
Hi There,

I am playing around CTFE, and I get different compile time
behavior with the reference compiler (both 64-bit Linux):
      DMD64 D Compiler v2.064
and the LLVM compiler:
      LDC - the LLVM D compiler (37ee99): based on DMD v2.063.2 and
LLVM 3.3

The code snippet at the bottom of the post compiles fine with the
reference compiler, but with LDC I get the following error:
> ldc2 example.d
example.d(4): Error: pure function 'append_index' cannot call
impure function 'to'

'to' is not pure, however it seems the reference compiler is able
to determine that to is effectively pure. If I remove the 'pure'
keyword from the definition of 'append_index', the problem is
resolved.

Is it "reasonable" that ldc gives this error?
What is the best practice in this situation (I require the result
of such function calls for constructing more complicated strings
at compile time).

------------------------------------------------------

import std.conv;

string append_index(uint i) pure {
          return "v_" ~ to!string(i);
}

void main() {
      static assert(A.append_index(3)=="v_3");
}
January 13, 2014
On Monday, 13 January 2014 at 13:37:05 UTC, Ben Cumming wrote:
> Hi There,
>
> I am playing around CTFE, and I get different compile time
> behavior with the reference compiler (both 64-bit Linux):
>       DMD64 D Compiler v2.064
> and the LLVM compiler:
>       LDC - the LLVM D compiler (37ee99): based on DMD v2.063.2 and
> LLVM 3.3

This is the answer. Current LDC is still based on 2.063.2 version of frontend. There have been several tweaks in `std.conv` to make `to` more pure-friendly between those two releases.
January 13, 2014
On Monday, 13 January 2014 at 13:46:26 UTC, Dicebot wrote:
> This is the answer. Current LDC is still based on 2.063.2 version of frontend. There have been several tweaks in `std.conv` to make `to` more pure-friendly between those two releases.

Thanks! I will recompile the latest version of LDC then...
January 13, 2014
On Monday, 13 January 2014 at 14:18:49 UTC, Ben Cumming wrote:
> On Monday, 13 January 2014 at 13:46:26 UTC, Dicebot wrote:
>> This is the answer. Current LDC is still based on 2.063.2 version of frontend. There have been several tweaks in `std.conv` to make `to` more pure-friendly between those two releases.
>
> Thanks! I will recompile the latest version of LDC then...

I don't think 2.064 LDC has been released yet
January 13, 2014
On Monday, 13 January 2014 at 14:32:03 UTC, Dicebot wrote:
> I don't think 2.064 LDC has been released yet

So I see, thanks.
January 13, 2014
On Monday, 13 January 2014 at 15:12:21 UTC, Ben Cumming wrote:
> On Monday, 13 January 2014 at 14:32:03 UTC, Dicebot wrote:
>> I don't think 2.064 LDC has been released yet
>
> So I see, thanks.

The "merge-2.064" branch in Git is stable enough already for most purposes, so if you don't mind building from Git, you can have an LDC version based on 2.064.2 already.

We really need to work out a plan to get a release done… ;)

David