Jump to page: 1 2
Thread overview
[Issue 8542] New: crosstalk between template instantiations
Aug 12, 2012
timon.gehr@gmx.ch
Aug 12, 2012
timon.gehr@gmx.ch
Aug 17, 2012
deadalnix
Oct 19, 2012
Jesse Phillips
Jan 04, 2013
Walter Bright
August 12, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8542

           Summary: crosstalk between template instantiations
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: timon.gehr@gmx.ch


--- Comment #0 from timon.gehr@gmx.ch 2012-08-12 12:41:55 PDT ---
With DMD 2.060, the following code compiles and runs correctly with dmd
-version=A and dmd -version=B, but it fails to compile with
dmd -version=A -version=B

The code should compile and run correctly even when both version specifiers are set.

import std.stdio, std.algorithm, std.range, std.bigint; template Apply(alias a,T...){ alias a!T Apply; }

auto fun(T)(T n, T function(T) i, T function(T) d){
    return
    (z=>((T delegate(T,T) delegate(T delegate(T delegate(T,T),T,T)) AOY)
    =>((m,e)=>reduce!((a,b)=>AOY((f,a,b)=>z(a)?b:i(f(d(a),
    b)))(a,b))(zip([(T[] a)=>a.map!((T x)=>m(i(i(n)),x)).array,(T[]
    a)=>a.map!((T x)=>m(i(i(i(n))),x)).array,delegate(T[] a)=>a.map!
    (a=>a).array].map!(a=>&Apply!(map!a,T[][])),[[i(n),i(i(n)),i(i(i(n))),
    i(i(i(i(n)))),i(i(i(i(i(n))))),i(i(i(i(i(i(n))))))],

[i(i(i(i(i(n))))),i(i(i(i(i(i(n)))))),i(i(i(i(i(i(i(n))))))),i(i(i(i(i(i(i(i(n)))))))),

i(i(i(i(i(i(i(i(i(n))))))))),i(i(i(i(n))))],[e(n,i(n)),e(i(n),i(i(n))),e(i(i(n)),i(n))]]

).map!(t=>t[0](t[1].map!(a=>[a,i(a),m(a,i(i(n)))]).array)).joiner.map!(a=>zip(a,retro(a))

.map!(t=>AOY((f,a,b)=>z(a)?b:i(f(d(a),b)))(t[0],t[1]))).joiner.chain(repeat(
    i(i(i(i(i(i(i(i(i(i(i(i(n))))))))))))).map!(a=>AOY
    ((f,a,b)=>z(b)?a:f(d(a),d(b)))(a,i(i(i(i(i(i(i(i(i(i(i(i(i(n)))))))))))
    )))).take(1))))((T a,T b)=>AOY((f,a,b)=>z(a)?n:AOY((g,a,b)=>z(a)?

b:i(g(d(a),b)))(b,f(d(a),b)))(a,b),AOY((h,a,b)=>z(a)?z(b)?i(n):n:z(b)?n:h(d(a),d(b)))))(
    (a){struct S{ T delegate(T,T) delegate(S) r; } return
    ((x)=>x(S(x)))((S x)=>(T u,T v)=>a(x.r(x),u,v)); }))((T a)=>a==n);
}

void main(){
    version(A) assert(fun(0,(int a)=>a+1,(int a)=>a-1)==1337);

    static inc(int[] a){
        if(!a.length) return [1];
        if(a[0]<0) return a[0..$-1];
        return a~(a[$-1]+1);
    }

    static dec(int[] a){
        if(!a.length) return [-1];
        if(a[0]>0) return a[0..$-1];
        return a~(a[$-1]-1);
    }

    version(B) assert(fun((int[]).init,&inc,&dec).equal(iota(1,1338)));
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 12, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8542



--- Comment #1 from timon.gehr@gmx.ch 2012-08-12 12:45:44 PDT ---
importing std.bigint is not required to reproduce.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 17, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8542


deadalnix <deadalnix@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |deadalnix@gmail.com


--- Comment #3 from deadalnix <deadalnix@gmail.com> 2012-08-17 08:04:37 PDT ---
import std.algorithm, std.range;
template Apply(alias a,T...){ alias a!T Apply; }
auto fun(T)(T n, T function(T) i, T function(T) ){
(z=>(T delegate(T,T) delegate(T delegate(T delegate(T,T),T,T)) AOY)
=>((m,e)=>reduce!((a,b)=>AOY((f,a,b)=>z?b:i(a))(a,b))(zip([(T[]
a)=>a.map!(x=>m(n,x))].map!(a=>&Apply!(map!a,T[][])),[[n]]).map!(t=>t[0](t[1].map!(a=>[a]).array)).joiner.map!(a=>zip(a,retro(a)).map!(t=>AOY((f,a,b)=>z?b:i(a))(t[0],t[1]))).joiner.chain))((T
a,T b)=>AOY((f,a,b)=>z?n:AOY((g,a,b)=>z?b:i(a))(b,f(a,b)))(a,b),AOY))((T
a)=>a==n);
}
void main(){
version(A) fun(0,(int a)=>a+1,(int a)=>a-1);
static inc(int[] a){
return a;
}
static dec(int[] a){
return a;
}
version(B) fun((int[]).init,&inc,&dec);
}

I reduced it to that. I fail to got further.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 17, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8542


hsteoh@quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh@quickfur.ath.cx


--- Comment #4 from hsteoh@quickfur.ath.cx 2012-10-16 17:24:02 PDT ---
Here's a somewhat simpler case:

auto cprod(R1,R2)(R1 A, R2 B)
{
    return zip(sequence!"n"(cast(size_t)0), A.save, B.save, repeat(A),
repeat(B))
        .map!(function(a) => chain(
            zip(repeat(a[1]), take(a[4].save,a[0])),
            zip(take(a[3].save,a[0]+1), repeat(a[2]))
        )).joiner;
}

void main()
{
    auto A = sequence!"2*n"(0);
    auto B = sequence!"2*n+1"(0);
    auto AB = cprod(A,B);

    auto C = sequence!"100+n"(0);
    auto D = sequence!"200+n"(0);
    auto CD = cprod(C,D);
}

Produces the error:

Error: function
test3.cprod!(Sequence!("2*n",Tuple!(int)),Sequence!("2*n+1",Tuple!(int))).cprod.map!(__
funcliteral2).map!(Zip!(Sequence!("n",Tuple!(uint)),Sequence!("100+n",Tuple!(int)),Sequence!("200+n",Tupl
e!(int)),Repeat!(Sequence!("100+n",Tuple!(int))),Repeat!(Sequence!("200+n",Tuple!(int))))).map
is a neste
d function and cannot be accessed from
test3.cprod!(Sequence!("100+n",Tuple!(int)),Sequence!("200+n",Tupl
e!(int))).cprod


Commenting out either the first three lines (A, B, AB) or the second three
lines (C, D, CD) makes the problem go away.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 19, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8542


Jesse Phillips <Jesse.K.Phillips+D@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Jesse.K.Phillips+D@gmail.co
                   |                            |m


--- Comment #5 from Jesse Phillips <Jesse.K.Phillips+D@gmail.com> 2012-10-19 11:23:02 PDT ---
I may have duplicated this issue:

http://d.puremagic.com/issues/show_bug.cgi?id=8850

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 04, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=8542



--- Comment #6 from hsteoh@quickfur.ath.cx 2013-01-03 21:39:09 PST ---
Here's an unexpected data point: I discovered that this bug may be linked to the -property compiler flag. To reproduce this odd effect, checkout the code from: https://github.com/D-Programming-Language/phobos/pull/856, build Phobos without unittest, then check the output of the following commands (I tested this on Linux/64):

1) This one compiles just fine:

dmd -unittest -m64 std/algorithm.d generated/linux/debug/64/emptymain.d -of/tmp/x

2) This one produces a whole bunch of template crosstalk errors:

dmd -property -unittest -m64 std/algorithm.d generated/linux/debug/64/emptymain.d -of/tmp/x

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 04, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=8542



--- Comment #7 from hsteoh@quickfur.ath.cx 2013-01-03 21:43:08 PST ---
Hmm, the -property effect also happens with the simpler test case I posted earlier in comment 4:

$ dmd test.d
$ # Compiled successfully
$ dmd -property test.d
test.d(5): Error: no property 'map' for type 'Zip!(Sequence!("n",
Tuple!(ulong)), Sequence!("2*n", Tuple!(int)), Sequence!("2*n+1", Tuple!(int)),
Repeat!(Sequence!("2*n", Tuple!(int))), Repeat!(Sequence!("2*n+1",
Tuple!(int))))'
test.d(17): Error: template instance test.cprod!(Sequence!("2*n", Tuple!(int)),
Sequence!("2*n+1", Tuple!(int))) error instantiating
test.d(5): Error: no property 'map' for type 'Zip!(Sequence!("n",
Tuple!(ulong)), Sequence!("100+n", Tuple!(int)), Sequence!("200+n",
Tuple!(int)), Repeat!(Sequence!("100+n", Tuple!(int))),
Repeat!(Sequence!("200+n", Tuple!(int))))'
test.d(21): Error: template instance test.cprod!(Sequence!("100+n",
Tuple!(int)), Sequence!("200+n", Tuple!(int))) error instantiating
$

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 04, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=8542



--- Comment #8 from hsteoh@quickfur.ath.cx 2013-01-03 21:49:54 PST ---
Actually, nevermind that. I just realized that -property requires () for map
and joiner because they aren't declared with @property (and UFCS does not
alleviate the need for parentheses).

The sad thing, though, is that my reduced test case no longer produces template crosstalk in git HEAD. :-(

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 04, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=8542



--- Comment #9 from hsteoh@quickfur.ath.cx 2013-01-03 22:01:51 PST ---
Hmph. It seems that Timon's original code also compiles fine in git head (without -property). With -property it fails, but seems the reason is that -property requires functions like map and joiner to have trailing parentheses (). The template crosstalk problem seems to have gone away.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 04, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=8542



--- Comment #10 from hsteoh@quickfur.ath.cx 2013-01-03 22:28:37 PST ---
git bisect appears to indicate that it was dmd commit 688f7ce593eef75997a2b8f2527d3cd9338692aa that fixed this issue.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2