On 9/16/11 2:10 PM, Marijn Haverbeke wrote:
The problem: Accessor functions always have to copy their return
value, so you can't efficiently get at the content of data structures
(except by duplicating the logic needed to access them).

The original solution proposed was to pass the accessor a block and
pass the value to that block by reference. This would cause blocks to
spring up everywhere (with all the indentation and noise that comes
with it) and be extremely un-composable. A while ago I wrote a message
to this list proposing a system whereby functions could return
references. This week, I've finally implemented that. The exact syntax
and semantics are not yet set in stone, so if you see room for
improvement, reply.

How about having container types in which accessors swap the original with none?

fn get_swap<T>(&mutable option<T> : opt) -> T {
        let opt2 = none;
        opt :=: opt2;
        ret alt opt2 { none. { fail } some(x) { x } }
}

Rationale: For boxes (option<@T>) get() is fine; it just returns a pointer (maybe bumping an RC; in GC this is free). For interior types (option<large_rec>)... well, programmers are paying a huge performance/memory penalty for these anyway, because |none| is so large, so I'm not sure it's worth optimizing. For unique pointers (vectors, strings too), this is where we get big wins for performance, and it seems to me that we can easily optimize the return statement above to move the pointer.

I've been quite concerned about the complexity of incorporating type-based alias analysis into the language semantics for some time. TBAA is traditionally an optimization, not something necessary for soundness. I'd like to see how far we can go with alias analysis that isn't type-based, but rather layer- (interior/unique/box) and mutability-based.

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

Reply via email to