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

Classify type with empty base as non-blittable #46769

Merged
merged 4 commits into from
Jan 20, 2021
Merged

Classify type with empty base as non-blittable #46769

merged 4 commits into from
Jan 20, 2021

Conversation

am11
Copy link
Member

@am11 am11 commented Jan 8, 2021

Attempt to fix #46738.

@am11 am11 marked this pull request as ready for review January 8, 2021 22:34
Copy link
Member

@MichalStrehovsky MichalStrehovsky left a comment

Choose a reason for hiding this comment

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

I'll need to step through all of this in a debugger because I'm not sure what the logic should be. Layout-related things always require extra care. I don't have time/setup for that right now unfortunately (it's also why I just filed the issue instead of just fixing this :)).

Cc @dotnet/crossgen-contrib if someone has time to review this earlier.

Copy link
Member

@davidwrighton davidwrighton left a comment

Choose a reason for hiding this comment

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

@am11, thank you for looking into this. Please look at my comments and respond. Once you've done that I'll have a larger test pass run on this.

@davidwrighton
Copy link
Member

@am11 I see the new IsZeroSized bool property, but the implementation is quite confusing and feels like it is possibly fragile. Could you add a test that IsZeroSized returns false/true in a few interesting cases? In particular, if you could test the behavior of that api with both structs and classes that are empty/have a single field?

@am11
Copy link
Member Author

am11 commented Jan 19, 2021

@davidwrighton, admittedly, I am not an expert on crossgen2; but to my understanding, size calculation without padding: _instanceByteCountUnaligned == _instanceByteAlignment (or _instanceByteCountUnaligned - _instanceByteAlignment == LayoutInt.Zero) is true for empty reference type, and false for non-empty ones. This is the case for LayoutKind.Explicit and LayoutKind.Sequential.

I have added a comment and renamed the property to IsZeroSizedReferenceType as this logic is only applicable for classes.

@davidwrighton
Copy link
Member

@am11 Thank you for indulging me on adding these various tests and the refactorings. IMO the way you are checking for empty in the property isn't a behavior that I believe we are certain to keep for all of time; however, I agree the behavior is correct at this time, and the tests are in place to ensure we don't break this behavior in the future (and if we do, all we'll have to do is fix the one property implementation).

@davidwrighton davidwrighton merged commit 95d9425 into dotnet:master Jan 20, 2021
@davidwrighton
Copy link
Member

@am11 Thank you for your contribution. We really appreciate it.

@am11 am11 deleted the feature/crossgen2/R2RTests/MarshalUtils branch January 21, 2021 04:29
@ghost ghost locked as resolved and limited conversation to collaborators Feb 20, 2021
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.

Definition of IsBlittable doesn't match runtime
5 participants