On 02/10/2010 3:02 PM, Graydon Hoare wrote:
If you do have restrictions in mind that make these operations safe,
in what situations can you usefully use freeze and thaw?
Hopefully all contexts. I don't have any other restrictions in mind; did
you have any you were thinking of?
Sigh. Of course there are complications:
state obj mem(mutable int x) {
fn get() -> int {
ret x;
}
fn set(int i) {
x = i;
}
}
auto cell = mem(10);
let chan[mem] c = ...;
auto surprise = freeze cell;
c <| surprise;
surprise.set(11); // oops.
Guess you can't freeze state objs or fns (closures), only state *data*
that happens to contain already-immutable objs and fns. Unless the
freeze operator is going to go rewriting their state-mutating code!
(I mean, I guess you could implicitly have a
check sys.is_still_thawed(self);
as the first statement of every method on a state-mutating object, and
therefore have it fail when you try to execute such a method on its
frozen form. But that sounds a bit too cutesy. I think I'd prefer the
type system tell me I'm making a mistake here.)
Oh well. Sometimes code and data are just a bit too different.
-Graydon
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev