-
-
Notifications
You must be signed in to change notification settings - Fork 228
wip: allow custom derive to work on generics #37
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
Conversation
Sorry, got ahead of myself. Noticed some problems where its still not playing nicely. |
I've missed something 🤔
|
I got stuck on the |
Thanks for this PR! Making Implementing this can be quite involved, since we need to explicitly instantiate each monomorphization (type instantiation for a certain Maybe we should start from a very simple test case (in the |
I added
from |
Sorry, this is a bit under-documented at the moment. Simply running The bash script from CI is an absolute hack to detect printed errors from Godot, took me forever to get working and is not recommended for general use 😬 |
@Bromeon I've got the test to a point where it correctly fails to compile due to a lack of generic parameters.
Using impl ::godot::obj::Inherits<::godot::engine::Node> for GenericStructTest {}
impl ::godot::obj::Inherits<::godot::engine::Object> for GenericStructTest {}
Unfortunately, it looks like this is extremely difficult (if not impossible) to do in If we could move this functionality to the |
Maybe before we go head over heels, what are we exactly trying to achieve? 😉 Ultimately we will need to have explicit monomorphizations (generic instantiations) in order to register the types to Godot, so at which stage do we do that? Would it be possible to do that for now, before going all the way generic? That is, like in the |
Oh! I'm sorry, I follow now. 🤦🏻♂️ Thanks for your patience. Hmm 🤔 this might be a little beyond my current skill level, though thats how we learn. I might have a crack at the suggestion in #36 first as that seems a little more achievable and should get me going in the right direction. From my current understanding of the project though, rather than having an implicit implementation for non-generics, it might be better to have a separate derive function that only does the Rust part on generics. This would allow you to keep the "this does not work on generics" message and add "you can use |
The original motivation
seems to have been achieved differently, through conditional compilation. At the same time, I think it's too early to support generic classes in GDExtension-Rust. A lot of concepts still have to be fleshed out for simple types, and the added complexity in the proc-macro parsing (without full test coverage) might get in the way of faster refactorings. So I would close this for now. @Gisleburt Would you be OK if your code ended up being reused at some point in the future (with you credited as co-author, of course)? Just asking, might also be that things diverge too much over time 🙂 |
Yeap, feel free to use anything committed. I'm just getting around to looking at the test stuff now, will add to #36 with what I'm thinking there. I might come back to this at some point but don't wait on me. |
What
Gets any Generics and Where clauses on the type we're deriving additional functionality for and adds them to the derived code.
This needs checking over as I'm not 100% sure what I've done is right, however, what I'm aiming to do in this PR is allow the custom derive macros to work over generic items and where clauses.
Why
What I'd like to do is allow my code to be tested somewhat in isolation from the library code, see #36. One possible way to do this might be to allow
Godotclass::base
to be a generic item that does not need to be tied to the godot engine. Eg:AbstractBase
can then be a trait that has only the methods I need for my code and that mirror the signature of Base.