Repository navigation
JIT: Pass constrained type context to resolved shared generic calls - #137990
NinoFloris wants to merge 4 commits into
Conversation
|
Azure Pipelines: Successfully started running 5 pipeline(s). 10 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
|
@MihuBot -nuget |
|
@MihuBot -nuget (nuget support was off for a little bit) |
|
@jakobbotsch this has hits all over the place. Regressions and improvements are all inlining related. |
There was a problem hiding this comment.
🔵 Needs a closer look
Shared-generic hidden-context ABI changes span the VM, JIT, and interpreter, requiring checked-runtime regressions, interpreter coverage, and x64/ARM64 disassembly checks that static review alone could not provide.
No open issues 🎉
What changed in this PR
This PR enables direct calls to resolved non-generic methods on constrained value types by explicitly passing their type context through CoreCLR’s JIT and interpreter.
Changes:
- Allows eligible shared generic calls to bypass runtime dispatch while preserving fallback lookup for unsupported or ambiguous targets.
- Updates the JIT and interpreter to obtain the implementation’s context from the constrained type token.
- Adds functional and codegen regressions covering inlining, context-dependent behavior, mutation, initialization, delegates, generic methods, and return shapes.
| File | Description |
|---|---|
src/tests/Loader/classloader/generics/Misc/ConstrainedTypeContext.csproj |
Configures isolated, optimized regression tests with disassembly checks. |
src/tests/Loader/classloader/generics/Misc/ConstrainedTypeContext.cs |
Adds functional assertions and inlining codegen checks. |
src/coreclr/vm/jitinterface.cpp |
Permits direct calls when the constrained type supplies the required context. |
src/coreclr/jit/importercalls.cpp |
Uses the constrained token to construct the hidden context argument. |
src/coreclr/jit/compiler.h |
Adds the constrained token parameter to the importer helper declaration. |
src/coreclr/interpreter/compiler.cpp |
Mirrors constrained-token context lookup in the interpreter. |
Review effort: Balanced
Allow direct calls to resolved non-generic methods on the constrained value type by passing its type context explicitly. Teach the JIT and interpreter to obtain that context from the constrained token, preserving runtime lookup for unsupported or ambiguous targets. Add functional and codegen regressions covering inlining, context-dependent implementations, mutation, initialization, delegates, generic methods, and return shapes.
ff9e525 to
7e996e0
Compare
…iveAOT Mirror the CoreCLR getCallInfo decision in the NativeAOT compiler. When a constrained call resolves to a non-generic method on the constrained value type itself, keep the call direct and inlinable and supply the instantiation argument from the constrained token instead of falling back to a fat function pointer through a dictionary slot. NativeAOT precomputes generic dictionary layouts in the scanner, so the scanner must reserve the same lookup the compile-time JIT requests. Teach the scanner to keep the call direct for this case and reserve the constrained type's handle as the instantiation argument, matching getCallInfo and the shared importer that reads the context from the constrained token.
…dyToRun Mirror the CoreCLR getCallInfo decision in crossgen2. When a constrained call resolves to a non-generic method on the constrained value type itself, keep the call direct and inlinable and supply the instantiation argument from the constrained token instead of a fat function pointer through a dictionary slot. The constrained type is captured before it is cleared for static virtual calls. Resolution already refuses targets outside the version bubble, so the direct call stays version resilient. Crossgen2 has no separate scanner, so no dictionary layout reservation is needed beyond keeping the call off the code pointer path.
LowerVirtualStubCall rewrites an interface dispatch into a direct call to the dispatch helper and clears the method handle, leaving a CT_USER_FUNC call whose gtCallMethHnd is null. The debug dump and disassembly paths passed that handle to eeGetMethodFullName and eeGetMethodName, which call getMethodClass without a null check and assert on hosts that reject a null handle, such as a Checked ILC, so JitDump and JitDisasm tore down the compiler on any surviving interface dispatch. Guard both name helpers so a null handle yields a placeholder rather than a crash. In the tree dump, recognize the lowered dispatch-helper shape, a direct-address call with no method handle, and describe it as the stub dispatch helper with its target address. Normal compilation never takes these dump paths and is unchanged.
7e996e0 to
49c0461
Compare
Allow direct calls to resolved non-generic methods on the constrained value type by passing its type context explicitly. Teach the JIT and interpreter to obtain that context from the constrained token, preserving runtime lookup for unsupported or ambiguous targets.
Add functional and codegen regressions covering inlining, context-dependent implementations, mutation, initialization, delegates, generic methods, and return shapes.