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

Fix bug in virtual annotation logic for RequiresUnreferencedCode #100707

Merged
merged 3 commits into from
Apr 8, 2024

Conversation

sbomer
Copy link
Member

@sbomer sbomer commented Apr 5, 2024

The following virtual methods are correctly annotated and do not warn:

class Base {
  virtual void M() {}
}

[RequiresUnreferencedCode("Derived")]
class Derived : Base {
  override void M() {}
}

However, if the method also happens to have DynamicallyAccessedMembers annotations, there's a bug in the logic that causes this to produce warnings in illink. This change fixes the bug.

Hit this while experimenting with ComponentModel annotations.

@sbomer sbomer requested a review from marek-safar as a code owner April 5, 2024 21:56
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Apr 5, 2024
@dotnet-policy-service dotnet-policy-service bot added the linkable-framework Issues associated with delivering a linker friendly framework label Apr 5, 2024
Copy link
Contributor

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

Copy link
Contributor

Tagging subscribers to 'linkable-framework': @eerhardt, @vitek-karas, @LakshanF, @sbomer, @joperezr, @marek-safar
See info in area-owners.md if you want to be subscribed.

Copy link
Member

@jtschuster jtschuster left a comment

Choose a reason for hiding this comment

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

What exactly are the semantics of RUC on a type? Is it like putting it on the .ctor and static methods, or all methods, static and instance? LGTM if it's the former, but if it's the latter then the existing behavior doesn't seem right.

Co-authored-by: Jackson Schuster <36744439+jtschuster@users.noreply.github.com>
@sbomer
Copy link
Member Author

sbomer commented Apr 5, 2024

It's a bit of both - it will silence warnings inside of all methods, static and instance, but it will only produce warnings for callsites to static methods and constructors. Since we protect constructors, there's no need to warn for calls to virtual methods.

By the same reasoning, we don't need to warn for the example above because we've already prevented calls to constructors of the type.

@sbomer
Copy link
Member Author

sbomer commented Apr 8, 2024

Failure is known: #100249. I've updated the error text to be slightly looser, but build analysis hasn't matched it with this build yet.

@sbomer
Copy link
Member Author

sbomer commented Apr 8, 2024

Ah, it figured it out after a rerun.

@sbomer sbomer merged commit 8508806 into dotnet:main Apr 8, 2024
78 of 80 checks passed
matouskozak pushed a commit to matouskozak/runtime that referenced this pull request Apr 30, 2024
…net#100707)

The following virtual methods are correctly annotated and do not warn:

```csharp
class Base {
  virtual void M() {}
}

[RequiresUnreferencedCode("Derived")]
class Derived : Base {
  override void M() {}
}
```

However, if the method also happens to have DynamicallyAccessedMembers
annotations, there's a bug in the logic that causes this to produce
warnings in illink. This change fixes the bug.

Hit this while experimenting with ComponentModel annotations.

---------

Co-authored-by: Jackson Schuster <36744439+jtschuster@users.noreply.github.com>
@github-actions github-actions bot locked and limited conversation to collaborators May 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Tools-ILLink .NET linker development as well as trimming analyzers linkable-framework Issues associated with delivering a linker friendly framework
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants