News for hackers. Stuff that matters.
Re:Interoperability: Swift’s Super Power by mpweiher on Friday September 22, 2023 @06:26AM (#37610242)
Hmm...Swift never struck me as a particularly interoperable design. Really rather the opposite. It has weird and super-specific calling conventions, requires mangled identifiers, is uber-static, uses Swift syntax for its "module" files etc.

And it turns out...

"Instead, Swift embeds a copy of clang, the C and C++ compiler,"

...well gosh, you can brute force "interoperability" by simply creating the union of all the languages you "interoperate" with.

https://www.youtube.com/watch?v=XqUgUgiToNs

"The F4 Phantom, America's proof to the world that with a big enough engine, even a brick can fly"

Re:Interoperability: Swift’s Super Power by Tarq0n on Friday September 22, 2023 @06:31AM (#37610271)
Sounds like the precursor to what Lattner is trying to do with Mojo: embed everything into a Frankenstein of a compiler and runtime. Time will tell if such a thing is maintainable.
Re:Interoperability: Swift’s Super Power by mpweiher on Tuesday October 03, 2023 @03:44AM (#37748976)
I think we already have fairly overwhelming evidence that it is not.
Re:Interoperability: Swift’s Super Power by pohl on Friday September 22, 2023 @07:15AM (#37610521)
Don’t forget that this interoperability was put in place to support a specific engineering goal: to make it possible to slowly (over decades, probably) transition from 4 different languages (C, ObjC, C++, ObjC++) at every level of Apple’s stack towards a single successor language.

Would you recommend they wait for some weird Java-esque 100% Pure implementation within the compiler itself before they can begin that work?

The ideal you’re suggesting is actually made more possible by this work. One can imagine a Swift LLVM/Clang now.

See: https://www.youtube.com/watch?v=lgivCGdmFrw

Re:Interoperability: Swift’s Super Power by stephen_g on Friday September 22, 2023 @11:33AM (#37613393)
Wow, I'm only three minutes in, but it's a good talk. Among other parts of Apple's ecosystem (especially Webkit would make sense to move to Swift for memory safety), imagine if they start incrementally moving llvm/Clang over to Swift using this, that would be very interesting.
Re:Interoperability: Swift’s Super Power by jmull on Friday September 22, 2023 @07:42AM (#37610699)
If you want to interoperate with C and C++ and could either make people specify low-level details of the interface themselves or process C and C++ header files to do it automatically. Obviously the latter is a much better interoperability solution.

Processing C and C++ header files means using a C/C++ compiler. It would hardly make sense to write a new one if there was a good one already available.

Re:Interoperability: Swift’s Super Power by Someone on Friday September 22, 2023 @08:02AM (#37610856)
> “Instead, Swift embeds a copy of clang, the C and C++ compiler," ...well gosh, you can brute force "interoperability" by simply creating the union of all the languages you "interoperate" with.

That’s not what they do. To efficiently use C and C++ structs and classes from another language you have to know their layout and calling conventions.

With C and C++, you have to run the preprocessor and (e.g. for C++ templates) large parts of the compiler to reliably do that. How else are you going to figure out what foo_t and bar_t in header files mean?

If you need to run a compiler, using an existing compiler is the wise thing to do.