On 07/26/2013 06:18 PM, Patrick Walton wrote:
On 7/26/13 8:54 AM, Michael Woerister wrote:
To me this seems very much like a slightly clunky way of emulating
inheritance (with a lot more typing involved at definition and usage
sites). Field accessor functions or traits can alleviate some of this
clunkyness at the usage site; however, at the cost of even more
boilerplate needed at the definition site:
pub enum decl {
decl_local(@Local, span),
decl_item(@item, span),
}
impl decl {
fn get_span(&self) {
// this match statement also introduces some unnecessary
runtime overhead...
match *self {
decl_local(_, span) => span,
decl_item(_, span) => span
}
}
}
This situation is not very satisfactory but I don't know an easy
solution to the problem. I certainly don't suggest adding such a heavy
tool as inheritance to Rust just for this use case.
This is the preferred method of emulating common fields. We use this
in Servo.
I would like to add an optimization to remove the unnecessary runtime
overhead in this case. In theory this should be amenable to compiler
optimizations.
Yes, if all common fields are placed in the same order at the beginning
of every variant, all arms of the match should result in the same LLVM
code generated. Maybe LLVM can optimize this already?
Thanks for your answer!
-Michael
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev