Skip to content

Reflection annotate more of CoreLib #37418

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

Merged
merged 5 commits into from
Jun 9, 2020

Conversation

MichalStrehovsky
Copy link
Member

No description provided.

@@ -47,6 +50,8 @@ public override bool Equals(object? obj)
return true;
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
Justification = "Unused fields don't make a difference for hashcode quality")]
Copy link
Member

Choose a reason for hiding this comment

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

I assume we're OK with the hascode value itself changing as a result of trimming, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

I would think so. We can make this invariant if we keep all fields of attributes in linker, but I don't think we care so much.

Whoever cares about these hashcodes is probably already overriding this implementation (this returns the hashcode of the first non-null field and if that field also happens to be unused - that's a pretty bad hashcode).

@@ -149,6 +149,8 @@ public virtual Type[] GetGenericParameterConstraints()
protected abstract ConstructorInfo? GetConstructorImpl(BindingFlags bindingAttr, Binder? binder, CallingConventions callConvention, Type[] types, ParameterModifier[]? modifiers);

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
Justification = "Linker doesn't recongnize GetConstructors(BindingFlags.Public) but this is safe")]
Copy link
Member

Choose a reason for hiding this comment

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

Please don't use "safe"... it resembles security, which this is not about (I know we use it a lot, but we should try to stay away from it)

@@ -278,6 +279,8 @@ public void SetThreadPrincipal(IPrincipal principal)
}
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
Copy link
Member

Choose a reason for hiding this comment

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

Same question on RequiresUnreferencedCode.

Copy link
Member Author

Choose a reason for hiding this comment

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

Linker intrinsically recognizes all these weird overloads. This was ported from @marek-safar's original prototype. I don't think we would add them based on API usage telemetry since nobody uses these APIs.

Yes, my preference would be to make these string,string overloads RequiresUnreferencedCode, delete the linker handling, and be done with it.

Having to mark these UnconditionalSuppressMessage is unfortunate because it puts us into a situation where forgetting to intrinsically recognize this API (e.g. once we build a Roslyn analyzer) will result in potentially broken apps.

With the other annotations in this pull request, if we forget to intrinsically recognize a rare overload, it will result in more warnings, not less warnings.

Copy link
Contributor

Choose a reason for hiding this comment

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

You could start with more aggressive mode and block less APIs based on previews feedback.

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks!

@MichalStrehovsky MichalStrehovsky merged commit 0f97c7a into dotnet:master Jun 9, 2020
@MichalStrehovsky MichalStrehovsky deleted the moreCoreLibAnnot branch June 9, 2020 07:30
@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2020
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.

5 participants