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
C# / dotnet target for diplomat-tool
#124
Conversation
Wow, this is amazing! cc @sffc @nciric I can't commit to maintaining this backend, and I may still be making changes to the rest of the code here: I'm kinda fine with landing this here with the understanding that the backend may occasionally break (which I can always tag you in for). Does that seem okay to you? In general Diplomat is still kinda unstable so users should be installing specific git hashes (or cargo versions) anyway. Over time this should become less of a problem, it's just that right now there are still missing features and in the process of adding these features I can't (at the moment) commit to making sure the dotnet backend works too. Another option is to create a separate dotnet repo that lives underneath (We may have more bandwidth to work on dotnet ourselves in the future, it's certainly something we'd like to support, and we're happy to make space for this backend to be worked on right now as well, just that we may not be able to commit to working on it too) |
Yeah I think we need some kind of DiplomatWriteable-like thing that allows one to return In the meantime, it should be possible to define your own custom vector type that has an API exposed over FFI. That's the solution for the general case anyway. |
Yay! Having C#/.net target is great.
чет, 20. јан 2022. у 15:48 Manish Goregaokar ***@***.***> је
написао/ла:
… The only missing piece is a way to return a buffer of bytes (basically
something like the DiplomatWriteable, but using std::io::Write instead of
std::fmt::Write I guess).
Yeah I think we need some kind of DiplomatWriteable thing that allows one
to return Vec<T>s. It's complicated though, since not all T types can
interchange cleanly.
—
Reply to this email directly, view it on GitHub
<#124 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA7GEKXRVH4NEDU62GTDVLTUXCNMHANCNFSM5MOC56RA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Yeah, restricting to bytes (and maybe other primitive types) sounds like a good stopgap. Not urgent, since one can work around using a custom vector type as you mentioned, but still nice to have.
Sure, this sounds good to me 👍 I'm happy to see you guys are interested as well! |
Sounds great! Once this is ready and lands I'll be sure to tag you (but not block on you) for any changes to the dotnet module. I may feature-gate the dotnet module and add a separate CI job that does dotnet generation and testing if it ends up breaking often, but I suspect that may not be necessary. |
If you'd like to add such a feature I'd be happy to help out! Writeable is certainly a bit annoying implementation-wise so duplicating it is probably similarly annoying, but maybe not too bad. |
8c19b1f
to
ff5afc1
Compare
Current state: C# bindings for
This sounds good.
Great! I'll give it a try for my next contribution then 😄 |
3be0548
to
0bcdbd8
Compare
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.
Should we be checking in:
.editorconfig, .gitignore?
Anything under Generated (I assume those files are a product of running the diplomat-tool c# command.
We should check in any Most non-build artifact files under example/ and feature-tests/ should be committed. It should be possible to run the tests without regen |
3f00dfb
to
a595bb6
Compare
I rebased on |
f7a5f59
to
0aa6bc5
Compare
0aa6bc5
to
0923e6a
Compare
5ceacb6
to
6838b8d
Compare
Thanks for your patience (been rather busy this week), I've started reviewing: For future changes can you push them as individual commits without squashing/rebasing? We use squash merges and GitHub isn't good at remembering review state between rebases. If you need to rebase over |
Oh, sorry if i caused any inconvenience. I’ll refrain from squashing my commits next time 👍 |
Oh, no worries, I hadn't started yet and planned to let you know when I did |
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.
Looking pretty good so far! I haven't done a thorough review but I don't think I'll be able to do one and I'm happy to land this without that level of review since we discussed potentially disabling this if things break.
One common thread here is the handling of opaque/non-opaque types, which has cropped up a couple times. Might be worth discussing further.
(I would like to eventually get all my thoughts on this documented in the diplomat book so that backend writers have it easy, but I don't have time for that right now)
tool/tests/snapshots/dotnet_target__boolean_type@MyStruct.cs.snap
Outdated
Show resolved
Hide resolved
Yes, as long as I didn’t break anything for other backends it should be safe! I’m pretty satisfied with a general review for stuff like how opaque/non-opaque types are managed.
I’ll indeed revisit non-opaque types following your comments 👍 My understanding so far: non-opaque structs should be as dumb as it comes: fully managed by C#, no destructor. Since destructor do not need to be run, I don’t even need to manually allocate the raw struct on heap like I did in current implementation (it was mostly done for simplicity assuming destructor could be run… because I didn’t want to manage I’ll also remove the "move semantic" from generated C# classes. |
Correct. WASM does need to allocate the raw struct because it needs a place to read it from (a quirk of how WASM memory works), but you do have a stack-able As a followup we probably should tighten some of the restrictions here. |
This test was taking references to non-opaque structs. However, Diplomat doesn't allow this pattern and only opaque types can be passed by reference.
Okay, I think I addressed all current concerns.
Let me know if there any remaining concern! |
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.
minor issues.
I think in the long run C# non opaques will not be able to cache the full struct locally since they'll also support references to opaque types and such. But it's fine for now
tool/src/c/types.rs
Outdated
struct MyStruct { | ||
a: Box<MyStruct>, | ||
a: Box<MyOpaqueStruct>, |
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.
nit: I think this needs to be & MyOpaqueStruct
and we can later enforce that non opaque structs are fully Copy
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.
Good point, I changed that
Absolutely, I'll open a follow-up issue about that. |
Except cpp one because it currently panics
I think we're good now! Thanks for all this work! We've found a bunch of followups to fix, which I might take a stab at if I get time, but if you plan to pick stuff up please leave a comment so we don't end up duplicating work 😄 |
Just letting you know: I also changed tho |
CPP does support structs, fwiw. But that's fine, I think it might not support refs-in-structs yet |
Sorry I indeed meant refs-in-structs (forgot to re-read myself).
Great! Definitely going to let you know! 😄 |
Hi,
I've been writing a dotnet target for
diplomat-tool
in order to expose a C# API topicky
.I actually used it to generate fully functional bindings to
picky
in my experiment repository. The only missing piece is a way to return a buffer of bytes (basically something like theDiplomatWriteable
, but usingstd::io::Write
instead ofstd::fmt::Write
I guess).I still have a few corner cases to fix, but I figured I could open this PR as a draft.
Todo before I consider the MVP complete
bool
type is in return position.()
type as error.Future improvements
Option
ofenum
in parameters