Skip to content

Conversation

@ranjitjhala
Copy link
Contributor

@ranjitjhala ranjitjhala commented Feb 4, 2026

  1. Track an int index with the pointer, to track how much is "valid" to write,
  2. Check at deref that the associated index is (strictly) positive,
  3. Defer tracking provenance etc. to later, perhaps once we have more experience with what is needed.

e.g. the following now works, with an error reported without the preconditions.

#[flux::opts(check_raw_pointer = "checked")]
#[flux::spec(fn (ptr: *mut{v: v > 0} T, value: T))]
fn write<T>(ptr: *mut T, value: T) {
    unsafe {
        *ptr = value;
    }
}

#[flux::opts(check_raw_pointer = "checked")]
#[flux::spec(fn (ptr: *mut{v: v > 0} T, value: T))]
fn write<T>(ptr: *mut T, value: T) {
    unsafe {
        *ptr = value;
    }
}

@ranjitjhala
Copy link
Contributor Author

@nilehmann ping -- I'd like to merge this one in to do more stuff on core.

@nilehmann
Copy link
Member

I'm looking at this now.

@ranjitjhala ranjitjhala changed the title Basic support for checking raw pointer derefs Basic support for checking raw pointer read/write Feb 10, 2026
@ranjitjhala
Copy link
Contributor Author

@nilehmann I made the changes we discussed yesterday

This comment was marked as resolved.

* Initial plan

* Initial plan for addressing PR feedback

Co-authored-by: nilehmann <[email protected]>

* Address PR feedback: refactor symbols, inline function, remove unused variants

Co-authored-by: nilehmann <[email protected]>

* Properly use sym

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: nilehmann <[email protected]>
Co-authored-by: Nico Lehmann <[email protected]>
Copy link
Member

@nilehmann nilehmann left a comment

Choose a reason for hiding this comment

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

@ranjitjhala some comments

if matches!(mut_a, Mutability::Mut) {
self.tys(infcx, ty_b, ty_a)?;
}
Ok(())
Copy link
Member

Choose a reason for hiding this comment

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

This makes me nervous. Did you add it because as_mut_ptr returns whatever refined type was in the input, and you wanted to keep using it the pointer at that type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sort of -- I was just trying to mirror the story for &mut T here?

The option is to remove subtyping between raw-ptr, but that seemed to be worse, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or is your point that we IGNORE the refinements for stuff read through raw-ptr so it doesn't matter e.g.
https://github.com/flux-rs/flux/blob/9c27760a7bbbda9c95bceb21f831334bee11408e/crates/flux-refineck/src/checker.rs#L1403-L1404

@ranjitjhala
Copy link
Contributor Author

@nilehmann I did the changes, except the ptr-subtyping, see discussion above.

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.

3 participants