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

[mono] Skip exact interface matches when an interface has variance #103757

Merged
merged 21 commits into from
Jul 12, 2024

Conversation

kg
Copy link
Member

@kg kg commented Jun 20, 2024

Issue #103365 appears to be caused by us preferring an 'exact match' for interfaces even when variance means an inexact match may be what we should actually use, because the exact match is on a base class and the inexact one is on a derived class.

This PR changes mono's variance interface lookup to more closely match the spec, by doing two scans per class and walking up the class hierarchy. To reduce the performance cost of this more complex scan, a new 'variance search table' is maintained (created on demand) for each type, which only contains generically variant interfaces so that we're not checking against all interfaces.

I also noticed our list of interfaces implemented by Array was incomplete, so this PR updates it.

@kg kg added area-VM-meta-mono runtime-mono specific to the Mono runtime labels Jun 20, 2024
@kg kg closed this Jun 27, 2024
@kg kg reopened this Jun 27, 2024
@kg kg marked this pull request as ready for review July 2, 2024 04:20
src/tests/Regressions/coreclr/103365/103365.cs Outdated Show resolved Hide resolved
src/mono/mono/metadata/class-init.c Outdated Show resolved Hide resolved
src/mono/mono/metadata/class-init.c Show resolved Hide resolved
// Is any interface at this level of the type hierarchy variantly compatible with the desired interface?
// If so, select the first compatible one we find.
for (i = 0; i < vst_count; i++) {
if (!mono_class_is_variant_compatible (itf, vst [i], FALSE))
Copy link
Member

Choose a reason for hiding this comment

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

Question: how is this variance search table different from the interfaces_packed table? Do we really need both? if the variance search table is more correct, can we get rid of the interfaces_packed table?

Copy link
Member Author

Choose a reason for hiding this comment

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

The variance search table should be smaller. I can try to figure out whether we can get rid of interfaces_packed

Copy link
Member Author

Choose a reason for hiding this comment

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

Two examples of what I was thinking in action:

  System.IBinaryFloatParseAndFormatInfo`1 vst_size=1 io_count=39
  System.Single vst_size=1 io_count=40

kg added 2 commits July 9, 2024 18:59
Don't build search tables for interfaces
src/mono/mono/metadata/class-init.c Outdated Show resolved Hide resolved
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-VM-meta-mono runtime-mono specific to the Mono runtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants