Skip to content

Conversation

@AaronRobinsonMSFT
Copy link
Member

This eases consumption of the LibraryImport source generator by not forcing the use of DisableRuntimeMarshalling for types where we can determine the type is blittable based on the following rules:

  1. The type is "always blittable" (i.e., int or double, but not char).
  2. A value type defined in the source project the current source generator is running on.
  3. Is a type made up of types adhering to (1) and (2).

This will permit marshalling of the following:

public struct S
{
    public short A;
    public short B;
}

[CustomTypeMarshaller(typeof(S))]
public struct Native
{
    private short a;
    private short b;
    public Native(S s) { ... }
    public S ToManaged() { ... }
}

Fixes #69033

/cc @dotnet/interop-contrib

@ghost
Copy link

ghost commented May 10, 2022

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

Issue Details

This eases consumption of the LibraryImport source generator by not forcing the use of DisableRuntimeMarshalling for types where we can determine the type is blittable based on the following rules:

  1. The type is "always blittable" (i.e., int or double, but not char).
  2. A value type defined in the source project the current source generator is running on.
  3. Is a type made up of types adhering to (1) and (2).

This will permit marshalling of the following:

public struct S
{
    public short A;
    public short B;
}

[CustomTypeMarshaller(typeof(S))]
public struct Native
{
    private short a;
    private short b;
    public Native(S s) { ... }
    public S ToManaged() { ... }
}

Fixes #69033

/cc @dotnet/interop-contrib

Author: AaronRobinsonMSFT
Assignees: AaronRobinsonMSFT
Labels:

area-System.Runtime.InteropServices

Milestone: 7.0.0

@jkotas
Copy link
Member

jkotas commented May 10, 2022

@AaronRobinsonMSFT
Copy link
Member Author

Are we keeping this design doc up-to-date?

Yep. This was simply to get feedback first. I thought had marked it "Draft". I do have one more test to add and will update doc once that passes.

Add test to validate check for blittability for assembly reference
@AaronRobinsonMSFT
Copy link
Member Author

Failing leg is unrelated, Docker pull failure.

@AaronRobinsonMSFT AaronRobinsonMSFT merged commit 094b787 into dotnet:main May 11, 2022
@AaronRobinsonMSFT AaronRobinsonMSFT deleted the support_strictly_blittable_marshalling branch May 11, 2022 14:25
@ghost ghost locked as resolved and limited conversation to collaborators Jun 10, 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.

Support blittable type marshalling without DisableRuntimeMarshalling

3 participants