Do not generate reflectable sealed
methods as virtual
#96738
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Noticed this while working on #96672. There are two ways how virtual method can be referred to: as a direct reference to the method body (i.e. non-virtually), or as a reference to a particular slot number (virtually). When we mark a virtual method as visible by reflection, it typically means “virtually visible to reflection” (one can invoke the method with a random derived
this
so the invoke happens through the slot).But we still try to optimize this into a direct reference if possible so that we don’t waste an extra slot. This is possible for final methods, or methods on sealed classes for example. The marking in dependency graph didn’t take into account this optimization – it was creating an unnecessary virtual slot for reflection-visible final methods that then went unused. With this half of the diff in #96672 is technically not necessary (we no longer end up with the new virtual method in the vtable), but that fix is still a correct fix.
Cc @dotnet/ilc-contrib