epfl-lara / rust-stainless

An experimental Rust frontend for Stainless
Apache License 2.0
6 stars 2 forks source link

Mutable references #140

Open yannbolliger opened 3 years ago

yannbolliger commented 3 years ago

For now, the frontend allows only local mutation and no mutable borrowing for safety reasons. It would however, provide great value to also allow mutable references. This should be possible by targetting the imperative phase of Stainless.

Example in Scala: https://github.com/jad-hamza/stainless/blob/72c0052255878c440e0a1d00260f4ebf04ba5860/frontends/benchmarks/imperative/valid/ReturnWithMutation.scala

yannbolliger commented 3 years ago

The current plan is to support mutable references &mut T by modelling them as mutable ADT:

case class Mut[T](var value: T)

In that way we can model the fact, that one can remotely overwrite the entire T i.e.

fn foo(x: &mut Bar) { 
  *x = Bar(...)
}
yannbolliger commented 3 years ago

Survey of possible problems with mutable references