Recently, I have been struggling with Swift Compile MergeSwiftModule process for a long time. What confused me is that, if the *.swiftmodule is support a serious module APIs for other project to call, why does it must have to Request SIL Generate ?
What's the benefit or reason for *.swiftmodule to Request SIL Generate? Just because it can improve the efficiency of LLVM compiling Swift?
And, cause it has contain ASTs and SIL, why could't it be designed a whole binary, so that it could be linked directly?
I'm curious about the *.swiftmodule file, but I haven't found any tools to dump the file to get the exact structure of it.
I will so appreciate that anyone could solve my confusion. Thanks.
AFAIK, the SIL contained in a .swiftmodule file is for inlinable methods. Since a compilation depending on the module only has access to the .swiftmodule file and not any of the dependency's sources, in order to inline certain things it needs the actual SIL so that the compiler can drop it in where it's being called. (Similarly, when using library evolution, generated .swiftinterface files contain the actual bodies of inlinable methods as source, but that needs to be recompiled into SIL before it can be used.)
There may be other reasons SIL is included in the compiled module; someone more familiar with the codegen space can probably add some more color here.
This seems to be an implementation question and not an evolution one, so I'm going to change the category of this thread.
I'm really not sure what you're asking here, so I'll just give a quick technical summary. A
swiftmodule file is a binary description of the interface to a Swift module. It contains binary serializations of the public and ABI-exposed declarations of the module, as well as binary serializations of the SIL representation of functions which can inlined outside of the module. It is not an object file and does not contain machine code, and therefore it cannot be linked.
Thanks a lot. That is what confused me. I did't know why should *.swiftmodule generate SIL when SwiftMergeModule, cause I have been faced on several Swift Compiler Crash cases during merge Swift and quite difficult to solve.