Improvements in regards to interop with the Swift compiler

A few years ago I checked swift, and the internals documentation was out of date, non existent, or wrong in some cases. Nor was there any other good way to interact with the swift compiler and get things like abi info, parameters info, field offsets or encoding information from the outside (without having to hack the compiler itself).

My question now is this: Has the situation been improved?

My goal is to be able to interact from non swift with swift libraries (like swiftui, or really any new libraries for osx/ios that are swift only).

3 Likes

You can find ABI related documentation under https://github.com/apple/swift/tree/main/docs/ABI, but they're in different states... The mangling doc is generally kept up-to-date and register use doc should be easily verifiable in case it is out-of-date, whereas the type layout and type metadata docs are outdated...

You can get field offsets using MemoryLayout.offsetOf thanks to SE-0210.

1 Like

Yep. That's pretty much the same state as it was in back then. I do have mangling covered already. But the swift compiler has so many undocumented rules that it becomes impossible to interact with:

  • most types use or extend some objc types, whose renaming doesn't match the documentation
  • some type parameter or associated type parameters in abi calls depend on if the body needs them
  • enums reuse bits in a way I can't figure out or find consistency in

(Tons more but I don't remember them all)

1 Like
Terms of Service

Privacy Policy

Cookie Policy