Skip to content

[NOMERGE] JIT: Widen shared generic struct constrained call inlining - #138037

Draft
NinoFloris wants to merge 9 commits into
dotnet:mainfrom
NinoFloris:abstraction-tax/widen-constrained-inlining
Draft

NinoFloris wants to merge 9 commits into
dotnet:mainfrom
NinoFloris:abstraction-tax/widen-constrained-inlining

Conversation

@NinoFloris

Copy link
Copy Markdown
Contributor

Based on #137990 and #138013

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.
Move runtime lookup construction for CORINFO_CALL_CODE_POINTER from getCallInfo to prepareCallLookups. Calls that disappear before preparation no longer reserve dictionary entries. Mark pending lookups as CORINFO_LOOKUP_DEFERRED, preserving NOT_SUPPORTED for inline rejection, and record completed lookups in SuperPMI.
Route hidden arguments and code pointers through call-specific materialization helpers in the JIT and interpreter. Each helper completes a deferred lookup before consuming it, so call sites no longer need a separate preparation step.
…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.
Carry the selected implementation in the deferred lookup and instantiate it when preparing the dictionary entry instead of repeating interface resolution. Handle inherited and static default implementations, retain ambiguous-target and ReadyToRun versioning fallbacks, and record the deferred payload explicitly in SuperPMI.
Resolve a constrained interface call on a shared value type to the concrete
implementation on that type and emit a direct call instead of an indirect
runtime-lookup code pointer. The direct call is an inline candidate, so the
implementation can be inlined and the type context can fold away when unused.

The hidden instantiation argument is obtained from the constrained type token,
which names the exact value type, rather than the interface method token.
Ambiguous or forced targets, default implementations on another owner,
generic-method targets, and reference-type receivers keep the runtime-lookup path.

Add ConstrainedTypeContext covering used and unused contexts, class and method
caller contexts, constructed contexts, mutation, initialization, default
implementations, reference types, generic-method fallbacks, and static delegate
creation.
Obtain the constrained type context through the deferred instParamLookup and
prepareCallLookups instead of reading the constrained token eagerly in the JIT.
The EE selects the token and context, keeping on-demand preparation and matching
the deferred lookup path used for the rest of the call. Behavior is unchanged.

Retire the note describing the missing dictionary infrastructure now that
prepareCallLookups embeds the constrained handle.
…tructs

Make a constrained static virtual call that resolves to a default interface
method a direct, inlinable call instead of a runtime-lookup code pointer. The
declaring interface's context is supplied as a deferred lookup, computed from the
resolved method through a DeclaringTypeHandleFromMethodSlot dictionary entry.

getCallInfo keeps the call direct when the default implementation resolves
through a single interface slot and falls back to the code-pointer path
otherwise. Wire the slot through the JIT dictionary encoder and resolver.
Make a constrained call that resolves to a generic method on the constrained
value type a direct, inlinable call instead of a runtime-lookup code pointer.
The method's own context is supplied as a deferred lookup, computed from the
resolved method through a MethodDescSlot dictionary entry.

getCallInfo keeps the call direct for a resolved generic-method target and falls
back to the code-pointer path when the constraint cannot be resolved.
@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 20, 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 20, 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.

@NinoFloris

Copy link
Copy Markdown
Contributor Author

@MihuBot -nuget

@NinoFloris NinoFloris changed the title [NOMERGE] JIT: Widen shared struct constrained call inlining [NOMERGE] JIT: Widen shared generic struct constrained call inlining Nov 20, 2026

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.

1 participant