Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Initial proposal for P/Invokes via Source Generators #33742
Initial proposal for P/Invokes via Source Generators #33742
Changes from 4 commits
f9a32c7
162dee8
517421d
717a47e
f9270e4
caa8af3
61a77bb
dc9c3a0
20ac655
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
A few questions related to marshallers:
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.
@jeffschwMSFT Here are my thoughts:
Sure. That is already possible since users can convert their non-blittable P/Invoke signature into a blittable one and instead implement a wrapper that does all the marshaling manually. There would be little need to do any generation if the signature only contain blittable types - at least that seems to be the tenor of the current thought.
That would be a design consideration for the default Source Generator supplied by the .NET team. If that source generator is extensible or not is entirely up to us. Third parties that want their own P/Invoke source generator would need to define their own mechanism to extensible marshaling. For the default, we would add support as types become interesting.
Span<T>
would of course be in the default as well asNullable<T>
and various others as the language continues to evolve, but we could add support and users could opt in without requiring a runtime update.That is an interesting question for the Source Generator team. @chsienki How is the Source Generator team thinking about propagation of source generator states? How does a Source Generator convey failures to the users?
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.
Generators can produce diagnostics (much like an analyzer does today), which are presented to the user via the command line / IDE etc.
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.
Thanks @chsienki. @jeffschwMSFT Seems like any Source Generator for P/Invokes would be able to alert a user when a type is hit that can't be marshaled in a nice message. This could point to the classic P/Invoke mechanism when the Source Generator can't support the scenario and/or we point users to a repo to file an issue or guidance for how to manually work around support.