-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add defstruct macro #14
base: master
Are you sure you want to change the base?
Conversation
I absolutely love this. You've done a fantastic job! I look forward to seeing the tests that you add for this, and I'm also thinking ahead to reorganizing some of the existing serde code to use the new generate-serialize and generate-deserialize to add some inline arities to |
So I like the way you've chosen to introduce the type registry. It integrates well with the existing tools, and provides a way to do inline arities for serialize and deserialize in the future. One hesitation I have at the moment looking over the code is the use of ArraysCurrently in coffi the I also think that your compromise around using a record-like type with both map and array style accesses is appropriate and well-done. I might personally want to go the other direction with the serde registryThe serde registry as it stands with The first is just an observation and not a problem, that being that these functions all generate the equivalent of a The second is that these macros as they stand are unhegenic macro helpers. I think it would be appropriate for the multimethod to take in the symbol which will be used to refer to the segment. with-c-layoutFor the All the structs being passed over the C abi will most certainly use the Specifically though, if we remove the |
right types consistently
I've been hacking away at this more. I really like the idea of the optional keyword. I don't know what the default for the Regarding the generated type: I've ran into issues with more implementations of the IPersistentMap interface colliding with IPersistentVector than i anticipated (like the serde registry is unchanged for now, i'll have to think about nicely making them hygenic. it would definitely make things more complicated. i also don't have a solution for the I still have to clean up a bit, and the above mentioned things aren't addressed yet, but functionality wise, i think things are mostly done and tested. attached is a file with some random criterium runs that i've done to test the speed of stuff: results are promising. the new defstruct is faster than records, maps and sometimes vectors and seem to improve the speed of calling native functions with struct arguments / return types. |
I've been following along as you've been adding commits, and it's been really fun to watch as it grows. Thanks for the wrap-up, it's helped clear everything up in my head though, since I don't usually haven enough time to fully dig into and understand the diffs when I do that. I think I'd like the I really like the solution of adding If making the generation functions hygenic would be a significant amount of work then I would be comfortable with delaying that work and ensuring that the generation functions aren't a part of the public api of coffi for now. So the I'd like to thank you again for taking on this feature! I really like the work you're doing. :) |
Thanks for the feedback! I'm glad you like the progress so far. I think I simply didn't fully get how you meant the I also think your rationale on Thank you for also clearing up that misunderstanding on the whole also, i think i forgot to mention it, but i really like the idea of supporting different layouts, especially in the context of OpenGL / graphics development! so with all that information, the layout namespace makes a whole lot more sense to me! i'll continue on the PR then and update when i hit what feels like the next milestone |
[Note: I would consider this a draft PR, as I have not yet added tests (which could unearth some bugs and necessitate appropriate fixes).]
Hi, this PR contains the addition of a
defstruct
macro. It does the following:c-layout
deserialize-from
andserialize-into
clojure.pprint/simple-dispatch
serde registry
The "registry" is implemented via the multimethods
generate-deserialize
andgenerate-serialize
which produce code to de/serialize the respective types. This removes indirection in the de/serialize code for types that use other types. i think in the original discussion we were on the same page, but thought the other meant something different. Thedefstruct
macro adds implementations to the multimethods for the newly generated type.the generated type
The new type is generated via
deftype
in the private functiongenerate-struct-record
. This is an attempt to strike a middle ground between the two positions of the original discussion, although the result might be a bit odd:IPersistentVector
andIPersistentMap
.nth
as well as map-like methods likewithout
(for e.g.dissoc
).assoc
, it supports both paradigms of indices-as-keys and membernames-as-keys. Practically speaking, if you use something likeassoc
with a number as a key, it behaves like a vector (and will return a vector), otherwise like a map (and will return a map).foreach
which can't support both paradigms, and it is therefore implemented as if it's a vector. The rationale here is that the value of the type is composed of the actual values of the members, not the associated names of the places of the values. If youmap
orreduce
over an object of this type, you will do so over the values of the members.with-c-layout
There was one implementation problem. Since padding was needed to be taken into account to allow for inline serdes, the new code for the macro needed to rely on
with-c-layout
. The problem here is thatwith-c-layout
is in thelayout
namespace which already depends onmem
. As a stopgap solution i simply copied the function over as a private function. I would be in favor of actually deprecating thelayout
namespace. for backwards compatibility thewith-c-layout
function inlayout
could depend on the one inmem
. Not only is thelayout
namespace at this point somewhat anemic, it has also caused me trouble. I'm not sure if it's a bug, but due towith-c-layout
being inlayout
, i ran into the problem that there are now two different:padding
keywords, which i found confusing.tests & benchmarks
No tests or benchmarks exist right now. I don't expect the custom type to be slower than defrecord, but I want to test it.
Similarly, i do want to add a first set of tests for the de/serialization.