Skip to content

[NOMERGE] Forward generic type arguments - #138320

Draft
NinoFloris wants to merge 36 commits into
dotnet:mainfrom
NinoFloris:abstraction-tax/forward-generic-type-arguments
Draft

NinoFloris wants to merge 36 commits into
dotnet:mainfrom
NinoFloris:abstraction-tax/forward-generic-type-arguments

Conversation

@NinoFloris

Copy link
Copy Markdown
Contributor

Purely interested in diffs

Add prepareCallLookups to supply the hidden instantiation argument as a full CORINFO_LOOKUP. The JIT and interpreter request runtime-dependent lookups only when needed, preserving on-demand preparation while moving token and context selection into the EE. Update NativeAOT, ReadyToRun and SuperPMI for the shared interface.
Give prepareCallLookups its own transition and share the lookup implementation with embedGenericHandle so both JIT entry points cross the boundary once.
Carry the dictionary entry kind through getCallInfo and prepare the code pointer at its JIT or interpreter use. Reuse the call token for the method, preserve the VM transition, and include the lookup kind in the SuperPMI preparation key.
…tion

Record shared generic interface dispatch lookups in getCallInfo and complete them through prepareCallLookups only when the importer still needs the stub. Keep the call symbolic through early devirtualization so calls resolved there do not reserve unused dictionary slots.

Apply the same deferral in ReadyToRun and teach SuperPMI preparation recording and replay to handle stub lookups. Cover surviving interface dispatch and exact-receiver devirtualization in shared generic code.
Prepare code pointers and shared interface dispatch stubs at their importer use. Preserve the NativeAOT fat-pointer helper and its inline-context restriction.
For an adjacent ldftn and delegate constructor in the same block, pass the target token to the delegate helper. Exercise delegate creation, a standalone pointer, and a pointer passed to an ordinary constructor.
Keep the call-site method arguments and use the resolved override's declaring type for its dictionary lookup. Prepare that lookup when the JIT accepts the direct target.
Prepare a fat ldftn through ComputeLookup when its entry is needed. Fall back to the existing helper if the scanner predicted only a delegate dependency. Keep missing-slot checks strict for other lookup requests.
For direct static calls that forward a single method parameter, let CoreCLR describe its location in the caller's dictionary. Use that binding when importing ldtoken !!0 in the inlinee. Other lookups keep their existing context.
Map each inlinee parameter to the root caller at direct static calls that forward method parameters. Use the composed binding for ldtoken and keep the ordinary lookup for constructed arguments and unsupported contexts.
Keep a forwarded MethodSpec and its input context on the lookup node. During morph, prepare only the hidden arguments that survived inlining. Re-resolve surviving requests in their original caller and scope, and reuse the prepared lookup across clones.
Try devirtualizing the call before constructing its virtual function pointer. Materialize the dispatch helper only for calls that remain virtual, evaluating the receiver once.
Carry the EE's resolved override token on the pending hidden argument. If inlining removes the argument, skip the override query and dictionary slot. Materialize remaining lookups in their original caller context.
Carry SZARRAY constructors with the caller's method argument binding. Ask CoreCLR for the root-relative type signature only when a type handle survives inlining.
Substitute method parameters inside bounded reference- and value-type instantiations and vector arrays. Keep named constructor tokens relative to their original module and fall back when the root cannot reuse them.
@NinoFloris

Copy link
Copy Markdown
Contributor Author

@MihuBot -nuget

@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Nov 25, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 6 pipeline(s).
9 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 @dotnet/jit-contrib for JIT-EE GUID update

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Nov 25, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

Compose an unconstrained ldftn MethodSpec in the root context and defer its callable entry lookup until morph. Reuse the existing scope and loader lifetime checks for forwarding method templates.
Bind the declaring type for ordinary instance calls and constructors. For resolved generic virtual calls, combine the original method arguments with the exact override owner validated by the EE. Keep receiver dictionary lookups when rebasing would only move the same access.
Compose the declaring interface in the root context and retain the method template only when the EE permits it. Materialize the ordinary dispatch cell if the call survives. Keep receiver-based, variant and constrained lookups on their existing paths.
Integrate dotnet#137990 on the split call-lookup interface. CoreCLR, NativeAOT and ReadyToRun select a direct call when the constrained type supplies the context. The existing lookup preparation path handles the constrained token for both the importer and interpreter.
(cherry picked from commit ea2a086be962aac34ca8920e176abf6ee2cf2d12)
@NinoFloris

Copy link
Copy Markdown
Contributor Author

@MihuBot -nuget

@MihuBot

MihuBot commented Nov 26, 2026

Copy link
Copy Markdown

Warning

2 extra test assemblies failed to produce JIT diffs and were excluded from the diff analysis:

  • KubernetesClient.dll (pr)
  • YamlDotNet.dll (pr)

All failures happened only on the PR branch, which likely indicates a bug introduced by the PR (e.g. a JIT assert or crash while compiling these assemblies).

See job details in MihuBot/runtime-utils#2217, triggered by #138320 (comment).

Reusing the caller’s spill temp can turn its store of a return expression into a self-store. Drop it before attempting to record the existing type expression for the same local.

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-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI 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.

2 participants