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

Avoid GetConstructors in constraint validation #81068

Merged
merged 4 commits into from
Jan 25, 2023

Conversation

MichalStrehovsky
Copy link
Member

Contributes to #80165.

Avoids bringing ConstructorInfo to simple apps.

This and whatever we do for #80896 is all that's left.

Cc @dotnet/ilc-contrib

Avoids bringing ConstructorInfo to simple apps.
@MichalStrehovsky MichalStrehovsky marked this pull request as ready for review January 24, 2023 05:06
@ghost
Copy link

ghost commented Jan 24, 2023

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Issue Details

Contributes to #80165.

Avoids bringing ConstructorInfo to simple apps.

This and whatever we do for #80896 is all that's left.

Cc @dotnet/ilc-contrib

Author: MichalStrehovsky
Assignees: -
Labels:

area-NativeAOT-coreclr

Milestone: -

@jkotas
Copy link
Member

jkotas commented Jan 24, 2023

Avoids bringing ConstructorInfo to simple apps.

Do simple apps call MakeGenericType? Or is the constraint validation brought in through other paths as well?

@MichalStrehovsky
Copy link
Member Author

It's through the type resolution logic. We keep fields, including the ability to get/set them (due to the use in Attribute.GetHashCode/Equals). The field type could be generic. We need to call into the type loader to resolve the generic type in the signature. This does a constraint check.

@jkotas
Copy link
Member

jkotas commented Jan 24, 2023

We assume that the program is valid. Would it be better to omit the constraint check completely in this case?

@MichalStrehovsky
Copy link
Member Author

We assume that the program is valid. Would it be better to omit the constraint check completely in this case?

Done, looks better!


internal static RuntimeConstructedGenericTypeInfo GetRuntimeConstructedGenericTypeInfoNoConstraintCheck(RuntimeTypeInfo genericTypeDefinition, RuntimeTypeInfo[] genericTypeArguments)
{
RuntimeTypeHandle precomputedTypeHandle = GetRuntimeTypeHandleIfAny(genericTypeDefinition, genericTypeArguments, ReflectionCoreExecution.ExecutionEnvironment.TryGetConstructedGenericTypeForComponentsNoConstraintCheck);
Copy link
Member

Choose a reason for hiding this comment

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

Does Roslyn generate delegate cache for this pattern? If not, it would be nice to tweak this to make the delegate cached.

Copy link
Member Author

Choose a reason for hiding this comment

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

😲 assumed it did, I was wrong. But I understand why. Fixed.

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

Yes, this looks better. LGTM modulo comment.

@MichalStrehovsky MichalStrehovsky merged commit c60a61c into dotnet:main Jan 25, 2023
@MichalStrehovsky MichalStrehovsky deleted the constraintval branch January 25, 2023 05:39
@ghost ghost locked as resolved and limited conversation to collaborators Feb 24, 2023
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.

2 participants