On 2013-11-15, at 9:47, Oren Ben-Kiki <o...@ben-kiki.org> wrote: > In your code, when providing a default implementation for `inflate_by`, you > are invoking the trait (hence "virtual") method `get_radius`. If the compiler > compiles `inflate_by` when seeing just the `Inflate` source code, then this > must be translated to an indirect call through the vtable. > > The point of anonymous members (and, to a greater extent, of the single > inheritance) is to ensure that access to data members is just that, without > any function calls. > > To achieve that with the approach you described, the compiler will need to > re-compile `inflate_by` for each and every struct that implements it; only > then it would be able to inline `get_radius`. > > Is this what the Rust compiler does today? I have no specific knowledge of > the answer, but the simplest thing for the compiler would be to keep > `get_radius` as a virtual function call. > > Doing otherwise would require quite a bit of machinery (e.g., what if > `Inflate` is defined in another crate, and all we have is its fully-compiled > shared object file? There would need to be some "extra stuff" available to > the compiler to do this re-compilation, as the source is not available at > that point). > > Therefore I suspect that this approach would suffer from significant > performance issues.
Okay, that makes sense. I wonder if LLVM's de-virtualization capabilities would be of any help in all this. _______________________________________________ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev