On 7/14/11 3:08 AM, Marijn Haverbeke wrote:
First, a relatively non-controversial case:

auto&ccx = cx.fcx.lcx.ccx;   // Look ma, no refcounting bumps!

This case is very similar to alt/for blocks, and the alias checker
could check it with a relatively simple extension.

Next, of couse, I'm going to argue that 'accessing things through
blocks', for example the proposed hash table accessor approach (where
you pass a block to the accessor in which you'll have access to the
value) is an abomination, and we should allow functions to return
aliases to the content of their arguments. To the alias checker, this
isn't any more complicated than the alias-in-a-block case, and it is
certainly more pleasant on the programmer.

After the conversation among Dave, Dan Grossman, and me yesterday, I actually think that we don't want "accessing things through blocks" at all. I believe it's impossible to make memory-safe. Consider:

let h1 = @hashmap::mk();
let h2 = id(h1);    // identity fn; compiler can't see through this
hashmap::insert(*h1, "foo", "bar");
hashmap::get(*h1, "foo", { |&val|
    hashmap::delete(h2, "foo");
    print val;      // crash
});

I think we *have* to copy the values. (Note that we are already copying the values to please the alias checker in the hashmap implementation, so this adds no more overhead than what we have!) This gives get() a more natural return value, making the "accessing things through blocks" pattern pointless. So the problem goes away.

Patrick
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to