D guest bindings generator - #1561
Conversation
|
This PR is not yet finished. Just opening a draft early to help interested parties keep track. |
|
Thanks! One thing I'd also recommend as you're implementing things is to add Happy to help answer questions about anything in specific if you have them, and if you have any questions about Rust/idioms/etc feel free to leave a comment here and I can dig in. Otherwise I'll leave this be until you're ready, in which case feel free to ping me and I can take a closer look. |
[skip ci]
[skip ci]
[skip ci]
|
Things are coming along nicely, but there's one question I have so far. The Problems arise with the testing of the export wrappers. The way I've implemented exports is using D templates, which are not and cannot be semantically analyzed at all until they have been instantiated. Until an implementation is provided, the wrappers can't be tested. Is this a problem? This gap in the testing? Or are the |
|
A good question! If I understand the problem right I believe you're looking for this. The |
|
Yeah! That's pretty much the answer I'm looking for. Something that can create a very basic stub (no impl; just declarations of functions and types) that I can pump into the exports wrapper soley for tests. Thanks! |
[skip ci]
[skip ci]
|
I'm still working on getting full test coverage, but I'm ready for this to start getting reviewed. Support for the new async stuff will be tackled in a future PR. Same with |
alexcrichton
left a comment
There was a problem hiding this comment.
Integration points all look good to me 👍. I can't speak much to D idioms and I'm not looking too closesly at crates/d/src/lib.rs, but that's what'd be in your purview
|
For the CI failure, can you publish a |
I'll do that closer to when this is all ready. I might find more small things needing tweaking as I flesh out the tests. No point making more releases than necessary. |
|
Perhaps you have some opinion or suggestions... (e.g. based on the choices made by other bindings)? Up to now I've been hammering this out trying to make the API as symmetric as possible, and deferring certain aspects of memory management to the user. Import parameters are "borrowing" (caller takes a constant reference; callee retains ownership of memory), and returns are owning, where the user has to free when they are done. D's Same applies to exports, where for parameters the API provides you a const "borrow" and frees the memory itself. However you have to move any returned memory to the C heap ( To keep signatures consistent for parameters vs. arguments, a thin But once resources come into play, this starts getting more difficult. Right now you have to drop own handles yourself when you are done, and there are no guardrails to prevent use-after-free. And I just realized that borrow handles provided to you via parameters must ALSO be dropped. I've been allowing quietly coercing owns into borrows, but now one has to keep track of where the So I'm considering maybe bringing in some RAII (and some other D features) to help make this easier to deal with. Specifically, I'm thinking of making resource handles drop themselves on destroy, and disabling copying, making moves explicit. But moving an own handle out of a parameter requires said parameter to be mutable. Lists, etc. also have to be aware of this. So I'm thinking maybe switch things up. Split the types used for parameters from the ones use for returns (which requires duplicating all the record types; making two variants). Parameters can be idiomatic D slices (since lifting lists of lists requires extra copies anyway because of And returns can be wrapped in their own RAII type that handles freeing all the memory and handles contained (if you don't explicitly move particular buffers or handles out). Switching it now would be setting this back, as I have to rework... most of it. Increases the convenience of the bindings, but increases the complexity of the generator. But better to do it before merging, rather than breaking things later? |
|
After some more thought, I think I'll just keep going with the current model, since I'm so close to having something working available. I might switch things up later. Need to get more feedback first. |
Implements a
dsubcrate to support generating bindings for the D programming language.