Authoritative source of type layout/ABI conventions?

Where in the compiler or Apple's LLVM branch can I find the code that generates the layout of types, type metadata and other ABI-related information? The ABI stability manifesto is the youngest among the related documentation, but I'm not sure if it's totally up-to-date, and it's also referring to the fact that other docs on this topic could be fairly outdated by now, so I suppose the best source would be the actual compiler code — the thing is that, sadly, I'm not familiar with its architecture enough to be able to locate it.

I suppose that it's the IRGen module that's mainly responsible for generating the layout, but I'm not sure if there's also some Swift-specific LLVM code that I'd also need to read into. Some simple links to the relevant files/folders would suffice for me — thank you.

There are two somewhat different questions here. Looking at the code that is generating the structures might not be the easiest way to understand what the layout of different structures is. For example, there are a bunch of different pointer types.

I'm not entirely sure what the best way to go about understanding this is but I think it's probably useful to look at:

  1. Existing documentation in docs/ABI (with a grain of salt, since parts are out-dated).
  2. Look at the headers in include/swift/ABI.h.

This should cover type metadata, but I don't think you'll get a good sense of type layout. I'm not sure what is the best way to understand the type layout. It's spread out over many different files, like GenStruct.cpp, GenClass.cpp and so on.

It might help to understand what you're trying to do (e.g. it might not require fully understanding all the layout information, which will save you time).

I'm generally not looking for the easiest way to understand this per se — my overall goal is to get the total understanding of how exactly Swift translates into the machine language, eliminating the parts that do not play a major role here (basically everything that happens before generating the canonical SIL). Compared to (my understanding of) C, it's fairly straightforward to understand how C-to-assemly lowering happens, but being a compiler-outsider, I'm not having the best times tracing this back for Swift — for instance, it took me some fair amount of time to find a doc that would explain me what's the difference between thick and thin Swift functions, and I suppose that this'd be simpler to learn straight from the code.

So I'm actually striving to understand this process fully — my question was simply in narrowing down the relevant parts. I'll look into these files, thanx ;)

1 Like