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

Share code between source-generated and built-in marshallers #69043

Merged
merged 2 commits into from
May 13, 2022

Conversation

jkotas
Copy link
Member

@jkotas jkotas commented May 9, 2022

No description provided.

@jkotas
Copy link
Member Author

jkotas commented May 9, 2022

@dotnet/interop-contrib What do you think about this? If we get an agreement that it is a good idea to share the implementation like this, I will reformat the other string marshallers to follow the same pattern.

@AaronRobinsonMSFT
Copy link
Member

AaronRobinsonMSFT commented May 9, 2022

Looking only at the title, I am hesitant to do this. My reasoning is the unintentional impact this may have on the built-in system that we are stating is "static" minus bug fixes. I could easily see a scenario where we decided to change something minor in the new system and that flows into the built-in. I appreciate the desire to remove duplicate code but I think the two systems are separate for reasons of stability and innovative opportunity - these are competing interests in my mind.

@jkotas
Copy link
Member Author

jkotas commented May 9, 2022

I believe that the fragility of the built-in system is in the advanced cases like reference type marshalling or COM interop. I would hope that string marshalling is simple-enough to not suffer from the fragility. We are making the string marshaller types public, so the innovation that can be applied to them will be fairly limited.

One of my motivations for doing this is to reduce the engineering dept in NativeAOT. The built-in system in NativeAOT is using different set of helpers for interop. I wanted to use this as an opportunity to get everything on the same plan.

@AaronRobinsonMSFT
Copy link
Member

We are making the string marshaller types public, so the innovation that can be applied to them will be fairly limited.

I'd hope we have some latitude here, but your point is fair. I don't think this argument moves me much though.

One of my motivations for doing this is to reduce the engineering dept in NativeAOT. The built-in system in NativeAOT is using different set of helpers for interop. I wanted to use this as an opportunity to get everything on the same plan.

Ugh. Well crap... this does change my perspective. I agree reconciling all of them would be a win. I will say the new entry points do seem to clutter the implementation and make something that is nicely standalone and easy to reason about more complicated. I guess I'm going to have to review this in detail. I think this is worth exploring.

@elinor-fung
Copy link
Member

What do you think about this? If we get an agreement that it is a good idea to share the implementation like this

Haven't looked through all the changes (only skimmed the marshaller and stub helper in managed), but I am pro sharing. I consider the possibility of sharing like this to be one of the reasons we wanted the public string marshallers.

@@ -101,5 +103,26 @@ public void FreeNative()
if (_allocated != null)
Marshal.FreeCoTaskMem((IntPtr)_allocated);
}

internal static string? ConvertToManaged(byte* value)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these internal helpers are a sore spot, I can try to update the built-in marshalling to use the public methods and follow the regular pattern that depends on the marshaller instance everywhere.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is the sore spot for me, at least that is what I initially noticed. If we could get rid of them I think I'd be willing to let my other concerns go.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I have reverted the internal helpers and change the IL generation to target the public methods. How does it look?

@jkotas jkotas marked this pull request as ready for review May 13, 2022 03:42
@jkotas jkotas merged commit f4d0310 into dotnet:main May 13, 2022
@jkotas jkotas deleted the unify-marshallers branch May 13, 2022 13:48
@ghost ghost locked as resolved and limited conversation to collaborators Jun 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants