-
Notifications
You must be signed in to change notification settings - Fork 206
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
Basic structure for composing stub code #87
Basic structure for composing stub code #87
Conversation
- IMarshallingGenerator interface - Implementation that is just a forwarder - Use Roslyn APIs for syntax generation
DllImportGenerator/DllImportGenerator/Marshalling/BoolMarshaller.cs
Outdated
Show resolved
Hide resolved
DllImportGenerator/DllImportGenerator/Marshalling/MarshallingGenerator.cs
Outdated
Show resolved
Hide resolved
@elinor-fung Can we also get a |
Added a |
|
||
Generation of the stub code happens in stages. The marshalling generator for each parameter and return is called to generate code for each stage of the stub. The statements and syntax provided by each marshalling generator for each stage combine to form the full stub implementation. | ||
|
||
### Stages |
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.
The stages look good. One question is regarding positional and implicit arguments. For example LCID creates an argument to pass and PreserveSig
adds an out param to the method signature. Is this scheme able to handle that efficiently? Do we have an example/pattern for how handle those cases?
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 was thinking most of the handling would be on creating all the TypePositionInfo
s during processing of symbols/metadata - setting Managed/UnmanagedIndex
properties accordingly and creating ones to represent an LCID argument / out param / HResult if needed. We could have specific marshalling generators for the LCID argument and HResult checking.
Then, going through the stages should not be affected other than a bit of extra cruft around declaring variables for the return value of the stub and the invoke (if needed) and determining identifier names.
I didn't want to deal with actually handling those cases yet. I can add some placeholder TODOs to indicate what I had in mind.
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.
LCID argument
FWIW, LCID arguments is an obscure legacy feature. I would be perfectly happy to not support it for the source generators if it were to add even a bit of extra complexity anywhere.
One thing I've noticed with this design is the marshaler selector will need to know about the particular target scenario (P/Invoke, Reverse P/Invoke, Struct) to correctly support marshalers that either pin or allocate depending on the scenario. I'm ok with that, but I just wanted to make sure that we expected that. |
I thought that would be something that could go on the context that gets passed to the |
You are correct. I misread how the context was created/passed in. This should work for those cases then. |
Add placeholders for handling PreserveSig
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.
Just a few comments around places we'll have to change in the future as we add features. We can fix these now or modify them in the future when we'll need the changes.
Other than that, this looks great!
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.
Just one comment. Other than that, LGTM!
Co-authored-by: Jeremy Koritzinsky <[email protected]>
It enforces a bogus rule: dotnet/runtime#60454
IMarshallingGenerator
- called for each stage of generationStubCodeContext
- context for what marshalling code should be generatedTypePositionInfo
- type to be marshalledGenerateSyntax
calls into the marshalling generators and uses the returned statements to create the stub code