You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Motivation: the runtime team would like to add support for more calling conventions in the future, without necessarily having to rev the language (and make more work in the compiler).
Proposal:
335 specifies a calling convention bit that means "calling convention is defined by a modreq on the return type".
We specify that calling convention keywords are platform-dependent.
The calling convention comes from a type in the System.Runtime.CompilerServices namespace. Type names that start with CallConv are considered.
These types must come from CorLib.
You can put 1 and only 1 calling convention on the function pointer.
If the calling convention is one of the ones understood by the platform today (managed, thiscall, stdcall, cdecl), we'll use the existing bit.
Otherwise, we use the new bit and modreq.
For C# syntax here, my proposal is as follows:
We strip off the CallConv bit from the front, and use the lowercase version of the remaining part of the name as the convention. This allows us to continue having these be contextual keywords in traditional C# fashion (ie, all lowercase).
Alternatively, we can just directly use the text from the remaing characters after CallConv.
In this version, we likely want to standardize our existing keyword proposal with the type names in the BCL, so that both Stdcall and stdcall are not options, for example.
Supporting other attributes on function pointer types.
There is a request to support attributes like GCSuppressTransition as part of function pointers (ie, being able to tell the GC that this function pointer call is quick, and it shouldn't do a full managed->native transition).
There is no native place in a function pointer type to put this type of information, so the proposal is as follows:
We put types specified as modreqs on the return type.
Changing these attributes is a breaking change for library authors (because the type is changing).
Types used in these attributes must come from the System.Runtime.InteropServices (or some specific namespace, to be worked out with the runtime team. The intent is to make it so that any old type may not be used, just names supported by the runtime.)
Syntax proposal (where valid identifiers will be platform-dependent):
Issues in Function Pointers
Creating an issue for LDM topic on 4/1/20.
Confirm
NativeCallableAttribute
support:Supporting extensible calling conventions:
System.Runtime.CompilerServices
namespace. Type names that start withCallConv
are considered.managed
,thiscall
,stdcall
,cdecl
), we'll use the existing bit.CallConv
bit from the front, and use the lowercase version of the remaining part of the name as the convention. This allows us to continue having these be contextual keywords in traditional C# fashion (ie, all lowercase).CallConv
.Stdcall
andstdcall
are not options, for example.Supporting other attributes on function pointer types.
GCSuppressTransition
as part of function pointers (ie, being able to tell the GC that this function pointer call is quick, and it shouldn't do a full managed->native transition).System.Runtime.InteropServices
(or some specific namespace, to be worked out with the runtime team. The intent is to make it so that any old type may not be used, just names supported by the runtime.)identifier
s will be platform-dependent):The text was updated successfully, but these errors were encountered: