-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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 warnings due to RUC on type when marking assembly as library #84620
Conversation
Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas Issue DetailsMarking an assembly as "library" will mark all public APIs. If some of the marked members have RUC on them we decided we don't want to produce warnings, since there's nothing especially wrong with the library. The callers of those members would still get the right warnings. Currently linker implements this correctly for methods and properties, but it fails for fields and events and it still produces some warnings, especially if the RUC is on the parent type. This change fixes those cases and adds a special test for the library marked assembly in combination with several RUCs. Fixes #81864
|
Tagging subscribers to 'linkable-framework': @eerhardt, @vitek-karas, @LakshanF, @sbomer, @joperezr, @marek-safar Issue DetailsMarking an assembly as "library" will mark all public APIs. If some of the marked members have RUC on them we decided we don't want to produce warnings, since there's nothing especially wrong with the library. The callers of those members would still get the right warnings. Currently linker implements this correctly for methods and properties, but it fails for fields and events and it still produces some warnings, especially if the RUC is on the parent type. This change fixes those cases and adds a special test for the library marked assembly in combination with several RUCs. Fixes #81864
|
|
browser failures are unrelated |
|
||
[ExpectedNoWarnings] | ||
[RequiresUnreferencedCode ("--ClassWithRequires--")] | ||
public sealed class ClassWithRequires |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the visibility of the class/member matter at all? All of the places I hit this were not public.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can also be internal, but then the assembly must have InternalsVisibleTo - so I intentionally avoided that. It should not matter at all to the warning behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need InternalsVisibleTo in order to get the trimmer to emit the bad warning. I hit it here:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sort of - it needs IVT if the type is internal... but I guess fields are taken as a whole (probably because of base classes, in which case we should still be able to exclude statics... eventually)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So in dotnet/aspnetcore#46518, this bug was encountered only because the assembly has IVT to tests?
[RequiresUnreferencedCode ("--ClassWithRequires--")] | ||
public sealed class ClassWithRequires | ||
{ | ||
public static int Field; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've also seen this warning for private const string
. Should we add that test as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will try with a private field, again visibility should not really matter, but worth a try.
@@ -3270,6 +3279,20 @@ protected virtual void DoAdditionalMethodProcessing (MethodDefinition method) | |||
{ | |||
} | |||
|
|||
static DependencyKind PropagateDependencyKindToAccessors(DependencyKind parentDependencyKind, DependencyKind kind) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a little unfortunate that we are tweaking the dependency graph just to give the right warnings. This will make it look like properties/events got marked due to descriptors even if they were actually only marked by our internal logic that keeps them for marked accessors.
I think we already do this in a number of places and this is just continuing with the existing pattern - but I'll continue to bring up the concern as a general point. :) Eventually I'd love to get rid of any logic that changes warning behavior based on DependencyKind
and use that solely for tracking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not that bad - the edge will be as is right now, just the "kind" on the edge will be different.
But I agree.
The long term goal -> do it the same way ILC does this. Meaning we don't actually generate any warnings for usage in MarkMethod, instead they're produced at the callsite. In short, everything should go through ReflectionMarker which will take care of these things.
if (dependencyKind == DependencyKind.DynamicallyAccessedMemberOnType) { | ||
switch (dependencyKind) { | ||
// Marked through things like descriptor - don't want to warn as it's intentional choice | ||
case DependencyKind.TypePreserve: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this different than the logic in ProcessAnalysisAnnotationsForMethod
which has an early return for Alreadymarked
, TypePreserve
, and PreservedMethod
- should those be added here too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other 2 can't ever happen for fields, but I'll unify it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Marking an assembly as "library" will mark all public APIs. If some of the marked members have RUC on them we decided we don't want to produce warnings, since there's nothing especially wrong with the library. The callers of those members would still get the right warnings.
Currently linker implements this correctly for methods and properties, but it fails for fields and events and it still produces some warnings, especially if the RUC is on the parent type.
This change fixes those cases and adds a special test for the library marked assembly in combination with several RUCs.
Fixes #81864