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

Copy ctor handling for crossgen2 #40113

Merged
merged 2 commits into from
Jul 30, 2020

Conversation

davidwrighton
Copy link
Member

@davidwrighton davidwrighton commented Jul 29, 2020

  • Add IL based test for copy ctor to allow testing in Crossgen2 which doesn't yet support IJW
  • Add api to determine proper EmbeddedSignatureData index for these
    • And tests to ensure this remains functional
  • Marshaller changes to recognize copy constructor cases
    • Note that there isn't actual marshaller support. Instead the compiler can now able to detect when copy ctors should be used, and falls back to the runtime interop layer

Fixes #39423

Note that with this change there is only one more case of custom modifier examination that is used to affect runtime codegen. (The use of the IsCXXReferenceModifier type when searching for destructors to implement this form of marshalling.) Also, as that syntax hasn't been generated from a C++/CLI compiler in many years, it is unlikely that it will ever need to be implemented.

- Add IL based test for copy ctor to allow testing in Crossgen2 which doesn't yet support IJW
- Add api to determine proper EmbeddedSignatureData index for these
  - And tests to ensure this remains functional
- Marshaller changes to recognize copy constructor cases
  - Note that there isn't actual marshaller support. Instead the compiler can now able to detect when copy ctors should be used, and falls back to the runtime interop layer
@davidwrighton
Copy link
Member Author

@dotnet/crossgen-contrib

@davidwrighton
Copy link
Member Author

@jkoritzinsky I've added this IL only copy ctor test in order to get coverage on this form of marshalling in crossgen2.

internal static MarshallerKind GetMarshallerKind(
TypeDesc type,
MarshalAsDescriptor marshalAs,
int? parameterIndex,
Copy link
Member

Choose a reason for hiding this comment

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

Indentation looks off.

@@ -183,6 +214,12 @@ public static partial class MarshalHelpers

type = type.GetParameterType();

if (!type.IsPrimitive && type.IsValueType && !(marshallerType == MarshallerType.Field)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (!type.IsPrimitive && type.IsValueType && !(marshallerType == MarshallerType.Field)
if (!type.IsPrimitive && type.IsValueType && marshallerType != MarshallerType.Field

// Parameter index 0 represents the return type, and indices 1-n represent the parameters to the signature
public static string GetIndexOfCustomModifierOnPointedAtTypeByParameterIndex(int parameterIndex)
{
return $"0.1.1.2.{(parameterIndex + 1).ToStringInvariant()}.1";
Copy link
Member

Choose a reason for hiding this comment

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

Not reviewing this part. I don't want to spend time learning how this address is computed because that code upsets me.

@@ -444,7 +481,15 @@ public static partial class MarshalHelpers
else if (type.IsPointer)
{
if (nativeType == NativeTypeKind.Default)
{
var pointedAtType = type.GetParameterType();
if (!pointedAtType.IsPrimitive && !type.IsEnum && !(marshallerType == MarshallerType.Field)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (!pointedAtType.IsPrimitive && !type.IsEnum && !(marshallerType == MarshallerType.Field)
if (!pointedAtType.IsPrimitive && !type.IsEnum && marshallerType != MarshallerType.Field

@davidwrighton davidwrighton merged commit 65b8cf2 into dotnet:master Jul 30, 2020
Jacksondr5 pushed a commit to Jacksondr5/runtime that referenced this pull request Aug 10, 2020
- Add IL based test for copy ctor to allow testing in Crossgen2 which doesn't yet support IJW
- Add api to determine proper EmbeddedSignatureData index for these
  - And tests to ensure this remains functional
- Marshaller changes to recognize copy constructor cases
  - Note that there isn't actual marshaller support. Instead the compiler can now able to detect when copy ctors should be used, and falls back to the runtime interop layer
@karelz karelz added this to the 5.0.0 milestone Aug 18, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2020
@davidwrighton davidwrighton deleted the copyctor_r2r branch April 20, 2021 17:43
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.

Crossgen2 doesn't respect NeedsCopyConstructorModifier/IsCopyConstructed
5 participants