hax icon indicating copy to clipboard operation
hax copied to clipboard

Handle `IndexMut` and `UpdateAt` in Rust

Open W95Psp opened this issue 1 year ago • 2 comments

Currently we don't support user-defined impls of IndexMut. We need a way of translating IndexMut impls, probably as UpdateAt (a hax only construct).

W95Psp avatar Apr 30 '24 07:04 W95Psp

We use hax::fstar for now to inject the necessary code. We'll fix this properly later.

franziskuskiefer avatar May 02 '24 12:05 franziskuskiefer

In more details, the work around is:

struct Foo(u8);

impl std::ops::Index<()> for Foo {
    type Output = u8;
    fn index(&self, idx: ()) -> &u8 {
        &self.0
    }
}

#[hax_lib::exclude]
impl std::ops::IndexMut<()> for Foo {
    fn index_mut(&mut self, idx: ()) -> &mut u8 {
        &mut self.0
    }
}

#[hax_lib::fstar::after(
    r#"
instance _: Rust_primitives.Hax.update_at_tc $:Foo $:{()} = {
   super_index = (_ by (Tactics.Typeclasses.tcresolve ()));
   update_at = $update_at;
}
"#
)]
fn update_at(mut x: Foo, i: (), v: u8) -> Foo {
    Foo(v)
}

W95Psp avatar May 02 '24 16:05 W95Psp

This issue has been marked as stale due to a lack of activity for 60 days. If you believe this issue is still relevant, please provide an update or comment to keep it open. Otherwise, it will be closed in 7 days.

github-actions[bot] avatar Aug 28 '24 09:08 github-actions[bot]

We have a workaround, but we should still be able to support those directly.

W95Psp avatar Aug 28 '24 09:08 W95Psp

This issue has been marked as stale due to a lack of activity for 60 days. If you believe this issue is still relevant, please provide an update or comment to keep it open. Otherwise, it will be closed in 7 days.

github-actions[bot] avatar Oct 28 '24 02:10 github-actions[bot]

This issue has been marked as stale due to a lack of activity for 60 days. If you believe this issue is still relevant, please provide an update or comment to keep it open. Otherwise, it will be closed in 7 days.

github-actions[bot] avatar Feb 20 '25 01:02 github-actions[bot]

Closing in favour of full &mut support

franziskuskiefer avatar Mar 06 '25 12:03 franziskuskiefer