News for hackers. Stuff that matters.
Re:Why I love Rust by steveklabnik on Friday January 08, 2016 @12:37PM (#10866604)
Yes, this is a good point about AAA.

The issue with interop is on the C++ side, unfortunately, not our side. Until C++ has a well-defined ABI, it's not really possible.

Re:Why I love Rust by pcwalton on Friday January 08, 2016 @12:51PM (#10866714)
It's not clear to me that it's impossible. The ABI isn't a huge issue; templates are, though. I can see a potential path forward by using clang heavily, but it requires a lot of thought.

Isn't Swift looking heavily into C++ interop? It might make sense to collaborate with them to get it to work in both languages.

Re:Why I love Rust by steveklabnik on Friday January 08, 2016 @12:57PM (#10866753)
Swift is implemented in C++, and uses LLVM stuff that we don't because it's not exposed in the C ABI, last I heard.
Re:Why I love Rust by pcwalton on Friday January 08, 2016 @01:55PM (#10867236)
Well, sure, but how the compiler calls into libclang/LLVM isn't the difficult issue here. The more interesting issue is how, conceptually, the Swift or Rust compiler would use libclang to interoperate with C++ in a foreign environment. Once that's established, writing C bindings to whatever part of libclang is necessary should be straightforward.
Re:Why I love Rust by mike_hearn on Friday January 08, 2016 @12:52PM (#10866724)
C++ has a well defined ABI on many important platforms.

On GCC/LLVM based platforms it's standardised in specification documents. On Windows, I think the Visual C++ ABI is the de-facto standard.

Regardless, there are only a handful of top C++ compilers. Interop with even one of them would be of tremendous value.

Re:Why I love Rust by pcwalton on Friday January 08, 2016 @02:02PM (#10867282)
I totally agree. As I mentioned in a sibling comment, maybe the right solution is for Swift and Rust to solve the problem together by using libclang in the same way.

To be concrete, I could envision some sort of bolt-on "inline C++" feature that libclang would expose to all LLVM-based languages. It wouldn't have to be principled interop any more than Objective-C++ is principled interop. It'd just need to get the job done.

Re:Why I love Rust by steveklabnik on Friday January 08, 2016 @12:58PM (#10866770)
Yeah, I mean, the basics of interop might be possible, it will just never be as robust as it could be if C++ had features better designed to play with other languages.

(This of course also affects Rust as well; we don't have a defined ABI either.)

Re:Why I love Rust by mike_hearn on Friday January 08, 2016 @03:22PM (#10867916)
Sure, you can't get completely perfect interop. However a LOT of real C++ codebases don't use or explicitly ban some of the trickiest features, so even partial support can go a long way. For instance, supporting the basic class/vtable layout C++ uses (or even just adopting the C++ ABI for Rust itself here) along with char* strings, would immediately allow you to call into a lot of real C++ APIs, albeit older ones.

Supporting C++ value types, even without templates, would in turn be enough to support quite a lot more. For instance Unreal Engine defines its own string types, as do Qt and so on.

Re:Why I love Rust by steveklabnik on Friday January 08, 2016 @04:56PM (#10868616)
Yeah, to be clear, I think such a thing would have value too. Just hard to get 100%, there are always gonna be caveats.