Suppose I have a project using Swift 5.1, and it depends on a pre-built static library. This static library was built with a slightly different compiler version, but still Swift 5.1. It was not built for distribution because the library has issues with this (which is true of some big libraries like Alamofire). Is it still safe to use?
No. Libraries must be built with the exact same version of the compiler. On Apple platforms Xcode versions provide the guarantee.
Well, patch versions of Xcode may work if it has the same version of the compiler, but patch versions of the compiler certainly don’t.
Additionally, when the versions are incompatible, Xcode will give you a nice error rather than crashing at runtime. The compiler itself may produce a similar error. So it’s not dangerous per se, just a build error.