Skip to content

ILC: Preserve declaring contexts for constrained NativeAOT calls - #137909

Merged
MichalStrehovsky merged 2 commits into
dotnet:mainfrom
NinoFloris:jit/naot-constrained-substitution
Nov 20, 2026
Merged

MichalStrehovsky merged 2 commits into
dotnet:mainfrom
NinoFloris:jit/naot-constrained-substitution

Conversation

@NinoFloris

Copy link
Copy Markdown
Contributor

Reconstruct shared targets on their runtime-determined declaring interface or base type before applying method arguments. Share this reconstruction between the scanner, call lookup, and delegate construction, retaining constrained dispatch when the declaring context is ambiguous.

Cover nested and swapped arguments, inherited contexts, and generic methods through calls and delegates. Fixes #137846.

Reconstruct shared targets on their runtime-determined declaring interface or base type before applying method arguments. Share this reconstruction between the scanner, call lookup, and delegate construction, retaining constrained dispatch when the declaring context is ambiguous.

Cover nested and swapped arguments, inherited contexts, and generic methods through calls and delegates. Fixes dotnet#137846.
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Nov 19, 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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The regression can bypass scanner reconstruction and does not cover distinct declaring interfaces that canonicalize to the same owner, leaving reconstruction correctness and the ambiguity guard unverified.

1 open issue
What changed in this PR

This PR updates NativeAOT constrained-call resolution to preserve the implementation’s declaring interface or base-type context before applying method arguments.

Changes:

  • Adds shared target reconstruction with fallback to constrained dispatch when the declaring context is ambiguous.
  • Uses the reconstruction helper in scanning, call lookup, and delegate construction.
  • Adds regression scenarios for nested, swapped, inherited, and generic contexts through calls and delegates.
File Description
src/​tests/​Loader/​classloader/​StaticVirtualMethods/​Regression/​ConstrainedStaticInterfaceContext.csproj Configures the regression test with process isolation and tiering disabled.
src/​tests/​Loader/​classloader/​StaticVirtualMethods/​Regression/​ConstrainedStaticInterfaceContext.cs Adds constrained-call and delegate regression scenarios.
src/​coreclr/​tools/​Common/​Compiler/​TypeExtensions.cs Adds declaring-context reconstruction and ambiguity detection.
src/​coreclr/​tools/​aot/​ILCompiler.RyuJit/​JitInterface/​CorInfoImpl.RyuJit.cs Applies shared reconstruction to call and delegate lookup.
src/​coreclr/​tools/​aot/​ILCompiler.Compiler/​IL/​ILImporter.Scanner.cs Aligns scanner dependencies with reconstructed targets.

Review effort: Balanced

@NinoFloris
NinoFloris force-pushed the jit/naot-constrained-substitution branch from f1ae488 to 0efecea Compare November 20, 2026 10:22
@MichalStrehovsky

Copy link
Copy Markdown
Member

/ba-g abandoned macos legs

@MichalStrehovsky MichalStrehovsky left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@MichalStrehovsky
MichalStrehovsky merged commit b8c2333 into dotnet:main Nov 20, 2026
99 of 101 checks passed
@NinoFloris
NinoFloris deleted the jit/naot-constrained-substitution branch November 20, 2026 13:57
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-NativeAOT-coreclr 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.

ILC: (bug) constrained call to a static DIM from shared code is rebound to the constrained type's instantiation

3 participants