digitalmars.D.bugs - [Issue 8542] New: crosstalk between template instantiations
- d-bugmail puremagic.com (62/62) Aug 12 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8542
- d-bugmail puremagic.com (6/6) Aug 12 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8542
- d-bugmail puremagic.com (29/29) Aug 17 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8542
- d-bugmail puremagic.com (39/39) Oct 16 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8542
- d-bugmail puremagic.com (12/12) Oct 19 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8542
- d-bugmail puremagic.com (16/16) Jan 03 2013 http://d.puremagic.com/issues/show_bug.cgi?id=8542
- d-bugmail puremagic.com (23/23) Jan 03 2013 http://d.puremagic.com/issues/show_bug.cgi?id=8542
- d-bugmail puremagic.com (10/10) Jan 03 2013 http://d.puremagic.com/issues/show_bug.cgi?id=8542
- d-bugmail puremagic.com (9/9) Jan 03 2013 http://d.puremagic.com/issues/show_bug.cgi?id=8542
- d-bugmail puremagic.com (7/7) Jan 03 2013 http://d.puremagic.com/issues/show_bug.cgi?id=8542
- d-bugmail puremagic.com (12/12) Jan 03 2013 http://d.puremagic.com/issues/show_bug.cgi?id=8542
- d-bugmail puremagic.com (8/8) Feb 03 2013 http://d.puremagic.com/issues/show_bug.cgi?id=8542
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
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: -------
Aug 12 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8542 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: -------
Aug 12 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8542
deadalnix <deadalnix gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |deadalnix gmail.com
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: -------
Aug 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
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: -------
Oct 16 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
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: -------
Oct 19 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8542 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: -------
Jan 03 2013
http://d.puremagic.com/issues/show_bug.cgi?id=8542
Hmm, the -property effect also happens with the simpler test case I posted
earlier in comment 4:
$ dmd test.d
$ 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: -------
Jan 03 2013
http://d.puremagic.com/issues/show_bug.cgi?id=8542 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: -------
Jan 03 2013
http://d.puremagic.com/issues/show_bug.cgi?id=8542 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: -------
Jan 03 2013
http://d.puremagic.com/issues/show_bug.cgi?id=8542 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: -------
Jan 03 2013
http://d.puremagic.com/issues/show_bug.cgi?id=8542
Walter Bright <bugzilla digitalmars.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |bugzilla digitalmars.com
Resolution| |WORKSFORME
23:46:02 PST ---
Then we can resolve this as WORKSFORME.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 03 2013
http://d.puremagic.com/issues/show_bug.cgi?id=8542 Commit pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/468f7e12c4b1eea25bc88463f700fa62988a90cd Replace unittests to avoid issue 8542. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 03 2013









d-bugmail puremagic.com 