Not quite. Swift requires a runtime, so you probably won't see people writing OS kernels in Swift.
Not quite. Swift requires a runtime, so you probably won't see people writing OS kernels in Swift.
Also, Swift, unlike Objective-C, is not a superset of C.
Which also happens to have a runtime, crt0.o.
Usually in these scenarios I believe it just requires a company to bully developers to accept it and an eventual generation change.
If tomorrow Apple decides, for whatever reason, that new kext or IOKit modules are to be written in Swift, then whoever cares about their Apple OS customers will just comply with it.
However if you are willing to accept some functionality will be written in C it is possible to run Swift directly on bare metal.
I would rather use Assembly or compiler intrinsics instead, just like many C alternatives, some much older like NEWP, do.
Also many of the C library calls are impossible to implement in pure ANSI C without language extensions or Assembly, malloc() and free() being two of them.
[1] https://www.rust-lang.org/faq.html#does-rust-have-a-runtime (also mentions what's in the C runtime)
IIRC, Swift's runtime is like C++'s with v-table lookup for dispatch on functions that do not involve Objective-C objects.
(For the record, I believe Chris Lattner is on the record as saying "yes, Swift has a runtime, let's not bother arguing that point" though I can't find the link, but I agree that Swift's runtime is less invasive than most other languages (e.g. Go).)
And the Swift runtime is pretty minimal, mostly used for storing dynamic type information, dispatching protocol methods, generating (unspecialised) generic types, checking conformances etc. It's mostly used by the compiler to add the dynamic features of the language; for example, the compiler observes the lifetimes of variables and inserts retain/release instructions, which are lowered down to a swift_retain or swift_release calls on the runtime instance. These functions are implemented in the runtime and do the manipulation of reference counts and deallocation.
https://github.com/apple/swift/tree/master/stdlib/public/run...