-
Notifications
You must be signed in to change notification settings - Fork 198
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
Implement support for collections of collections marshalling #1226
Merged
jkoritzinsky
merged 16 commits into
dotnet:feature/DllImportGenerator
from
jkoritzinsky:collections-of-collections
Jun 12, 2021
Merged
Implement support for collections of collections marshalling #1226
jkoritzinsky
merged 16 commits into
dotnet:feature/DllImportGenerator
from
jkoritzinsky:collections-of-collections
Jun 12, 2021
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Use a topological sort of the parameter+return marshallers to unmarshal "CountElementName"-referenced parameters/return before unmarshalling the elements that have a dependency on them through "CountElementName".
…zed) to search for edges.
…abstractions to enable more perf optimizations.
… native-only parameters as distinct nodes in the graph model.
…types of the CountElementName'd elements, even in nested scenarios.
… non-collection sub contexts.
jkoritzinsky
added
the
area-DllImportGenerator
Source Generated stubs for P/Invokes in C#
label
Jun 10, 2021
DllImportGenerator/DllImportGenerator/ContiguousCollectionElementMarshallingCodeContext.cs
Outdated
Show resolved
Hide resolved
DllImportGenerator/DllImportGenerator/ContiguousCollectionElementMarshallingCodeContext.cs
Show resolved
Hide resolved
DllImportGenerator/DllImportGenerator/Marshalling/ICustomNativeTypeMarshallingStrategy.cs
Show resolved
Hide resolved
DllImportGenerator/DllImportGenerator/Marshalling/MarshallerHelpers.cs
Outdated
Show resolved
Hide resolved
DllImportGenerator/DllImportGenerator/Marshalling/MarshallerHelpers.cs
Outdated
Show resolved
Hide resolved
DllImportGenerator/DllImportGenerator/Marshalling/MarshallingGenerator.cs
Outdated
Show resolved
Hide resolved
DllImportGenerator/DllImportGenerator/Marshalling/MarshallingGenerator.cs
Outdated
Show resolved
Hide resolved
AaronRobinsonMSFT
approved these changes
Jun 12, 2021
jkoritzinsky
added a commit
to jkoritzinsky/runtime
that referenced
this pull request
Sep 20, 2021
…runtimelab#1226) * Refactor indexer naming to be nested-collection safe. * Implement initial collections-of-collections/jagged array support. Use a topological sort of the parameter+return marshallers to unmarshal "CountElementName"-referenced parameters/return before unmarshalling the elements that have a dependency on them through "CountElementName". * Fixes for edge cases around HResult/Exception handling. * Flip the edgeMap indices so we can use Array.IndexOf (which is optimized) to search for edges. * Comments and optimizations. * Add citation for algorithm, * Hoist elementIndex out of the loop. * Encapsulate the edgeMap in a private struct type and add some simple abstractions to enable more perf optimizations. * Make Topological sort more flexible for element ids * Use native index if managed index is unset to allow handling multiple native-only parameters as distinct nodes in the graph model. * Fix using the return value for passing collection size. Validate the types of the CountElementName'd elements, even in nested scenarios. * Change how we initialize the numRows array. * Fix cycle breaking in count info. * Update nested indexer creation for num elements expressions to handle non-collection sub contexts. * Add stress test for collections of collections that uses 0-11 nested arrays. * PR feedback. Commit migrated from dotnet/runtimelab@aa2c08c
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The current code in the feature/DllImportGenerator branch almost supports passing collections of collections (like jagged arrays) by value or by-ref
in
(it only needs the first commit that handles nested for loops), but it does not correctly support passing collections of collections in a way that requires unmarshalling.This PR adds the functionality required to enable marshalling collections of collections like jagged arrays from native code back to managed code.
This code is designed such that if n levels of indirection is supported, then n+1 levels is also supported. The
CollectionsOfCollectionsStress
code snippet test validates this by testing 0-11 dimensional jagged arrays.To enable safely tracing dependencies of "CountElementName" metadata values, this PR enhances the cycle-breaking in the MarshallingAttributeInfoParser to correctly break cycles.
To identify dependencies between parameters/return values, this PR also introduces a topological sorting algorithm to order the parameter/return value unmarshalling in an order that ensures dependencies are marshalled before elements that depend on them.
This algorithm is specified generically so developers of interop source generators could use this mechanism to support their own scenarios. For example, WinRT's implicit array length parameters could have part of their implementation supported by the topological sort.