What is libswiftabi / <swift/runtime.h>?

Following the returned for revision announcement for SE-0262, one of the bullet points to discuss was a new "Runtime" module in Swift, separate to the stdlib. I want to open discussion on what that might look like and what other features it might entail. The core team believes that a demangle function would make for a "natural candidate" for such module, but Joe also mentioned that other functionality from the Swift runtime could be used for things like reflection. Could this module be where full reflection support would be implemented, or just some of the building blocks? What other "low-level" features could this potentially offer?

Another important question to consider: what would be a good name for this module? Kidding aside, it seemed implied that we could name this Runtime, but considering potential other features, are there any other names that could fit the bill as well?

5 Likes

I think that using the term runtime for the name is slightly confusing - are you referring to the language runtime or the runtime, runtime-support? Without really thinking about it - why not something like SwiftSupport or SwiftLanguageSupport? I do like the latter - and it is ripe for some amusing things - can be initialized as SLS (pronounced as "slice", a library that slices and dices!).

The other piece of low-hanging fruit I can immediately think of is an officially supported version of _typeByName(_:). There’s also an SPI for _typeName(_:qualified:) that might make sense to expose (although I think we already call it when you use String(describing:) or String(reflecting:) on a metatype). If the runtime can also give you the mangled name of a metatype, that might also be a good thing to have in the runtime module.

Beyond that? There’s a big, deferred task that ought to be in the runtime module: Reading Swift’s type metadata. There’s a ton of detailed metadata in Swift binaries—enough to list types and their conformances, make key paths for their variables and closures for their methods, pack and unpack enums, and almost everything else you might want to do—but we don’t have any APIs to read it yet. That would all be great stuff to include in the runtime module.

11 Likes

100% agree. An official way to mess with Swift’s type metadata would be a great addition to this new module.

3 Likes

+1

I'm not sure this captures the "low-level" aspect of this new module. I agree that Runtime could be confusing, but it does encompass the low-level aspect and communicates that facilities found in this module are related to runtime functionality.

1 Like

I suppose could do SwiftLowLevelServices, but, I don't think that really tells you what it really provides. Trying to come up with something more pithy is probably valuable for the longer term IMO.

1 Like