epfl-lara / rust-stainless

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

Check soundness of clone erasure #136

Open yannbolliger opened 3 years ago

yannbolliger commented 3 years ago

From #124 on, calls to st::clone::Clone::clone as well as implementations of the trait are erased/replaced by identity. This is to facilitate some benchmarks and is correct on the small and immutable examples of the test suite. However, in general this is unsound:

The frontend needs to check these cases and forbid them. A more complicated problem arises with generic functions that have type parameters.

fn f<T: Clone>(t: T) { t.clone() }

Here, it cannot be decided at definition site of the function, whether the Clone is safe and can be erased or not. Two solutions come to mind: