www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - rust reaction to walter's talk on interfacing to C++

reply Laeeth Isharc <laeethnospam nospam.laeeth.com> writes:
https://internals.rust-lang.org/t/interfacing-d-to-legacy-c-code-a-summary-of-a-competing-languages-capabilities/1406/3
from > a year back, but I didn't see it mentioned here before.

"
Personal thoughts for Rust:

     This could be a killer feature for D. As far as I know, no 
language (which doesn't just translate to C++) supports C++ 
interfacing in any non-insane manner. It would significantly 
reduce the barrier to incrementally replacing C++ with D code. I 
believe that if Rust wants to compete in this space, matching D's 
capabilities here would be of considerable value.
     Rust is not as well-off as D in some areas: D has the 
advantage of its template system actually being a superset of 
C++'s. It also has conventional OO features. Finally, it has a 
several-year head start.
     Rust has two advantages I can think of: it doesn't have the 
struct/class split that D does, and it has non-transitive *mut 
and *const (at least, I don't think they're transitive in Rust).
     This isn't a question of all-or-nothing. Clearly, interfacing 
with any possible C++ code is just complete lunacy. D has thus 
far demonstrated that there's a decently-sized proportion of C++ 
code that can be bound to without needing to integrate a full C++ 
compiler.
     With the Servo team looking to start adding components 
written in Rust into Firefox, might be an excellent opportunity 
to look at exactly what features would be most useful.
"
Mar 22 2016
next sibling parent Ola Fosheim =?UTF-8?B?R3LDuHN0YWQ=?= writes:
On Tuesday, 22 March 2016 at 08:52:23 UTC, Laeeth Isharc wrote:
     This isn't a question of all-or-nothing. Clearly, 
 interfacing with any possible C++ code is just complete lunacy.
You need to define what you mean by interfacing: 1. Interfacing with existing C++ libraries. 2. Interfacing with C++ code written with D in mind. 3. Interfacing with legacy C++ applications(pre C++11) Point 3 will become irrelevant over time, so it is not worth the trouble. Point 2 is achievable even from Python (Boost Python). Point 1 is what is needed for C++ interfacing to be a selling point and then you do need: 1. Redefine or extend D semantics to match C++. 2. Link in clang.
 D has thus far demonstrated that there's a decently-sized 
 proportion of C++ code that can be bound to without needing to 
 integrate a full C++ compiler.
I don't think this has been demonstrated. What projects are you talking about?
Mar 22 2016
prev sibling next sibling parent reply Guillaume Piolat <name.lastname gmail.com> writes:
On Tuesday, 22 March 2016 at 08:52:23 UTC, Laeeth Isharc wrote:
 https://internals.rust-lang.org/t/interfacing-d-to-legacy-c-code-a-summary-of-a-competing-languages-capabilities/1406/3
 from > a year back, but I didn't see it mentioned here before.
Cynic me would say the first one to link the clang front-end to their compiler will win. Who wants to write bindings when you can just add source files? :)
Mar 22 2016
next sibling parent Ola Fosheim =?UTF-8?B?R3LDuHN0YWQ=?= writes:
On Tuesday, 22 March 2016 at 10:48:42 UTC, Guillaume Piolat wrote:
 Cynic me would say the first one to link the clang front-end to 
 their compiler will win. Who wants to write bindings when you 
 can just add source files? :)
Yes, + IDE + same targets.
Mar 22 2016
prev sibling parent Jacob Carlborg <doob me.com> writes:
On 2016-03-22 11:48, Guillaume Piolat wrote:
 On Tuesday, 22 March 2016 at 08:52:23 UTC, Laeeth Isharc wrote:
 https://internals.rust-lang.org/t/interfacing-d-to-legacy-c-code-a-summary-of-a-competing-languages-capabilities/1406/3

 from > a year back, but I didn't see it mentioned here before.
Cynic me would say the first one to link the clang front-end to their compiler will win. Who wants to write bindings when you can just add source files? :)
i.e. Swift, but that is for C. -- /Jacob Carlborg
Mar 22 2016
prev sibling parent reply Jonathan M Davis <jmdavisProg gmx.com> writes:
On Tuesday, 22 March 2016 at 08:52:23 UTC, Laeeth Isharc wrote:
     Rust has two advantages I can think of: it doesn't have the 
 struct/class split that D does, and it has non-transitive *mut 
 and *const (at least, I don't think they're transitive in Rust).
That's funny. I would have said that those were _advantages_ for D. D's constness can certainly be unwieldy (some sort of equivalent to C++ mutable would be a very welcome addition if we could pull it off), but whatever flaws D's const may have, the transitivity is a huge plus overall IMHO, and I would have said that the struct/class split was a huge win. It properly segregates the inheritance stuff to reference types while not forcing all user-defined types of any complexity to be reference types. So, while I'm quite sure that Rust has advantages over D, I would not have listed those among them. - Jonathan M Davis
Mar 22 2016
next sibling parent reply Mike Parker <aldacron gmail.com> writes:
 That's funny. I would have said that those were _advantages_ 
 for D. D's constness can certainly be unwieldy (some sort of 
 equivalent to C++ mutable would be a very welcome addition if 
 we could pull it off), but whatever flaws D's const may have, 
 the transitivity is a huge plus overall IMHO, and I would have 
 said that the struct/class split was a huge win. It properly 
 segregates the inheritance stuff to reference types while not 
 forcing all user-defined types of any complexity to be 
 reference types.

 So, while I'm quite sure that Rust has advantages over D, I 
 would not have listed those among them.
In general, yes, but in terms of interfacing with C++ they are a bit irksome.
Mar 22 2016
parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Tuesday, 22 March 2016 at 11:03:10 UTC, Mike Parker wrote:
 That's funny. I would have said that those were _advantages_ 
 for D. D's constness can certainly be unwieldy (some sort of 
 equivalent to C++ mutable would be a very welcome addition if 
 we could pull it off), but whatever flaws D's const may have, 
 the transitivity is a huge plus overall IMHO, and I would have 
 said that the struct/class split was a huge win. It properly 
 segregates the inheritance stuff to reference types while not 
 forcing all user-defined types of any complexity to be 
 reference types.

 So, while I'm quite sure that Rust has advantages over D, I 
 would not have listed those among them.
In general, yes, but in terms of interfacing with C++ they are a bit irksome.
That's true. If you're talking specifically about interfacing with C++, then some of D's improvements over C++ do become a problem. - Jonathan M Davis
Mar 22 2016
prev sibling next sibling parent reply Johan Engelen <j j.nl> writes:
On Tuesday, 22 March 2016 at 11:00:44 UTC, Jonathan M Davis wrote:
 On Tuesday, 22 March 2016 at 08:52:23 UTC, Laeeth Isharc wrote:
     Rust has two advantages I can think of: it doesn't have 
 the struct/class split that D does, and it has non-transitive 
 *mut and *const (at least, I don't think they're transitive in 
 Rust).
That's funny. I would have said that those were _advantages_ for D. [...], and I would have said that the struct/class split was a huge win.
Shoot me down if unrelated and easily worked around: MSVC mangles "struct" differently from "class". Perhaps the D split between struct/class makes it hard to represent this MSVC mangling? (without changing the C++ source)
Mar 22 2016
parent Walter Bright <newshound2 digitalmars.com> writes:
On 3/22/2016 4:05 AM, Johan Engelen wrote:
 Shoot me down if unrelated and easily worked around:  MSVC mangles "struct"
 differently from "class". Perhaps the D split between struct/class makes it
hard
 to represent this MSVC mangling? (without changing the C++ source)
It is a current problem. I've thought of many solutions, but none were satisfying.
Mar 22 2016
prev sibling next sibling parent Ola Fosheim =?UTF-8?B?R3LDuHN0YWQ=?= writes:
On Tuesday, 22 March 2016 at 11:00:44 UTC, Jonathan M Davis wrote:
 we could pull it off), but whatever flaws D's const may have, 
 the transitivity is a huge plus overall IMHO, and I would have 
 said that the struct/class split was a huge win. It properly 
 segregates the inheritance stuff to reference types while not 
 forcing all user-defined types of any complexity to be 
 reference types.
Well, it could have been a win if structs were more restricted and acted like non-referenced types (pure functional values without identity, just like a CPU register) + if classes were put on the stack (or many objects were allocated as a group) by the compiler as an optimization. The problem is that D is trying hard to be like C/C++ in terms of low-level semantics, and then just about all the advantages are lost.
 So, while I'm quite sure that Rust has advantages over D, I 
 would not have listed those among them.
The big win for Rust would be some of the basic semantics and the aliasing guarantees for their "unique_ptr" system. Rust can potentially support better optimization and better correctness guarantees than C++/D. But Rust needs a faster compiler, since the Rust feature set matters more for large projects...
Mar 22 2016
prev sibling parent QAston <qaston gmail.com> writes:
On Tuesday, 22 March 2016 at 11:00:44 UTC, Jonathan M Davis wrote:
 That's funny. I would have said that those were _advantages_ 
 for D. D's constness can certainly be unwieldy (some sort of 
 equivalent to C++ mutable would be a very welcome addition if 
 we could pull it off), but whatever flaws D's const may have, 
 the transitivity is a huge plus overall IMHO, and I would have 
 said that the struct/class split was a huge win. It properly 
 segregates the inheritance stuff to reference types while not 
 forcing all user-defined types of any complexity to be 
 reference types.

 So, while I'm quite sure that Rust has advantages over D, I 
 would not have listed those among them.

 - Jonathan M Davis
Rust doesn't need D-style transitive const because it can be replicated using variable bindings and ownership. When you create an object and only assign it immutable binding for it it's transitively immutable forever. Tail mutability can be achieved by wrapping a field in std::Cell: https://doc.rust-lang.org/std/cell/ . Imo much less invasive than D's constness. Rust doesn't have implementation inheritance yet, so no class/struct split. We'll see how they deal with that, various proposals are made.
Mar 24 2016