Skip to content

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

Merged
carolynzech merged 16 commits into
model-checking:mainfrom
danielhumanmod:daniel/ref_con
Nov 15, 2024
Merged

carolynzech merged 16 commits into
model-checking:mainfrom
danielhumanmod:daniel/ref_con

Conversation

@danielhumanmod

@danielhumanmod danielhumanmod commented Oct 16, 2024 •

Copy link
Copy Markdown

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
Comment thread library/core/src/ptr/non_null.rs Resolved
Comment thread library/core/src/ptr/non_null.rs Resolved
Comment thread library/core/src/ptr/non_null.rs Resolved
Comment thread library/core/src/ptr/non_null.rs Resolved
Comment thread library/core/src/ptr/non_null.rs Resolved
Comment thread library/core/src/ptr/non_null.rs Resolved
Comment thread library/core/src/ptr/non_null.rs Resolved
Comment thread library/core/src/ptr/non_null.rs Resolved
Comment thread library/core/src/ptr/non_null.rs Resolved
@danielhumanmod

danielhumanmod commented Nov 13, 2024 •

Copy link
Copy Markdown
Author

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.

Comment thread library/core/src/ptr/non_null.rs Resolved
Comment thread library/core/src/ptr/non_null.rs Resolved
Comment thread library/core/src/ptr/non_null.rs Resolved
Comment thread library/core/src/ptr/non_null.rs Resolved
Comment thread library/core/src/ptr/non_null.rs Resolved

@qinheping qinheping left a comment

Copy link
Copy Markdown

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
Copy Markdown
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

@carolynzech carolynzech left a comment

Copy link
Copy Markdown

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
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