Conversation
|
Tagging subscribers to this area: @dotnet/runtime-infrastructure |
Fix closed_over_null computation in mono_marshal_get_delegate_invoke_internal by comparing invoke sig param count with actual target method param count directly, rather than via the stripped signature which underflows when the invoke sig has 0 params. Fix MINT_CALL_DELEGATE in the interpreter to handle closed-over-null case where an instance method is bound with null this, instead of incorrectly falling through to the static-call memmove path. Add regression tests for CreateDelegate closed over null. Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/b2d407d8-e6b9-4fba-974a-ec751a17db84 Co-authored-by: EgorBo <523221+EgorBo@users.noreply.github.com>
|
@copilot investigate the failures in the new tests |
The new delegate tests (
The only CI failures are in The 3 cancelled jobs (CoreCLR windows x64/x86 Debug/Release, browser-wasm windows LibraryTests) were dependency-cancelled due to the unrelated wasm failures. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/49c5407b-85f7-464b-ba8e-255cf0fcab34 Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/dd0dd922-0dee-48e2-a8cb-ee3299c87022 Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
|
I think it should be picked up by someone who understands mono better |
|
@copilot Please remove the closed over null special path instead and make it work with normal non virtual bound path there |
🤖 Copilot Code Review — PR #126285Note This review was generated by GitHub Copilot. Holistic AssessmentMotivation: The PR fixes a real bug in Mono where delegates closed over null (i.e., Approach: The fix introduces a dedicated Summary: Detailed Findings✅ Correctness — Core bug fix in
|
Remove the WRAPPER_SUBTYPE_DELEGATE_INVOKE_CLOSED_OVER_NULL subtype and all related special casing (separate cache, AOT encoding/decoding, indirect call in marshal-lightweight, interpreter fix). Instead, route closed-over-null non-virtual instance delegates through the existing WRAPPER_SUBTYPE_NONE wrapper by: - Returning WRAPPER_SUBTYPE_NONE for these delegates in subtype detection - Not setting callvirt for these delegates - Setting bound=TRUE so the wrapper passes null target as 'this' - Using impl_this in the JIT trampoline for the fast path Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/8f7b5ccb-6f4c-4dd0-bc18-3be9c8dbbc4c Co-authored-by: EgorBo <523221+EgorBo@users.noreply.github.com>
Done in ed51d75. Removed the |
|
@copilot fix ci failures you introduced, e.g. CreateDelegate_ClosedOverNull_instanceMethod test |
The interpreter's MINT_CALL_DELEGATE fast path was missing handling for closed-over-null delegates (instance method with null target and matching param count). Without this, the interpreter fell through to the static call path which strips the delegate pointer via memmove, causing a crash. Add a check: when the target method is non-static and param counts match, pass NULL as 'this' instead of treating it as a static call. Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/ee6a26c2-c6dd-470a-8436-90d93ae83c25 Co-authored-by: EgorBo <523221+EgorBo@users.noreply.github.com>
Fixed in 79fa63f. The issue was that the interpreter's |
Description
Fixes delegates closed over null so they work in AOT-only mode on Mono.
Previously, closed-over-null delegates for non-virtual instance methods on reference types were routed through the
WRAPPER_SUBTYPE_DELEGATE_INVOKE_VIRTUAL(callvirt) path, which embeds a direct CALL to the target method in the wrapper IL. This wrapper cannot be pre-compiled by AOT since it is specific to each target method.The fix routes these delegates through the existing
WRAPPER_SUBTYPE_NONEwrapper withbound = TRUE, so the wrapper uses an indirect call throughmethod_ptr— which is AOT-compatible and does not require a special subtype.Changes
marshal.c:mono_marshal_get_delegate_invoke_subtypeandmono_marshal_get_delegate_invokenow returnWRAPPER_SUBTYPE_NONE(instead ofDELEGATE_INVOKE_VIRTUAL) for closed-over-null non-virtual instance methods on reference types, so the normal invoke wrapper is used.marshal.h/loader-internals.h: Removed theWRAPPER_SUBTYPE_DELEGATE_INVOKE_CLOSED_OVER_NULLsubtype and thedelegate_closed_over_null_cache— no special subtype or cache is needed.marshal-lightweight.c: Reverted the indirect call codegen for closed-over-null back to the original direct CALL (this path is no longer reached for closed-over-null delegates since they now go through the normal wrapper).aot-compiler.c/aot-runtime.c: Removed pre-compilation and decoding of the closed-over-null wrapper variant — no longer needed since the normal wrapper handles it.llvmonly-runtime.c:mini_llvmonly_init_delegatedetects closed-over-null delegates and setsbound = TRUE, so the existing wrapper passestarget(null) asthisvia indirect call.mini-trampolines.c:mono_delegate_trampolineclearscallvirt, setsbound = TRUE, and usesimpl_thisfor the JIT fast path for closed-over-null non-virtual instance delegates.interp/interp.c: The interpreter'sMINT_CALL_DELEGATEinline fast path (which bypasses the invoke wrapper for single-cast delegates) now handles closed-over-null: when the target method is non-static and param counts match, it passes NULL asthisinstead of falling through to the static callmemmovepath.DelegateTests.cs: Reverted theConditionalFactskip and added two regression tests for closed-over-null delegates (CreateDelegate_ClosedOverNull_InstanceMethodandCreateDelegate_ClosedOverNull_InstanceMethodViaMethodInfoCreateDelegate).Testing
📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.