Stable interface to see content of abi stable module

Presuming I compile a shared object, dylib or static library with Swift. Is .swiftinterface the most stable way to see what's in it? If yes, is the format .swiftinterface final yet?

my use case:

I'm researching if I can interact with a swift library from another unrelated compiler and need to find out what's in a library.

That's the goal of the swiftinterface format, yes (cf. Plan for module stability). It's not quite final yet but we're pretty close, at least on the master branch. If you spot any omissions or errors in your experiments, please file a bug!

3 Likes

One thing that would be very useful for me and possibly for swift future proofing would be including the (object level) symbol names of types, accessors and methods. I realize I'm talking from a pov that makes it easier for me, but annotating the symbol names makes it possible to modify the mangling later for swift while keeping back/forward compatibility.

Interesting idea! It's tricky because there are manglings for things that don't have declarations in the base language, like Fooable & Barable (the composition type that includes both of these protocols as requirements), or Int: Equatable (the conformance of Int to Equatable). Because of that, the general plan is to consider mangling to be part of the ABI.

SourceKit can give you mangled names for declarations, though, and that ought to work with swiftinterface files (by importing the appropriate module so that they get loaded with their options intact, rather than reading them directly).

Fair enough. My goal will be to do this without source kit so I'll have to redo the mangling. Thanks for the info though.

1 Like

The mangling related parts of the compiler should hopefully be easily separable from the rest of the compiler, since they’re also shared by the Swift runtime and used by various tools outside the Swift compiler. You might try using our libraries instead of rolling your own implementation from scratch.

1 Like

To follow up on this. Is there any guidance on what I can do here? Which libraries and samples of how they work (or just hints at which libs I can use)?

What I'm after:

  • Names of all libraries available to Swift (including objc wrappers)
  • Names of all types, their members, their mangling, their calling convention etc

This (old) thread made it sound like that info can be gotten from via some api.

We build a libswiftDemangle.dylib as part of the toolchain distribution, and part of the OS, but its stable API is probably too high level. However, you could take the sources used to build it from the Swift source tree, such as Demangler.cpp, which includes the underlying AST representation and C++ API, and use that to get an interpretable structural representation of mangled names.

But can I get all of this through the sourcekit c api somehow too?

I think you would need to integrate the demangler code in order to process what SourceKit gives you, given the state of things today. We could certainly extend SourceKit to provide more requests too, though.