Skip to content

[mono] Fix double inflation in mono_class_get_virtual_method - #137124

Open
vrimar wants to merge 1 commit into
dotnet:mainfrom
vrimar:mono-get-virtual-method-inflation
Open

vrimar wants to merge 1 commit into
dotnet:mainfrom
vrimar:mono-get-virtual-method-inflation

Conversation

@vrimar

@vrimar vrimar commented Nov 7, 2026

Copy link
Copy Markdown

mono_class_get_virtual_method re-inflates the vtable slot method with the requested method's full context. If the slot method is already inflated, re-applying class_inst substitutes into its remaining shared type variables.

In shared code this breaks devirtualized EqualityComparer<F>.Default.Equals and GetHashCode calls, which the C# compiler emits for every field of a generic record struct. For F = Change<T_REF> the call binds to GenericEqualityComparer<Change<Change<T_REF>>>. On browser-wasm AOT the caller then asserts in mini_method_get_rgctx if the doubled type breaks a constraint, or traps with function signature mismatch if it changes layout.

The fix applies only method_inst to an already-inflated slot method, as get_method_constrained and MONO_RGCTX_INFO_VIRT_METHOD already do.

Risk: closed types are unaffected, because re-inflating a closed method returns it unchanged. The same code is on release/8.0 through release/11.0, so this isn't a regression.

Testing: two new ValueTypeTests cover the constraint failure and the layout failure. With a browser-wasm mono-aot-cross built from the rc.3 source, both fail without the fix and pass with it. Both pass on CoreCLR. Not run: XHarness, iOS/Android, CI.

Resolves #137123

Re-applying the base method's class instantiation to an inflated vtable
method doubled shared type arguments in devirtualized calls.
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Nov 7, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@vrimar

vrimar commented Nov 7, 2026

Copy link
Copy Markdown
Author

@dotnet-policy-service agree

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-VM-meta-mono community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[wasm][mono][AOT] Record struct Equals in shared generic code asserts in mini_method_get_rgctx or traps with "function signature mismatch"

1 participant