digitalmars.D.learn - swap doesn't work in CTFE?
- Johann MacDonagh (21/21) Jul 04 2011 Although CTFE supports ref parameters, swap doesn't appear to work. This...
- Daniel Murphy (18/39) Jul 04 2011 Same thing happens with pointers. Reduced:
- bearophile (4/5) Jul 04 2011 Pointers to structs in CTFE will work in DMD 2.054 :-)
- Daniel Murphy (4/7) Jul 04 2011 When they don't crash the compiler, that is.
- Ary Manzana (6/15) Jul 05 2011 Is there any point in implementing CTFE in the compiler when LLVM
- Jonathan M Davis (12/28) Jul 05 2011 CTFE has a major impact on how programs are compiled. It wouldn't make a...
- Johann MacDonagh (4/13) Jul 05 2011 Perfect! Thank you. I verified the exception is a stack overflow for the...
Although CTFE supports ref parameters, swap doesn't appear to work. This casues dmd to segfault in 2.053 and the current dmd master. import std.algorithm; import std.stdio; string ctfeRef(ref string a, ref string b) { return a; } string ctfeSort() { auto x = [ "a", "c", "b" ]; swap(x[1], x[0]); // This is the problem here return ctfeRef(x[1], x[0]); } void main() { enum xx = ctfeSort(); writeln(xx); } This means things like sort won't work in CTFE. Does anyone know if this is a known bug? My searching didn't bring anything up.
Jul 04 2011
"Johann MacDonagh" <johann.macdonagh..no spam..gmail.com> wrote in message news:iusp80$vnr$1 digitalmars.com...Although CTFE supports ref parameters, swap doesn't appear to work. This casues dmd to segfault in 2.053 and the current dmd master. import std.algorithm; import std.stdio; string ctfeRef(ref string a, ref string b) { return a; } string ctfeSort() { auto x = [ "a", "c", "b" ]; swap(x[1], x[0]); // This is the problem here return ctfeRef(x[1], x[0]); } void main() { enum xx = ctfeSort(); writeln(xx); } This means things like sort won't work in CTFE. Does anyone know if this is a known bug? My searching didn't bring anything up.Same thing happens with pointers. Reduced: void swap(int[]* lhs, int[]* rhs) { *lhs = *rhs; *rhs = *lhs; } int ctfeSort() { int[][2] x; swap(&x[0], &x[1]); return 0; } void main() { enum x = ctfeSort(); }
Jul 04 2011
Daniel Murphy:Same thing happens with pointers. Reduced:Pointers to structs in CTFE will work in DMD 2.054 :-) Bye, bearophile
Jul 04 2011
"bearophile" <bearophileHUGS lycos.com> wrote in message news:iut093$1bjg$1 digitalmars.com...Daniel Murphy:When they don't crash the compiler, that is. http://d.puremagic.com/issues/show_bug.cgi?id=6250Same thing happens with pointers. Reduced:Pointers to structs in CTFE will work in DMD 2.054 :-)
Jul 04 2011
On 7/4/11 11:39 PM, Daniel Murphy wrote:"bearophile"<bearophileHUGS lycos.com> wrote in message news:iut093$1bjg$1 digitalmars.com...Is there any point in implementing CTFE in the compiler when LLVM already allows you to define functions and JIT compile them? Why write yet another "JIT compiler" that in fact doesn't optimize anything and just interprets everything as it comes? I'm sure with LLVM you can do all of what DMD currently does and more.Daniel Murphy:When they don't crash the compiler, that is. http://d.puremagic.com/issues/show_bug.cgi?id=6250Same thing happens with pointers. Reduced:Pointers to structs in CTFE will work in DMD 2.054 :-)
Jul 05 2011
On 2011-07-05 12:10, Ary Manzana wrote:On 7/4/11 11:39 PM, Daniel Murphy wrote:CTFE has a major impact on how programs are compiled. It wouldn't make any sense to try and take it out the compiler itself. Not only does it affect what you can initialize module and static variables to, but you can use it in conditional compilation and template instantiation. It's an integral part of the language itself and an integral part of the compilation process. Splitting it out wouldn't work. Not to mention, CTFE happens in the _frontend_ of the compiler, not the backend, and LLVM is the backend of LDC. dmd, gdc, and LDC all share the same frontend. So, unless the JIT compiler were in the frontend, it wouldn't matter on whit how good it is, because it couldn't be used in the frontend - which is where CTFE needs to happen. - Jonathan M Davis"bearophile"<bearophileHUGS lycos.com> wrote in message news:iut093$1bjg$1 digitalmars.com...Is there any point in implementing CTFE in the compiler when LLVM already allows you to define functions and JIT compile them? Why write yet another "JIT compiler" that in fact doesn't optimize anything and just interprets everything as it comes? I'm sure with LLVM you can do all of what DMD currently does and more.Daniel Murphy:When they don't crash the compiler, that is. http://d.puremagic.com/issues/show_bug.cgi?id=6250Same thing happens with pointers. Reduced:Pointers to structs in CTFE will work in DMD 2.054 :-)
Jul 05 2011
On 7/4/2011 10:39 PM, Daniel Murphy wrote:"bearophile"<bearophileHUGS lycos.com> wrote in message news:iut093$1bjg$1 digitalmars.com...Perfect! Thank you. I verified the exception is a stack overflow for the ref case as well (but since you know the compiler internals I'm sure you knew that already ;) ).Daniel Murphy:When they don't crash the compiler, that is. http://d.puremagic.com/issues/show_bug.cgi?id=6250Same thing happens with pointers. Reduced:Pointers to structs in CTFE will work in DMD 2.054 :-)
Jul 05 2011