On 10/08/2013 02:55 PM, Keegan McAllister wrote:
I was excited to see the recent work [1] regarding link-time optimization between C or
C++ and Rust code. In Servo we access JavaScript objects through small C++ functions [2]
declared as extern "C". It would be great if the code for these accessors
(which depends on the C++ ABI and the contents of the SpiderMonkey header files) could be
inlined into Rust functions.
The main problem I see with the approach described in [1] is that it requires a
special build process for the whole Rust program. One compiles Rust to LLVM
bytecode and then links using clang. So my question is: how can we make a
mixed C++/Rust library which exposes LTO for the C++ components, and yet can be
used like any other Rust library crate? I suppose we would have to compile the
C++ with clang and then store the resulting LLVM bytecode as metadata in the
library crate's shared object. Does rustc already do inlining from LLVM
bytecode stored as metadata, or does it store Rust ASTs only?
I would be interested to hear any thoughts regarding this project, in
particular estimates of how difficult or time-consuming it would be.
It seems to me like Servo's use case *could* be solved by simply
accepting some arbitrary IR on the command line to merge into the LLVM
module, without worrying about storing it in metadata. As long as none
of the Rust that calls into C was generic or inlined then the C would
get properly inlined. For the generic and inlined bits of Rust you could
simply pass the IR again to the crate that does the generic
instantiation. That sounds pretty trivial to do.
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev