GaloisInc / saw-script

The SAW scripting language.
BSD 3-Clause "New" or "Revised" License
438 stars 63 forks source link

MIR: Make it easier to write specifications involving `Vec` #2032

Open RyanGlScott opened 8 months ago

RyanGlScott commented 8 months ago

Rust's Vec type is very common, and we'd like to make it simpler to write specifications that use Vec values. At a first approximation, we'd like to offer a mir_vec_value : [MIRType] -> MIRType function that constructs a Vec value from a list of element values.

Note that Vec is not a primitive MIR type, but it is instead a struct defined in terms of RawVec (which is in turn defined in terms of NonNull). As such, mir_vec_value could be thought of as a convenient shorthand for building a particular type of struct. We might also consider offering some kind of indexing operator à la mir_elem, as indexing into a RawVec manually would be tedious.

Some unresolved questions:

RyanGlScott commented 7 months ago

For a first cut at this, we can keep it simple:

RyanGlScott commented 7 months ago

Note that non-empty Vec values need to be allocated, so perhaps we should call this mir_alloc_vec to make this more explicit.

sauclovian-g commented 6 months ago

An array and a length works reasonably well for vectors, FWIW. You can run into problems with values in the array outside the intended valid region (so e.g. if you shrink the vector you need to explicitly clear the entries that are dropped) but as long as one remembers the hazard it isn't a big problem.