Adding type support for mutable vs. immutable slices #326
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
.