digitalmars.D - Type wrapping blockers
- Steven Schveighoffer (18/18) Oct 05 2010 One of the good goals of D I think is to be able to automatically
- Mafi (7/25) Oct 05 2010 Iff you are only wrapping one other thing (ie struct, class...), you
- Steven Schveighoffer (4/35) Oct 05 2010 Alias this does not allow interception of calls.
- Andrei Alexandrescu (7/42) Oct 05 2010 If you only want to intercept a few specific calls, you may want to use
- Don (2/22) Oct 05 2010 That is bug 4953.
- Steven Schveighoffer (23/40) Oct 05 2010 I don't think so, because I'm using IFTI to imply the argument types. A...
- Simen kjaeraas (5/12) Oct 05 2010 Not directly. However, you could probably coerce std.typecons'
- Denis Koroskin (5/23) Oct 05 2010 You can try iterating over all class methods and construct proxy ones
- Steven Schveighoffer (13/30) Oct 05 2010 Found another one, really old bug: 1748
- Steven Schveighoffer (6/18) Oct 06 2010 I found a solution: http://d.puremagic.com/issues/show_bug.cgi?id=4998
- Jonathan M Davis (3/4) Oct 06 2010 Though I'm not sure that 5000 bugs is exactly something to celebrate...
- Lars T. Kyllingstad (5/11) Oct 06 2010 That depends on how many are using D, and to which degree they are
- Lutger (4/19) Oct 09 2010 I agree. I always welcome the increase of list of bugs at work, my co-wo...
- Andrei Alexandrescu (8/11) Oct 06 2010 Sorry, I just snatched #5000...
- Juanjo Alvarez (4/5) Oct 06 2010 404 Not Found.
- Andrei Alexandrescu (4/9) Oct 06 2010 Hm, it works for me but it asks me to log in first. Probably you need an...
One of the good goals of D I think is to be able to automatically encapsulate a type, and all its attributes/functions, in order to slightly alter the functionality. I think this is probably a pattern, but I don't know what it is (Interceptor?). One of the best methods to wrap a type is to use opDispatch. But there are some problems that block this. It might be good to get a bug report that gathers these together. I have one that I just ran into -- IFTI and literals. Basically, if you have a function: void foo(short x); you can call foo(1) no problem. But if you *wrap* the type that contains foo, you cannot use opDispatch to implement foo(1), because IFTI treats 1 as an int. So what you get is an instantiation of opDispatch like this: opDispatch!("foo", int)(1) Which then cannot call foo, because you cannot cast int to short. Does anyone have any other blockers that prevent type wrapping? Does anyone have any ideas on how to fix the above issue? -Steve
Oct 05 2010
Am 05.10.2010 14:50, schrieb Steven Schveighoffer:One of the good goals of D I think is to be able to automatically encapsulate a type, and all its attributes/functions, in order to slightly alter the functionality. I think this is probably a pattern, but I don't know what it is (Interceptor?). One of the best methods to wrap a type is to use opDispatch. But there are some problems that block this. It might be good to get a bug report that gathers these together. I have one that I just ran into -- IFTI and literals. Basically, if you have a function: void foo(short x); you can call foo(1) no problem. But if you *wrap* the type that contains foo, you cannot use opDispatch to implement foo(1), because IFTI treats 1 as an int. So what you get is an instantiation of opDispatch like this: opDispatch!("foo", int)(1) Which then cannot call foo, because you cannot cast int to short. Does anyone have any other blockers that prevent type wrapping? Does anyone have any ideas on how to fix the above issue? -SteveIff you are only wrapping one other thing (ie struct, class...), you should be able to use alias this. It should in my opinion correctly resolve to foo(short). If dmd doesn't find foo in your wrapper it should look for foo in the alias before saying that 1 has to be int. But I didn't test. Mafi
Oct 05 2010
On Tue, 05 Oct 2010 10:06:58 -0400, Mafi <mafi example.org> wrote:Am 05.10.2010 14:50, schrieb Steven Schveighoffer:Alias this does not allow interception of calls. I want to do something inside opDispatch besides just calling foo(1). -SteveOne of the good goals of D I think is to be able to automatically encapsulate a type, and all its attributes/functions, in order to slightly alter the functionality. I think this is probably a pattern, but I don't know what it is (Interceptor?). One of the best methods to wrap a type is to use opDispatch. But there are some problems that block this. It might be good to get a bug report that gathers these together. I have one that I just ran into -- IFTI and literals. Basically, if you have a function: void foo(short x); you can call foo(1) no problem. But if you *wrap* the type that contains foo, you cannot use opDispatch to implement foo(1), because IFTI treats 1 as an int. So what you get is an instantiation of opDispatch like this: opDispatch!("foo", int)(1) Which then cannot call foo, because you cannot cast int to short. Does anyone have any other blockers that prevent type wrapping? Does anyone have any ideas on how to fix the above issue? -SteveIff you are only wrapping one other thing (ie struct, class...), you should be able to use alias this. It should in my opinion correctly resolve to foo(short). If dmd doesn't find foo in your wrapper it should look for foo in the alias before saying that 1 has to be int. But I didn't test.
Oct 05 2010
On 10/5/10 9:15 CDT, Steven Schveighoffer wrote:On Tue, 05 Oct 2010 10:06:58 -0400, Mafi <mafi example.org> wrote:If you only want to intercept a few specific calls, you may want to use alias this and simply define the appropriate methods. They will be found by name lookup before alias this kicks in. For intercepting all calls even to method names you don't know, indeed opDispatch is the way to go. AndreiAm 05.10.2010 14:50, schrieb Steven Schveighoffer:Alias this does not allow interception of calls. I want to do something inside opDispatch besides just calling foo(1). -SteveOne of the good goals of D I think is to be able to automatically encapsulate a type, and all its attributes/functions, in order to slightly alter the functionality. I think this is probably a pattern, but I don't know what it is (Interceptor?). One of the best methods to wrap a type is to use opDispatch. But there are some problems that block this. It might be good to get a bug report that gathers these together. I have one that I just ran into -- IFTI and literals. Basically, if you have a function: void foo(short x); you can call foo(1) no problem. But if you *wrap* the type that contains foo, you cannot use opDispatch to implement foo(1), because IFTI treats 1 as an int. So what you get is an instantiation of opDispatch like this: opDispatch!("foo", int)(1) Which then cannot call foo, because you cannot cast int to short. Does anyone have any other blockers that prevent type wrapping? Does anyone have any ideas on how to fix the above issue? -SteveIff you are only wrapping one other thing (ie struct, class...), you should be able to use alias this. It should in my opinion correctly resolve to foo(short). If dmd doesn't find foo in your wrapper it should look for foo in the alias before saying that 1 has to be int. But I didn't test.
Oct 05 2010
Steven Schveighoffer wrote:One of the good goals of D I think is to be able to automatically encapsulate a type, and all its attributes/functions, in order to slightly alter the functionality. I think this is probably a pattern, but I don't know what it is (Interceptor?). One of the best methods to wrap a type is to use opDispatch. But there are some problems that block this. It might be good to get a bug report that gathers these together. I have one that I just ran into -- IFTI and literals. Basically, if you have a function: void foo(short x); you can call foo(1) no problem. But if you *wrap* the type that contains foo, you cannot use opDispatch to implement foo(1), because IFTI treats 1 as an int. So what you get is an instantiation of opDispatch like this: opDispatch!("foo", int)(1) Which then cannot call foo, because you cannot cast int to short.That is bug 4953.
Oct 05 2010
On Tue, 05 Oct 2010 10:25:31 -0400, Don <nospam nospam.com> wrote:Steven Schveighoffer wrote:I don't think so, because I'm using IFTI to imply the argument types. A generic opDispatch to wrap a function: auto opDispatch(string op, Args...)(Args args) { /* perform interception work here */ return mixin!("wrappedVal." ~ op ~ "(args)"); } If you don't know what the arguments are *supposed* to be, I'm unsure how to derive them based on what the type being wrapped supports. The specific situation that's failing, in dcollections, I have a function: add(V[] elems...) where V is the type being collected. When V == short, then calling add directly like this: add(1,2,3,4,5); works fine. But calling the wrapper with add(1,2,3,4,5) fails, because Args... is interpreted as int, int, int, int, int. What I really need is to say "hey IFTI, determine the argument types by looking up as if it were called on this type, because that's what I'm going to call" rather than use the arguments themselves. Bug 4953 is when IFTI should play no part in determing the argument types. Or am I missing something? -SteveOne of the good goals of D I think is to be able to automatically encapsulate a type, and all its attributes/functions, in order to slightly alter the functionality. I think this is probably a pattern, but I don't know what it is (Interceptor?). One of the best methods to wrap a type is to use opDispatch. But there are some problems that block this. It might be good to get a bug report that gathers these together. I have one that I just ran into -- IFTI and literals. Basically, if you have a function: void foo(short x); you can call foo(1) no problem. But if you *wrap* the type that contains foo, you cannot use opDispatch to implement foo(1), because IFTI treats 1 as an int. So what you get is an instantiation of opDispatch like this: opDispatch!("foo", int)(1) Which then cannot call foo, because you cannot cast int to short.That is bug 4953.
Oct 05 2010
Steven Schveighoffer <schveiguy yahoo.com> wrote:But if you *wrap* the type that contains foo, you cannot use opDispatch to implement foo(1), because IFTI treats 1 as an int. So what you get is an instantiation of opDispatch like this: opDispatch!("foo", int)(1) Which then cannot call foo, because you cannot cast int to short. Does anyone have any other blockers that prevent type wrapping? Does anyone have any ideas on how to fix the above issue?Not directly. However, you could probably coerce std.typecons' AutoImplement to do your wrapping for you. -- Simen
Oct 05 2010
On Tue, 05 Oct 2010 16:50:04 +0400, Steven Schveighoffer <schveiguy yahoo.com> wrote:One of the good goals of D I think is to be able to automatically encapsulate a type, and all its attributes/functions, in order to slightly alter the functionality. I think this is probably a pattern, but I don't know what it is (Interceptor?). One of the best methods to wrap a type is to use opDispatch. But there are some problems that block this. It might be good to get a bug report that gathers these together. I have one that I just ran into -- IFTI and literals. Basically, if you have a function: void foo(short x); you can call foo(1) no problem. But if you *wrap* the type that contains foo, you cannot use opDispatch to implement foo(1), because IFTI treats 1 as an int. So what you get is an instantiation of opDispatch like this: opDispatch!("foo", int)(1) Which then cannot call foo, because you cannot cast int to short. Does anyone have any other blockers that prevent type wrapping? Does anyone have any ideas on how to fix the above issue? -SteveYou can try iterating over all class methods and construct proxy ones using string mixins at compile time. Might be next to impossible to implement properly though :)
Oct 05 2010
On Tue, 05 Oct 2010 08:50:04 -0400, Steven Schveighoffer <schveiguy yahoo.com> wrote:One of the good goals of D I think is to be able to automatically encapsulate a type, and all its attributes/functions, in order to slightly alter the functionality. I think this is probably a pattern, but I don't know what it is (Interceptor?). One of the best methods to wrap a type is to use opDispatch. But there are some problems that block this. It might be good to get a bug report that gathers these together. I have one that I just ran into -- IFTI and literals. Basically, if you have a function: void foo(short x); you can call foo(1) no problem. But if you *wrap* the type that contains foo, you cannot use opDispatch to implement foo(1), because IFTI treats 1 as an int. So what you get is an instantiation of opDispatch like this: opDispatch!("foo", int)(1) Which then cannot call foo, because you cannot cast int to short. Does anyone have any other blockers that prevent type wrapping? Does anyone have any ideas on how to fix the above issue?Found another one, really old bug: 1748 Basically, if you have class C(T) { } and you try to get (C!int).stringof you get just "C". This makes specifying wrapped arguments that are class templates impossible for mixins. I'm giving up my workaround to try and implement the "Nifty chaining", it appears it's just not possible with the compiler bugs today :( -Steve
Oct 05 2010
On Tue, 05 Oct 2010 08:50:04 -0400, Steven Schveighoffer <schveiguy yahoo.com> wrote:One of the best methods to wrap a type is to use opDispatch. But there are some problems that block this. It might be good to get a bug report that gathers these together. I have one that I just ran into -- IFTI and literals. Basically, if you have a function: void foo(short x); you can call foo(1) no problem. But if you *wrap* the type that contains foo, you cannot use opDispatch to implement foo(1), because IFTI treats 1 as an int. So what you get is an instantiation of opDispatch like this: opDispatch!("foo", int)(1) Which then cannot call foo, because you cannot cast int to short. Does anyone have any ideas on how to fix the above issue?I found a solution: http://d.puremagic.com/issues/show_bug.cgi?id=4998 Anyone see any holes in it? BTW, bug 5000 coming up! Big milestone :) -Steve
Oct 06 2010
On Wednesday 06 October 2010 04:26:43 Steven Schveighoffer wrote:BTW, bug 5000 coming up! Big milestone :)Though I'm not sure that 5000 bugs is exactly something to celebrate... - Jonathan M Davis
Oct 06 2010
On Wed, 06 Oct 2010 05:24:18 -0700, Jonathan M Davis wrote:On Wednesday 06 October 2010 04:26:43 Steven Schveighoffer wrote:That depends on how many are using D, and to which degree they are putting DMD+Phobos through its paces. I have a project on dsource that has zero bug reports, but I don't think it's because it's bug-free. ;) -LarsBTW, bug 5000 coming up! Big milestone :)Though I'm not sure that 5000 bugs is exactly something to celebrate... - Jonathan M Davis
Oct 06 2010
Lars T. Kyllingstad wrote:On Wed, 06 Oct 2010 05:24:18 -0700, Jonathan M Davis wrote:I agree. I always welcome the increase of list of bugs at work, my co-workers sometimes find that strange. But I figure they are in the codebase anyway, better to get them in plain sight.On Wednesday 06 October 2010 04:26:43 Steven Schveighoffer wrote:That depends on how many are using D, and to which degree they are putting DMD+Phobos through its paces. I have a project on dsource that has zero bug reports, but I don't think it's because it's bug-free. ;) -LarsBTW, bug 5000 coming up! Big milestone :)Though I'm not sure that 5000 bugs is exactly something to celebrate... - Jonathan M Davis
Oct 09 2010
On 10/6/10 7:24 CDT, Jonathan M Davis wrote:On Wednesday 06 October 2010 04:26:43 Steven Schveighoffer wrote:There are 1516 open issues at the time being, and the derivative is still positive. But there are 2086 closed bugs, and the derivative is also positive (see http://tinyurl.com/2ewh8eq). There is some celebration to be had. If there were no bugs activity then the product wouldn't be used. AndreiBTW, bug 5000 coming up! Big milestone :)Though I'm not sure that 5000 bugs is exactly something to celebrate...
Oct 06 2010
On Wed, 06 Oct 2010 10:21:58 -0500, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:also positive (see http://tinyurl.com/2ewh8eq).404 Not Found. Should I open a bug report? ;)
Oct 06 2010
On 10/6/10 17:53 CDT, Juanjo Alvarez wrote:On Wed, 06 Oct 2010 10:21:58 -0500, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Hm, it works for me but it asks me to log in first. Probably you need an account. Andreialso positive (see http://tinyurl.com/2ewh8eq).404 Not Found. Should I open a bug report? ;)
Oct 06 2010