Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@davidwrighton
Copy link
Member

@davidwrighton davidwrighton commented Dec 19, 2025

This fixes several issues that were blocking the interop suite from passing:

  • Platform detection of IsBuiltInComEnabled in the presence of interpreter support
  • Move delegate creation to use the optimized constructors. This works around creating a delegate to a function which is marked with [UnmanagedCallersOnly]. We've since decided to fix the test suite, but this is an improvement to the compiler in any case.

- The HasUnmanagedCallersOnlyAttribute api is... not as accurate as I'd like. See comment in the code
- Fix an issue with platform detection where we are attempting to test COM interop tests with the interpreter enabled
- Fix an issue with creating a delegate to a method marked with an [UnmanagedCallersOnly] attribute. NOTE: This fix is probably not acceptable for long term usage as it injects a very expensive metadata lookup into the slow path delegate contruction logic.
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Dec 19, 2025
@davidwrighton
Copy link
Member Author

@AaronRobinsonMSFT @jkoritzinsky do you have an opinion on the check of HasUnmanagedCallersOnlyAttribute in the delegate constructor. We currently have a check for it in optimized delegate construction, which is almost always used by the JIT, but I need to know if we really need that to work, or if it's just a convenience feature that it fails.

@davidwrighton
Copy link
Member Author

/azp run runtime-interpreter

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@davidwrighton
Copy link
Member Author

/azp run runtime-interpreter

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@davidwrighton davidwrighton changed the title [DRAFT] [clr-interp] Fix some interop suite issues [clr-interp] Fix some interop suite issues Jan 6, 2026
@davidwrighton davidwrighton added area-CodeGen-Interpreter-coreclr and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jan 6, 2026
@davidwrighton davidwrighton marked this pull request as ready for review January 6, 2026 18:08
Copilot AI review requested due to automatic review settings January 6, 2026 18:08
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @BrzVlad, @janvorli, @kg
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes several interop suite issues related to the CoreCLR interpreter. The main changes include: (1) correcting platform detection for built-in COM support when the interpreter is active, and (2) implementing a peephole optimization for delegate constructor patterns to use optimized constructors.

Key changes:

  • Modified IsBuiltInComEnabled to return false when the CoreCLR interpreter is active
  • Added a peephole optimizer that recognizes LDFTN/LDVIRTFTN + NEWOBJ patterns and rewrites them to use optimized delegate constructors
  • Refactored ldftn-related code into reusable helper methods

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
InvalidSafeHandleMarshallingTests.cs Adds test skip attribute for interpreter mode with comment explaining COM interop behavior
PlatformDetection.cs Modifies IsBuiltInComEnabled to exclude CoreCLR interpreter from COM support detection
compiler.h Adds member variable m_pConstrainedToken and declares new helper methods for ldftn operations and delegate constructor optimization
compiler.cpp Implements delegate constructor peephole optimization, refactors ldftn/ldvirtftn code into EmitLdftn, extracts EmitDup and EmitLoadPointer helpers, and converts constrained token handling from local to member variable

Copy link
Member

@janvorli janvorli left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@davidwrighton
Copy link
Member Author

/ba-g known issues + a machine that would have produced a known issue instead dead-lettered.

@davidwrighton davidwrighton merged commit 78d6652 into dotnet:main Jan 6, 2026
101 of 104 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants