Hi,
I hope this question is not too specific for the mailing list, but I stumbled upon something I don't understand today and thought I'd better ask. In librustc/middle/ty.rs there is the mk_t() function which creates and caches objects of type "t" from values of type "sty". However, the way it uses the cache seems kind of strange, especially the key creation at the beginning:

fn mk_t(cx: ctxt, st: sty) -> t {
    // Check for primitive types.
    // ... omitted here ...

    let key = intern_key { sty: to_unsafe_ptr(&st) };
    match cx.interner.find(&key) {
      Some(t) => unsafe { return cast::transmute(&t.sty); },
      _ => ()
    }

The intern_key is created by taking a pointer to "st", which in effect is the address of the argument slot on the stack. That can't be right, can it? Is it possible that this cache is actually never used and the compiler always creates new t_box_ instances every time mk_t() is called somewhere? I don't know how bad this would be, maybe mk_t() is only called once per unique type anyway. Or maybe I'm overlooking something here?
Any insight on this would be appreciated :)

Cheers,
Michael
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to