-
Notifications
You must be signed in to change notification settings - Fork 5
Add marker traits for table-specific metadata. #158
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
cc @MomoLangenstein -- it'd be nice to see your thoughts on this. It is a minimal-ish API change, and it may affect how you are exporting your data. But it seems that the next release is about "type safety", which led me to this. |
This looks like a good change to me as well. Do you plan on adding marker traits for the other metadata types as well? I also noticed that you swapped out dynamic dispatch for generics in one location - what do you think about doing that for the entire API as well? Use generics is … well more generic and more expressive … and you can then still express the dynamic dispatch case in that. |
Yes, I'll do all the table types similarly. I just wanted some feedback
prior to diving in.
I'll also look at generics, too.
…On Fri, Aug 27, 2021, 10:32 PM Momo Langenstein ***@***.***> wrote:
cc @MomoLangenstein <https://github.com/MomoLangenstein> -- it'd be nice
to see your thoughts on this. It is a minimal-ish API change, and it may
affect how you are exporting your data. But it seems that the next release
is about "type safety", which led me to this.
This looks like a good change to me as well. Do you plan on adding marker
traits for the other metadata types as well?
I also noticed that you swapped out dynamic dispatch for generics in one
location - what do you think about doing that for the entire API as well?
Use generics is … well more generic and more expressive … and you can then
still express the dynamic dispatch case in that.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#158 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABQ6OHYDB3JPLR7YLKN37NDT7BYBTANCNFSM5C6K7ZHA>
.
|
The change to a generic for the current diff involves a private class, and was to enable absorbing all the new trait markers. But it won't break API to make all the other functions generics as well, so may as well do it in this pull request. |
@MomoLangenstein -- I now realized the issue with generics vs |
Ah, I see where that compilation error comes from. Have you already merged the API changes to provide methods which accept no metadata or metadata unconditionally? In that case, there are methods that always work for the user and if they want to supply an option, then it’s their responsibility to type it (since they go down the explicit route, they should pass Another option would be to give M the default value The reason why I’d personally still prefer generics is that they are more Rusty and provide the compiler with better optimisation potential. |
Yes, the I'll think more on this. |
Aha--this is the key.... |
Is there a C++ version of the tskit API? In that case, you could use |
No, the canonical API is C, and always will be. The unsafe bit here is that |
The most recent commit changes to generics (for one of the tables). It is now a bit funky, maybe, as the back-end private struct still expects an Option, but that can be fiddled with if necessary. |
That change for one of the tables looks good to me |
Thanks. I'll sort the rest out on Monday, I hope. |
Thanks for the ping on this, very interesting! I share the same sentiments about generics where possible, and don't see it as much of a bad thing to have two
Are you saying it would be feasible for |
The option exists because metadata is optional. But you are right that you should know statically which function to call. The encoded metadata class is not visible to client code, so the option is harmless for the most part, but can (and probably should) be removed. |
I've eliminated the option entirely. I'm liking this mich more. |
It looks great - apart from: if self.encoded.is_empty() {
0
} else {
self.encoded.len() as tsk_size_t
} |
Yeah, oops! I'll fix that. |
* Add per-table metadata trait marker. * Remove use of Option<metadata> from the API Closes #157
ecdcf1b
to
734d93f
Compare
Currently, metadata is a single trait. When one thinks of external tools exporting to tskit, one starts to worry that loads of
Vec<T: tskit::metadata::MetadataRoundTrip>
accumulate, leading to the possibility that the wrong metadata will be sent to the wrong table.This PR is an attempt to add safety to the traits, meaning that a mutation table row can only get "mutation meta data", which client code must specify via a marker trait.
It seems that we can also provide little macros like
register_mutation_metadata!(...)
to streamline this a bit.