[rust-dev] Implementation of traits in Rust: could it be dynamic?
lionel.parreaux at gmail.com
Fri Jul 25 20:10:06 PDT 2014
Oh I'm sorry I completely missed your message, because I was not subscribed
to the list.
Thanks for the explanation. I do realize that this is the tough part,
compared to a system like Haskell where everything is boxed.
It's interesting to hear that this is how it was (meant to be) done in a
previous version of Rust. Could you expand on the sources of the
difficulties met trying to implement it? (Or just give me a pointer to some
material about it.)
I'm interested, because I'm working on a research language without GC and
without boxed allocation semantics, so this kind of things come up.
PS: I agree that the current system seems reasonable for what Rust targets.
Patrick Walton <pcwalton at mozilla.com>
Tue Jul 22 11:47:18 PDT 2014
> On 7/22/14 10:16 AM, Lionel Parreaux wrote:
> > I'm not sure whether this is a big problem in practice, but I was
> > wondering if it would be possible to switch to some runtime mechanism in
> > cases like this. Maybe we could make a special version of every generic
> > functions, that takes a dictionary at runtime and that would be able to
> > handle types unknown at compile-time. We would switch to this version
> > when monomorphization does not work. It could also allow dynamic linking
> > of libraries with generic functions, or it could be a way to compile
> > some programs (or some parts of programs) much faster.
> The hard part about doing that is not the dictionary passing. The hard
> part is that generic types may have unknown size or alignment. In
> Haskell this is not a problem because the language is garbage-collected
> and lazy so values have a uniform representation. But in Rust this is
> not true.
> Old Rust used to try to use runtime dictionary passing, where the
> dictionary contained size and alignment information, and all
> size/alignment info was computed at runtime for generics. I cannot
> overstate how *fiendishly* complex this was. We never got all the bugs
> out. In many cases, the amount of runtime code generated to compute size
> and alignment outweighed the cost of just monomorphizing.
> I strongly feel that the current system, where you can use generic type
> parameters to get monomorphization or trait objects to get dictionary
> passing, is the sweet spot.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Rust-dev