-
Notifications
You must be signed in to change notification settings - Fork 504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WeakPersistent Redesign #218
Conversation
The argument is not that ugly and it is not that inflexible. It is basically a back-port of the new v8 weak callback API to the old version, with a bit of added smartness and harmonization. The basic problem is that these are the two APIs from v8's end. On top of that you still need to be able to dispose of the New v8: template<class T, class P>
class v8::WeakCallbackObject< T, P >; template<typename P>
V8_INLINE void SetWeak(
P* parameter,
typename WeakCallbackData<T, P>::Callback callback);
template<typename S, typename P>
V8_INLINE void SetWeak(
P* parameter,
typename WeakCallbackData<S, P>::Callback callback); Old v8: typedef void(* v8::WeakReferenceCallback)(Persistent< Value > object, void *parameter)
template<class T >
void v8::Persistent< T >::MakeWeak (void * parameters, WeakReferenceCallback callback) [inline]
|
The V8 API only allows you to store a function pointer and a |
Hehe... all them technical arguments about gritty implementation details. Let's see... Please forget about the difficulties in implementing this, forget about the inside for a moment. Most of these issues are already dealt with in the current implementation. Let's focus on the user interface. @kkoopa mentioned some shortcomings of
... but you tell me. Then, after the decision to use a declarative macro, using a template becomes an attractive choice because you can capture the argument types at invocation time. Again, my own reverse-reasoning. If I'm wrong just tell me... In my view @kkoopa argument about free vs. static member functions boils down to this: C++ has to many things you can call. All or at least most of them have valid applications in the context of a NAN binding. A very node specific add-on with tight v8 coupling uses static member functions while a binding for an existing C library needs free functions, &c. In fact the most common use case of static member functions is to unpack The problem is all these $CALLABLES are slightly different, either in declaration- or in call site syntax or both (Everybody take cover, because @kkoopa is cocking his Haskell shotgun). That's why a declarative macro will never fit the bill. That's why I came up with the stuff in my first comment. But again, this is only my view on the subject. Tell me what kind of improvements you had in mind. |
Yeah, it's mostly cosmetical. I guess it might work without it. You want the arguments captured, yes. And this is 444 template<class T, class P>
445 class WeakCallbackData {
446 public:
447 typedef void (*Callback)(const WeakCallbackData<T, P>& data);
448
449 V8_INLINE Isolate* GetIsolate() const { return isolate_; }
450 V8_INLINE Local<T> GetValue() const { return handle_; }
451 V8_INLINE P* GetParameter() const { return parameter_; }
452
453 private:
454 friend class internal::GlobalHandles;
455 WeakCallbackData(Isolate* isolate, Local<T> handle, P* parameter)
456 : isolate_(isolate), handle_(handle), parameter_(parameter) { }
457 Isolate* isolate_;
458 Local<T> handle_;
459 P* parameter_;
460 }; |
I disagree. I'm convinced that Regarding the actual signature I take it that you want to keep it as close to the (new) v8 stuff as possible. I'm wondering a little why that is? I think coming up with own lightweight abstractions is not only successful ( |
At least rename |
Ok. Nobody seems to have an actual suggestion on how to improve this and my view on the subject wasn't to your liking... Guess it isn't that pressing and we can close it for now. |
Maybe |
Well, since you'd like to keep it close to the v8 API it would be something like:
... or what ever types |
Yes, I guess that would work, as such. But, it would still require the stub to On Thursday 20 November 2014 05:45:17 David Siegel wrote:
|
Again, either I don't get the point or you underestimate your doing. One sec... |
As I thought. It just works. See above. |
The template function |
Good, it does work. The stub I mentioned is |
Hehe... Ah, I see... 1337 micr0-optzns ala node. Let's worry about that single function call later*. Let's start by removing some unnecessary indirection in the design. I think the version above is a bit more readable. What do you think?
|
So, now regarding that optimization: You'd like the user callback to be inlined into what's now called |
That's probably not true. It probably is doable. However, I still think it is not worth it... |
Weak persistent cleanup looks good. At least it passes all tests. Avoiding the indirect call would be perfection. I was thinking of something along the lines of http://stackoverflow.com/a/2156899/4214433 using template by value. |
Perfection... Perfection is in the eye of the beholder. And since this is your eye and your perfection it is yours to achieve. This also seems fitting since you are in academia and you decided to learn/research this stuff ;) |
This is not connected to my research, it's a spare time project. There is little research to do in C++ template metaprogramming. It has already been proven Turing complete. Anyway, these changes can only go in the next major version, as they are breaking backwards compatibility. |
No C++ research... lol Please tell that David Abrahams, Andrei Alexandrescu et al. Tell that the boost guys. Tell that to the guys who are constantly revamping the standard to reflect the latest discoveries and insights gained in research. TMP is a great example because its turing completeness is a discovery and not by design. Hence the awkward syntax. It not being invented is also a strength: It is mathematically pure, which in the context of an industry language like C++ makes it a very interesting subject of research. I understand that it is not your area of interest but to dismiss it as a subject altogether seems a bit arrogant. Just saying... |
That's not really accurate. Templates were suspected to be Turing-complete right from the start but it wasn't formally proven until years later because really, what's the point? Being Turing-complete doesn't say anything about usability or efficiency. Take Magic: The Gathering; it's Turing-complete but you wouldn't use it to power Crisis. |
I was not dismissing it as a subject in its entirety. I was merely stating that there was little research value in the particular problem of giving a function as a template argument and getting it inlined in another function. It is more a matter of implementation than theory. |
Exactly! Thank you.
Really? Cool. /me gets his cards and builds a fibonacci deck. I'm not an expert in C++ history. But I think when Bjarne Stroustrup designed them he was thinking only a little beyond |
Considering your current language skills it still would make an excellent exercise. However, you will discover that the amount of clutter it introduces is not worth the gain... ;) |
On second thought the turing completeness of templates is an important point. Because only if they are complete it makes sense to think about templates as compile-time meta programs. Efficiency is more a matter of compiler design and they are getting there. However, I still agree that just being turing complete proves nothing. INTERCAL illustrated this nicely in 1972. |
So, everybody, should we remove the not fully proper While I dislike seeing |
We should have an abbreviation for "no opinion, do what is best". Can I coin NODWIB? |
Merged as a65ee94 |
This is a follow-up on #210.
@kkoopa mentioned in a comment that the weak persistent callback stuff could use some love:
Let's discuss it.
I'm still in the process of wrapping my head around the current stuff but one thing seems obvious: It is not very flexible. Compared to
NanNew<T>(...)
it is totally rigid. I think the right thing to do is to get rid ofNAN_WEAK_CALLBACK
all together. Let users define the callbacks more freely (free function, static member function, functor, member function, what ever) and then deal with it inNanMakeWeakPersistent(...)
. I'd also like to do away with that ugly argument.Pseudo:
I might be a bit optimistic but I think this is doable. What do you guys think?