[swift-dev] Preserving and Applying CC in Imported Decls

John McCall rjmccall at apple.com
Mon Dec 18 21:13:14 CST 2017


> On Dec 18, 2017, at 9:34 PM, Greg Parker <gparker at apple.com> wrote:
> 
> 
>> On Dec 13, 2017, at 10:28 PM, John McCall via swift-dev <swift-dev at swift.org <mailto:swift-dev at swift.org>> wrote:
>> 
>>> On Dec 13, 2017, at 8:35 PM, Saleem Abdulrasool <compnerd at compnerd.org <mailto:compnerd at compnerd.org>> wrote:
>>> 
>>>> On Wed, Dec 13, 2017 at 4:14 PM, John McCall <rjmccall at apple.com <mailto:rjmccall at apple.com>> wrote:
>> 
>>>> 
>>>>   - SILGen may need to introduce thunks when passing around such functions as @convention(c) function values.  Code for this already exists in order to allow C functions to be passed around as native function values.
>>> 
>>> This sounds pretty good and would broaden the abilities for swift to FFI to existing code.
>> 
>> Yeah.  This should work well as long as there isn't an API that needs to traffic in non-standard function *pointers*.
> 
> 32-bit Windows needs to do that. Callback functions passed to the Windows API via parameters or struct fields are often __stdcall but the default calling convention is __cdecl.

Well, I should've guessed.  Fortunately, I don't think we're closing out the possibility of supporting multiple calling conventions in the user-facing type system in the future.  We can still import C function declarations without a @convention because a global function can be coerced to an arbitrary CC.  Technically, I guess you could argue that there ought to be a preference in the constraint-solver for matching a function declaration with its actual CC, but that's a minor enough source-compatibility problem (overloading based on the @convention of an argument function?) that I feel comfortable ignoring it for now, especially since we don't implement that today.

John.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20171218/ed11499c/attachment.html>


More information about the swift-dev mailing list