www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - UCFS, Reflection/Metadata, Overload Resolution, Templates, and other issues

reply %u <wfunction hotmail.com> writes:
I was trying to write a "Dynamic" class for D, which uses opDispatch
to allow for late binding, but I ran into a problem:

While my class works well for regular methods inside a class, it
fails to work for:
(1) Template methods inside a class
(2) Methods with overloads
(3) Global methods that have nothing to do with a class, like
writeln
Furthermore, it would also fail to work for (4) UCFS if/when it's
implemented.

It seems like templates by design *don't* allow for anything to
happen dynamically, and at the same time, it seems like _everything_
is becoming a template nowadays.

So my question is, is there anything we can do about it (either now
or later)? Or is a dynamic extension simply beyond the reach of D?
Apr 07 2011
next sibling parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Thu, 07 Apr 2011 14:20:53 -0400, %u <wfunction hotmail.com> wrote:

 I was trying to write a "Dynamic" class for D, which uses opDispatch
 to allow for late binding, but I ran into a problem:

 While my class works well for regular methods inside a class, it
 fails to work for:
 (1) Template methods inside a class
 (2) Methods with overloads
 (3) Global methods that have nothing to do with a class, like
 writeln
 Furthermore, it would also fail to work for (4) UCFS if/when it's
 implemented.

 It seems like templates by design *don't* allow for anything to
 happen dynamically, and at the same time, it seems like _everything_
 is becoming a template nowadays.

 So my question is, is there anything we can do about it (either now
 or later)? Or is a dynamic extension simply beyond the reach of D?
I tried a "wrapper" type using opDispatch in dcollections, but what I ran into is, opDispatch uses its called parameter types to decide the function parameter types, you have very little control over that. I basically ended up abandoning the use of opDispatch and implemented each covered function by hand. I filed an enhancement request for it, which probably doesn't cover everything you listed, but it might help: http://d.puremagic.com/issues/show_bug.cgi?id=4998 -Steve
Apr 07 2011
parent reply %u <wfunction hotmail.com> writes:
 I tried a "wrapper" type using opDispatch in dcollections, but what
I ran into is, opDispatch uses its called parameter types to decide the function parameter types, you have very little control over that. I basically ended up abandoning the use of opDispatch and implemented each covered function by hand. I managed to get this far (my file attached), using D-style runtime variadic functions... it seems to work well in most cases, with the notable exceptions being: (1) Things I already mentioned (2) Possibly ref/out/lazy parameters (I haven't tested them yet) Any thoughts? begin 644 std.dynamic.core.d M<&]R="!S=&0N86QG;W)I=&AM.PT*<')I=F%T92!I;7!O<G0 8V]R92YE>&-E M<'1I;VXL('-T9"YE>&-E<'1I;VXL('-T9"YT>7!E='5P;&4L('-T9"YM971A M<W1R:6YG<RP <W1D+G1R86ET<RP 8V]R92YV87)A<F<L('-T9"YS=&1I;SL- M" T*86)S=')A8W0 8VQA<W, 1'EN86UI8PT*>PT*"7!R;W1E8W1E9"!A8G-T M<F%C="!$>6YA;6EC(&EN=F]K92AS=')I;F< ;65M8F5R+"`N+BXI.PT*"7!R M;W1E8W1E9"!T:&ES*"D >R!A<W-E<G0H='EP96ED*'1H:7,I("$]('1Y<&5I M9"AT>7!E;V8H=&AI<RDI*3L ?0T*"7!U8FQI8R!$>6YA;6EC(&]P1&ES<&%T M8V H<W1R:6YG(&YA;64L(%0N+BXI*%0 87)G<RD >R!R971U<FX =&AI<RYI M;G9O:V4H;F%M92P 87)G<RD[('T-" EP<F]T96-T960 0'!R;W!E<G1Y(&%B M<W1R86-T('9O:60J('!686QU92 I.PT*"7!U8FQI8R!`<')O<&5R='D 86)S M*"D >R!A<W-E<G0H=&AI<RYT>7!E260 /3T ='EP96ED*%0I*3L <F5T=7)N M1'EN86UI8RA4>7!E26YF;R!T*2![(&%U=&\ 87-424-L87-S(#T 8V%S="A4 M("AA<U1)0VQA<W, /3T ='EP96ED*$1Y;F%M:6,I*3L ?0T*<W1A=&EC(&)O M;VP :7-686QI9$%R9W5M96YT*%1Y<&5);F9O('1!<F<L(%1Y<&5);F9O('10 M87)A;2D >R!R971U<FX =$%R9R`]/2!T4&%R86T[('T +R]&25A-13H 06QL M;W< 9F]R(&EM<&QI8VET(&-O;G9E<G-I;VYS("AB;W1H('=I9&5N:6YG(&-O M=&4 <W1A=&EC24UA<$EN=&5R;F%L*'-I>F5?="!I4W1A<G0L(&%L:6%S($UA M<'!E<BP 5"XN+BD >R!S=&%T:6, :68 *%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"AT>7!E M('TL('-T871I8TE-87`A*'9A7VUA:V5?;&]C86Q?87)G(2A005)!35]04D5& M25 L(&%R9W,I+"!087)A;65T97)4>7!E5'5P;&4A*%1&;BDI*2P-" D)"0D) M8TIO:6XA*'%[+"!]+"!S=&%T:6-)36%P(2A*;VEN97(A*%!!4D%-7U!2149) M6"DL(%!A<F%M971E<E1Y<&54=7!L92$H1G5N8W1I;VY4>7!E3V8A*&UI>&EN M<UMM96UB97)=(#T M"0D)"0DO+W!R86=M82AM<V<L("))9VYO<FEN9R!N;VXM:6YS=&%N8V4 ;65M M;F%M:6-/9B$H5"DN;65M8F5R<R`](&UE;6)E<G,N87-S=6UE56YI<75E*"D[ M<B!I;B!M96UB97)S.PT*"0EI9B`H<$UE;6)E<B`]/2!N=6QL*2![('1H<F]W M(&YE=R!(:61D96Y&=6YC17)R;W(H='EP96ED*$1Y;F%M:6-/9B$H5"DI*3L M+"!A<F=S*3L-" D)=F%?96YD*&%R9W,I.PT*"0ER971U<FX <F5S=6QT.PT* M"7T-" T*"7!R;W1E8W1E9"!`<')O<&5R='D ;W9E<G)I9&4 5'EP94EN9F\ M='EP94ED*"D >R!R971U<FX ='EP96ED*'1H:7,N;V)J*3L ?0T*"7!R;W1E M8W1E9"!`<')O<&5R='D ;W9E<G)I9&4 =F]I9"H <%9A;'5E*"D >R!R971U M5"DH5"!V86QU92D >R!S=&%T:6, :68 *"%I<RA4(#H 1'EN86UI8RDI('L M<F5T=7)N(&YE=R!$>6YA;6EC3V8A*%0I*'9A;'5E*3L ?2!E;'-E('L <F5T .=7)N('9A;'5E.R!]('T` ` end
Apr 07 2011
parent reply Caligo <iteronvexor gmail.com> writes:
What's UCFS?
Apr 07 2011
parent %u <wfunction hotmail.com> writes:
 What's UCFS?
Whoops, typo. xD Uniform Function Call Syntax. :)
Apr 07 2011
prev sibling parent reply "Robert Jacques" <sandford jhu.edu> writes:
On Thu, 07 Apr 2011 14:20:53 -0400, %u <wfunction hotmail.com> wrote:

 I was trying to write a "Dynamic" class for D, which uses opDispatch
 to allow for late binding, but I ran into a problem:

 While my class works well for regular methods inside a class, it
 fails to work for:
 (1) Template methods inside a class
 (2) Methods with overloads
 (3) Global methods that have nothing to do with a class, like
 writeln
 Furthermore, it would also fail to work for (4) UCFS if/when it's
 implemented.

 It seems like templates by design *don't* allow for anything to
 happen dynamically, and at the same time, it seems like _everything_
 is becoming a template nowadays.

 So my question is, is there anything we can do about it (either now
 or later)? Or is a dynamic extension simply beyond the reach of D?
I've added reflection capabilities to an update to std.variant I'm working on. Overloads work. General functions work. (Although a few bugs with opCall and opDispatch prevents the ideal syntax: var.x(5) vs var.x = 5 and var.call(5) vs var(5), but I assume those will be eventually fixed). I've also added an internal type database, so you can auto-magically build a Variant(TypeInfo, void*) or Variant(Object) and then call methods on the real, underlying type. Templates, I think, will out of the range of dynamic D capabilities for some time to come. Also, because I'm wrapping / unwrapping all arguments, ref doesn't work.
Apr 07 2011
parent reply %u <wfunction hotmail.com> writes:
 I've added reflection capabilities to an update to std.variant I'm working on.
Overloads work.
General functions work. (Although a few bugs with opCall and opDispatch prevents the ideal syntax: var.x(5) vs var.x = 5 and var.call(5) vs var(5), but I assume those will be eventually fixed). I've also added an internal type database, so you can auto-magically build a Variant(TypeInfo, void*) or Variant(Object) and then call methods on the real, underlying type. Whoa nice. I'm eagerly waiting to see it. :)
 Templates, I think, will out of the range of dynamic D capabilities for some
time to come.
Yeah, 'cause I just realized they basically need you to implement the entire compiler.
Apr 08 2011
parent reply "Robert Jacques" <sandford jhu.edu> writes:
On Fri, 08 Apr 2011 11:31:48 -0400, %u <wfunction hotmail.com> wrote:

 I've added reflection capabilities to an update to std.variant I'm  
 working on. Overloads work.
General functions work. (Although a few bugs with opCall and opDispatch prevents the ideal syntax: var.x(5) vs var.x = 5 and var.call(5) vs var(5), but I assume those will be eventually fixed). I've also added an internal type database, so you can auto-magically build a Variant(TypeInfo, void*) or Variant(Object) and then call methods on the real, underlying type. Whoa nice. I'm eagerly waiting to see it. :)
Here's a snapshot I posted a while ago, if you'd like to have a look: https://jshare.johnshopkins.edu/rjacque2/public_html/ I'd love some feedback, particularly with regard to the runtime-reflection API.
 Templates, I think, will out of the range of dynamic D capabilities for  
 some time to come.
Yeah, 'cause I just realized they basically need you to implement the entire compiler.
Yah, you'd need a VM.
Apr 08 2011
parent reply %u <wfunction hotmail.com> writes:
Thanks for the link!

I tried compiling the file, and I got these errors:

variant.d(454): Warning: statement is not reachable
variant.d(454): Warning: statement is not reachable
variant.d(454): Warning: statement is not reachable
variant.d(634): Warning: statement is not reachable
variant.d(660): Warning: statement is not reachable
variant.d(337): Error: template variant.Variant.Box.opAssign(A : Variant) does
not match any function template declaration
variant.d(337): Error: template variant.Variant.Box.opAssign(A : Variant)
cannot deduce template function from argument types !
()(char[])
variant.d(612): Error: template instance variant.Variant.Box.opAssign!(char[])
error instantiating
variant.d(1041): instantiated from here: __vtableOf!(char[])
variant.d(605): instantiated from here: opAssign!(char[])
variant.d(757): instantiated from here: SaveResult!(char[])
    ... (23 instantiations, -v to show) ...
variant.d(376): instantiated from here: SaveResult!(TypeInfo)
variant.d(351): instantiated from here: __vtableOf!(void)

Any ideas how I should fix them?
Apr 09 2011
parent reply "Robert Jacques" <sandford jhu.edu> writes:
On Sat, 09 Apr 2011 04:07:11 -0400, %u <wfunction hotmail.com> wrote:

 Thanks for the link!

 I tried compiling the file, and I got these errors:

 variant.d(454): Warning: statement is not reachable
 variant.d(454): Warning: statement is not reachable
 variant.d(454): Warning: statement is not reachable
 variant.d(634): Warning: statement is not reachable
 variant.d(660): Warning: statement is not reachable
 variant.d(337): Error: template variant.Variant.Box.opAssign(A :  
 Variant) does not match any function template declaration
 variant.d(337): Error: template variant.Variant.Box.opAssign(A :  
 Variant) cannot deduce template function from argument types !
 ()(char[])
 variant.d(612): Error: template instance  
 variant.Variant.Box.opAssign!(char[]) error instantiating
 variant.d(1041): instantiated from here: __vtableOf!(char[])
 variant.d(605): instantiated from here: opAssign!(char[])
 variant.d(757): instantiated from here: SaveResult!(char[])
     ... (23 instantiations, -v to show) ...
 variant.d(376): instantiated from here: SaveResult!(TypeInfo)
 variant.d(351): instantiated from here: __vtableOf!(void)

 Any ideas how I should fix them?
Sorry. It was late and I forgot to mention some things. A) My code is dependent on patch 5155, and B) I forgot about changes, etc, that I had to make to go from DMD 2.051 to DMD 2.052. I've uploaded my current working copy and remade the docs. Let me know if you have any issues with this. (And please include a brief description of what/how you're building it: i.e. dmd 2.052, debug mode, etc) Also, if you want to try my updated std.json, it requires a few more patches, each listed at the top of the file.
Apr 09 2011
parent reply %u <wfunction hotmail.com> writes:
 Sorry. It was late and I forgot to mention some things. A) My code is
dependent on patch 5155, and B) I forgot about
changes, etc, that I had to make to go from DMD 2.051 to DMD 2.052. I've uploaded my current working copy and remade the docs. Let me know if you have any issues with this. (And please include a brief description of what/how you're building it: i.e. dmd 2.052, debug mode, etc) Also, if you want to try my updated std.json, it requires a few more patches, each listed at the top of the file. Whoops my bad. I'm using DMD 2.052, the version on the website, to compile variant.d. I tried recompiling the file (standalone) and got the same error again; I suspect it's because of the patch 5155 you mentioned, which I haven't applied. I'm actually not familiar with the patching system yet, so I'll try to use your file when I find a bit more time to figure it out. Thanks! :)
Apr 09 2011
parent reply "Robert Jacques" <sandford jhu.edu> writes:
On Sat, 09 Apr 2011 18:08:58 -0400, %u <wfunction hotmail.com> wrote:

 Sorry. It was late and I forgot to mention some things. A) My code is  
 dependent on patch 5155, and B) I forgot about
changes, etc, that I had to make to go from DMD 2.051 to DMD 2.052. I've uploaded my current working copy and remade the docs. Let me know if you have any issues with this. (And please include a brief description of what/how you're building it: i.e. dmd 2.052, debug mode, etc) Also, if you want to try my updated std.json, it requires a few more patches, each listed at the top of the file. Whoops my bad. I'm using DMD 2.052, the version on the website, to compile variant.d. I tried recompiling the file (standalone) and got the same error again; I suspect it's because of the patch 5155 you mentioned, which I haven't applied. I'm actually not familiar with the patching system yet, so I'll try to use your file when I find a bit more time to figure it out. Thanks! :)
Well, 5155 is fairly simple. The bug report details four one line changes to Object.di and Object_.d. See http://d.puremagic.com/issues/show_bug.cgi?id=5155 Also, If that doesn't do the trick, please e-mail me as I would like to fix the root cause. (And let you test the library)
Apr 10 2011
parent %u <wfunction hotmail.com> writes:
 Well, 5155 is fairly simple. The bug report details four one line
changes to Object.di and Object_.d. See http://d.puremagic.com/issues/show_bug.cgi?id=5155 Also, If that doesn't do the trick, please e-mail me as I would like to fix the root cause. (And let you test the library) Oops sorry, I got a bit busier these couple of days and totally forgot about this. I'll try to come back to it in the near future, and I'll let you know if I have any success/failure. Thanks for the info! :)
Apr 12 2011