On Sat, Oct 2, 2010 at 8:02 PM, Graydon Hoare <[email protected]> wrote:
> 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!

Well, I see two ways to handle this problem, although there may be
more subtle problems lurking:

1) C++'s const qualifier on methods, which says that such methods
stick around on frozen versions of objects. Probably not good for
Rust.
2) Recursively remove "mutable" from the frozen object's arguments,
and then re-typecheck the methods. Methods that fail are removed from
the frozen type. Since surprise.set would fail to typecheck if 'x'
weren't mutable, it would give a "method not found" error at your
"oops" line. Similarly for captured arguments in frozen functions.

> (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
>
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to