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

Contracts & Harnesses for Reference Conversion APIs at std::NonNull #116

Merged
merged 16 commits into from
Nov 15, 2024

Conversation

danielhumanmod
Copy link

@danielhumanmod danielhumanmod commented Oct 16, 2024

Description:
This PR introduces function contracts and proof harness for the NonNull pointer in the Rust core library. Specifically, it verifies reference conversion APIs, covering:

  • NonNull::as_mut<'a>
  • NonNull::as_ref<'a>
  • NonNull::as_uninit_mut<'a>
  • NonNull::as_uninit_ref<'a>
  • NonNull::as_uninit_slice<'a>
  • NonNull::as_uninit_slice_mut<'a>
  • NonNull::get_unchecked_mut

Proof harness:

  • non_null_check_as_mut
  • non_null_check_as_ref
  • non_null_check_as_uninit_mut
  • non_null_check_as_as_uninit_ref
  • non_null_check_as_as_uninit_slice
  • non_null_check_as_uninit_slice_mut
  • non_null_check_as_get_unchecked_mut

Towards #53

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

@danielhumanmod danielhumanmod marked this pull request as ready for review October 25, 2024 19:06
@danielhumanmod danielhumanmod requested a review from a team as a code owner October 25, 2024 19:06
@danielhumanmod
Copy link
Author

danielhumanmod commented Nov 13, 2024

Hi @carolynzech , thanks for your review and suggestions! I have updated the code based on your comments, and solved most of them.

But one thing I can not directly do is add a in-bound check in function contracts for get_unchecked_mut.

The reason is the input index cannot be reused after being consumed in the precondition due to the shift of ownership. And SliceIndex trait does not guarantee that index implements Clone or Copy, it cannot be reused after being consumed in the precondition. To comply with Rust's ownership rules and ensure index is only used once, the in-bounds check is moved to the proof harness as a workaround.

Copy link

@qinheping qinheping left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@danielhumanmod
Copy link
Author

Hi @carolynzech @qinheping , do you mind triggering the merge flow for this PR again, I just solved some conflicts, thanks!

@carolynzech carolynzech enabled auto-merge (squash) November 15, 2024 19:24
Copy link

@carolynzech carolynzech left a comment

Choose a reason for hiding this comment

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

trigger approval workflow

@carolynzech carolynzech merged commit 922c51a into model-checking:main Nov 15, 2024
9 checks passed
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