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

Refactor our linear collection marshalling implementation #86519

Merged
merged 3 commits into from
May 19, 2023

Conversation

jkoritzinsky
Copy link
Member

@jkoritzinsky jkoritzinsky commented May 19, 2023

Refactor the elements marshalling logic to split out space allocation and source/destination span construction from the elements marshalling logic. Pull out the element marshalling logic to a common base class and separate it out from the actual marshalling strategies.

This refactoring is required to provide customization points to author the fix for #85795.

I've validated that this change is a zero-diff change on all of the generated code for the LibraryImportGenerator integration tests.

Refactor the elements marshalling logic to split out space allocation and source/destination span construction from the elements marshalling logic. Pull out the element marshalling logic to a common base class and separate it out from the actual marshalling strategies.

This refactoring is required to provide customization points to correctly fix dotnet#85795.

I've validated that this change is a zero-diff change on all of the generated code for the LibraryImportGenerator integration tests.
@ghost
Copy link

ghost commented May 19, 2023

Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.

Issue Details

Refactor the elements marshalling logic to split out space allocation and source/destination span construction from the elements marshalling logic. Pull out the element marshalling logic to a common base class and separate it out from the actual marshalling strategies.

This refactoring is required to provide customization points to correctly fix #85795.

I've validated that this change is a zero-diff change on all of the generated code for the LibraryImportGenerator integration tests.

Author: jkoritzinsky
Assignees: -
Labels:

area-System.Runtime.InteropServices

Milestone: 8.0.0

@ghost ghost assigned jkoritzinsky May 19, 2023
…erop.SourceGeneration/Marshalling/StatefulMarshallingStrategy.cs
/// </summary>
internal sealed class StatelessLinearCollectionBlittableElementsMarshalling : BlittableElementsMarshalling, ICustomTypeMarshallingStrategy
internal sealed class StatelessLinearCollectionSpaceAllocator : ICustomTypeMarshallingStrategy
Copy link
Member

Choose a reason for hiding this comment

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

Is this type ever meant to be used as an ICustomTypeMarshallingStrategy on its own? It looks like it's pretty coupled to the StatelessLinearCollectionMarshalling. Probably not in this PR, but for types like this where it has all the methods of ICustomTypeMarshallingStrategy, but is always supposed to be an "inner marshaller" and isn't meant to be its own the top level ICustomTypeMarshallingStrategy, maybe we should make a different type to make that more clear.

e.g. We could move all the methods from ICustomTypeMarshallingStrategy to a base interface "IMarshallingStatementsGenerator" and have ICustomTypeMarshallingStrategy and ISpaceAllocator both "Marker interfaces" that inherit from it. It might add a little metadata, but I was a bit confused about these scenarios when starting in the codebase.

Copy link
Member Author

Choose a reason for hiding this comment

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

I like that idea. Once this is in, I'll take a look at doing something like that to make it clearer.

Copy link
Member

@jtschuster jtschuster left a comment

Choose a reason for hiding this comment

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

Love the diff stat, and LGTM

Co-authored-by: Jackson Schuster <36744439+jtschuster@users.noreply.github.com>
@jkoritzinsky
Copy link
Member Author

All failures are known issues. Merging this in.

@jkoritzinsky jkoritzinsky merged commit 4dd7e87 into dotnet:main May 19, 2023
@jkoritzinsky jkoritzinsky deleted the elements-marshalling-refactor branch May 19, 2023 22:57
@ghost ghost locked as resolved and limited conversation to collaborators Jun 19, 2023
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.

2 participants