Formalizing @cdecl

Does Delphi use the Pascal calling convention? Embarcadero still sells it as part of RAD Studio, targeting modern platforms including iOS.

@Joe_Groff sadly this is something that I am actively looking into and running into :).

runtime: allow over-aligned types in the runtime by compnerd ¡ Pull Request #42143 ¡ apple/swift (github.com)
IRGen: setup foreign calls properly by compnerd ¡ Pull Request #42157 ¡ apple/swift (github.com)
CoreFoundation: correct alignment mis-assumption by compnerd ¡ Pull Request #3164 ¡ apple/swift-corelibs-foundation (github.com)

were unearthed by reviving the Win32 port for the runtime. I actually am running into problems with calling conventions for foreign functions being dropped on the floor (the current case being closures).

Aha :-) For some reason I had them muddled in my head — probably because Win16 used pascal and then Win32 changed to stdcall so I'd rather assumed that they were the same (I knew they were both callee-pop). I hadn't really appreciated that they'd changed the argument order.

1 Like

Did an official proposal ever come out of this?

6 Likes

Not yet as far as I know. The remaining issues need to be hashed out in a pitch or review cycle.

According to @Joe_Groff :

Hi, is there any movement in pitching and implementing the aforementioned @expose attribute? Currently I can't see a way to control what Swift API gets exposed to C++ and that would be really helpful.

I guess here is latest thread about this:

4 Likes

Hey @jrose

Stumbled across this thread while doing some RnD around creating Python Bindings via Swift. Especially with the robust macro systems here is some interesting paths here.

Love this proposal! In games, VFX, and creative pipelines, Python dominates thanks to its tight integration with tools like Houdini and Maya. A lot of the industry depends on Python bindings to C/C++, which can be powerful but also cumbersome. This proposal could make Swift a strong alternative for those cases.

If it gains some more traction, it could open up exciting new opportunities—bringing together Python’s flexibility with Swift’s performance and modern design. Especially with Swift's C interop there is potentially a straight forward path forward.

I am some on the same page with you in regards to MVP and limiting the scope of the proposal to C for now. I do think NOT folding struct declarations in the proposal might be a might opportunity but I digress for now.

Great example of what is possible:

2 Likes

Seconding what @paxsonsa said. I’m also using _cdecl to declare a C API of Swift code to write Python bindings for Swift (in animation too). I’m using PythonKit to do so instead of the modulemap approach, but either way I’d love to see something like _cdecl formalized.

@JonathanPenner3D @paxsonsa
The latest pitch is in a different thread:
https://forums.swift.org/t/pitch-formalize-cdecl/79557

2 Likes