Skip to content
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

Support Pulse.Lib.Slice.subslice #534

Merged
merged 1 commit into from
Feb 12, 2025
Merged

Support Pulse.Lib.Slice.subslice #534

merged 1 commit into from
Feb 12, 2025

Conversation

gebner
Copy link
Contributor

@gebner gebner commented Feb 12, 2025

This adds support for the missing Pulse builtin Pulse.Lib.Slice.subslice.

Copy link
Contributor

@msprotz msprotz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, so this is always an immutable slice?

@msprotz
Copy link
Contributor

msprotz commented Feb 12, 2025

I guess mutability inference will kick in later on for this too, so I think we're good.

@msprotz msprotz merged commit a1f6dd1 into master Feb 12, 2025
2 checks passed
@msprotz msprotz deleted the gebner_subslice branch February 12, 2025 20:36
@gebner
Copy link
Contributor Author

gebner commented Feb 12, 2025

Yes, I checked that mutability inference triggers. Take this Pulse code, which takes a subslice and writes the subslice's length to its first element:

module Example.Subslice
#lang-pulse
open Pulse
open Pulse.Lib.Slice.Util
module A = Pulse.Lib.Array

fn test (arr: A.array UInt8.t)
    requires pts_to arr seq![0uy; 1uy; 2uy]
    ensures exists* s. pts_to arr s ** pure (s `Seq.equal` seq![0uy; 1uy; 1uy]) {
  A.pts_to_len arr;
  let slice = from_array arr 3sz;
  let last_one = subslice slice 2sz 3sz;
  pts_to_len last_one;
  last_one.(0sz) <- Int.Cast.uint64_to_uint8 (SizeT.sizet_to_uint64 (len last_one));
  unfold subslice_rest; join last_one _ _; join _ _ slice;
  to_array slice
}

Karamel correctly adds the &mut here:

#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(unused_assignments)]
#![allow(unreachable_patterns)]

pub fn test(arr: &mut [u8])
{
    let slice: &mut [u8] = arr;
    let last_one: &mut [u8] = &mut slice[2usize..3usize];
    last_one[0usize] = last_one.len() as u64 as u8
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants