Could anyone shed some light on what calls the Driver.main and what takes place before the call? Even better, please point me to the relevant code where this happens.
I haven't looked into that so perhaps someone else can tell, but I wonder if you could be more clear about what exactly you're looking for.
The reason is, I don't think on a Swift level, much happens before calling main. Sure maybe some concurrency related stuff (run the global executor? start some threads? not sure if some are started up front or are all lazy-initialized), but, not much.
It's similar to asking what happens before calling int main(int argc, char *argv[]) in C/C++. Where, again, not much happens. The kernel loads the app into memory typically after calling one of the exec functions, likely after the parent process forks itself, and calls the entry point of the app (the main func). Now in Swift, Swift itself probably does a bit of work before calling the main func, I'm assuming, but again, it should amount to "not much".
So basically I'm wondering if you actually are looking to know what that "not much" is, or you're looking for something else, or perhaps, both.
Godbolt is really good for these kinds of explorations.
For a normal, non-throwing synchronous main, there's not much going on. Swift generates a C-calling convention main, which calls a synthesized static $main method on your @main type, which calls the actual main that you wrote (link).
A throwing main is similar but it has to do a little bit more work to prepare for a possible error being thrown, and if your main does then it calls a runtime function to report the error and exit abnormally.
For an async main, there's quite a bit more that happens before your main gets called, since it has to set up the concurrency runtime, put your main in a Task, and wait for it to complete.
EDIT: I forgot to mention what happens before the C main entry point is called, but that's dependent on the startup code used by your target platform, and not typically something you need to be concerned about unless you're doing embedded work.
Furthermore, the lack of features like C++ static constructors in Swift means you don't have to worry about random (Swift) code in your binary executing before your main does. However, the Swift runtime itself does have some code that uses __attribute__((constructor)) to initialize itself, to handle things like the global protocol conformance lookup tables.