Skip to content

Conversation

@jkoritzinsky
Copy link
Member

@jkoritzinsky jkoritzinsky commented Sep 17, 2020

Create a basic data model to represent parsed attribute metadata either with the old system or with the new attribute model described in the StructMarshalling design doc. (Reading the metadata into the model for the new attributes TBD).

Update MarshalerGenerators.TryCreate to use the new data model to determine generators and have more specific coverage of primitive types.

Make the bool marshaler more compatible with the new data model (use a parameterized marshaler instance instead of reading the metadata in the marshaler).

Implement more efficient blittable byref marshalling so we can more efficiently marshal blittable structs (which are coming with the new model)

Implement delegate->function pointer marshaller generator to show the flexibility of the pattern matching approach for the MarshalerGenerators.TryCreate method.

I've validated that the Roslyn code-gen for the pattern matching switch is as optimal as doing a nested switch statement model more similar to what we currently do in the runtime. I will say that the readability for the more complex patterns could use some improvement, so I'm open to suggestions/recommendations.

…number of casts in the fast-path scenario of unmarked blittable primitives) and collapse the nested switch into patterns (since Roslyn optimizes the two the same way)
…g expensive struct copies for large blittable structs.
…stem (since we aren't parsing the new attributes yet).
@jkoritzinsky jkoritzinsky added the area-DllImportGenerator Source Generated stubs for P/Invokes in C# label Sep 17, 2020
Signed-off-by: Jeremy Koritzinsky <[email protected]>
Signed-off-by: Jeremy Koritzinsky <[email protected]>
…ntext and move it into the P/Invoke generator.
…lling boundary when the native representation doesn't keep the managed representation alive.
…ttableTypeAttrbiute on the type instead of on the parameter/return value.
…bugs.

Treat in byref as byref.

Correctly compare against false when unmarshalling bools.
…stackalloc constructor exists."

This reverts commit 09f0f8c.
@jkoritzinsky
Copy link
Member Author

I've added the metadata reader for the new attributes and added some tests around the BlittableType attribute.

I did do some work around non-blittable structs, but I've pulled that out of this PR and I'll put out a new PR in the future once we get to supporting them. From this work though, I found a bug where we were treating in parameters as by-value, and another bug in the bool unmarshalling code, which are both fixed in this PR.

Can I get another review pass?

@jkoritzinsky jkoritzinsky merged commit ebf31e6 into dotnet:DllImportGenerator Sep 29, 2020
@jkoritzinsky jkoritzinsky deleted the marshaler-selector branch September 29, 2020 18:38
jkoritzinsky added a commit to jkoritzinsky/runtime that referenced this pull request Sep 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-DllImportGenerator Source Generated stubs for P/Invokes in C#

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants