[metadata] Fields whose types are gparams with a reference type const… #1211
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.
…raint aren't blittlable. (mono#15761)
aren't blittlable.
Don't try to layout the field to find out if it's blittable.
For gshared gparams, follow the blittability of the constraint.
Fixes certain recursive examples.
Fixes mono#15760
Unity Fixes https://fogbugz.unity3d.com/f/cases/1147579/
Unity Release Note: Fixes issue where recursive type definitions would fail to compile successfully
The failure is happening when we are doing mono_class_setup_fields ("BaseClass") which needs to decide for each field whether it is blittable or not. So therefore we are trying to decide if ValueTest (that is: the ValueTest field inside BaseClass) is blittable or not.
So we instantiate U with T.
Now to decide whether VaueTest is blittable or not, we look at every field.
So then we look at T value.
To decide if T is blittable we first check if it's a reference type.
That check is currently inadequate for generic parameters - what the PR adds is the ability to see if theres a T : class constraint or a T : C constraint - where C is some class. As soon as we know that T's constraint will force it to be a reference type we can definitely say that T won't be blittable without having to initialize C, at all.
Previously, Mono would see that T is some kind of type for which it couldn't definitively decide that it's a reference type and it would call: mono_class_setup_fields (field_class) which would then try to setup the fields of the parent class BaseClass. And that would hit the recursion check.
Unity cherry-pick note: Needed to bring MONO_CLASS_IS_INTERFACE_INTERNAL
and mono_class_get_valuetype_class forward