-
Notifications
You must be signed in to change notification settings - Fork 9
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
Automatically synthesize message types for sends to arbitrary handlers #276
Automatically synthesize message types for sends to arbitrary handlers #276
Comments
@mperrinel will start on this - assigned the rest of us as observers. |
Hello. |
Turns out Jonathan largely implemented this in |
@hobywan Please comment with your plan for integrating this more broadly in VT. Let's have a discussion on that before you get started |
To document what I encountered before: the fundamental problem with this is that you can't infer the arguments for a value-template (in the standard called a "non-type template"): struct MyCol : Collection<MyCol,Index1D> {
void method(int a, int b);
};
template <typename ColT, typename... Args>
using ActiveColMemberArgsFnType = void(ColT::*)(Args...);
template <typename... Args, ActiveColMemberArgsFnType<ColT,Args...> f>
void send(Args&&... args) const;
proxy(i).send<&MyCol::method>(10,20); @hobywan I'm not sure how to solve this, but this is the main problem to address for the API to be usable. From reading the standard this is not possible in C++14: inferring the type of a non-type template. See this answer: https://stackoverflow.com/questions/27372492/c-template-parameter-type-inference This deficiency was addressed by the standard in C++17 with |
I searched for workarounds without the use an #define send(handler) sendData<decltype(handler), &handler> like the example here. template <typename ColT, typename... Args>
EventType send(...) {
// argument checking or parsing here
auto const& handler = auto_registry::makeAutoHandler<ColT>(); // should be updated
return sendData<ColT, handler>(std::forward<Tuple>(Args));
} Another workaround would be to restrict this feature to be enabled only if C++17 is enabled (using macros) but that is far from being an elegant solution. |
For reference, that |
Making this low priority to implement as a opt-in when using C++17 |
Per http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0127r2.html#FeatureTestMacro, we can conditionalize relevant functionality and tests on |
More than a year later, Nvidia is still the laggard in implementing P0127 support. I'm going to de-assign this, just to take it off the radar. |
@PhilMiller Sounds like a plan. Should be have a label for back burner type tasks? Is pri:low enough to signify that? |
Yeah, I think so. |
And, as a note, Nvidia's compiler generally says that it doesn't implement partial standards, so we won't have any C++17 support from them until they offer complete C++17 support. We should maybe see if this code would work there in spite of their lacking support, possibly by it not parsing code that it's not going to need to generate anything for itself. |
As of nvcc 11.0, C++17 support is available. |
Following on #272, I think it would not be all that difficult to write template code that would let applications make a
send
call with arguments matching those of some handler, and the template code would take care of describing a suitable message type and actual target handler to unwrap the message and make the call.The pieces I see playing into this are roughly as follows:
std::forward_as_tuple
template <void (*Func)(Args...), typename Args...> sendMagic(Args&& ...args)
template <typename Args...> struct MagicMsg { std::tuple<...Args> a;};
std::apply
template <void (*Func)(Args...), typename Args...> receiveMagic(MagicMsg<...Args>* m)
Once the simplest cases are working, we should probably apply a type trait to each of the argument types to represent how they should be represented in the message / on the wire, in cases where they shouldn't be literal. In particular, automatic handling of anything array-like on the sending side coming out to whatever array-like thing the receiver expects would be very convenient.
The text was updated successfully, but these errors were encountered: