You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here, we have individually malloced columns col1, etc which we want to give to the library. Note that once these are pointers obtained from malloc, there's no need to mark the tables read-only, we can operate as normal.
tsk_treeseq_init(ts, tables, options)
Here, we want to pass ownership of the tables from the client to the tree sequence. Currently treeseq_init always takes a copy, which is often unnecessary.
I suggest we use the same flag in each case. We could also use TSK_NO_COPY, but it's not as clear that we're transferring the responsibility for freeing as well then.
@bhaller, @molpopgen, any thoughts on the flag naming and semantics as downstream users?
I'm a fan of this idea. Will probably use it only in the reference sequence case, in SLiM, but it sounds generally useful. TSK_TRANSFER_OWNERSHIP, as in the issue title, seems pretty clear. TSK_TAKE_OWNERSHIP might be even clearer, to say "tsk is taking" – active construct, versus the more passive "transferring". You could emphasize that the block must be malloced, as in TSK_TAKE_MALLOCED_BLOCKS or something, but that's pretty wordy, and makes it sounds like maybe if the blocks aren't malloced then tsk just won't take them (when in fact a crash would presumably eventually result); and anyway I think everybody who isn't a total newbie programmer would assume that if tsk is taking ownership then the blocks have to be malloced. So I think my vote is for TSK_TAKE_OWNERSHIP maybe?
It depends on who you see as doing the "transferring" and "taking" doesn't it? On balance I think TSK_TAKE_OWNERSHIP is clearer, you're telling tskit to take ownership of the buffer.
Is it important to any clients of tskit to have that API guarantee of constness? Const is nice to support when it works well, but if a bunch of API would have to be doubled, maybe it just isn't worth it...?
That makes sense; I would just say that you probably shouldn't switch the semantics of any existing API from "take a copy" to "take ownership", because that will introduce nasty crashing bugs, right? If you're going to change the ownership semantics, it would probably be best to abandon the old API completely, to force compile errors that people have to think about the right way to fix. Of course the refseq APIs are brand new anyway, so nobody should be surprised if their semantics are still in flux; but you're talking about doing this API shift for other calls too, right? So maybe use take_data() and copy_data(), and abandon set_data() names throughout?
Yes, good points @bhaller, that's one to consider carefully. You're right we shouldn't change the semantics of set_columns, so take_columns is better. The question then is whether we bother renaming set_columns to copy_columns...
OK, I think this is definitive. I'll open/close a bunch of issues to try and split things into independent discussions.
Closing this for now in favour of the "takeset" methods in #2016. We'll still probably want a "TAKE_OWNERSHIP" flag for the treeseq_init case, but lets deal with that separately.
Activity
bhaller commentedon Dec 3, 2021
I'm a fan of this idea. Will probably use it only in the reference sequence case, in SLiM, but it sounds generally useful.
TSK_TRANSFER_OWNERSHIP, as in the issue title, seems pretty clear.TSK_TAKE_OWNERSHIPmight be even clearer, to say "tsk is taking" – active construct, versus the more passive "transferring". You could emphasize that the block must be malloced, as inTSK_TAKE_MALLOCED_BLOCKSor something, but that's pretty wordy, and makes it sounds like maybe if the blocks aren't malloced then tsk just won't take them (when in fact a crash would presumably eventually result); and anyway I think everybody who isn't a total newbie programmer would assume that if tsk is taking ownership then the blocks have to be malloced. So I think my vote is forTSK_TAKE_OWNERSHIPmaybe?jeromekelleher commentedon Dec 3, 2021
Let's have some votes (:+1: :-1:)
jeromekelleher commentedon Dec 3, 2021
or
jeromekelleher commentedon Dec 3, 2021
It depends on who you see as doing the "transferring" and "taking" doesn't it? On balance I think TSK_TAKE_OWNERSHIP is clearer, you're telling tskit to take ownership of the buffer.
molpopgen commentedon Dec 3, 2021
This will be a great addition.
molpopgen commentedon Dec 3, 2021
I should do a mock-up (for my own edification at least) of the implications for rust. The borrow checker is strict!(
jeromekelleher commentedon Dec 3, 2021
Which is timely... We're hitting some serious const tedium when I started working through this.
All the pointers that we're passing will have to be marked non-const, which will really muck up the test suite.
It would nearly be easier to have a separate set of methods to be honest... Any opinions?
molpopgen commentedon Dec 3, 2021
Ugh, right--const! I hadn't even gone there yet in my head. Yeah, it seems that a "tree seq from const table collection" function is the way to go?
bhaller commentedon Dec 3, 2021
Is it important to any clients of tskit to have that API guarantee of constness? Const is nice to support when it works well, but if a bunch of API would have to be doubled, maybe it just isn't worth it...?
jeromekelleher commentedon Dec 3, 2021
So, we could change to something like
and
So the
setform takes ownership of the reference, and the copy for takes a copy.We'd also have to rename the current
x_table_set_columnstox_table_copy_columnsand make a new non-const methodsx_table_set_columns.Overall, this is a more logical setup tbh. Compiler warnings are there for a reason...
bhaller commentedon Dec 3, 2021
That makes sense; I would just say that you probably shouldn't switch the semantics of any existing API from "take a copy" to "take ownership", because that will introduce nasty crashing bugs, right? If you're going to change the ownership semantics, it would probably be best to abandon the old API completely, to force compile errors that people have to think about the right way to fix. Of course the refseq APIs are brand new anyway, so nobody should be surprised if their semantics are still in flux; but you're talking about doing this API shift for other calls too, right? So maybe use
take_data()andcopy_data(), and abandonset_data()names throughout?jeromekelleher commentedon Dec 4, 2021
Yes, good points @bhaller, that's one to consider carefully. You're right we shouldn't change the semantics of
set_columns, sotake_columnsis better. The question then is whether we bother renamingset_columnstocopy_columns...OK, I think this is definitive. I'll open/close a bunch of issues to try and split things into independent discussions.
jeromekelleher commentedon Dec 5, 2021
Closing this for now in favour of the "takeset" methods in #2016. We'll still probably want a "TAKE_OWNERSHIP" flag for the treeseq_init case, but lets deal with that separately.