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

Add safety preconditions to alloc/src/collections/binary_heap/mod.rs #120

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

tautschnig
Copy link
Member

This diff adds #[requires(...)] attributes to the unsafe functions, translating the "SAFETY:" comments into code contracts. These contracts specify the preconditions that must be met for the function to be safely called.

This diff adds `#[requires(...)]` attributes to the unsafe functions, translating the "SAFETY:" comments into code contracts. These contracts specify the preconditions that must be met for the function to be safely called.
@tautschnig tautschnig force-pushed the bedrock-library/alloc/src/collections/binary_heap/mod.rs branch from 29b2c87 to 8e6b212 Compare October 17, 2024 14:05

Choose a reason for hiding this comment

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

Do these function require self to be safe?

Copy link
Member Author

Choose a reason for hiding this comment

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

Are you asking whether there are requirements that the object is in some sort of sane state? I would believe so, but why would we ever permit for that not to be the case?

Choose a reason for hiding this comment

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

I agree that we shouldn't, but we do.

Conceptually, internal functions can temporary break the safety invariants of the types.

mod verify {
use super::*;

// TODO: Kani reports as failing property "Only a single top-level call", which does not

Choose a reason for hiding this comment

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

what exactly is the error?

Choose a reason for hiding this comment

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

Following up on this: can you extend the TODO to say what function it's complaining about for the single top-level call?

Choose a reason for hiding this comment

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

Otherwise, this PR LGTM, but I am curious if we can do a bit of debugging on this harness before merging it as a TODO. If we really get stuck, I'll approve.

@tautschnig tautschnig self-assigned this Nov 27, 2024
@tautschnig tautschnig removed their assignment Dec 13, 2024
@tautschnig tautschnig marked this pull request as ready for review December 13, 2024 12:59
@tautschnig tautschnig requested a review from a team as a code owner December 13, 2024 12:59
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