Skip to content
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

Defstruct Macro Added: #6

Closed
wants to merge 1 commit into from

Conversation

SkippityPaps
Copy link

A small macro has been made to clean up reptitive instances of '(defalias ::type [::struct [[:foo ::int] [:bar ::int]]])' such that they can be written as '(defstruct ::type [[:foo ::int] [:bar ::int]]).' Spec fdef added to ensure input is keyword and a non-empty collection of keyword/::type pairs.

A small macro has been made to clean up reptitive instances of '(defalias ::type [::struct [[:foo ::int] [:bar ::int]]])' such that they can be written as '(defstruct ::type [[:foo ::int] [:bar ::int]]).'
Spec fdef added to ensure input is keyword and a non-empty collection of keyword/::type pairs.
@IGJoshua
Copy link
Owner

Hey! Thanks so much for the interest!

I'm really open to a defstruct macro being added to the public API of coffi.

I don't want the macro to just be a shorthand for defalias though. Right now, there's a lot of performance issues with marshaling structs using the built-in mechanism for it with the ::mem/struct types, because there's a lot of computation that has to be done at runtime.

A defstruct macro though, has access to all the information that ::mem/struct types do, except it has access to it at macroexpansion time. You may see where I'm going with this.

For me to be happy with the inclusion of a defstruct macro, it should have unrolled loops, it should use the write-* primitive functions for primitive fields, it should support different layouts (which can be done by just making padding fields not be written to at all after calling the layout function on the struct definition), and should otherwise go to significant effort to increase performance in every feasible case. You can see the lengths I am willing to go to when doing this by looking at the definition of inline-serde-wrapper in coffi.ffi.

If you have any questions about details for how this could be implemented, I'd be happy to answer them. I also wouldn't blame you for deciding that this would be too much work to be worth it and just use the implementation you've provided in your own projects until I am able to take the time to build out a defstruct macro myself.

@IGJoshua
Copy link
Owner

Superceded by #14

@IGJoshua IGJoshua closed this Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants