pure is as pure does with LLVM compiler

2014-01-13 Thread Ben Cumming

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);
}


Re: pure is as pure does with LLVM compiler

2014-01-13 Thread Dicebot

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.


Re: pure is as pure does with LLVM compiler

2014-01-13 Thread Ben Cumming

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...


Re: pure is as pure does with LLVM compiler

2014-01-13 Thread Dicebot

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


Re: pure is as pure does with LLVM compiler

2014-01-13 Thread Ben Cumming

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.


Re: pure is as pure does with LLVM compiler

2014-01-13 Thread David Nadlinger

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