Skip to content

Replace tailcall dispatcher with C# version once there is function pointer support #35559

Closed
@jakobbotsch

Description

@jakobbotsch

Currently the helper-based tailcall support dynamically emits a dispatcher that uses calli:

// This creates the dispatcher used to dispatch sequences of tailcalls. In C#
// code it is the following function. Once C# gets function pointer support this
// function can be put in System.Private.CoreLib.
// private static unsafe void DispatchTailCalls(
// IntPtr callersRetAddrSlot, IntPtr callTarget, IntPtr retVal)
// {
// IntPtr callersRetAddr;
// TailCallTls* tls = GetTailCallInfo(callersRetAddrSlot, &callersRetAddr);
// PortableTailCallFrame* prevFrame = tls->Frame;
// if (callersRetAddr == prevFrame->TailCallAwareReturnAddress)
// {
// prevFrame->NextCall = callTarget;
// return;
// }
//
// PortableTailCallFrame newFrame;
// newFrame.Prev = prevFrame;
//
// try
// {
// tls->Frame = &newFrame;
//
// do
// {
// newFrame.NextCall = IntPtr.Zero;
// var fptr = (func* void(IntPtr, IntPtr, void*))callTarget;
// fptr(tls->ArgBuffer, retVal, &newFrame.TailCallAwareReturnAddress);
// callTarget = newFrame.NextCall;
// } while (callTarget != IntPtr.Zero);
// }
// finally
// {
// tls->Frame = prevFrame;
// }
// }

This dispatcher can be put in System.Private.CoreLib once there is function pointer support.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions