-
Notifications
You must be signed in to change notification settings - Fork 8
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: develop
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've got a few specific things in the review I'd like resolved or to discuss, and attached here I've got a few patches that I'd like if they were applied to the PR.
0004-Don-t-use-underscore-on-used-args.patch.txt
0003-Remove-duplicate-c-layout-implementation.patch.txt
0002-Fix-warning-about-defstruct-redefinition.patch.txt
0001-Use-a-once-only-impl-rather-than-with-typehints.patch.txt
Signed-off-by: Kristin Rutenkolk <[email protected]>
Signed-off-by: Kristin Rutenkolk <[email protected]>
Signed-off-by: Kristin Rutenkolk <[email protected]>
Signed-off-by: Kristin Rutenkolk <[email protected]>
…or strings Co-authored-by: Joshua Suskalo <[email protected]>
Co-authored-by: Joshua Suskalo <[email protected]>
to document a last touch: i moved defstruct can still be called from |
register-new-struct-deserialization
[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.