Sonder is a static analysis tool for C, for determining the necessary sementics for converting the analyzed C programs to Rust.
- The address of only one variable at a time is taken
&(foo + bar) // illegal
- Only one pointer is dereferenced at a time
*(foo + bar) // illegal
- Only pointers are dereferenced
*not_ptr // illegal
- UNSAFE ASSUMPTION: Mutatble references can't be made unless they're tied to a ptr declaration. Adresses are always immutable unless explicitely annotated otherwise by the ptr declaration.
list.append(&mut other_list) // not something we're going to worry about for now
In the future, we will treat arguments as being bound to parameters as variables
So,&mut other_list
will be treated as if it's bound to the variable value inside the function
Any of these will immediantly result in raw pointers being used, although at the moment, they panic
- Figure out how to represent lifetimes
- This seems to rely on line numbers, which are lost information.
- Perhaps we could find a way to represent lifetimes through position on the ast, but that seems exceedingly difficult
- Including line-numbers in the initial ast seems to be the way to go
let t = 8;
let n = &t;
// n dropped here
let m = &mut t;
// m dropped here
- Figure out how to represent scope
-
Get list of all owned data
-
For each piece of owned data:
- Get list of all usages of all refs to it in each scope
- Iterate through scope to check if each one is mutable, or immutable
- this may include parsing called scopes
- some escape analysis may be will here
- whether full borrow-checking will be needed is still unclear
- we will need a way of checking branching
- this includes being passed mutably, or mutating
- Count to make sure at any given point, only a single mutable, or any number of immutable references are used (otherwise leave it as a raw pointer)
- If we have time, check for common Smart Pointer semantics
-
Generate a new AST with previously implicit pointer semantics made explicit
-
Try converting the new AST to semantically identical, idiomatic Rust.
- Branches are counted as their own scopes
- Exclusive branches can hold different references to an object
- But they all must consider the higher-scoped references to higher-scoped data
- Assume all non-exclusive branches occur