Skip to content

Conversation

@jtschuster
Copy link
Member

@jtschuster jtschuster commented Jul 28, 2022

Static interface methods that are implicitly implemented are not virtual in IL, so they are not processed in the same ways other methods are. This changes the collection to be _methodsWithBases and adds methods that have base methods in addition to virtual methods to that collection.

Also adds tests for ensuring DAM and RUC annotations are the same for static interface overrides.

Completes work for #2058

@jtschuster jtschuster marked this pull request as draft July 29, 2022 15:15
@jtschuster jtschuster marked this pull request as ready for review July 29, 2022 16:03
@jtschuster jtschuster requested a review from sbomer August 1, 2022 23:19
if (!method.IsVirtual)
return;

// Implementations of static interface methods are not virtual and won't reach here
Copy link
Member

Choose a reason for hiding this comment

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

We are tracking implementations of static interface methods now in _virtual_methods, so could we adjust the check above (if (!method.IsVirtual)) to allow these through instead?

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 actually removed the implementations of static interface methods from _virtual_methods, so it should only be methods that are actually 'virtual' in IL in the list. Do you think it's worth it to add both the base and the implementations?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

@jtschuster jtschuster Aug 3, 2022

Choose a reason for hiding this comment

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

Adding them in MarkBaseMethods is necessary for static methods in a preserved scope. Otherwise we miss annotation checks and marking the implementations for "Base is in a preserved scope".

Copy link
Member

Choose a reason for hiding this comment

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

Thanks - would you mind adding a testcase for that? The tests pass for me without that check.

Copy link
Member

Choose a reason for hiding this comment

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

I think it would make sense to merge your other PR first, then maybe this can be simplified since we are already checking for interface methods in preserved scopes there: https://github.com/dotnet/linker/pull/2868/files#diff-f3ab7d627296ba105613b9cc039ca6f4ddc7a9aa66c6060ca82f6456ae0ede4fR612

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've added some tests here that fail when the line is removed. I also found that instance interface methods aren't checked for matching annotations if the base in a preserved scope, so I removed the IsStatic check. This may warn if the interface implementation is removed or if the static interface methodImpl is removed, but I think it makes sense to still warn there.

Copy link
Member

Choose a reason for hiding this comment

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

I think there is some small risk that comes with warning even if the interface impl is removed, but the analyzer should in theory warn about it either way so I am fine with this. Please add a note that this is the case. cc @vitek-karas in case you have opinions on this.

@jtschuster jtschuster requested a review from sbomer August 4, 2022 20:40
if (!method.IsVirtual)
return;

// Implementations of static interface methods are not virtual and won't reach here
Copy link
Member

Choose a reason for hiding this comment

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

I think there is some small risk that comes with warning even if the interface impl is removed, but the analyzer should in theory warn about it either way so I am fine with this. Please add a note that this is the case. cc @vitek-karas in case you have opinions on this.

Copy link
Member

@sbomer sbomer left a comment

Choose a reason for hiding this comment

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

A few nits, otherwise looks good to me. Thanks!

@jtschuster jtschuster merged commit e45a935 into dotnet:main Aug 11, 2022
@jtschuster jtschuster deleted the methodsWithBases branch August 11, 2022 20:38
agocke pushed a commit to dotnet/runtime that referenced this pull request Nov 16, 2022
Static methods implementing static interface methods are not marked as virtual and were not checked for matching RUC and DAM annotations. This change adds all base methods to the _virtual_methods list to be checked for matching DAM and RUC annotations. This may cause extra/unnecessary warnings for mismatched annotations even a method is removed by the linker.

Commit migrated from dotnet/linker@e45a935
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants