Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Functional purification for Cell and other types with interior mutability #4

Open
tyrbentsen opened this issue Feb 5, 2018 · 1 comment

Comments

@tyrbentsen
Copy link

Could you elaborate on whether functional purification can still hold when using types with interior mutability, like 'Cell'?

In the following example, c2 is mutated through c1. Is there any rule that can be used to transform this into a purely functional equivalent (without having to track all the aliases to c1, which might be difficult for non-trivial cases)?

let c1: &Cell<i32> = &Cell::new(0);
let c2: &Cell<i32> = c1;
c1.set(2);
println!("{:?}", c2.get()); // Prints 2

What about RefCell, Mutex, ... ?

@Kha
Copy link
Owner

Kha commented Feb 5, 2018

Yes, types with interior mutability are outside the thesis' language subset a priori. Some of them like Rc could still be modeled in a referentially transparent way as long methods like try_unwrap that expose the mutable state are not exposed. For all other types, you would have to introduce a global heap and presumably reason about it using separation logic. My hope is that this would still be simpler than other models that use separation logic for every single type, but this was out of scope for the thesis.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants