-
Notifications
You must be signed in to change notification settings - Fork 9
Adding type support for mutable vs. immutable slices #326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
repository: mtzguido/karamel | ||
ref: dev | ||
repository: FStarLang/karamel | ||
ref: _taramana_mutable_slice |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops didn't realize this was still pointing to my repo. When restoring let's just go the main one.
: Lemma (timeless (pts_to x #p s)) | ||
[SMTPat (timeless (pts_to x #p s))] | ||
|
||
val from_arrayptr (#t: Type) (a: AP.ptr t) (#p: perm) (#v: Ghost.erased (Seq.seq t)) : stt (ptr t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use pulse vals here?
val base #t (p: ptr t) : GTot (A.array t) | ||
val offset #t (p: ptr t) : GTot nat | ||
|
||
instance val has_pts_to_array_ptr (t: Type) : has_pts_to (ptr t) (Seq.seq t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should expose a pts_to function and make this transparent. Otherwise we will get unfolded projectors in the context (at least currently). It would be nice to have exactly this at some point, though.
tl;dr Breaking changes
If you need mutable slices, you will need to change your code to use
Pulse.Lib.MutableSlice
instead ofPulse.Lib.Slice
.Adding type support for mutable vs. immutable slices
With FStarLang/karamel#533, Karamel is on track to supporting F* interfaces implemented in Rust. Thus, mutability analysis requires annotations on the types of such interfaces, to determine which arguments should be
mut
and which shouldn't. (@msprotz, please correct me if I'm wrong.)Following a suggestion by @gebner , this PR:
Pulse.Lib.Slice.slice
immutablePulse.Lib.MutableSlice.slice
for mutable slices (although this wouldn't preclude Karamel's whole-program analysis from refining them as immutable.)To implement immutable slices, I duplicated
Pulse.Lib.ArrayPtr
asPulse.Lib.ConstArrayPtr
for const array pointers, which I extract to Cconst
pointers. To do so, I rely on type abstraction: supported operations are the same exceptop_Array_Assignment
andcopy
, which I removed fromPulse.Lib.ConstArrayPtr
.For compatibility purposes, I left interfaces unchanged as much as possible. So, there is a lot of code duplication. Maybe we want a type class for slice operations? I don't know.
I need to:
Pulse.Lib.Slice
to mark them immutable, and add support forPulse.Lib.MutableSlice
.